]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
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> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
55682965 JB |
22 | #include "core.h" |
23 | #include "nl80211.h" | |
b2e1b302 | 24 | #include "reg.h" |
55682965 | 25 | |
4c476991 JB |
26 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
27 | struct genl_info *info); | |
28 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
29 | struct genl_info *info); | |
30 | ||
55682965 JB |
31 | /* the netlink family */ |
32 | static struct genl_family nl80211_fam = { | |
33 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
34 | .name = "nl80211", /* have users key off the name instead */ | |
35 | .hdrsize = 0, /* no private header */ | |
36 | .version = 1, /* no particular meaning now */ | |
37 | .maxattr = NL80211_ATTR_MAX, | |
463d0183 | 38 | .netnsok = true, |
4c476991 JB |
39 | .pre_doit = nl80211_pre_doit, |
40 | .post_doit = nl80211_post_doit, | |
55682965 JB |
41 | }; |
42 | ||
79c97e97 | 43 | /* internal helper: get rdev and dev */ |
463d0183 | 44 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
79c97e97 | 45 | struct cfg80211_registered_device **rdev, |
55682965 JB |
46 | struct net_device **dev) |
47 | { | |
463d0183 | 48 | struct nlattr **attrs = info->attrs; |
55682965 JB |
49 | int ifindex; |
50 | ||
bba95fef | 51 | if (!attrs[NL80211_ATTR_IFINDEX]) |
55682965 JB |
52 | return -EINVAL; |
53 | ||
bba95fef | 54 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
463d0183 | 55 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
55682965 JB |
56 | if (!*dev) |
57 | return -ENODEV; | |
58 | ||
463d0183 | 59 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
79c97e97 | 60 | if (IS_ERR(*rdev)) { |
55682965 | 61 | dev_put(*dev); |
79c97e97 | 62 | return PTR_ERR(*rdev); |
55682965 JB |
63 | } |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | /* policy for the attributes */ | |
b54452b0 | 69 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
70 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
71 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 72 | .len = 20-1 }, |
31888487 | 73 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
72bdcf34 | 74 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 75 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
b9a5f8ca JM |
76 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
77 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
78 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
79 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 80 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
81 | |
82 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
83 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
84 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f JB |
85 | |
86 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, | |
3e5d7649 | 87 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
41ade00f | 88 | |
b9454e83 | 89 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
90 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
91 | .len = WLAN_MAX_KEY_LEN }, | |
92 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
93 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
94 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
9f26a952 | 95 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
e31b8213 | 96 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
97 | |
98 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
99 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
100 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
101 | .len = IEEE80211_MAX_DATA_LEN }, | |
102 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
103 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
104 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
105 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
106 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
107 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
108 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 109 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 110 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 111 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 LCC |
112 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
113 | .len = IEEE80211_MAX_MESH_ID_LEN }, | |
114 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, | |
9f1ba906 | 115 | |
b2e1b302 LR |
116 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
117 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
118 | ||
9f1ba906 JM |
119 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
120 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
121 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
122 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
123 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 124 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 125 | |
24bdd9f4 | 126 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 127 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 128 | |
36aedc90 JM |
129 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
130 | .len = NL80211_HT_CAPABILITY_LEN }, | |
9aed3cc1 JM |
131 | |
132 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
133 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
134 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
135 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
136 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
137 | |
138 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
139 | .len = IEEE80211_MAX_SSID_LEN }, | |
140 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
141 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 142 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 143 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 144 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
145 | [NL80211_ATTR_STA_FLAGS2] = { |
146 | .len = sizeof(struct nl80211_sta_flag_update), | |
147 | }, | |
3f77316c | 148 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
149 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
150 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
151 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
152 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
153 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 154 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 155 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
156 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
157 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
158 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
159 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 160 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
161 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
162 | .len = IEEE80211_MAX_DATA_LEN }, | |
163 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 164 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 165 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 166 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 167 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
168 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
169 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 170 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
171 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
172 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 173 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 174 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 175 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 176 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 177 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 178 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 179 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
55682965 JB |
180 | }; |
181 | ||
e31b8213 | 182 | /* policy for the key attributes */ |
b54452b0 | 183 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 184 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
185 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
186 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
187 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, | |
188 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
189 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 190 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
191 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
192 | }; | |
193 | ||
194 | /* policy for the key default flags */ | |
195 | static const struct nla_policy | |
196 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
197 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
198 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
199 | }; |
200 | ||
ff1b6e69 JB |
201 | /* policy for WoWLAN attributes */ |
202 | static const struct nla_policy | |
203 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
204 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
205 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
206 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
207 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
208 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
209 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
210 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
211 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
ff1b6e69 JB |
212 | }; |
213 | ||
e5497d76 JB |
214 | /* policy for GTK rekey offload attributes */ |
215 | static const struct nla_policy | |
216 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
217 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
218 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
219 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
220 | }; | |
221 | ||
a043897a HS |
222 | /* ifidx get helper */ |
223 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
224 | { | |
225 | int res; | |
226 | ||
227 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
228 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
229 | nl80211_policy); | |
230 | if (res) | |
231 | return res; | |
232 | ||
233 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
234 | return -EINVAL; | |
235 | ||
236 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
237 | if (!res) | |
238 | return -EINVAL; | |
239 | return res; | |
240 | } | |
241 | ||
67748893 JB |
242 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
243 | struct netlink_callback *cb, | |
244 | struct cfg80211_registered_device **rdev, | |
245 | struct net_device **dev) | |
246 | { | |
247 | int ifidx = cb->args[0]; | |
248 | int err; | |
249 | ||
250 | if (!ifidx) | |
251 | ifidx = nl80211_get_ifidx(cb); | |
252 | if (ifidx < 0) | |
253 | return ifidx; | |
254 | ||
255 | cb->args[0] = ifidx; | |
256 | ||
257 | rtnl_lock(); | |
258 | ||
259 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
260 | if (!*dev) { | |
261 | err = -ENODEV; | |
262 | goto out_rtnl; | |
263 | } | |
264 | ||
265 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3cc25e51 FF |
266 | if (IS_ERR(*rdev)) { |
267 | err = PTR_ERR(*rdev); | |
67748893 JB |
268 | goto out_rtnl; |
269 | } | |
270 | ||
271 | return 0; | |
272 | out_rtnl: | |
273 | rtnl_unlock(); | |
274 | return err; | |
275 | } | |
276 | ||
277 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | |
278 | { | |
279 | cfg80211_unlock_rdev(rdev); | |
280 | rtnl_unlock(); | |
281 | } | |
282 | ||
f4a11bb0 JB |
283 | /* IE validation */ |
284 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
285 | { | |
286 | const u8 *pos; | |
287 | int len; | |
288 | ||
289 | if (!attr) | |
290 | return true; | |
291 | ||
292 | pos = nla_data(attr); | |
293 | len = nla_len(attr); | |
294 | ||
295 | while (len) { | |
296 | u8 elemlen; | |
297 | ||
298 | if (len < 2) | |
299 | return false; | |
300 | len -= 2; | |
301 | ||
302 | elemlen = pos[1]; | |
303 | if (elemlen > len) | |
304 | return false; | |
305 | ||
306 | len -= elemlen; | |
307 | pos += 2 + elemlen; | |
308 | } | |
309 | ||
310 | return true; | |
311 | } | |
312 | ||
55682965 JB |
313 | /* message building helper */ |
314 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, | |
315 | int flags, u8 cmd) | |
316 | { | |
317 | /* since there is no private header just add the generic one */ | |
318 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); | |
319 | } | |
320 | ||
5dab3b8a LR |
321 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
322 | struct ieee80211_channel *chan) | |
323 | { | |
324 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, | |
325 | chan->center_freq); | |
326 | ||
327 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
328 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); | |
329 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) | |
330 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); | |
331 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) | |
332 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); | |
333 | if (chan->flags & IEEE80211_CHAN_RADAR) | |
334 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); | |
335 | ||
336 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, | |
337 | DBM_TO_MBM(chan->max_power)); | |
338 | ||
339 | return 0; | |
340 | ||
341 | nla_put_failure: | |
342 | return -ENOBUFS; | |
343 | } | |
344 | ||
55682965 JB |
345 | /* netlink command implementations */ |
346 | ||
b9454e83 JB |
347 | struct key_parse { |
348 | struct key_params p; | |
349 | int idx; | |
e31b8213 | 350 | int type; |
b9454e83 | 351 | bool def, defmgmt; |
dbd2fd65 | 352 | bool def_uni, def_multi; |
b9454e83 JB |
353 | }; |
354 | ||
355 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
356 | { | |
357 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
358 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
359 | nl80211_key_policy); | |
360 | if (err) | |
361 | return err; | |
362 | ||
363 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
364 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
365 | ||
dbd2fd65 JB |
366 | if (k->def) { |
367 | k->def_uni = true; | |
368 | k->def_multi = true; | |
369 | } | |
370 | if (k->defmgmt) | |
371 | k->def_multi = true; | |
372 | ||
b9454e83 JB |
373 | if (tb[NL80211_KEY_IDX]) |
374 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
375 | ||
376 | if (tb[NL80211_KEY_DATA]) { | |
377 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
378 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
379 | } | |
380 | ||
381 | if (tb[NL80211_KEY_SEQ]) { | |
382 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
383 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
384 | } | |
385 | ||
386 | if (tb[NL80211_KEY_CIPHER]) | |
387 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
388 | ||
e31b8213 JB |
389 | if (tb[NL80211_KEY_TYPE]) { |
390 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
391 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
392 | return -EINVAL; | |
393 | } | |
394 | ||
dbd2fd65 JB |
395 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
396 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
397 | int err = nla_parse_nested(kdt, | |
398 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
399 | tb[NL80211_KEY_DEFAULT_TYPES], | |
400 | nl80211_key_default_policy); | |
401 | if (err) | |
402 | return err; | |
403 | ||
404 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
405 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
406 | } | |
407 | ||
b9454e83 JB |
408 | return 0; |
409 | } | |
410 | ||
411 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
412 | { | |
413 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
414 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
415 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
416 | } | |
417 | ||
418 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
419 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
420 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
421 | } | |
422 | ||
423 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
424 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
425 | ||
426 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
427 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
428 | ||
429 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
430 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
431 | ||
dbd2fd65 JB |
432 | if (k->def) { |
433 | k->def_uni = true; | |
434 | k->def_multi = true; | |
435 | } | |
436 | if (k->defmgmt) | |
437 | k->def_multi = true; | |
438 | ||
e31b8213 JB |
439 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
440 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
441 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
442 | return -EINVAL; | |
443 | } | |
444 | ||
dbd2fd65 JB |
445 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
446 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
447 | int err = nla_parse_nested( | |
448 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
449 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
450 | nl80211_key_default_policy); | |
451 | if (err) | |
452 | return err; | |
453 | ||
454 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
455 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
456 | } | |
457 | ||
b9454e83 JB |
458 | return 0; |
459 | } | |
460 | ||
461 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
462 | { | |
463 | int err; | |
464 | ||
465 | memset(k, 0, sizeof(*k)); | |
466 | k->idx = -1; | |
e31b8213 | 467 | k->type = -1; |
b9454e83 JB |
468 | |
469 | if (info->attrs[NL80211_ATTR_KEY]) | |
470 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
471 | else | |
472 | err = nl80211_parse_key_old(info, k); | |
473 | ||
474 | if (err) | |
475 | return err; | |
476 | ||
477 | if (k->def && k->defmgmt) | |
478 | return -EINVAL; | |
479 | ||
dbd2fd65 JB |
480 | if (k->defmgmt) { |
481 | if (k->def_uni || !k->def_multi) | |
482 | return -EINVAL; | |
483 | } | |
484 | ||
b9454e83 JB |
485 | if (k->idx != -1) { |
486 | if (k->defmgmt) { | |
487 | if (k->idx < 4 || k->idx > 5) | |
488 | return -EINVAL; | |
489 | } else if (k->def) { | |
490 | if (k->idx < 0 || k->idx > 3) | |
491 | return -EINVAL; | |
492 | } else { | |
493 | if (k->idx < 0 || k->idx > 5) | |
494 | return -EINVAL; | |
495 | } | |
496 | } | |
497 | ||
498 | return 0; | |
499 | } | |
500 | ||
fffd0934 JB |
501 | static struct cfg80211_cached_keys * |
502 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
503 | struct nlattr *keys) | |
504 | { | |
505 | struct key_parse parse; | |
506 | struct nlattr *key; | |
507 | struct cfg80211_cached_keys *result; | |
508 | int rem, err, def = 0; | |
509 | ||
510 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
511 | if (!result) | |
512 | return ERR_PTR(-ENOMEM); | |
513 | ||
514 | result->def = -1; | |
515 | result->defmgmt = -1; | |
516 | ||
517 | nla_for_each_nested(key, keys, rem) { | |
518 | memset(&parse, 0, sizeof(parse)); | |
519 | parse.idx = -1; | |
520 | ||
521 | err = nl80211_parse_key_new(key, &parse); | |
522 | if (err) | |
523 | goto error; | |
524 | err = -EINVAL; | |
525 | if (!parse.p.key) | |
526 | goto error; | |
527 | if (parse.idx < 0 || parse.idx > 4) | |
528 | goto error; | |
529 | if (parse.def) { | |
530 | if (def) | |
531 | goto error; | |
532 | def = 1; | |
533 | result->def = parse.idx; | |
dbd2fd65 JB |
534 | if (!parse.def_uni || !parse.def_multi) |
535 | goto error; | |
fffd0934 JB |
536 | } else if (parse.defmgmt) |
537 | goto error; | |
538 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 539 | parse.idx, false, NULL); |
fffd0934 JB |
540 | if (err) |
541 | goto error; | |
542 | result->params[parse.idx].cipher = parse.p.cipher; | |
543 | result->params[parse.idx].key_len = parse.p.key_len; | |
544 | result->params[parse.idx].key = result->data[parse.idx]; | |
545 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
546 | } | |
547 | ||
548 | return result; | |
549 | error: | |
550 | kfree(result); | |
551 | return ERR_PTR(err); | |
552 | } | |
553 | ||
554 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
555 | { | |
556 | ASSERT_WDEV_LOCK(wdev); | |
557 | ||
fffd0934 JB |
558 | switch (wdev->iftype) { |
559 | case NL80211_IFTYPE_AP: | |
560 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 561 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 562 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
563 | break; |
564 | case NL80211_IFTYPE_ADHOC: | |
565 | if (!wdev->current_bss) | |
566 | return -ENOLINK; | |
567 | break; | |
568 | case NL80211_IFTYPE_STATION: | |
074ac8df | 569 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
570 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
571 | return -ENOLINK; | |
572 | break; | |
573 | default: | |
574 | return -EINVAL; | |
575 | } | |
576 | ||
577 | return 0; | |
578 | } | |
579 | ||
7527a782 JB |
580 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
581 | { | |
582 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
583 | int i; | |
584 | ||
585 | if (!nl_modes) | |
586 | goto nla_put_failure; | |
587 | ||
588 | i = 0; | |
589 | while (ifmodes) { | |
590 | if (ifmodes & 1) | |
591 | NLA_PUT_FLAG(msg, i); | |
592 | ifmodes >>= 1; | |
593 | i++; | |
594 | } | |
595 | ||
596 | nla_nest_end(msg, nl_modes); | |
597 | return 0; | |
598 | ||
599 | nla_put_failure: | |
600 | return -ENOBUFS; | |
601 | } | |
602 | ||
603 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
604 | struct sk_buff *msg) | |
605 | { | |
606 | struct nlattr *nl_combis; | |
607 | int i, j; | |
608 | ||
609 | nl_combis = nla_nest_start(msg, | |
610 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
611 | if (!nl_combis) | |
612 | goto nla_put_failure; | |
613 | ||
614 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
615 | const struct ieee80211_iface_combination *c; | |
616 | struct nlattr *nl_combi, *nl_limits; | |
617 | ||
618 | c = &wiphy->iface_combinations[i]; | |
619 | ||
620 | nl_combi = nla_nest_start(msg, i + 1); | |
621 | if (!nl_combi) | |
622 | goto nla_put_failure; | |
623 | ||
624 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
625 | if (!nl_limits) | |
626 | goto nla_put_failure; | |
627 | ||
628 | for (j = 0; j < c->n_limits; j++) { | |
629 | struct nlattr *nl_limit; | |
630 | ||
631 | nl_limit = nla_nest_start(msg, j + 1); | |
632 | if (!nl_limit) | |
633 | goto nla_put_failure; | |
634 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, | |
635 | c->limits[j].max); | |
636 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, | |
637 | c->limits[j].types)) | |
638 | goto nla_put_failure; | |
639 | nla_nest_end(msg, nl_limit); | |
640 | } | |
641 | ||
642 | nla_nest_end(msg, nl_limits); | |
643 | ||
644 | if (c->beacon_int_infra_match) | |
645 | NLA_PUT_FLAG(msg, | |
646 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); | |
647 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
648 | c->num_different_channels); | |
649 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, | |
650 | c->max_interfaces); | |
651 | ||
652 | nla_nest_end(msg, nl_combi); | |
653 | } | |
654 | ||
655 | nla_nest_end(msg, nl_combis); | |
656 | ||
657 | return 0; | |
658 | nla_put_failure: | |
659 | return -ENOBUFS; | |
660 | } | |
661 | ||
55682965 JB |
662 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
663 | struct cfg80211_registered_device *dev) | |
664 | { | |
665 | void *hdr; | |
ee688b00 JB |
666 | struct nlattr *nl_bands, *nl_band; |
667 | struct nlattr *nl_freqs, *nl_freq; | |
668 | struct nlattr *nl_rates, *nl_rate; | |
8fdc621d | 669 | struct nlattr *nl_cmds; |
ee688b00 JB |
670 | enum ieee80211_band band; |
671 | struct ieee80211_channel *chan; | |
672 | struct ieee80211_rate *rate; | |
673 | int i; | |
2e161f78 JB |
674 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
675 | dev->wiphy.mgmt_stypes; | |
55682965 JB |
676 | |
677 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | |
678 | if (!hdr) | |
679 | return -1; | |
680 | ||
b5850a7a | 681 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
55682965 | 682 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
b9a5f8ca | 683 | |
f5ea9120 JB |
684 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
685 | cfg80211_rdev_list_generation); | |
686 | ||
b9a5f8ca JM |
687 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
688 | dev->wiphy.retry_short); | |
689 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
690 | dev->wiphy.retry_long); | |
691 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
692 | dev->wiphy.frag_threshold); | |
693 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
694 | dev->wiphy.rts_threshold); | |
81077e82 LT |
695 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
696 | dev->wiphy.coverage_class); | |
2a519311 JB |
697 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
698 | dev->wiphy.max_scan_ssids); | |
93b6aa69 LC |
699 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
700 | dev->wiphy.max_sched_scan_ssids); | |
18a83659 JB |
701 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
702 | dev->wiphy.max_scan_ie_len); | |
5a865bad LC |
703 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
704 | dev->wiphy.max_sched_scan_ie_len); | |
ee688b00 | 705 | |
e31b8213 JB |
706 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
707 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); | |
15d5dda6 JC |
708 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
709 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); | |
e31b8213 | 710 | |
25e47c18 JB |
711 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
712 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
713 | dev->wiphy.cipher_suites); | |
714 | ||
67fbb16b SO |
715 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
716 | dev->wiphy.max_num_pmkids); | |
717 | ||
c0692b8f JB |
718 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
719 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); | |
720 | ||
39fd5de4 BR |
721 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
722 | dev->wiphy.available_antennas_tx); | |
723 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
724 | dev->wiphy.available_antennas_rx); | |
725 | ||
7f531e03 BR |
726 | if ((dev->wiphy.available_antennas_tx || |
727 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { | |
afe0cbf8 BR |
728 | u32 tx_ant = 0, rx_ant = 0; |
729 | int res; | |
730 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); | |
731 | if (!res) { | |
732 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); | |
733 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); | |
734 | } | |
735 | } | |
736 | ||
7527a782 JB |
737 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
738 | dev->wiphy.interface_modes)) | |
f59ac048 LR |
739 | goto nla_put_failure; |
740 | ||
ee688b00 JB |
741 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
742 | if (!nl_bands) | |
743 | goto nla_put_failure; | |
744 | ||
745 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
746 | if (!dev->wiphy.bands[band]) | |
747 | continue; | |
748 | ||
749 | nl_band = nla_nest_start(msg, band); | |
750 | if (!nl_band) | |
751 | goto nla_put_failure; | |
752 | ||
d51626df JB |
753 | /* add HT info */ |
754 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { | |
755 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
756 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
757 | &dev->wiphy.bands[band]->ht_cap.mcs); | |
758 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
759 | dev->wiphy.bands[band]->ht_cap.cap); | |
760 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
761 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); | |
762 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
763 | dev->wiphy.bands[band]->ht_cap.ampdu_density); | |
764 | } | |
765 | ||
ee688b00 JB |
766 | /* add frequencies */ |
767 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
768 | if (!nl_freqs) | |
769 | goto nla_put_failure; | |
770 | ||
771 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
772 | nl_freq = nla_nest_start(msg, i); | |
773 | if (!nl_freq) | |
774 | goto nla_put_failure; | |
775 | ||
776 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
777 | |
778 | if (nl80211_msg_put_channel(msg, chan)) | |
779 | goto nla_put_failure; | |
e2f367f2 | 780 | |
ee688b00 JB |
781 | nla_nest_end(msg, nl_freq); |
782 | } | |
783 | ||
784 | nla_nest_end(msg, nl_freqs); | |
785 | ||
786 | /* add bitrates */ | |
787 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
788 | if (!nl_rates) | |
789 | goto nla_put_failure; | |
790 | ||
791 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
792 | nl_rate = nla_nest_start(msg, i); | |
793 | if (!nl_rate) | |
794 | goto nla_put_failure; | |
795 | ||
796 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
797 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, | |
798 | rate->bitrate); | |
799 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) | |
800 | NLA_PUT_FLAG(msg, | |
801 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); | |
802 | ||
803 | nla_nest_end(msg, nl_rate); | |
804 | } | |
805 | ||
806 | nla_nest_end(msg, nl_rates); | |
807 | ||
808 | nla_nest_end(msg, nl_band); | |
809 | } | |
810 | nla_nest_end(msg, nl_bands); | |
811 | ||
8fdc621d JB |
812 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
813 | if (!nl_cmds) | |
814 | goto nla_put_failure; | |
815 | ||
816 | i = 0; | |
817 | #define CMD(op, n) \ | |
818 | do { \ | |
819 | if (dev->ops->op) { \ | |
820 | i++; \ | |
821 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ | |
822 | } \ | |
823 | } while (0) | |
824 | ||
825 | CMD(add_virtual_intf, NEW_INTERFACE); | |
826 | CMD(change_virtual_intf, SET_INTERFACE); | |
827 | CMD(add_key, NEW_KEY); | |
828 | CMD(add_beacon, NEW_BEACON); | |
829 | CMD(add_station, NEW_STATION); | |
830 | CMD(add_mpath, NEW_MPATH); | |
24bdd9f4 | 831 | CMD(update_mesh_config, SET_MESH_CONFIG); |
8fdc621d | 832 | CMD(change_bss, SET_BSS); |
636a5d36 JM |
833 | CMD(auth, AUTHENTICATE); |
834 | CMD(assoc, ASSOCIATE); | |
835 | CMD(deauth, DEAUTHENTICATE); | |
836 | CMD(disassoc, DISASSOCIATE); | |
04a773ad | 837 | CMD(join_ibss, JOIN_IBSS); |
29cbe68c | 838 | CMD(join_mesh, JOIN_MESH); |
67fbb16b SO |
839 | CMD(set_pmksa, SET_PMKSA); |
840 | CMD(del_pmksa, DEL_PMKSA); | |
841 | CMD(flush_pmksa, FLUSH_PMKSA); | |
9588bbd5 | 842 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
13ae75b1 | 843 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
2e161f78 | 844 | CMD(mgmt_tx, FRAME); |
f7ca38df | 845 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
5be83de5 | 846 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
463d0183 JB |
847 | i++; |
848 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); | |
849 | } | |
f444de05 | 850 | CMD(set_channel, SET_CHANNEL); |
e8347eba | 851 | CMD(set_wds_peer, SET_WDS_PEER); |
807f8a8c LC |
852 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
853 | CMD(sched_scan_start, START_SCHED_SCAN); | |
8fdc621d JB |
854 | |
855 | #undef CMD | |
b23aa676 | 856 | |
6829c878 | 857 | if (dev->ops->connect || dev->ops->auth) { |
b23aa676 SO |
858 | i++; |
859 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); | |
860 | } | |
861 | ||
6829c878 | 862 | if (dev->ops->disconnect || dev->ops->deauth) { |
b23aa676 SO |
863 | i++; |
864 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); | |
865 | } | |
866 | ||
8fdc621d JB |
867 | nla_nest_end(msg, nl_cmds); |
868 | ||
a293911d JB |
869 | if (dev->ops->remain_on_channel) |
870 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
871 | dev->wiphy.max_remain_on_channel_duration); | |
872 | ||
f7ca38df JB |
873 | /* for now at least assume all drivers have it */ |
874 | if (dev->ops->mgmt_tx) | |
875 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); | |
876 | ||
2e161f78 JB |
877 | if (mgmt_stypes) { |
878 | u16 stypes; | |
879 | struct nlattr *nl_ftypes, *nl_ifs; | |
880 | enum nl80211_iftype ift; | |
881 | ||
882 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | |
883 | if (!nl_ifs) | |
884 | goto nla_put_failure; | |
885 | ||
886 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
887 | nl_ftypes = nla_nest_start(msg, ift); | |
888 | if (!nl_ftypes) | |
889 | goto nla_put_failure; | |
890 | i = 0; | |
891 | stypes = mgmt_stypes[ift].tx; | |
892 | while (stypes) { | |
893 | if (stypes & 1) | |
894 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, | |
895 | (i << 4) | IEEE80211_FTYPE_MGMT); | |
896 | stypes >>= 1; | |
897 | i++; | |
898 | } | |
899 | nla_nest_end(msg, nl_ftypes); | |
900 | } | |
901 | ||
74b70a4e JB |
902 | nla_nest_end(msg, nl_ifs); |
903 | ||
2e161f78 JB |
904 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
905 | if (!nl_ifs) | |
906 | goto nla_put_failure; | |
907 | ||
908 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
909 | nl_ftypes = nla_nest_start(msg, ift); | |
910 | if (!nl_ftypes) | |
911 | goto nla_put_failure; | |
912 | i = 0; | |
913 | stypes = mgmt_stypes[ift].rx; | |
914 | while (stypes) { | |
915 | if (stypes & 1) | |
916 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, | |
917 | (i << 4) | IEEE80211_FTYPE_MGMT); | |
918 | stypes >>= 1; | |
919 | i++; | |
920 | } | |
921 | nla_nest_end(msg, nl_ftypes); | |
922 | } | |
923 | nla_nest_end(msg, nl_ifs); | |
924 | } | |
925 | ||
ff1b6e69 JB |
926 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
927 | struct nlattr *nl_wowlan; | |
928 | ||
929 | nl_wowlan = nla_nest_start(msg, | |
930 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | |
931 | if (!nl_wowlan) | |
932 | goto nla_put_failure; | |
933 | ||
934 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) | |
935 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); | |
936 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) | |
937 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); | |
938 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) | |
939 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); | |
77dbbb13 JB |
940 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
941 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); | |
942 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) | |
943 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); | |
944 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) | |
945 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); | |
946 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) | |
947 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); | |
948 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) | |
949 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); | |
ff1b6e69 JB |
950 | if (dev->wiphy.wowlan.n_patterns) { |
951 | struct nl80211_wowlan_pattern_support pat = { | |
952 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
953 | .min_pattern_len = | |
954 | dev->wiphy.wowlan.pattern_min_len, | |
955 | .max_pattern_len = | |
956 | dev->wiphy.wowlan.pattern_max_len, | |
957 | }; | |
958 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
959 | sizeof(pat), &pat); | |
960 | } | |
961 | ||
962 | nla_nest_end(msg, nl_wowlan); | |
963 | } | |
964 | ||
7527a782 JB |
965 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
966 | dev->wiphy.software_iftypes)) | |
967 | goto nla_put_failure; | |
968 | ||
969 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) | |
970 | goto nla_put_failure; | |
971 | ||
55682965 JB |
972 | return genlmsg_end(msg, hdr); |
973 | ||
974 | nla_put_failure: | |
bc3ed28c TG |
975 | genlmsg_cancel(msg, hdr); |
976 | return -EMSGSIZE; | |
55682965 JB |
977 | } |
978 | ||
979 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
980 | { | |
981 | int idx = 0; | |
982 | int start = cb->args[0]; | |
983 | struct cfg80211_registered_device *dev; | |
984 | ||
a1794390 | 985 | mutex_lock(&cfg80211_mutex); |
79c97e97 | 986 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
987 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
988 | continue; | |
b4637271 | 989 | if (++idx <= start) |
55682965 JB |
990 | continue; |
991 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, | |
992 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
b4637271 JV |
993 | dev) < 0) { |
994 | idx--; | |
55682965 | 995 | break; |
b4637271 | 996 | } |
55682965 | 997 | } |
a1794390 | 998 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
999 | |
1000 | cb->args[0] = idx; | |
1001 | ||
1002 | return skb->len; | |
1003 | } | |
1004 | ||
1005 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1006 | { | |
1007 | struct sk_buff *msg; | |
4c476991 | 1008 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1009 | |
fd2120ca | 1010 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1011 | if (!msg) |
4c476991 | 1012 | return -ENOMEM; |
55682965 | 1013 | |
4c476991 JB |
1014 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
1015 | nlmsg_free(msg); | |
1016 | return -ENOBUFS; | |
1017 | } | |
55682965 | 1018 | |
134e6375 | 1019 | return genlmsg_reply(msg, info); |
55682965 JB |
1020 | } |
1021 | ||
31888487 JM |
1022 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1023 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1024 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1025 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1026 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1027 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1028 | }; | |
1029 | ||
1030 | static int parse_txq_params(struct nlattr *tb[], | |
1031 | struct ieee80211_txq_params *txq_params) | |
1032 | { | |
1033 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || | |
1034 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || | |
1035 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1036 | return -EINVAL; | |
1037 | ||
1038 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); | |
1039 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); | |
1040 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1041 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1042 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1043 | ||
1044 | return 0; | |
1045 | } | |
1046 | ||
f444de05 JB |
1047 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1048 | { | |
1049 | /* | |
1050 | * You can only set the channel explicitly for AP, mesh | |
1051 | * and WDS type interfaces; all others have their channel | |
1052 | * managed via their respective "establish a connection" | |
1053 | * command (connect, join, ...) | |
1054 | * | |
1055 | * Monitors are special as they are normally slaved to | |
1056 | * whatever else is going on, so they behave as though | |
1057 | * you tried setting the wiphy channel itself. | |
1058 | */ | |
1059 | return !wdev || | |
1060 | wdev->iftype == NL80211_IFTYPE_AP || | |
1061 | wdev->iftype == NL80211_IFTYPE_WDS || | |
1062 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || | |
074ac8df JB |
1063 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1064 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1065 | } |
1066 | ||
1067 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, | |
1068 | struct wireless_dev *wdev, | |
1069 | struct genl_info *info) | |
1070 | { | |
1071 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
1072 | u32 freq; | |
1073 | int result; | |
1074 | ||
1075 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1076 | return -EINVAL; | |
1077 | ||
1078 | if (!nl80211_can_set_dev_channel(wdev)) | |
1079 | return -EOPNOTSUPP; | |
1080 | ||
1081 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
1082 | channel_type = nla_get_u32(info->attrs[ | |
1083 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1084 | if (channel_type != NL80211_CHAN_NO_HT && | |
1085 | channel_type != NL80211_CHAN_HT20 && | |
1086 | channel_type != NL80211_CHAN_HT40PLUS && | |
1087 | channel_type != NL80211_CHAN_HT40MINUS) | |
1088 | return -EINVAL; | |
1089 | } | |
1090 | ||
1091 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1092 | ||
1093 | mutex_lock(&rdev->devlist_mtx); | |
1094 | if (wdev) { | |
1095 | wdev_lock(wdev); | |
1096 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); | |
1097 | wdev_unlock(wdev); | |
1098 | } else { | |
1099 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); | |
1100 | } | |
1101 | mutex_unlock(&rdev->devlist_mtx); | |
1102 | ||
1103 | return result; | |
1104 | } | |
1105 | ||
1106 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1107 | { | |
4c476991 JB |
1108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1109 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1110 | |
4c476991 | 1111 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1112 | } |
1113 | ||
e8347eba BJ |
1114 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1115 | { | |
43b19952 JB |
1116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1117 | struct net_device *dev = info->user_ptr[1]; | |
1118 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1119 | const u8 *bssid; |
e8347eba BJ |
1120 | |
1121 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1122 | return -EINVAL; | |
1123 | ||
43b19952 JB |
1124 | if (netif_running(dev)) |
1125 | return -EBUSY; | |
e8347eba | 1126 | |
43b19952 JB |
1127 | if (!rdev->ops->set_wds_peer) |
1128 | return -EOPNOTSUPP; | |
e8347eba | 1129 | |
43b19952 JB |
1130 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1131 | return -EOPNOTSUPP; | |
e8347eba BJ |
1132 | |
1133 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
43b19952 | 1134 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
e8347eba BJ |
1135 | } |
1136 | ||
1137 | ||
55682965 JB |
1138 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1139 | { | |
1140 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1141 | struct net_device *netdev = NULL; |
1142 | struct wireless_dev *wdev; | |
a1e567c8 | 1143 | int result = 0, rem_txq_params = 0; |
31888487 | 1144 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1145 | u32 changed; |
1146 | u8 retry_short = 0, retry_long = 0; | |
1147 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1148 | u8 coverage_class = 0; |
55682965 | 1149 | |
f444de05 JB |
1150 | /* |
1151 | * Try to find the wiphy and netdev. Normally this | |
1152 | * function shouldn't need the netdev, but this is | |
1153 | * done for backward compatibility -- previously | |
1154 | * setting the channel was done per wiphy, but now | |
1155 | * it is per netdev. Previous userland like hostapd | |
1156 | * also passed a netdev to set_wiphy, so that it is | |
1157 | * possible to let that go to the right netdev! | |
1158 | */ | |
4bbf4d56 JB |
1159 | mutex_lock(&cfg80211_mutex); |
1160 | ||
f444de05 JB |
1161 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1162 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1163 | ||
1164 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1165 | if (netdev && netdev->ieee80211_ptr) { | |
1166 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1167 | mutex_lock(&rdev->mtx); | |
1168 | } else | |
1169 | netdev = NULL; | |
4bbf4d56 JB |
1170 | } |
1171 | ||
f444de05 JB |
1172 | if (!netdev) { |
1173 | rdev = __cfg80211_rdev_from_info(info); | |
1174 | if (IS_ERR(rdev)) { | |
1175 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1176 | return PTR_ERR(rdev); |
f444de05 JB |
1177 | } |
1178 | wdev = NULL; | |
1179 | netdev = NULL; | |
1180 | result = 0; | |
1181 | ||
1182 | mutex_lock(&rdev->mtx); | |
1183 | } else if (netif_running(netdev) && | |
1184 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) | |
1185 | wdev = netdev->ieee80211_ptr; | |
1186 | else | |
1187 | wdev = NULL; | |
1188 | ||
1189 | /* | |
1190 | * end workaround code, by now the rdev is available | |
1191 | * and locked, and wdev may or may not be NULL. | |
1192 | */ | |
4bbf4d56 JB |
1193 | |
1194 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1195 | result = cfg80211_dev_rename( |
1196 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1197 | |
1198 | mutex_unlock(&cfg80211_mutex); | |
1199 | ||
1200 | if (result) | |
1201 | goto bad_res; | |
31888487 JM |
1202 | |
1203 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1204 | struct ieee80211_txq_params txq_params; | |
1205 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1206 | ||
1207 | if (!rdev->ops->set_txq_params) { | |
1208 | result = -EOPNOTSUPP; | |
1209 | goto bad_res; | |
1210 | } | |
1211 | ||
1212 | nla_for_each_nested(nl_txq_params, | |
1213 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1214 | rem_txq_params) { | |
1215 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1216 | nla_data(nl_txq_params), | |
1217 | nla_len(nl_txq_params), | |
1218 | txq_params_policy); | |
1219 | result = parse_txq_params(tb, &txq_params); | |
1220 | if (result) | |
1221 | goto bad_res; | |
1222 | ||
1223 | result = rdev->ops->set_txq_params(&rdev->wiphy, | |
1224 | &txq_params); | |
1225 | if (result) | |
1226 | goto bad_res; | |
1227 | } | |
1228 | } | |
55682965 | 1229 | |
72bdcf34 | 1230 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
f444de05 | 1231 | result = __nl80211_set_channel(rdev, wdev, info); |
72bdcf34 JM |
1232 | if (result) |
1233 | goto bad_res; | |
1234 | } | |
1235 | ||
98d2ff8b JO |
1236 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
1237 | enum nl80211_tx_power_setting type; | |
1238 | int idx, mbm = 0; | |
1239 | ||
1240 | if (!rdev->ops->set_tx_power) { | |
60ea385f | 1241 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1242 | goto bad_res; |
1243 | } | |
1244 | ||
1245 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1246 | type = nla_get_u32(info->attrs[idx]); | |
1247 | ||
1248 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1249 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1250 | result = -EINVAL; | |
1251 | goto bad_res; | |
1252 | } | |
1253 | ||
1254 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1255 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1256 | mbm = nla_get_u32(info->attrs[idx]); | |
1257 | } | |
1258 | ||
1259 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); | |
1260 | if (result) | |
1261 | goto bad_res; | |
1262 | } | |
1263 | ||
afe0cbf8 BR |
1264 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1265 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1266 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1267 | if ((!rdev->wiphy.available_antennas_tx && |
1268 | !rdev->wiphy.available_antennas_rx) || | |
1269 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1270 | result = -EOPNOTSUPP; |
1271 | goto bad_res; | |
1272 | } | |
1273 | ||
1274 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1275 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
1276 | ||
a7ffac95 | 1277 | /* reject antenna configurations which don't match the |
7f531e03 BR |
1278 | * available antenna masks, except for the "all" mask */ |
1279 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
1280 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
1281 | result = -EINVAL; |
1282 | goto bad_res; | |
1283 | } | |
1284 | ||
7f531e03 BR |
1285 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
1286 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 1287 | |
afe0cbf8 BR |
1288 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
1289 | if (result) | |
1290 | goto bad_res; | |
1291 | } | |
1292 | ||
b9a5f8ca JM |
1293 | changed = 0; |
1294 | ||
1295 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
1296 | retry_short = nla_get_u8( | |
1297 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
1298 | if (retry_short == 0) { | |
1299 | result = -EINVAL; | |
1300 | goto bad_res; | |
1301 | } | |
1302 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
1303 | } | |
1304 | ||
1305 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
1306 | retry_long = nla_get_u8( | |
1307 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
1308 | if (retry_long == 0) { | |
1309 | result = -EINVAL; | |
1310 | goto bad_res; | |
1311 | } | |
1312 | changed |= WIPHY_PARAM_RETRY_LONG; | |
1313 | } | |
1314 | ||
1315 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
1316 | frag_threshold = nla_get_u32( | |
1317 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
1318 | if (frag_threshold < 256) { | |
1319 | result = -EINVAL; | |
1320 | goto bad_res; | |
1321 | } | |
1322 | if (frag_threshold != (u32) -1) { | |
1323 | /* | |
1324 | * Fragments (apart from the last one) are required to | |
1325 | * have even length. Make the fragmentation code | |
1326 | * simpler by stripping LSB should someone try to use | |
1327 | * odd threshold value. | |
1328 | */ | |
1329 | frag_threshold &= ~0x1; | |
1330 | } | |
1331 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
1332 | } | |
1333 | ||
1334 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
1335 | rts_threshold = nla_get_u32( | |
1336 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
1337 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
1338 | } | |
1339 | ||
81077e82 LT |
1340 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
1341 | coverage_class = nla_get_u8( | |
1342 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
1343 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
1344 | } | |
1345 | ||
b9a5f8ca JM |
1346 | if (changed) { |
1347 | u8 old_retry_short, old_retry_long; | |
1348 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 1349 | u8 old_coverage_class; |
b9a5f8ca JM |
1350 | |
1351 | if (!rdev->ops->set_wiphy_params) { | |
1352 | result = -EOPNOTSUPP; | |
1353 | goto bad_res; | |
1354 | } | |
1355 | ||
1356 | old_retry_short = rdev->wiphy.retry_short; | |
1357 | old_retry_long = rdev->wiphy.retry_long; | |
1358 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
1359 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 1360 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
1361 | |
1362 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1363 | rdev->wiphy.retry_short = retry_short; | |
1364 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1365 | rdev->wiphy.retry_long = retry_long; | |
1366 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
1367 | rdev->wiphy.frag_threshold = frag_threshold; | |
1368 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
1369 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
1370 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
1371 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca JM |
1372 | |
1373 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); | |
1374 | if (result) { | |
1375 | rdev->wiphy.retry_short = old_retry_short; | |
1376 | rdev->wiphy.retry_long = old_retry_long; | |
1377 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
1378 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 1379 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
1380 | } |
1381 | } | |
72bdcf34 | 1382 | |
306d6112 | 1383 | bad_res: |
4bbf4d56 | 1384 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
1385 | if (netdev) |
1386 | dev_put(netdev); | |
55682965 JB |
1387 | return result; |
1388 | } | |
1389 | ||
1390 | ||
1391 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
d726405a | 1392 | struct cfg80211_registered_device *rdev, |
55682965 JB |
1393 | struct net_device *dev) |
1394 | { | |
1395 | void *hdr; | |
1396 | ||
1397 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); | |
1398 | if (!hdr) | |
1399 | return -1; | |
1400 | ||
1401 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
d726405a | 1402 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
55682965 | 1403 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
60719ffd | 1404 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
f5ea9120 JB |
1405 | |
1406 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, | |
1407 | rdev->devlist_generation ^ | |
1408 | (cfg80211_rdev_list_generation << 2)); | |
1409 | ||
55682965 JB |
1410 | return genlmsg_end(msg, hdr); |
1411 | ||
1412 | nla_put_failure: | |
bc3ed28c TG |
1413 | genlmsg_cancel(msg, hdr); |
1414 | return -EMSGSIZE; | |
55682965 JB |
1415 | } |
1416 | ||
1417 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
1418 | { | |
1419 | int wp_idx = 0; | |
1420 | int if_idx = 0; | |
1421 | int wp_start = cb->args[0]; | |
1422 | int if_start = cb->args[1]; | |
f5ea9120 | 1423 | struct cfg80211_registered_device *rdev; |
55682965 JB |
1424 | struct wireless_dev *wdev; |
1425 | ||
a1794390 | 1426 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
1427 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1428 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1429 | continue; |
bba95fef JB |
1430 | if (wp_idx < wp_start) { |
1431 | wp_idx++; | |
55682965 | 1432 | continue; |
bba95fef | 1433 | } |
55682965 JB |
1434 | if_idx = 0; |
1435 | ||
f5ea9120 JB |
1436 | mutex_lock(&rdev->devlist_mtx); |
1437 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
bba95fef JB |
1438 | if (if_idx < if_start) { |
1439 | if_idx++; | |
55682965 | 1440 | continue; |
bba95fef | 1441 | } |
55682965 JB |
1442 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
1443 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
f5ea9120 JB |
1444 | rdev, wdev->netdev) < 0) { |
1445 | mutex_unlock(&rdev->devlist_mtx); | |
bba95fef JB |
1446 | goto out; |
1447 | } | |
1448 | if_idx++; | |
55682965 | 1449 | } |
f5ea9120 | 1450 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
1451 | |
1452 | wp_idx++; | |
55682965 | 1453 | } |
bba95fef | 1454 | out: |
a1794390 | 1455 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1456 | |
1457 | cb->args[0] = wp_idx; | |
1458 | cb->args[1] = if_idx; | |
1459 | ||
1460 | return skb->len; | |
1461 | } | |
1462 | ||
1463 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
1464 | { | |
1465 | struct sk_buff *msg; | |
4c476991 JB |
1466 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
1467 | struct net_device *netdev = info->user_ptr[1]; | |
55682965 | 1468 | |
fd2120ca | 1469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1470 | if (!msg) |
4c476991 | 1471 | return -ENOMEM; |
55682965 | 1472 | |
d726405a | 1473 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
4c476991 JB |
1474 | dev, netdev) < 0) { |
1475 | nlmsg_free(msg); | |
1476 | return -ENOBUFS; | |
1477 | } | |
55682965 | 1478 | |
134e6375 | 1479 | return genlmsg_reply(msg, info); |
55682965 JB |
1480 | } |
1481 | ||
66f7ac50 MW |
1482 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
1483 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
1484 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
1485 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
1486 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
1487 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
1488 | }; | |
1489 | ||
1490 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
1491 | { | |
1492 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
1493 | int flag; | |
1494 | ||
1495 | *mntrflags = 0; | |
1496 | ||
1497 | if (!nla) | |
1498 | return -EINVAL; | |
1499 | ||
1500 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
1501 | nla, mntr_flags_policy)) | |
1502 | return -EINVAL; | |
1503 | ||
1504 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
1505 | if (flags[flag]) | |
1506 | *mntrflags |= (1<<flag); | |
1507 | ||
1508 | return 0; | |
1509 | } | |
1510 | ||
9bc383de | 1511 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
1512 | struct net_device *netdev, u8 use_4addr, |
1513 | enum nl80211_iftype iftype) | |
9bc383de | 1514 | { |
ad4bb6f8 | 1515 | if (!use_4addr) { |
f350a0a8 | 1516 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 1517 | return -EBUSY; |
9bc383de | 1518 | return 0; |
ad4bb6f8 | 1519 | } |
9bc383de JB |
1520 | |
1521 | switch (iftype) { | |
1522 | case NL80211_IFTYPE_AP_VLAN: | |
1523 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
1524 | return 0; | |
1525 | break; | |
1526 | case NL80211_IFTYPE_STATION: | |
1527 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
1528 | return 0; | |
1529 | break; | |
1530 | default: | |
1531 | break; | |
1532 | } | |
1533 | ||
1534 | return -EOPNOTSUPP; | |
1535 | } | |
1536 | ||
55682965 JB |
1537 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
1538 | { | |
4c476991 | 1539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 1540 | struct vif_params params; |
e36d56b6 | 1541 | int err; |
04a773ad | 1542 | enum nl80211_iftype otype, ntype; |
4c476991 | 1543 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 1544 | u32 _flags, *flags = NULL; |
ac7f9cfa | 1545 | bool change = false; |
55682965 | 1546 | |
2ec600d6 LCC |
1547 | memset(¶ms, 0, sizeof(params)); |
1548 | ||
04a773ad | 1549 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 1550 | |
723b038d | 1551 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 1552 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 1553 | if (otype != ntype) |
ac7f9cfa | 1554 | change = true; |
4c476991 JB |
1555 | if (ntype > NL80211_IFTYPE_MAX) |
1556 | return -EINVAL; | |
723b038d JB |
1557 | } |
1558 | ||
92ffe055 | 1559 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
1560 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
1561 | ||
4c476991 JB |
1562 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
1563 | return -EINVAL; | |
29cbe68c JB |
1564 | if (netif_running(dev)) |
1565 | return -EBUSY; | |
1566 | ||
1567 | wdev_lock(wdev); | |
1568 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
1569 | IEEE80211_MAX_MESH_ID_LEN); | |
1570 | wdev->mesh_id_up_len = | |
1571 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1572 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
1573 | wdev->mesh_id_up_len); | |
1574 | wdev_unlock(wdev); | |
2ec600d6 LCC |
1575 | } |
1576 | ||
8b787643 FF |
1577 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
1578 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
1579 | change = true; | |
ad4bb6f8 | 1580 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 1581 | if (err) |
4c476991 | 1582 | return err; |
8b787643 FF |
1583 | } else { |
1584 | params.use_4addr = -1; | |
1585 | } | |
1586 | ||
92ffe055 | 1587 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
1588 | if (ntype != NL80211_IFTYPE_MONITOR) |
1589 | return -EINVAL; | |
92ffe055 JB |
1590 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
1591 | &_flags); | |
ac7f9cfa | 1592 | if (err) |
4c476991 | 1593 | return err; |
ac7f9cfa JB |
1594 | |
1595 | flags = &_flags; | |
1596 | change = true; | |
92ffe055 | 1597 | } |
3b85875a | 1598 | |
ac7f9cfa | 1599 | if (change) |
3d54d255 | 1600 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
1601 | else |
1602 | err = 0; | |
60719ffd | 1603 | |
9bc383de JB |
1604 | if (!err && params.use_4addr != -1) |
1605 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
1606 | ||
55682965 JB |
1607 | return err; |
1608 | } | |
1609 | ||
1610 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
1611 | { | |
4c476991 | 1612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 1613 | struct vif_params params; |
f9e10ce4 | 1614 | struct net_device *dev; |
55682965 JB |
1615 | int err; |
1616 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 1617 | u32 flags; |
55682965 | 1618 | |
2ec600d6 LCC |
1619 | memset(¶ms, 0, sizeof(params)); |
1620 | ||
55682965 JB |
1621 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
1622 | return -EINVAL; | |
1623 | ||
1624 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
1625 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
1626 | if (type > NL80211_IFTYPE_MAX) | |
1627 | return -EINVAL; | |
1628 | } | |
1629 | ||
79c97e97 | 1630 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
1631 | !(rdev->wiphy.interface_modes & (1 << type))) |
1632 | return -EOPNOTSUPP; | |
55682965 | 1633 | |
9bc383de | 1634 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 1635 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 1636 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 1637 | if (err) |
4c476991 | 1638 | return err; |
9bc383de | 1639 | } |
8b787643 | 1640 | |
66f7ac50 MW |
1641 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
1642 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
1643 | &flags); | |
f9e10ce4 | 1644 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
66f7ac50 | 1645 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
2ec600d6 | 1646 | type, err ? NULL : &flags, ¶ms); |
f9e10ce4 JB |
1647 | if (IS_ERR(dev)) |
1648 | return PTR_ERR(dev); | |
2ec600d6 | 1649 | |
29cbe68c JB |
1650 | if (type == NL80211_IFTYPE_MESH_POINT && |
1651 | info->attrs[NL80211_ATTR_MESH_ID]) { | |
1652 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1653 | ||
1654 | wdev_lock(wdev); | |
1655 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
1656 | IEEE80211_MAX_MESH_ID_LEN); | |
1657 | wdev->mesh_id_up_len = | |
1658 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1659 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
1660 | wdev->mesh_id_up_len); | |
1661 | wdev_unlock(wdev); | |
1662 | } | |
1663 | ||
f9e10ce4 | 1664 | return 0; |
55682965 JB |
1665 | } |
1666 | ||
1667 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
1668 | { | |
4c476991 JB |
1669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1670 | struct net_device *dev = info->user_ptr[1]; | |
55682965 | 1671 | |
4c476991 JB |
1672 | if (!rdev->ops->del_virtual_intf) |
1673 | return -EOPNOTSUPP; | |
55682965 | 1674 | |
4c476991 | 1675 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
55682965 JB |
1676 | } |
1677 | ||
41ade00f JB |
1678 | struct get_key_cookie { |
1679 | struct sk_buff *msg; | |
1680 | int error; | |
b9454e83 | 1681 | int idx; |
41ade00f JB |
1682 | }; |
1683 | ||
1684 | static void get_key_callback(void *c, struct key_params *params) | |
1685 | { | |
b9454e83 | 1686 | struct nlattr *key; |
41ade00f JB |
1687 | struct get_key_cookie *cookie = c; |
1688 | ||
1689 | if (params->key) | |
1690 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, | |
1691 | params->key_len, params->key); | |
1692 | ||
1693 | if (params->seq) | |
1694 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
1695 | params->seq_len, params->seq); | |
1696 | ||
1697 | if (params->cipher) | |
1698 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
1699 | params->cipher); | |
1700 | ||
b9454e83 JB |
1701 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
1702 | if (!key) | |
1703 | goto nla_put_failure; | |
1704 | ||
1705 | if (params->key) | |
1706 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, | |
1707 | params->key_len, params->key); | |
1708 | ||
1709 | if (params->seq) | |
1710 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, | |
1711 | params->seq_len, params->seq); | |
1712 | ||
1713 | if (params->cipher) | |
1714 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, | |
1715 | params->cipher); | |
1716 | ||
1717 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); | |
1718 | ||
1719 | nla_nest_end(cookie->msg, key); | |
1720 | ||
41ade00f JB |
1721 | return; |
1722 | nla_put_failure: | |
1723 | cookie->error = 1; | |
1724 | } | |
1725 | ||
1726 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
1727 | { | |
4c476991 | 1728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 1729 | int err; |
4c476991 | 1730 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 1731 | u8 key_idx = 0; |
e31b8213 JB |
1732 | const u8 *mac_addr = NULL; |
1733 | bool pairwise; | |
41ade00f JB |
1734 | struct get_key_cookie cookie = { |
1735 | .error = 0, | |
1736 | }; | |
1737 | void *hdr; | |
1738 | struct sk_buff *msg; | |
1739 | ||
1740 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1741 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1742 | ||
3cfcf6ac | 1743 | if (key_idx > 5) |
41ade00f JB |
1744 | return -EINVAL; |
1745 | ||
1746 | if (info->attrs[NL80211_ATTR_MAC]) | |
1747 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1748 | ||
e31b8213 JB |
1749 | pairwise = !!mac_addr; |
1750 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
1751 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
1752 | if (kt >= NUM_NL80211_KEYTYPES) | |
1753 | return -EINVAL; | |
1754 | if (kt != NL80211_KEYTYPE_GROUP && | |
1755 | kt != NL80211_KEYTYPE_PAIRWISE) | |
1756 | return -EINVAL; | |
1757 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
1758 | } | |
1759 | ||
4c476991 JB |
1760 | if (!rdev->ops->get_key) |
1761 | return -EOPNOTSUPP; | |
41ade00f | 1762 | |
fd2120ca | 1763 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
1764 | if (!msg) |
1765 | return -ENOMEM; | |
41ade00f JB |
1766 | |
1767 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
1768 | NL80211_CMD_NEW_KEY); | |
4c476991 JB |
1769 | if (IS_ERR(hdr)) |
1770 | return PTR_ERR(hdr); | |
41ade00f JB |
1771 | |
1772 | cookie.msg = msg; | |
b9454e83 | 1773 | cookie.idx = key_idx; |
41ade00f JB |
1774 | |
1775 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1776 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1777 | if (mac_addr) | |
1778 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1779 | ||
e31b8213 JB |
1780 | if (pairwise && mac_addr && |
1781 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
1782 | return -ENOENT; | |
1783 | ||
1784 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, | |
1785 | mac_addr, &cookie, get_key_callback); | |
41ade00f JB |
1786 | |
1787 | if (err) | |
6c95e2a2 | 1788 | goto free_msg; |
41ade00f JB |
1789 | |
1790 | if (cookie.error) | |
1791 | goto nla_put_failure; | |
1792 | ||
1793 | genlmsg_end(msg, hdr); | |
4c476991 | 1794 | return genlmsg_reply(msg, info); |
41ade00f JB |
1795 | |
1796 | nla_put_failure: | |
1797 | err = -ENOBUFS; | |
6c95e2a2 | 1798 | free_msg: |
41ade00f | 1799 | nlmsg_free(msg); |
41ade00f JB |
1800 | return err; |
1801 | } | |
1802 | ||
1803 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
1804 | { | |
4c476991 | 1805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 1806 | struct key_parse key; |
41ade00f | 1807 | int err; |
4c476991 | 1808 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 1809 | |
b9454e83 JB |
1810 | err = nl80211_parse_key(info, &key); |
1811 | if (err) | |
1812 | return err; | |
41ade00f | 1813 | |
b9454e83 | 1814 | if (key.idx < 0) |
41ade00f JB |
1815 | return -EINVAL; |
1816 | ||
b9454e83 JB |
1817 | /* only support setting default key */ |
1818 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
1819 | return -EINVAL; |
1820 | ||
dbd2fd65 | 1821 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 1822 | |
dbd2fd65 JB |
1823 | if (key.def) { |
1824 | if (!rdev->ops->set_default_key) { | |
1825 | err = -EOPNOTSUPP; | |
1826 | goto out; | |
1827 | } | |
41ade00f | 1828 | |
dbd2fd65 JB |
1829 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
1830 | if (err) | |
1831 | goto out; | |
1832 | ||
dbd2fd65 JB |
1833 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
1834 | key.def_uni, key.def_multi); | |
1835 | ||
1836 | if (err) | |
1837 | goto out; | |
fffd0934 | 1838 | |
3d23e349 | 1839 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
1840 | dev->ieee80211_ptr->wext.default_key = key.idx; |
1841 | #endif | |
1842 | } else { | |
1843 | if (key.def_uni || !key.def_multi) { | |
1844 | err = -EINVAL; | |
1845 | goto out; | |
1846 | } | |
1847 | ||
1848 | if (!rdev->ops->set_default_mgmt_key) { | |
1849 | err = -EOPNOTSUPP; | |
1850 | goto out; | |
1851 | } | |
1852 | ||
1853 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1854 | if (err) | |
1855 | goto out; | |
1856 | ||
1857 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, | |
1858 | dev, key.idx); | |
1859 | if (err) | |
1860 | goto out; | |
1861 | ||
1862 | #ifdef CONFIG_CFG80211_WEXT | |
1863 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 1864 | #endif |
dbd2fd65 JB |
1865 | } |
1866 | ||
1867 | out: | |
fffd0934 | 1868 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 1869 | |
41ade00f JB |
1870 | return err; |
1871 | } | |
1872 | ||
1873 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
1874 | { | |
4c476991 | 1875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 1876 | int err; |
4c476991 | 1877 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 1878 | struct key_parse key; |
e31b8213 | 1879 | const u8 *mac_addr = NULL; |
41ade00f | 1880 | |
b9454e83 JB |
1881 | err = nl80211_parse_key(info, &key); |
1882 | if (err) | |
1883 | return err; | |
41ade00f | 1884 | |
b9454e83 | 1885 | if (!key.p.key) |
41ade00f JB |
1886 | return -EINVAL; |
1887 | ||
41ade00f JB |
1888 | if (info->attrs[NL80211_ATTR_MAC]) |
1889 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1890 | ||
e31b8213 JB |
1891 | if (key.type == -1) { |
1892 | if (mac_addr) | |
1893 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
1894 | else | |
1895 | key.type = NL80211_KEYTYPE_GROUP; | |
1896 | } | |
1897 | ||
1898 | /* for now */ | |
1899 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
1900 | key.type != NL80211_KEYTYPE_GROUP) | |
1901 | return -EINVAL; | |
1902 | ||
4c476991 JB |
1903 | if (!rdev->ops->add_key) |
1904 | return -EOPNOTSUPP; | |
25e47c18 | 1905 | |
e31b8213 JB |
1906 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
1907 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
1908 | mac_addr)) | |
4c476991 | 1909 | return -EINVAL; |
41ade00f | 1910 | |
fffd0934 JB |
1911 | wdev_lock(dev->ieee80211_ptr); |
1912 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1913 | if (!err) | |
1914 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, | |
e31b8213 | 1915 | key.type == NL80211_KEYTYPE_PAIRWISE, |
fffd0934 JB |
1916 | mac_addr, &key.p); |
1917 | wdev_unlock(dev->ieee80211_ptr); | |
41ade00f | 1918 | |
41ade00f JB |
1919 | return err; |
1920 | } | |
1921 | ||
1922 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
1923 | { | |
4c476991 | 1924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 1925 | int err; |
4c476991 | 1926 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 1927 | u8 *mac_addr = NULL; |
b9454e83 | 1928 | struct key_parse key; |
41ade00f | 1929 | |
b9454e83 JB |
1930 | err = nl80211_parse_key(info, &key); |
1931 | if (err) | |
1932 | return err; | |
41ade00f JB |
1933 | |
1934 | if (info->attrs[NL80211_ATTR_MAC]) | |
1935 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1936 | ||
e31b8213 JB |
1937 | if (key.type == -1) { |
1938 | if (mac_addr) | |
1939 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
1940 | else | |
1941 | key.type = NL80211_KEYTYPE_GROUP; | |
1942 | } | |
1943 | ||
1944 | /* for now */ | |
1945 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
1946 | key.type != NL80211_KEYTYPE_GROUP) | |
1947 | return -EINVAL; | |
1948 | ||
4c476991 JB |
1949 | if (!rdev->ops->del_key) |
1950 | return -EOPNOTSUPP; | |
41ade00f | 1951 | |
fffd0934 JB |
1952 | wdev_lock(dev->ieee80211_ptr); |
1953 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
1954 | |
1955 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
1956 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
1957 | err = -ENOENT; | |
1958 | ||
fffd0934 | 1959 | if (!err) |
e31b8213 JB |
1960 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
1961 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
1962 | mac_addr); | |
41ade00f | 1963 | |
3d23e349 | 1964 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 1965 | if (!err) { |
b9454e83 | 1966 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 1967 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 1968 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
1969 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
1970 | } | |
1971 | #endif | |
fffd0934 | 1972 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 1973 | |
41ade00f JB |
1974 | return err; |
1975 | } | |
1976 | ||
ed1b6cc7 JB |
1977 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
1978 | { | |
1979 | int (*call)(struct wiphy *wiphy, struct net_device *dev, | |
1980 | struct beacon_parameters *info); | |
4c476991 JB |
1981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1982 | struct net_device *dev = info->user_ptr[1]; | |
56d1893d | 1983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
ed1b6cc7 | 1984 | struct beacon_parameters params; |
56d1893d | 1985 | int haveinfo = 0, err; |
ed1b6cc7 | 1986 | |
f4a11bb0 JB |
1987 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
1988 | return -EINVAL; | |
1989 | ||
074ac8df | 1990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
1991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
1992 | return -EOPNOTSUPP; | |
eec60b03 | 1993 | |
56d1893d JB |
1994 | memset(¶ms, 0, sizeof(params)); |
1995 | ||
ed1b6cc7 JB |
1996 | switch (info->genlhdr->cmd) { |
1997 | case NL80211_CMD_NEW_BEACON: | |
1998 | /* these are required for NEW_BEACON */ | |
1999 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
2000 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
4c476991 JB |
2001 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
2002 | return -EINVAL; | |
ed1b6cc7 | 2003 | |
56d1893d JB |
2004 | params.interval = |
2005 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
2006 | params.dtim_period = | |
2007 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
2008 | ||
2009 | err = cfg80211_validate_beacon_int(rdev, params.interval); | |
2010 | if (err) | |
2011 | return err; | |
2012 | ||
79c97e97 | 2013 | call = rdev->ops->add_beacon; |
ed1b6cc7 JB |
2014 | break; |
2015 | case NL80211_CMD_SET_BEACON: | |
79c97e97 | 2016 | call = rdev->ops->set_beacon; |
ed1b6cc7 JB |
2017 | break; |
2018 | default: | |
2019 | WARN_ON(1); | |
4c476991 | 2020 | return -EOPNOTSUPP; |
ed1b6cc7 JB |
2021 | } |
2022 | ||
4c476991 JB |
2023 | if (!call) |
2024 | return -EOPNOTSUPP; | |
ed1b6cc7 | 2025 | |
ed1b6cc7 JB |
2026 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
2027 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2028 | params.head_len = | |
2029 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2030 | haveinfo = 1; | |
2031 | } | |
2032 | ||
2033 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
2034 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
2035 | params.tail_len = | |
2036 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
2037 | haveinfo = 1; | |
2038 | } | |
2039 | ||
4c476991 JB |
2040 | if (!haveinfo) |
2041 | return -EINVAL; | |
3b85875a | 2042 | |
56d1893d JB |
2043 | err = call(&rdev->wiphy, dev, ¶ms); |
2044 | if (!err && params.interval) | |
2045 | wdev->beacon_interval = params.interval; | |
2046 | return err; | |
ed1b6cc7 JB |
2047 | } |
2048 | ||
2049 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) | |
2050 | { | |
4c476991 JB |
2051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2052 | struct net_device *dev = info->user_ptr[1]; | |
56d1893d JB |
2053 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2054 | int err; | |
ed1b6cc7 | 2055 | |
4c476991 JB |
2056 | if (!rdev->ops->del_beacon) |
2057 | return -EOPNOTSUPP; | |
ed1b6cc7 | 2058 | |
074ac8df | 2059 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
2060 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2061 | return -EOPNOTSUPP; | |
3b85875a | 2062 | |
56d1893d JB |
2063 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
2064 | if (!err) | |
2065 | wdev->beacon_interval = 0; | |
2066 | return err; | |
ed1b6cc7 JB |
2067 | } |
2068 | ||
5727ef1b JB |
2069 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
2070 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
2071 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
2072 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 2073 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 2074 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
5727ef1b JB |
2075 | }; |
2076 | ||
eccb8e8f JB |
2077 | static int parse_station_flags(struct genl_info *info, |
2078 | struct station_parameters *params) | |
5727ef1b JB |
2079 | { |
2080 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 2081 | struct nlattr *nla; |
5727ef1b JB |
2082 | int flag; |
2083 | ||
eccb8e8f JB |
2084 | /* |
2085 | * Try parsing the new attribute first so userspace | |
2086 | * can specify both for older kernels. | |
2087 | */ | |
2088 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
2089 | if (nla) { | |
2090 | struct nl80211_sta_flag_update *sta_flags; | |
2091 | ||
2092 | sta_flags = nla_data(nla); | |
2093 | params->sta_flags_mask = sta_flags->mask; | |
2094 | params->sta_flags_set = sta_flags->set; | |
2095 | if ((params->sta_flags_mask | | |
2096 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
2097 | return -EINVAL; | |
2098 | return 0; | |
2099 | } | |
2100 | ||
2101 | /* if present, parse the old attribute */ | |
5727ef1b | 2102 | |
eccb8e8f | 2103 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
2104 | if (!nla) |
2105 | return 0; | |
2106 | ||
2107 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
2108 | nla, sta_flags_policy)) | |
2109 | return -EINVAL; | |
2110 | ||
eccb8e8f JB |
2111 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
2112 | params->sta_flags_mask &= ~1; | |
5727ef1b JB |
2113 | |
2114 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) | |
2115 | if (flags[flag]) | |
eccb8e8f | 2116 | params->sta_flags_set |= (1<<flag); |
5727ef1b JB |
2117 | |
2118 | return 0; | |
2119 | } | |
2120 | ||
c8dcfd8a FF |
2121 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
2122 | int attr) | |
2123 | { | |
2124 | struct nlattr *rate; | |
2125 | u16 bitrate; | |
2126 | ||
2127 | rate = nla_nest_start(msg, attr); | |
2128 | if (!rate) | |
2129 | goto nla_put_failure; | |
2130 | ||
2131 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
2132 | bitrate = cfg80211_calculate_bitrate(info); | |
2133 | if (bitrate > 0) | |
2134 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | |
2135 | ||
2136 | if (info->flags & RATE_INFO_FLAGS_MCS) | |
2137 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); | |
2138 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | |
2139 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | |
2140 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) | |
2141 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | |
2142 | ||
2143 | nla_nest_end(msg, rate); | |
2144 | return true; | |
2145 | ||
2146 | nla_put_failure: | |
2147 | return false; | |
2148 | } | |
2149 | ||
fd5b74dc JB |
2150 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
2151 | int flags, struct net_device *dev, | |
98b62183 | 2152 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
2153 | { |
2154 | void *hdr; | |
f4263c98 | 2155 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc JB |
2156 | |
2157 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2158 | if (!hdr) | |
2159 | return -1; | |
2160 | ||
2161 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2162 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
2163 | ||
f5ea9120 JB |
2164 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
2165 | ||
2ec600d6 LCC |
2166 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
2167 | if (!sinfoattr) | |
fd5b74dc | 2168 | goto nla_put_failure; |
ebe27c91 MSS |
2169 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
2170 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
2171 | sinfo->connected_time); | |
2ec600d6 LCC |
2172 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
2173 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
2174 | sinfo->inactive_time); | |
2175 | if (sinfo->filled & STATION_INFO_RX_BYTES) | |
2176 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, | |
2177 | sinfo->rx_bytes); | |
2178 | if (sinfo->filled & STATION_INFO_TX_BYTES) | |
2179 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, | |
2180 | sinfo->tx_bytes); | |
2181 | if (sinfo->filled & STATION_INFO_LLID) | |
2182 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, | |
2183 | sinfo->llid); | |
2184 | if (sinfo->filled & STATION_INFO_PLID) | |
2185 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, | |
2186 | sinfo->plid); | |
2187 | if (sinfo->filled & STATION_INFO_PLINK_STATE) | |
2188 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, | |
2189 | sinfo->plink_state); | |
420e7fab HR |
2190 | if (sinfo->filled & STATION_INFO_SIGNAL) |
2191 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, | |
2192 | sinfo->signal); | |
541a45a1 BR |
2193 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
2194 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
2195 | sinfo->signal_avg); | |
420e7fab | 2196 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
2197 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
2198 | NL80211_STA_INFO_TX_BITRATE)) | |
2199 | goto nla_put_failure; | |
2200 | } | |
2201 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
2202 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
2203 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 2204 | goto nla_put_failure; |
420e7fab | 2205 | } |
98c8a60a JM |
2206 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
2207 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, | |
2208 | sinfo->rx_packets); | |
2209 | if (sinfo->filled & STATION_INFO_TX_PACKETS) | |
2210 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, | |
2211 | sinfo->tx_packets); | |
b206b4ef BR |
2212 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
2213 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, | |
2214 | sinfo->tx_retries); | |
2215 | if (sinfo->filled & STATION_INFO_TX_FAILED) | |
2216 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, | |
2217 | sinfo->tx_failed); | |
f4263c98 PS |
2218 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
2219 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
2220 | if (!bss_param) | |
2221 | goto nla_put_failure; | |
2222 | ||
2223 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) | |
2224 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); | |
2225 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) | |
2226 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); | |
2227 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) | |
2228 | NLA_PUT_FLAG(msg, | |
2229 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); | |
2230 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
2231 | sinfo->bss_param.dtim_period); | |
2232 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
2233 | sinfo->bss_param.beacon_interval); | |
2234 | ||
2235 | nla_nest_end(msg, bss_param); | |
2236 | } | |
2ec600d6 | 2237 | nla_nest_end(msg, sinfoattr); |
fd5b74dc JB |
2238 | |
2239 | return genlmsg_end(msg, hdr); | |
2240 | ||
2241 | nla_put_failure: | |
bc3ed28c TG |
2242 | genlmsg_cancel(msg, hdr); |
2243 | return -EMSGSIZE; | |
fd5b74dc JB |
2244 | } |
2245 | ||
2ec600d6 | 2246 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 2247 | struct netlink_callback *cb) |
2ec600d6 | 2248 | { |
2ec600d6 LCC |
2249 | struct station_info sinfo; |
2250 | struct cfg80211_registered_device *dev; | |
bba95fef | 2251 | struct net_device *netdev; |
2ec600d6 | 2252 | u8 mac_addr[ETH_ALEN]; |
bba95fef | 2253 | int sta_idx = cb->args[1]; |
2ec600d6 | 2254 | int err; |
2ec600d6 | 2255 | |
67748893 JB |
2256 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
2257 | if (err) | |
2258 | return err; | |
bba95fef JB |
2259 | |
2260 | if (!dev->ops->dump_station) { | |
eec60b03 | 2261 | err = -EOPNOTSUPP; |
bba95fef JB |
2262 | goto out_err; |
2263 | } | |
2264 | ||
bba95fef JB |
2265 | while (1) { |
2266 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, | |
2267 | mac_addr, &sinfo); | |
2268 | if (err == -ENOENT) | |
2269 | break; | |
2270 | if (err) | |
3b85875a | 2271 | goto out_err; |
bba95fef JB |
2272 | |
2273 | if (nl80211_send_station(skb, | |
2274 | NETLINK_CB(cb->skb).pid, | |
2275 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
2276 | netdev, mac_addr, | |
2277 | &sinfo) < 0) | |
2278 | goto out; | |
2279 | ||
2280 | sta_idx++; | |
2281 | } | |
2282 | ||
2283 | ||
2284 | out: | |
2285 | cb->args[1] = sta_idx; | |
2286 | err = skb->len; | |
bba95fef | 2287 | out_err: |
67748893 | 2288 | nl80211_finish_netdev_dump(dev); |
bba95fef JB |
2289 | |
2290 | return err; | |
2ec600d6 | 2291 | } |
fd5b74dc | 2292 | |
5727ef1b JB |
2293 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
2294 | { | |
4c476991 JB |
2295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2296 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 2297 | struct station_info sinfo; |
fd5b74dc JB |
2298 | struct sk_buff *msg; |
2299 | u8 *mac_addr = NULL; | |
4c476991 | 2300 | int err; |
fd5b74dc | 2301 | |
2ec600d6 | 2302 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
2303 | |
2304 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2305 | return -EINVAL; | |
2306 | ||
2307 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2308 | ||
4c476991 JB |
2309 | if (!rdev->ops->get_station) |
2310 | return -EOPNOTSUPP; | |
3b85875a | 2311 | |
4c476991 | 2312 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
fd5b74dc | 2313 | if (err) |
4c476991 | 2314 | return err; |
2ec600d6 | 2315 | |
fd2120ca | 2316 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 2317 | if (!msg) |
4c476991 | 2318 | return -ENOMEM; |
fd5b74dc JB |
2319 | |
2320 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | |
4c476991 JB |
2321 | dev, mac_addr, &sinfo) < 0) { |
2322 | nlmsg_free(msg); | |
2323 | return -ENOBUFS; | |
2324 | } | |
3b85875a | 2325 | |
4c476991 | 2326 | return genlmsg_reply(msg, info); |
5727ef1b JB |
2327 | } |
2328 | ||
2329 | /* | |
c258d2de | 2330 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 2331 | */ |
463d0183 | 2332 | static int get_vlan(struct genl_info *info, |
5727ef1b JB |
2333 | struct cfg80211_registered_device *rdev, |
2334 | struct net_device **vlan) | |
2335 | { | |
463d0183 | 2336 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
5727ef1b JB |
2337 | *vlan = NULL; |
2338 | ||
2339 | if (vlanattr) { | |
463d0183 JB |
2340 | *vlan = dev_get_by_index(genl_info_net(info), |
2341 | nla_get_u32(vlanattr)); | |
5727ef1b JB |
2342 | if (!*vlan) |
2343 | return -ENODEV; | |
2344 | if (!(*vlan)->ieee80211_ptr) | |
2345 | return -EINVAL; | |
2346 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) | |
2347 | return -EINVAL; | |
c258d2de FF |
2348 | if (!netif_running(*vlan)) |
2349 | return -ENETDOWN; | |
5727ef1b JB |
2350 | } |
2351 | return 0; | |
2352 | } | |
2353 | ||
2354 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
2355 | { | |
4c476991 | 2356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2357 | int err; |
4c476991 | 2358 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2359 | struct station_parameters params; |
2360 | u8 *mac_addr = NULL; | |
2361 | ||
2362 | memset(¶ms, 0, sizeof(params)); | |
2363 | ||
2364 | params.listen_interval = -1; | |
57cf8043 | 2365 | params.plink_state = -1; |
5727ef1b JB |
2366 | |
2367 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
2368 | return -EINVAL; | |
2369 | ||
2370 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2371 | return -EINVAL; | |
2372 | ||
2373 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2374 | ||
2375 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
2376 | params.supported_rates = | |
2377 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2378 | params.supported_rates_len = | |
2379 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2380 | } | |
2381 | ||
2382 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
2383 | params.listen_interval = | |
2384 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
2385 | ||
36aedc90 JM |
2386 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2387 | params.ht_capa = | |
2388 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
2389 | ||
eccb8e8f | 2390 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2391 | return -EINVAL; |
2392 | ||
2ec600d6 LCC |
2393 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2394 | params.plink_action = | |
2395 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2396 | ||
9c3990aa JC |
2397 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
2398 | params.plink_state = | |
2399 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | |
2400 | ||
463d0183 | 2401 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2402 | if (err) |
034d655e | 2403 | goto out; |
a97f4424 JB |
2404 | |
2405 | /* validate settings */ | |
2406 | err = 0; | |
2407 | ||
2408 | switch (dev->ieee80211_ptr->iftype) { | |
2409 | case NL80211_IFTYPE_AP: | |
2410 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 2411 | case NL80211_IFTYPE_P2P_GO: |
a97f4424 JB |
2412 | /* disallow mesh-specific things */ |
2413 | if (params.plink_action) | |
2414 | err = -EINVAL; | |
2415 | break; | |
074ac8df | 2416 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 JB |
2417 | case NL80211_IFTYPE_STATION: |
2418 | /* disallow everything but AUTHORIZED flag */ | |
2419 | if (params.plink_action) | |
2420 | err = -EINVAL; | |
2421 | if (params.vlan) | |
2422 | err = -EINVAL; | |
2423 | if (params.supported_rates) | |
2424 | err = -EINVAL; | |
2425 | if (params.ht_capa) | |
2426 | err = -EINVAL; | |
2427 | if (params.listen_interval >= 0) | |
2428 | err = -EINVAL; | |
2429 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
2430 | err = -EINVAL; | |
2431 | break; | |
2432 | case NL80211_IFTYPE_MESH_POINT: | |
2433 | /* disallow things mesh doesn't support */ | |
2434 | if (params.vlan) | |
2435 | err = -EINVAL; | |
2436 | if (params.ht_capa) | |
2437 | err = -EINVAL; | |
2438 | if (params.listen_interval >= 0) | |
2439 | err = -EINVAL; | |
b39c48fa JC |
2440 | if (params.sta_flags_mask & |
2441 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
8429828e | 2442 | BIT(NL80211_STA_FLAG_MFP) | |
b39c48fa | 2443 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
a97f4424 JB |
2444 | err = -EINVAL; |
2445 | break; | |
2446 | default: | |
2447 | err = -EINVAL; | |
034d655e JB |
2448 | } |
2449 | ||
5727ef1b JB |
2450 | if (err) |
2451 | goto out; | |
2452 | ||
79c97e97 | 2453 | if (!rdev->ops->change_station) { |
5727ef1b JB |
2454 | err = -EOPNOTSUPP; |
2455 | goto out; | |
2456 | } | |
2457 | ||
79c97e97 | 2458 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2459 | |
2460 | out: | |
2461 | if (params.vlan) | |
2462 | dev_put(params.vlan); | |
3b85875a | 2463 | |
5727ef1b JB |
2464 | return err; |
2465 | } | |
2466 | ||
2467 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
2468 | { | |
4c476991 | 2469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2470 | int err; |
4c476991 | 2471 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2472 | struct station_parameters params; |
2473 | u8 *mac_addr = NULL; | |
2474 | ||
2475 | memset(¶ms, 0, sizeof(params)); | |
2476 | ||
2477 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2478 | return -EINVAL; | |
2479 | ||
5727ef1b JB |
2480 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
2481 | return -EINVAL; | |
2482 | ||
2483 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
2484 | return -EINVAL; | |
2485 | ||
0e956c13 TLSC |
2486 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
2487 | return -EINVAL; | |
2488 | ||
5727ef1b JB |
2489 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2490 | params.supported_rates = | |
2491 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2492 | params.supported_rates_len = | |
2493 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2494 | params.listen_interval = | |
2495 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 2496 | |
0e956c13 TLSC |
2497 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
2498 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
2499 | return -EINVAL; | |
51b50fbe | 2500 | |
36aedc90 JM |
2501 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2502 | params.ht_capa = | |
2503 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 2504 | |
96b78dff JC |
2505 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2506 | params.plink_action = | |
2507 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2508 | ||
eccb8e8f | 2509 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2510 | return -EINVAL; |
2511 | ||
0e956c13 | 2512 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
074ac8df | 2513 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
96b78dff | 2514 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
2515 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2516 | return -EINVAL; | |
0e956c13 | 2517 | |
463d0183 | 2518 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2519 | if (err) |
e80cf853 | 2520 | goto out; |
a97f4424 JB |
2521 | |
2522 | /* validate settings */ | |
2523 | err = 0; | |
2524 | ||
79c97e97 | 2525 | if (!rdev->ops->add_station) { |
5727ef1b JB |
2526 | err = -EOPNOTSUPP; |
2527 | goto out; | |
2528 | } | |
2529 | ||
79c97e97 | 2530 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2531 | |
2532 | out: | |
2533 | if (params.vlan) | |
2534 | dev_put(params.vlan); | |
5727ef1b JB |
2535 | return err; |
2536 | } | |
2537 | ||
2538 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
2539 | { | |
4c476991 JB |
2540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2541 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
2542 | u8 *mac_addr = NULL; |
2543 | ||
2544 | if (info->attrs[NL80211_ATTR_MAC]) | |
2545 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2546 | ||
e80cf853 | 2547 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 2548 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 2549 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
2550 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2551 | return -EINVAL; | |
5727ef1b | 2552 | |
4c476991 JB |
2553 | if (!rdev->ops->del_station) |
2554 | return -EOPNOTSUPP; | |
3b85875a | 2555 | |
4c476991 | 2556 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
5727ef1b JB |
2557 | } |
2558 | ||
2ec600d6 LCC |
2559 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
2560 | int flags, struct net_device *dev, | |
2561 | u8 *dst, u8 *next_hop, | |
2562 | struct mpath_info *pinfo) | |
2563 | { | |
2564 | void *hdr; | |
2565 | struct nlattr *pinfoattr; | |
2566 | ||
2567 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2568 | if (!hdr) | |
2569 | return -1; | |
2570 | ||
2571 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2572 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
2573 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); | |
2574 | ||
f5ea9120 JB |
2575 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
2576 | ||
2ec600d6 LCC |
2577 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
2578 | if (!pinfoattr) | |
2579 | goto nla_put_failure; | |
2580 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) | |
2581 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
2582 | pinfo->frame_qlen); | |
d19b3bf6 RP |
2583 | if (pinfo->filled & MPATH_INFO_SN) |
2584 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, | |
2585 | pinfo->sn); | |
2ec600d6 LCC |
2586 | if (pinfo->filled & MPATH_INFO_METRIC) |
2587 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, | |
2588 | pinfo->metric); | |
2589 | if (pinfo->filled & MPATH_INFO_EXPTIME) | |
2590 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, | |
2591 | pinfo->exptime); | |
2592 | if (pinfo->filled & MPATH_INFO_FLAGS) | |
2593 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, | |
2594 | pinfo->flags); | |
2595 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) | |
2596 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
2597 | pinfo->discovery_timeout); | |
2598 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) | |
2599 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
2600 | pinfo->discovery_retries); | |
2601 | ||
2602 | nla_nest_end(msg, pinfoattr); | |
2603 | ||
2604 | return genlmsg_end(msg, hdr); | |
2605 | ||
2606 | nla_put_failure: | |
bc3ed28c TG |
2607 | genlmsg_cancel(msg, hdr); |
2608 | return -EMSGSIZE; | |
2ec600d6 LCC |
2609 | } |
2610 | ||
2611 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 2612 | struct netlink_callback *cb) |
2ec600d6 | 2613 | { |
2ec600d6 LCC |
2614 | struct mpath_info pinfo; |
2615 | struct cfg80211_registered_device *dev; | |
bba95fef | 2616 | struct net_device *netdev; |
2ec600d6 LCC |
2617 | u8 dst[ETH_ALEN]; |
2618 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 2619 | int path_idx = cb->args[1]; |
2ec600d6 | 2620 | int err; |
2ec600d6 | 2621 | |
67748893 JB |
2622 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
2623 | if (err) | |
2624 | return err; | |
bba95fef JB |
2625 | |
2626 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 2627 | err = -EOPNOTSUPP; |
bba95fef JB |
2628 | goto out_err; |
2629 | } | |
2630 | ||
eec60b03 JM |
2631 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2632 | err = -EOPNOTSUPP; | |
0448b5fc | 2633 | goto out_err; |
eec60b03 JM |
2634 | } |
2635 | ||
bba95fef JB |
2636 | while (1) { |
2637 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
2638 | dst, next_hop, &pinfo); | |
2639 | if (err == -ENOENT) | |
2ec600d6 | 2640 | break; |
bba95fef | 2641 | if (err) |
3b85875a | 2642 | goto out_err; |
2ec600d6 | 2643 | |
bba95fef JB |
2644 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
2645 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
2646 | netdev, dst, next_hop, | |
2647 | &pinfo) < 0) | |
2648 | goto out; | |
2ec600d6 | 2649 | |
bba95fef | 2650 | path_idx++; |
2ec600d6 | 2651 | } |
2ec600d6 | 2652 | |
2ec600d6 | 2653 | |
bba95fef JB |
2654 | out: |
2655 | cb->args[1] = path_idx; | |
2656 | err = skb->len; | |
bba95fef | 2657 | out_err: |
67748893 | 2658 | nl80211_finish_netdev_dump(dev); |
bba95fef | 2659 | return err; |
2ec600d6 LCC |
2660 | } |
2661 | ||
2662 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
2663 | { | |
4c476991 | 2664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2665 | int err; |
4c476991 | 2666 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
2667 | struct mpath_info pinfo; |
2668 | struct sk_buff *msg; | |
2669 | u8 *dst = NULL; | |
2670 | u8 next_hop[ETH_ALEN]; | |
2671 | ||
2672 | memset(&pinfo, 0, sizeof(pinfo)); | |
2673 | ||
2674 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2675 | return -EINVAL; | |
2676 | ||
2677 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2678 | ||
4c476991 JB |
2679 | if (!rdev->ops->get_mpath) |
2680 | return -EOPNOTSUPP; | |
2ec600d6 | 2681 | |
4c476991 JB |
2682 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2683 | return -EOPNOTSUPP; | |
eec60b03 | 2684 | |
79c97e97 | 2685 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 | 2686 | if (err) |
4c476991 | 2687 | return err; |
2ec600d6 | 2688 | |
fd2120ca | 2689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 2690 | if (!msg) |
4c476991 | 2691 | return -ENOMEM; |
2ec600d6 LCC |
2692 | |
2693 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
4c476991 JB |
2694 | dev, dst, next_hop, &pinfo) < 0) { |
2695 | nlmsg_free(msg); | |
2696 | return -ENOBUFS; | |
2697 | } | |
3b85875a | 2698 | |
4c476991 | 2699 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
2700 | } |
2701 | ||
2702 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
2703 | { | |
4c476991 JB |
2704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2705 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
2706 | u8 *dst = NULL; |
2707 | u8 *next_hop = NULL; | |
2708 | ||
2709 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2710 | return -EINVAL; | |
2711 | ||
2712 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2713 | return -EINVAL; | |
2714 | ||
2715 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2716 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2717 | ||
4c476991 JB |
2718 | if (!rdev->ops->change_mpath) |
2719 | return -EOPNOTSUPP; | |
35a8efe1 | 2720 | |
4c476991 JB |
2721 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2722 | return -EOPNOTSUPP; | |
2ec600d6 | 2723 | |
4c476991 | 2724 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 | 2725 | } |
4c476991 | 2726 | |
2ec600d6 LCC |
2727 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
2728 | { | |
4c476991 JB |
2729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2730 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
2731 | u8 *dst = NULL; |
2732 | u8 *next_hop = NULL; | |
2733 | ||
2734 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2735 | return -EINVAL; | |
2736 | ||
2737 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2738 | return -EINVAL; | |
2739 | ||
2740 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2741 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2742 | ||
4c476991 JB |
2743 | if (!rdev->ops->add_mpath) |
2744 | return -EOPNOTSUPP; | |
35a8efe1 | 2745 | |
4c476991 JB |
2746 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2747 | return -EOPNOTSUPP; | |
2ec600d6 | 2748 | |
4c476991 | 2749 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
2750 | } |
2751 | ||
2752 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
2753 | { | |
4c476991 JB |
2754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2755 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
2756 | u8 *dst = NULL; |
2757 | ||
2758 | if (info->attrs[NL80211_ATTR_MAC]) | |
2759 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2760 | ||
4c476991 JB |
2761 | if (!rdev->ops->del_mpath) |
2762 | return -EOPNOTSUPP; | |
3b85875a | 2763 | |
4c476991 | 2764 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2ec600d6 LCC |
2765 | } |
2766 | ||
9f1ba906 JM |
2767 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
2768 | { | |
4c476991 JB |
2769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2770 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
2771 | struct bss_parameters params; |
2772 | ||
2773 | memset(¶ms, 0, sizeof(params)); | |
2774 | /* default to not changing parameters */ | |
2775 | params.use_cts_prot = -1; | |
2776 | params.use_short_preamble = -1; | |
2777 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 2778 | params.ap_isolate = -1; |
50b12f59 | 2779 | params.ht_opmode = -1; |
9f1ba906 JM |
2780 | |
2781 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
2782 | params.use_cts_prot = | |
2783 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
2784 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
2785 | params.use_short_preamble = | |
2786 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
2787 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
2788 | params.use_short_slot_time = | |
2789 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
2790 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
2791 | params.basic_rates = | |
2792 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2793 | params.basic_rates_len = | |
2794 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2795 | } | |
fd8aaaf3 FF |
2796 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
2797 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
2798 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
2799 | params.ht_opmode = | |
2800 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 2801 | |
4c476991 JB |
2802 | if (!rdev->ops->change_bss) |
2803 | return -EOPNOTSUPP; | |
9f1ba906 | 2804 | |
074ac8df | 2805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
2806 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2807 | return -EOPNOTSUPP; | |
3b85875a | 2808 | |
4c476991 | 2809 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
9f1ba906 JM |
2810 | } |
2811 | ||
b54452b0 | 2812 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
2813 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
2814 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
2815 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
2816 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
2817 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
2818 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
2819 | }; | |
2820 | ||
2821 | static int parse_reg_rule(struct nlattr *tb[], | |
2822 | struct ieee80211_reg_rule *reg_rule) | |
2823 | { | |
2824 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
2825 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
2826 | ||
2827 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
2828 | return -EINVAL; | |
2829 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
2830 | return -EINVAL; | |
2831 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
2832 | return -EINVAL; | |
2833 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
2834 | return -EINVAL; | |
2835 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
2836 | return -EINVAL; | |
2837 | ||
2838 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
2839 | ||
2840 | freq_range->start_freq_khz = | |
2841 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
2842 | freq_range->end_freq_khz = | |
2843 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
2844 | freq_range->max_bandwidth_khz = | |
2845 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
2846 | ||
2847 | power_rule->max_eirp = | |
2848 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
2849 | ||
2850 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
2851 | power_rule->max_antenna_gain = | |
2852 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
2853 | ||
2854 | return 0; | |
2855 | } | |
2856 | ||
2857 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
2858 | { | |
2859 | int r; | |
2860 | char *data = NULL; | |
2861 | ||
80778f18 LR |
2862 | /* |
2863 | * You should only get this when cfg80211 hasn't yet initialized | |
2864 | * completely when built-in to the kernel right between the time | |
2865 | * window between nl80211_init() and regulatory_init(), if that is | |
2866 | * even possible. | |
2867 | */ | |
2868 | mutex_lock(&cfg80211_mutex); | |
2869 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
2870 | mutex_unlock(&cfg80211_mutex); |
2871 | return -EINPROGRESS; | |
80778f18 | 2872 | } |
fe33eb39 | 2873 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 2874 | |
fe33eb39 LR |
2875 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
2876 | return -EINVAL; | |
b2e1b302 LR |
2877 | |
2878 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
2879 | ||
fe33eb39 LR |
2880 | r = regulatory_hint_user(data); |
2881 | ||
b2e1b302 LR |
2882 | return r; |
2883 | } | |
2884 | ||
24bdd9f4 | 2885 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 2886 | struct genl_info *info) |
93da9cc1 | 2887 | { |
4c476991 | 2888 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 2889 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
2890 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2891 | struct mesh_config cur_params; | |
2892 | int err = 0; | |
93da9cc1 | 2893 | void *hdr; |
2894 | struct nlattr *pinfoattr; | |
2895 | struct sk_buff *msg; | |
2896 | ||
29cbe68c JB |
2897 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
2898 | return -EOPNOTSUPP; | |
2899 | ||
24bdd9f4 | 2900 | if (!rdev->ops->get_mesh_config) |
4c476991 | 2901 | return -EOPNOTSUPP; |
f3f92586 | 2902 | |
29cbe68c JB |
2903 | wdev_lock(wdev); |
2904 | /* If not connected, get default parameters */ | |
2905 | if (!wdev->mesh_id_len) | |
2906 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
2907 | else | |
24bdd9f4 | 2908 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
2909 | &cur_params); |
2910 | wdev_unlock(wdev); | |
2911 | ||
93da9cc1 | 2912 | if (err) |
4c476991 | 2913 | return err; |
93da9cc1 | 2914 | |
2915 | /* Draw up a netlink message to send back */ | |
fd2120ca | 2916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2917 | if (!msg) |
2918 | return -ENOMEM; | |
93da9cc1 | 2919 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
24bdd9f4 | 2920 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 2921 | if (!hdr) |
efe1cf0c | 2922 | goto out; |
24bdd9f4 | 2923 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 2924 | if (!pinfoattr) |
2925 | goto nla_put_failure; | |
2926 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2927 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
2928 | cur_params.dot11MeshRetryTimeout); | |
2929 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
2930 | cur_params.dot11MeshConfirmTimeout); | |
2931 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
2932 | cur_params.dot11MeshHoldingTimeout); | |
2933 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
2934 | cur_params.dot11MeshMaxPeerLinks); | |
2935 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
2936 | cur_params.dot11MeshMaxRetries); | |
2937 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | |
2938 | cur_params.dot11MeshTTL); | |
45904f21 JC |
2939 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
2940 | cur_params.element_ttl); | |
93da9cc1 | 2941 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
2942 | cur_params.auto_open_plinks); | |
2943 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2944 | cur_params.dot11MeshHWMPmaxPREQretries); | |
2945 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
2946 | cur_params.path_refresh_time); | |
2947 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2948 | cur_params.min_discovery_timeout); | |
2949 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2950 | cur_params.dot11MeshHWMPactivePathTimeout); | |
2951 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2952 | cur_params.dot11MeshHWMPpreqMinInterval); | |
2953 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2954 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); | |
63c5723b RP |
2955 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
2956 | cur_params.dot11MeshHWMPRootMode); | |
93da9cc1 | 2957 | nla_nest_end(msg, pinfoattr); |
2958 | genlmsg_end(msg, hdr); | |
4c476991 | 2959 | return genlmsg_reply(msg, info); |
93da9cc1 | 2960 | |
3b85875a | 2961 | nla_put_failure: |
93da9cc1 | 2962 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 2963 | out: |
d080e275 | 2964 | nlmsg_free(msg); |
4c476991 | 2965 | return -ENOBUFS; |
93da9cc1 | 2966 | } |
2967 | ||
b54452b0 | 2968 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 2969 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
2970 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
2971 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
2972 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
2973 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
2974 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 2975 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 2976 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
2977 | ||
2978 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | |
2979 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
2980 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
2981 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
2982 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
2983 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | |
2984 | }; | |
2985 | ||
c80d545d JC |
2986 | static const struct nla_policy |
2987 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
2988 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, | |
2989 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 2990 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
581a8b0f | 2991 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
c80d545d | 2992 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 2993 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
2994 | }; |
2995 | ||
24bdd9f4 | 2996 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
2997 | struct mesh_config *cfg, |
2998 | u32 *mask_out) | |
93da9cc1 | 2999 | { |
93da9cc1 | 3000 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 3001 | u32 mask = 0; |
93da9cc1 | 3002 | |
bd90fdcc JB |
3003 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
3004 | do {\ | |
3005 | if (table[attr_num]) {\ | |
3006 | cfg->param = nla_fn(table[attr_num]); \ | |
3007 | mask |= (1 << (attr_num - 1)); \ | |
3008 | } \ | |
3009 | } while (0);\ | |
3010 | ||
3011 | ||
24bdd9f4 | 3012 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 3013 | return -EINVAL; |
3014 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 3015 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 3016 | nl80211_meshconf_params_policy)) |
93da9cc1 | 3017 | return -EINVAL; |
3018 | ||
93da9cc1 | 3019 | /* This makes sure that there aren't more than 32 mesh config |
3020 | * parameters (otherwise our bitfield scheme would not work.) */ | |
3021 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
3022 | ||
3023 | /* Fill in the params struct */ | |
93da9cc1 | 3024 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
3025 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
3026 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | |
3027 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | |
3028 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | |
3029 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | |
3030 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | |
3031 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | |
3032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | |
3033 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
3034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | |
3035 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | |
45904f21 JC |
3036 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
3037 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); | |
93da9cc1 | 3038 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
3039 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | |
3040 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | |
3041 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
3042 | nla_get_u8); | |
3043 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | |
3044 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | |
3045 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | |
3046 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
3047 | nla_get_u16); | |
3048 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | |
3049 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3050 | nla_get_u32); | |
3051 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | |
3052 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
3053 | nla_get_u16); | |
3054 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
3055 | dot11MeshHWMPnetDiameterTraversalTime, | |
3056 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3057 | nla_get_u16); | |
63c5723b RP |
3058 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3059 | dot11MeshHWMPRootMode, mask, | |
3060 | NL80211_MESHCONF_HWMP_ROOTMODE, | |
3061 | nla_get_u8); | |
bd90fdcc JB |
3062 | if (mask_out) |
3063 | *mask_out = mask; | |
c80d545d | 3064 | |
bd90fdcc JB |
3065 | return 0; |
3066 | ||
3067 | #undef FILL_IN_MESH_PARAM_IF_SET | |
3068 | } | |
3069 | ||
c80d545d JC |
3070 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
3071 | struct mesh_setup *setup) | |
3072 | { | |
3073 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | |
3074 | ||
3075 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
3076 | return -EINVAL; | |
3077 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
3078 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
3079 | nl80211_mesh_setup_params_policy)) | |
3080 | return -EINVAL; | |
3081 | ||
3082 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) | |
3083 | setup->path_sel_proto = | |
3084 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
3085 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
3086 | IEEE80211_PATH_PROTOCOL_HWMP; | |
3087 | ||
3088 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
3089 | setup->path_metric = | |
3090 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
3091 | IEEE80211_PATH_METRIC_VENDOR : | |
3092 | IEEE80211_PATH_METRIC_AIRTIME; | |
3093 | ||
581a8b0f JC |
3094 | |
3095 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 3096 | struct nlattr *ieattr = |
581a8b0f | 3097 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
3098 | if (!is_valid_ie_attr(ieattr)) |
3099 | return -EINVAL; | |
581a8b0f JC |
3100 | setup->ie = nla_data(ieattr); |
3101 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 3102 | } |
b130e5ce JC |
3103 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
3104 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
c80d545d JC |
3105 | |
3106 | return 0; | |
3107 | } | |
3108 | ||
24bdd9f4 | 3109 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 3110 | struct genl_info *info) |
bd90fdcc JB |
3111 | { |
3112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3113 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 3114 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
3115 | struct mesh_config cfg; |
3116 | u32 mask; | |
3117 | int err; | |
3118 | ||
29cbe68c JB |
3119 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3120 | return -EOPNOTSUPP; | |
3121 | ||
24bdd9f4 | 3122 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
3123 | return -EOPNOTSUPP; |
3124 | ||
24bdd9f4 | 3125 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
3126 | if (err) |
3127 | return err; | |
3128 | ||
29cbe68c JB |
3129 | wdev_lock(wdev); |
3130 | if (!wdev->mesh_id_len) | |
3131 | err = -ENOLINK; | |
3132 | ||
3133 | if (!err) | |
24bdd9f4 | 3134 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3135 | mask, &cfg); |
3136 | ||
3137 | wdev_unlock(wdev); | |
3138 | ||
3139 | return err; | |
93da9cc1 | 3140 | } |
3141 | ||
f130347c LR |
3142 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
3143 | { | |
3144 | struct sk_buff *msg; | |
3145 | void *hdr = NULL; | |
3146 | struct nlattr *nl_reg_rules; | |
3147 | unsigned int i; | |
3148 | int err = -EINVAL; | |
3149 | ||
a1794390 | 3150 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
3151 | |
3152 | if (!cfg80211_regdomain) | |
3153 | goto out; | |
3154 | ||
fd2120ca | 3155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
3156 | if (!msg) { |
3157 | err = -ENOBUFS; | |
3158 | goto out; | |
3159 | } | |
3160 | ||
3161 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
3162 | NL80211_CMD_GET_REG); | |
3163 | if (!hdr) | |
efe1cf0c | 3164 | goto put_failure; |
f130347c LR |
3165 | |
3166 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, | |
3167 | cfg80211_regdomain->alpha2); | |
3168 | ||
3169 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
3170 | if (!nl_reg_rules) | |
3171 | goto nla_put_failure; | |
3172 | ||
3173 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
3174 | struct nlattr *nl_reg_rule; | |
3175 | const struct ieee80211_reg_rule *reg_rule; | |
3176 | const struct ieee80211_freq_range *freq_range; | |
3177 | const struct ieee80211_power_rule *power_rule; | |
3178 | ||
3179 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
3180 | freq_range = ®_rule->freq_range; | |
3181 | power_rule = ®_rule->power_rule; | |
3182 | ||
3183 | nl_reg_rule = nla_nest_start(msg, i); | |
3184 | if (!nl_reg_rule) | |
3185 | goto nla_put_failure; | |
3186 | ||
3187 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, | |
3188 | reg_rule->flags); | |
3189 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
3190 | freq_range->start_freq_khz); | |
3191 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
3192 | freq_range->end_freq_khz); | |
3193 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
3194 | freq_range->max_bandwidth_khz); | |
3195 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
3196 | power_rule->max_antenna_gain); | |
3197 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
3198 | power_rule->max_eirp); | |
3199 | ||
3200 | nla_nest_end(msg, nl_reg_rule); | |
3201 | } | |
3202 | ||
3203 | nla_nest_end(msg, nl_reg_rules); | |
3204 | ||
3205 | genlmsg_end(msg, hdr); | |
134e6375 | 3206 | err = genlmsg_reply(msg, info); |
f130347c LR |
3207 | goto out; |
3208 | ||
3209 | nla_put_failure: | |
3210 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 3211 | put_failure: |
d080e275 | 3212 | nlmsg_free(msg); |
f130347c LR |
3213 | err = -EMSGSIZE; |
3214 | out: | |
a1794390 | 3215 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
3216 | return err; |
3217 | } | |
3218 | ||
b2e1b302 LR |
3219 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
3220 | { | |
3221 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
3222 | struct nlattr *nl_reg_rule; | |
3223 | char *alpha2 = NULL; | |
3224 | int rem_reg_rules = 0, r = 0; | |
3225 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
3226 | struct ieee80211_regdomain *rd = NULL; | |
3227 | ||
3228 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
3229 | return -EINVAL; | |
3230 | ||
3231 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
3232 | return -EINVAL; | |
3233 | ||
3234 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3235 | ||
3236 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
3237 | rem_reg_rules) { | |
3238 | num_rules++; | |
3239 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 3240 | return -EINVAL; |
b2e1b302 LR |
3241 | } |
3242 | ||
61405e97 LR |
3243 | mutex_lock(&cfg80211_mutex); |
3244 | ||
d0e18f83 LR |
3245 | if (!reg_is_valid_request(alpha2)) { |
3246 | r = -EINVAL; | |
3247 | goto bad_reg; | |
3248 | } | |
b2e1b302 LR |
3249 | |
3250 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
3251 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
3252 | ||
3253 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
d0e18f83 LR |
3254 | if (!rd) { |
3255 | r = -ENOMEM; | |
3256 | goto bad_reg; | |
3257 | } | |
b2e1b302 LR |
3258 | |
3259 | rd->n_reg_rules = num_rules; | |
3260 | rd->alpha2[0] = alpha2[0]; | |
3261 | rd->alpha2[1] = alpha2[1]; | |
3262 | ||
3263 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
3264 | rem_reg_rules) { | |
3265 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
3266 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
3267 | reg_rule_policy); | |
3268 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
3269 | if (r) | |
3270 | goto bad_reg; | |
3271 | ||
3272 | rule_idx++; | |
3273 | ||
d0e18f83 LR |
3274 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
3275 | r = -EINVAL; | |
b2e1b302 | 3276 | goto bad_reg; |
d0e18f83 | 3277 | } |
b2e1b302 LR |
3278 | } |
3279 | ||
3280 | BUG_ON(rule_idx != num_rules); | |
3281 | ||
b2e1b302 | 3282 | r = set_regdom(rd); |
61405e97 | 3283 | |
a1794390 | 3284 | mutex_unlock(&cfg80211_mutex); |
d0e18f83 | 3285 | |
b2e1b302 LR |
3286 | return r; |
3287 | ||
d2372b31 | 3288 | bad_reg: |
61405e97 | 3289 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 3290 | kfree(rd); |
d0e18f83 | 3291 | return r; |
b2e1b302 LR |
3292 | } |
3293 | ||
83f5e2cf JB |
3294 | static int validate_scan_freqs(struct nlattr *freqs) |
3295 | { | |
3296 | struct nlattr *attr1, *attr2; | |
3297 | int n_channels = 0, tmp1, tmp2; | |
3298 | ||
3299 | nla_for_each_nested(attr1, freqs, tmp1) { | |
3300 | n_channels++; | |
3301 | /* | |
3302 | * Some hardware has a limited channel list for | |
3303 | * scanning, and it is pretty much nonsensical | |
3304 | * to scan for a channel twice, so disallow that | |
3305 | * and don't require drivers to check that the | |
3306 | * channel list they get isn't longer than what | |
3307 | * they can scan, as long as they can scan all | |
3308 | * the channels they registered at once. | |
3309 | */ | |
3310 | nla_for_each_nested(attr2, freqs, tmp2) | |
3311 | if (attr1 != attr2 && | |
3312 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
3313 | return 0; | |
3314 | } | |
3315 | ||
3316 | return n_channels; | |
3317 | } | |
3318 | ||
2a519311 JB |
3319 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
3320 | { | |
4c476991 JB |
3321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3322 | struct net_device *dev = info->user_ptr[1]; | |
2a519311 | 3323 | struct cfg80211_scan_request *request; |
2a519311 JB |
3324 | struct nlattr *attr; |
3325 | struct wiphy *wiphy; | |
83f5e2cf | 3326 | int err, tmp, n_ssids = 0, n_channels, i; |
2a519311 | 3327 | enum ieee80211_band band; |
70692ad2 | 3328 | size_t ie_len; |
2a519311 | 3329 | |
f4a11bb0 JB |
3330 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3331 | return -EINVAL; | |
3332 | ||
79c97e97 | 3333 | wiphy = &rdev->wiphy; |
2a519311 | 3334 | |
4c476991 JB |
3335 | if (!rdev->ops->scan) |
3336 | return -EOPNOTSUPP; | |
2a519311 | 3337 | |
4c476991 JB |
3338 | if (rdev->scan_req) |
3339 | return -EBUSY; | |
2a519311 JB |
3340 | |
3341 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
3342 | n_channels = validate_scan_freqs( |
3343 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
3344 | if (!n_channels) |
3345 | return -EINVAL; | |
2a519311 | 3346 | } else { |
83f5e2cf JB |
3347 | n_channels = 0; |
3348 | ||
2a519311 JB |
3349 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
3350 | if (wiphy->bands[band]) | |
3351 | n_channels += wiphy->bands[band]->n_channels; | |
3352 | } | |
3353 | ||
3354 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
3355 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
3356 | n_ssids++; | |
3357 | ||
4c476991 JB |
3358 | if (n_ssids > wiphy->max_scan_ssids) |
3359 | return -EINVAL; | |
2a519311 | 3360 | |
70692ad2 JM |
3361 | if (info->attrs[NL80211_ATTR_IE]) |
3362 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3363 | else | |
3364 | ie_len = 0; | |
3365 | ||
4c476991 JB |
3366 | if (ie_len > wiphy->max_scan_ie_len) |
3367 | return -EINVAL; | |
18a83659 | 3368 | |
2a519311 | 3369 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
3370 | + sizeof(*request->ssids) * n_ssids |
3371 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 3372 | + ie_len, GFP_KERNEL); |
4c476991 JB |
3373 | if (!request) |
3374 | return -ENOMEM; | |
2a519311 | 3375 | |
2a519311 | 3376 | if (n_ssids) |
5ba63533 | 3377 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 3378 | request->n_ssids = n_ssids; |
70692ad2 JM |
3379 | if (ie_len) { |
3380 | if (request->ssids) | |
3381 | request->ie = (void *)(request->ssids + n_ssids); | |
3382 | else | |
3383 | request->ie = (void *)(request->channels + n_channels); | |
3384 | } | |
2a519311 | 3385 | |
584991dc | 3386 | i = 0; |
2a519311 JB |
3387 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3388 | /* user specified, bail out if channel not found */ | |
2a519311 | 3389 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
3390 | struct ieee80211_channel *chan; |
3391 | ||
3392 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3393 | ||
3394 | if (!chan) { | |
2a519311 JB |
3395 | err = -EINVAL; |
3396 | goto out_free; | |
3397 | } | |
584991dc JB |
3398 | |
3399 | /* ignore disabled channels */ | |
3400 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3401 | continue; | |
3402 | ||
3403 | request->channels[i] = chan; | |
2a519311 JB |
3404 | i++; |
3405 | } | |
3406 | } else { | |
3407 | /* all channels */ | |
2a519311 JB |
3408 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
3409 | int j; | |
3410 | if (!wiphy->bands[band]) | |
3411 | continue; | |
3412 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
3413 | struct ieee80211_channel *chan; |
3414 | ||
3415 | chan = &wiphy->bands[band]->channels[j]; | |
3416 | ||
3417 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3418 | continue; | |
3419 | ||
3420 | request->channels[i] = chan; | |
2a519311 JB |
3421 | i++; |
3422 | } | |
3423 | } | |
3424 | } | |
3425 | ||
584991dc JB |
3426 | if (!i) { |
3427 | err = -EINVAL; | |
3428 | goto out_free; | |
3429 | } | |
3430 | ||
3431 | request->n_channels = i; | |
3432 | ||
2a519311 JB |
3433 | i = 0; |
3434 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3435 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 3436 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
3437 | err = -EINVAL; |
3438 | goto out_free; | |
3439 | } | |
57a27e1d | 3440 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 3441 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
3442 | i++; |
3443 | } | |
3444 | } | |
3445 | ||
70692ad2 JM |
3446 | if (info->attrs[NL80211_ATTR_IE]) { |
3447 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
3448 | memcpy((void *)request->ie, |
3449 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
3450 | request->ie_len); |
3451 | } | |
3452 | ||
463d0183 | 3453 | request->dev = dev; |
79c97e97 | 3454 | request->wiphy = &rdev->wiphy; |
2a519311 | 3455 | |
79c97e97 JB |
3456 | rdev->scan_req = request; |
3457 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | |
2a519311 | 3458 | |
463d0183 | 3459 | if (!err) { |
79c97e97 | 3460 | nl80211_send_scan_start(rdev, dev); |
463d0183 | 3461 | dev_hold(dev); |
4c476991 | 3462 | } else { |
2a519311 | 3463 | out_free: |
79c97e97 | 3464 | rdev->scan_req = NULL; |
2a519311 JB |
3465 | kfree(request); |
3466 | } | |
3b85875a | 3467 | |
2a519311 JB |
3468 | return err; |
3469 | } | |
3470 | ||
807f8a8c LC |
3471 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
3472 | struct genl_info *info) | |
3473 | { | |
3474 | struct cfg80211_sched_scan_request *request; | |
3475 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3476 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
3477 | struct nlattr *attr; |
3478 | struct wiphy *wiphy; | |
3479 | int err, tmp, n_ssids = 0, n_channels, i; | |
bbe6ad6d | 3480 | u32 interval; |
807f8a8c LC |
3481 | enum ieee80211_band band; |
3482 | size_t ie_len; | |
3483 | ||
3484 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
3485 | !rdev->ops->sched_scan_start) | |
3486 | return -EOPNOTSUPP; | |
3487 | ||
3488 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
3489 | return -EINVAL; | |
3490 | ||
bbe6ad6d LC |
3491 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
3492 | return -EINVAL; | |
3493 | ||
3494 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
3495 | if (interval == 0) | |
3496 | return -EINVAL; | |
3497 | ||
807f8a8c LC |
3498 | wiphy = &rdev->wiphy; |
3499 | ||
3500 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
3501 | n_channels = validate_scan_freqs( | |
3502 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
3503 | if (!n_channels) | |
3504 | return -EINVAL; | |
3505 | } else { | |
3506 | n_channels = 0; | |
3507 | ||
3508 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
3509 | if (wiphy->bands[band]) | |
3510 | n_channels += wiphy->bands[band]->n_channels; | |
3511 | } | |
3512 | ||
3513 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
3514 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
3515 | tmp) | |
3516 | n_ssids++; | |
3517 | ||
93b6aa69 | 3518 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
3519 | return -EINVAL; |
3520 | ||
3521 | if (info->attrs[NL80211_ATTR_IE]) | |
3522 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3523 | else | |
3524 | ie_len = 0; | |
3525 | ||
5a865bad | 3526 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
3527 | return -EINVAL; |
3528 | ||
c10841ca LC |
3529 | mutex_lock(&rdev->sched_scan_mtx); |
3530 | ||
3531 | if (rdev->sched_scan_req) { | |
3532 | err = -EINPROGRESS; | |
3533 | goto out; | |
3534 | } | |
3535 | ||
807f8a8c | 3536 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
3537 | + sizeof(*request->ssids) * n_ssids |
3538 | + sizeof(*request->channels) * n_channels | |
807f8a8c | 3539 | + ie_len, GFP_KERNEL); |
c10841ca LC |
3540 | if (!request) { |
3541 | err = -ENOMEM; | |
3542 | goto out; | |
3543 | } | |
807f8a8c LC |
3544 | |
3545 | if (n_ssids) | |
3546 | request->ssids = (void *)&request->channels[n_channels]; | |
3547 | request->n_ssids = n_ssids; | |
3548 | if (ie_len) { | |
3549 | if (request->ssids) | |
3550 | request->ie = (void *)(request->ssids + n_ssids); | |
3551 | else | |
3552 | request->ie = (void *)(request->channels + n_channels); | |
3553 | } | |
3554 | ||
3555 | i = 0; | |
3556 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
3557 | /* user specified, bail out if channel not found */ | |
3558 | nla_for_each_nested(attr, | |
3559 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
3560 | tmp) { | |
3561 | struct ieee80211_channel *chan; | |
3562 | ||
3563 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3564 | ||
3565 | if (!chan) { | |
3566 | err = -EINVAL; | |
3567 | goto out_free; | |
3568 | } | |
3569 | ||
3570 | /* ignore disabled channels */ | |
3571 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3572 | continue; | |
3573 | ||
3574 | request->channels[i] = chan; | |
3575 | i++; | |
3576 | } | |
3577 | } else { | |
3578 | /* all channels */ | |
3579 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
3580 | int j; | |
3581 | if (!wiphy->bands[band]) | |
3582 | continue; | |
3583 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
3584 | struct ieee80211_channel *chan; | |
3585 | ||
3586 | chan = &wiphy->bands[band]->channels[j]; | |
3587 | ||
3588 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3589 | continue; | |
3590 | ||
3591 | request->channels[i] = chan; | |
3592 | i++; | |
3593 | } | |
3594 | } | |
3595 | } | |
3596 | ||
3597 | if (!i) { | |
3598 | err = -EINVAL; | |
3599 | goto out_free; | |
3600 | } | |
3601 | ||
3602 | request->n_channels = i; | |
3603 | ||
3604 | i = 0; | |
3605 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3606 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
3607 | tmp) { | |
57a27e1d | 3608 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
3609 | err = -EINVAL; |
3610 | goto out_free; | |
3611 | } | |
57a27e1d | 3612 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
3613 | memcpy(request->ssids[i].ssid, nla_data(attr), |
3614 | nla_len(attr)); | |
807f8a8c LC |
3615 | i++; |
3616 | } | |
3617 | } | |
3618 | ||
3619 | if (info->attrs[NL80211_ATTR_IE]) { | |
3620 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3621 | memcpy((void *)request->ie, | |
3622 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
3623 | request->ie_len); | |
3624 | } | |
3625 | ||
3626 | request->dev = dev; | |
3627 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 3628 | request->interval = interval; |
807f8a8c LC |
3629 | |
3630 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); | |
3631 | if (!err) { | |
3632 | rdev->sched_scan_req = request; | |
3633 | nl80211_send_sched_scan(rdev, dev, | |
3634 | NL80211_CMD_START_SCHED_SCAN); | |
3635 | goto out; | |
3636 | } | |
3637 | ||
3638 | out_free: | |
3639 | kfree(request); | |
3640 | out: | |
c10841ca | 3641 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
3642 | return err; |
3643 | } | |
3644 | ||
3645 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
3646 | struct genl_info *info) | |
3647 | { | |
3648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 3649 | int err; |
807f8a8c LC |
3650 | |
3651 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
3652 | !rdev->ops->sched_scan_stop) | |
3653 | return -EOPNOTSUPP; | |
3654 | ||
c10841ca LC |
3655 | mutex_lock(&rdev->sched_scan_mtx); |
3656 | err = __cfg80211_stop_sched_scan(rdev, false); | |
3657 | mutex_unlock(&rdev->sched_scan_mtx); | |
3658 | ||
3659 | return err; | |
807f8a8c LC |
3660 | } |
3661 | ||
9720bb3a JB |
3662 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
3663 | u32 seq, int flags, | |
2a519311 | 3664 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
3665 | struct wireless_dev *wdev, |
3666 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 3667 | { |
48ab905d | 3668 | struct cfg80211_bss *res = &intbss->pub; |
2a519311 JB |
3669 | void *hdr; |
3670 | struct nlattr *bss; | |
48ab905d JB |
3671 | int i; |
3672 | ||
3673 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 3674 | |
9720bb3a | 3675 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
2a519311 JB |
3676 | NL80211_CMD_NEW_SCAN_RESULTS); |
3677 | if (!hdr) | |
3678 | return -1; | |
3679 | ||
9720bb3a JB |
3680 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
3681 | ||
f5ea9120 | 3682 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
48ab905d | 3683 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
2a519311 JB |
3684 | |
3685 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
3686 | if (!bss) | |
3687 | goto nla_put_failure; | |
3688 | if (!is_zero_ether_addr(res->bssid)) | |
3689 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); | |
3690 | if (res->information_elements && res->len_information_elements) | |
3691 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
3692 | res->len_information_elements, | |
3693 | res->information_elements); | |
34a6eddb JM |
3694 | if (res->beacon_ies && res->len_beacon_ies && |
3695 | res->beacon_ies != res->information_elements) | |
3696 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, | |
3697 | res->len_beacon_ies, res->beacon_ies); | |
2a519311 JB |
3698 | if (res->tsf) |
3699 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); | |
3700 | if (res->beacon_interval) | |
3701 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); | |
3702 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); | |
3703 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); | |
7c89606e HS |
3704 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
3705 | jiffies_to_msecs(jiffies - intbss->ts)); | |
2a519311 | 3706 | |
77965c97 | 3707 | switch (rdev->wiphy.signal_type) { |
2a519311 JB |
3708 | case CFG80211_SIGNAL_TYPE_MBM: |
3709 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); | |
3710 | break; | |
3711 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
3712 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); | |
3713 | break; | |
3714 | default: | |
3715 | break; | |
3716 | } | |
3717 | ||
48ab905d | 3718 | switch (wdev->iftype) { |
074ac8df | 3719 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d JB |
3720 | case NL80211_IFTYPE_STATION: |
3721 | if (intbss == wdev->current_bss) | |
3722 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3723 | NL80211_BSS_STATUS_ASSOCIATED); | |
3724 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
3725 | if (intbss != wdev->auth_bsses[i]) | |
3726 | continue; | |
3727 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3728 | NL80211_BSS_STATUS_AUTHENTICATED); | |
3729 | break; | |
3730 | } | |
3731 | break; | |
3732 | case NL80211_IFTYPE_ADHOC: | |
3733 | if (intbss == wdev->current_bss) | |
3734 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3735 | NL80211_BSS_STATUS_IBSS_JOINED); | |
3736 | break; | |
3737 | default: | |
3738 | break; | |
3739 | } | |
3740 | ||
2a519311 JB |
3741 | nla_nest_end(msg, bss); |
3742 | ||
3743 | return genlmsg_end(msg, hdr); | |
3744 | ||
3745 | nla_put_failure: | |
3746 | genlmsg_cancel(msg, hdr); | |
3747 | return -EMSGSIZE; | |
3748 | } | |
3749 | ||
3750 | static int nl80211_dump_scan(struct sk_buff *skb, | |
3751 | struct netlink_callback *cb) | |
3752 | { | |
48ab905d JB |
3753 | struct cfg80211_registered_device *rdev; |
3754 | struct net_device *dev; | |
2a519311 | 3755 | struct cfg80211_internal_bss *scan; |
48ab905d | 3756 | struct wireless_dev *wdev; |
2a519311 JB |
3757 | int start = cb->args[1], idx = 0; |
3758 | int err; | |
3759 | ||
67748893 JB |
3760 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
3761 | if (err) | |
3762 | return err; | |
2a519311 | 3763 | |
48ab905d | 3764 | wdev = dev->ieee80211_ptr; |
2a519311 | 3765 | |
48ab905d JB |
3766 | wdev_lock(wdev); |
3767 | spin_lock_bh(&rdev->bss_lock); | |
3768 | cfg80211_bss_expire(rdev); | |
3769 | ||
9720bb3a JB |
3770 | cb->seq = rdev->bss_generation; |
3771 | ||
48ab905d | 3772 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
3773 | if (++idx <= start) |
3774 | continue; | |
9720bb3a | 3775 | if (nl80211_send_bss(skb, cb, |
2a519311 | 3776 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 3777 | rdev, wdev, scan) < 0) { |
2a519311 | 3778 | idx--; |
67748893 | 3779 | break; |
2a519311 JB |
3780 | } |
3781 | } | |
3782 | ||
48ab905d JB |
3783 | spin_unlock_bh(&rdev->bss_lock); |
3784 | wdev_unlock(wdev); | |
2a519311 JB |
3785 | |
3786 | cb->args[1] = idx; | |
67748893 | 3787 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 3788 | |
67748893 | 3789 | return skb->len; |
2a519311 JB |
3790 | } |
3791 | ||
61fa713c HS |
3792 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
3793 | int flags, struct net_device *dev, | |
3794 | struct survey_info *survey) | |
3795 | { | |
3796 | void *hdr; | |
3797 | struct nlattr *infoattr; | |
3798 | ||
61fa713c HS |
3799 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
3800 | NL80211_CMD_NEW_SURVEY_RESULTS); | |
3801 | if (!hdr) | |
3802 | return -ENOMEM; | |
3803 | ||
3804 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
3805 | ||
3806 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
3807 | if (!infoattr) | |
3808 | goto nla_put_failure; | |
3809 | ||
3810 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
3811 | survey->channel->center_freq); | |
3812 | if (survey->filled & SURVEY_INFO_NOISE_DBM) | |
3813 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, | |
3814 | survey->noise); | |
17e5a808 FF |
3815 | if (survey->filled & SURVEY_INFO_IN_USE) |
3816 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); | |
8610c29a FF |
3817 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
3818 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
3819 | survey->channel_time); | |
3820 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) | |
3821 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
3822 | survey->channel_time_busy); | |
3823 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) | |
3824 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
3825 | survey->channel_time_ext_busy); | |
3826 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) | |
3827 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
3828 | survey->channel_time_rx); | |
3829 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) | |
3830 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
3831 | survey->channel_time_tx); | |
61fa713c HS |
3832 | |
3833 | nla_nest_end(msg, infoattr); | |
3834 | ||
3835 | return genlmsg_end(msg, hdr); | |
3836 | ||
3837 | nla_put_failure: | |
3838 | genlmsg_cancel(msg, hdr); | |
3839 | return -EMSGSIZE; | |
3840 | } | |
3841 | ||
3842 | static int nl80211_dump_survey(struct sk_buff *skb, | |
3843 | struct netlink_callback *cb) | |
3844 | { | |
3845 | struct survey_info survey; | |
3846 | struct cfg80211_registered_device *dev; | |
3847 | struct net_device *netdev; | |
61fa713c HS |
3848 | int survey_idx = cb->args[1]; |
3849 | int res; | |
3850 | ||
67748893 JB |
3851 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3852 | if (res) | |
3853 | return res; | |
61fa713c HS |
3854 | |
3855 | if (!dev->ops->dump_survey) { | |
3856 | res = -EOPNOTSUPP; | |
3857 | goto out_err; | |
3858 | } | |
3859 | ||
3860 | while (1) { | |
180cdc79 LR |
3861 | struct ieee80211_channel *chan; |
3862 | ||
61fa713c HS |
3863 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
3864 | &survey); | |
3865 | if (res == -ENOENT) | |
3866 | break; | |
3867 | if (res) | |
3868 | goto out_err; | |
3869 | ||
180cdc79 LR |
3870 | /* Survey without a channel doesn't make sense */ |
3871 | if (!survey.channel) { | |
3872 | res = -EINVAL; | |
3873 | goto out; | |
3874 | } | |
3875 | ||
3876 | chan = ieee80211_get_channel(&dev->wiphy, | |
3877 | survey.channel->center_freq); | |
3878 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
3879 | survey_idx++; | |
3880 | continue; | |
3881 | } | |
3882 | ||
61fa713c HS |
3883 | if (nl80211_send_survey(skb, |
3884 | NETLINK_CB(cb->skb).pid, | |
3885 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
3886 | netdev, | |
3887 | &survey) < 0) | |
3888 | goto out; | |
3889 | survey_idx++; | |
3890 | } | |
3891 | ||
3892 | out: | |
3893 | cb->args[1] = survey_idx; | |
3894 | res = skb->len; | |
3895 | out_err: | |
67748893 | 3896 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
3897 | return res; |
3898 | } | |
3899 | ||
255e737e JM |
3900 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
3901 | { | |
b23aa676 SO |
3902 | return auth_type <= NL80211_AUTHTYPE_MAX; |
3903 | } | |
3904 | ||
3905 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | |
3906 | { | |
3907 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
3908 | NL80211_WPA_VERSION_2)); | |
3909 | } | |
3910 | ||
3911 | static bool nl80211_valid_akm_suite(u32 akm) | |
3912 | { | |
3913 | return akm == WLAN_AKM_SUITE_8021X || | |
3914 | akm == WLAN_AKM_SUITE_PSK; | |
3915 | } | |
3916 | ||
3917 | static bool nl80211_valid_cipher_suite(u32 cipher) | |
3918 | { | |
3919 | return cipher == WLAN_CIPHER_SUITE_WEP40 || | |
3920 | cipher == WLAN_CIPHER_SUITE_WEP104 || | |
3921 | cipher == WLAN_CIPHER_SUITE_TKIP || | |
3922 | cipher == WLAN_CIPHER_SUITE_CCMP || | |
3923 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; | |
255e737e JM |
3924 | } |
3925 | ||
b23aa676 | 3926 | |
636a5d36 JM |
3927 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
3928 | { | |
4c476991 JB |
3929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3930 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 JB |
3931 | struct ieee80211_channel *chan; |
3932 | const u8 *bssid, *ssid, *ie = NULL; | |
3933 | int err, ssid_len, ie_len = 0; | |
3934 | enum nl80211_auth_type auth_type; | |
fffd0934 | 3935 | struct key_parse key; |
d5cdfacb | 3936 | bool local_state_change; |
636a5d36 | 3937 | |
f4a11bb0 JB |
3938 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3939 | return -EINVAL; | |
3940 | ||
3941 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3942 | return -EINVAL; | |
3943 | ||
1778092e JM |
3944 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
3945 | return -EINVAL; | |
3946 | ||
19957bb3 JB |
3947 | if (!info->attrs[NL80211_ATTR_SSID]) |
3948 | return -EINVAL; | |
3949 | ||
3950 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
3951 | return -EINVAL; | |
3952 | ||
fffd0934 JB |
3953 | err = nl80211_parse_key(info, &key); |
3954 | if (err) | |
3955 | return err; | |
3956 | ||
3957 | if (key.idx >= 0) { | |
e31b8213 JB |
3958 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
3959 | return -EINVAL; | |
fffd0934 JB |
3960 | if (!key.p.key || !key.p.key_len) |
3961 | return -EINVAL; | |
3962 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
3963 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
3964 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
3965 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
3966 | return -EINVAL; | |
3967 | if (key.idx > 4) | |
3968 | return -EINVAL; | |
3969 | } else { | |
3970 | key.p.key_len = 0; | |
3971 | key.p.key = NULL; | |
3972 | } | |
3973 | ||
afea0b7a JB |
3974 | if (key.idx >= 0) { |
3975 | int i; | |
3976 | bool ok = false; | |
3977 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
3978 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
3979 | ok = true; | |
3980 | break; | |
3981 | } | |
3982 | } | |
4c476991 JB |
3983 | if (!ok) |
3984 | return -EINVAL; | |
afea0b7a JB |
3985 | } |
3986 | ||
4c476991 JB |
3987 | if (!rdev->ops->auth) |
3988 | return -EOPNOTSUPP; | |
636a5d36 | 3989 | |
074ac8df | 3990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
3991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
3992 | return -EOPNOTSUPP; | |
eec60b03 | 3993 | |
19957bb3 | 3994 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 3995 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 3996 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
3997 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
3998 | return -EINVAL; | |
636a5d36 | 3999 | |
19957bb3 JB |
4000 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4001 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4002 | |
4003 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4004 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4005 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4006 | } |
4007 | ||
19957bb3 | 4008 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
4c476991 JB |
4009 | if (!nl80211_valid_auth_type(auth_type)) |
4010 | return -EINVAL; | |
636a5d36 | 4011 | |
d5cdfacb JM |
4012 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4013 | ||
4c476991 JB |
4014 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
4015 | ssid, ssid_len, ie, ie_len, | |
4016 | key.p.key, key.p.key_len, key.idx, | |
4017 | local_state_change); | |
636a5d36 JM |
4018 | } |
4019 | ||
c0692b8f JB |
4020 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
4021 | struct genl_info *info, | |
3dc27d25 JB |
4022 | struct cfg80211_crypto_settings *settings, |
4023 | int cipher_limit) | |
b23aa676 | 4024 | { |
c0b2bbd8 JB |
4025 | memset(settings, 0, sizeof(*settings)); |
4026 | ||
b23aa676 SO |
4027 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
4028 | ||
c0692b8f JB |
4029 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
4030 | u16 proto; | |
4031 | proto = nla_get_u16( | |
4032 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
4033 | settings->control_port_ethertype = cpu_to_be16(proto); | |
4034 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
4035 | proto != ETH_P_PAE) | |
4036 | return -EINVAL; | |
4037 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
4038 | settings->control_port_no_encrypt = true; | |
4039 | } else | |
4040 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
4041 | ||
b23aa676 SO |
4042 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
4043 | void *data; | |
4044 | int len, i; | |
4045 | ||
4046 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4047 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4048 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
4049 | ||
4050 | if (len % sizeof(u32)) | |
4051 | return -EINVAL; | |
4052 | ||
3dc27d25 | 4053 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
4054 | return -EINVAL; |
4055 | ||
4056 | memcpy(settings->ciphers_pairwise, data, len); | |
4057 | ||
4058 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
4059 | if (!nl80211_valid_cipher_suite( | |
4060 | settings->ciphers_pairwise[i])) | |
4061 | return -EINVAL; | |
4062 | } | |
4063 | ||
4064 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
4065 | settings->cipher_group = | |
4066 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
4067 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) | |
4068 | return -EINVAL; | |
4069 | } | |
4070 | ||
4071 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
4072 | settings->wpa_versions = | |
4073 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
4074 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
4075 | return -EINVAL; | |
4076 | } | |
4077 | ||
4078 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
4079 | void *data; | |
4080 | int len, i; | |
4081 | ||
4082 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4083 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4084 | settings->n_akm_suites = len / sizeof(u32); | |
4085 | ||
4086 | if (len % sizeof(u32)) | |
4087 | return -EINVAL; | |
4088 | ||
4089 | memcpy(settings->akm_suites, data, len); | |
4090 | ||
4091 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
4092 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) | |
4093 | return -EINVAL; | |
4094 | } | |
4095 | ||
4096 | return 0; | |
4097 | } | |
4098 | ||
636a5d36 JM |
4099 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
4100 | { | |
4c476991 JB |
4101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4102 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4103 | struct cfg80211_crypto_settings crypto; |
f444de05 | 4104 | struct ieee80211_channel *chan; |
3e5d7649 | 4105 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
4106 | int err, ssid_len, ie_len = 0; |
4107 | bool use_mfp = false; | |
636a5d36 | 4108 | |
f4a11bb0 JB |
4109 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4110 | return -EINVAL; | |
4111 | ||
4112 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
4113 | !info->attrs[NL80211_ATTR_SSID] || |
4114 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
4115 | return -EINVAL; |
4116 | ||
4c476991 JB |
4117 | if (!rdev->ops->assoc) |
4118 | return -EOPNOTSUPP; | |
636a5d36 | 4119 | |
074ac8df | 4120 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4121 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4122 | return -EOPNOTSUPP; | |
eec60b03 | 4123 | |
19957bb3 | 4124 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4125 | |
19957bb3 JB |
4126 | chan = ieee80211_get_channel(&rdev->wiphy, |
4127 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
4128 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4129 | return -EINVAL; | |
636a5d36 | 4130 | |
19957bb3 JB |
4131 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4132 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4133 | |
4134 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4135 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4136 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4137 | } |
4138 | ||
dc6382ce | 4139 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 4140 | enum nl80211_mfp mfp = |
dc6382ce | 4141 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 4142 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 4143 | use_mfp = true; |
4c476991 JB |
4144 | else if (mfp != NL80211_MFP_NO) |
4145 | return -EINVAL; | |
dc6382ce JM |
4146 | } |
4147 | ||
3e5d7649 JB |
4148 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
4149 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
4150 | ||
c0692b8f | 4151 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 4152 | if (!err) |
3e5d7649 JB |
4153 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
4154 | ssid, ssid_len, ie, ie_len, use_mfp, | |
19957bb3 | 4155 | &crypto); |
636a5d36 | 4156 | |
636a5d36 JM |
4157 | return err; |
4158 | } | |
4159 | ||
4160 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
4161 | { | |
4c476991 JB |
4162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4163 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4164 | const u8 *ie = NULL, *bssid; |
4c476991 | 4165 | int ie_len = 0; |
19957bb3 | 4166 | u16 reason_code; |
d5cdfacb | 4167 | bool local_state_change; |
636a5d36 | 4168 | |
f4a11bb0 JB |
4169 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4170 | return -EINVAL; | |
4171 | ||
4172 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4173 | return -EINVAL; | |
4174 | ||
4175 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4176 | return -EINVAL; | |
4177 | ||
4c476991 JB |
4178 | if (!rdev->ops->deauth) |
4179 | return -EOPNOTSUPP; | |
636a5d36 | 4180 | |
074ac8df | 4181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4183 | return -EOPNOTSUPP; | |
eec60b03 | 4184 | |
19957bb3 | 4185 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4186 | |
19957bb3 JB |
4187 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
4188 | if (reason_code == 0) { | |
f4a11bb0 | 4189 | /* Reason Code 0 is reserved */ |
4c476991 | 4190 | return -EINVAL; |
255e737e | 4191 | } |
636a5d36 JM |
4192 | |
4193 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4194 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4195 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4196 | } |
4197 | ||
d5cdfacb JM |
4198 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4199 | ||
4c476991 JB |
4200 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
4201 | local_state_change); | |
636a5d36 JM |
4202 | } |
4203 | ||
4204 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
4205 | { | |
4c476991 JB |
4206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4207 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4208 | const u8 *ie = NULL, *bssid; |
4c476991 | 4209 | int ie_len = 0; |
19957bb3 | 4210 | u16 reason_code; |
d5cdfacb | 4211 | bool local_state_change; |
636a5d36 | 4212 | |
f4a11bb0 JB |
4213 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4214 | return -EINVAL; | |
4215 | ||
4216 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4217 | return -EINVAL; | |
4218 | ||
4219 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4220 | return -EINVAL; | |
4221 | ||
4c476991 JB |
4222 | if (!rdev->ops->disassoc) |
4223 | return -EOPNOTSUPP; | |
636a5d36 | 4224 | |
074ac8df | 4225 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4226 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4227 | return -EOPNOTSUPP; | |
eec60b03 | 4228 | |
19957bb3 | 4229 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4230 | |
19957bb3 JB |
4231 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
4232 | if (reason_code == 0) { | |
f4a11bb0 | 4233 | /* Reason Code 0 is reserved */ |
4c476991 | 4234 | return -EINVAL; |
255e737e | 4235 | } |
636a5d36 JM |
4236 | |
4237 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4238 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4239 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4240 | } |
4241 | ||
d5cdfacb JM |
4242 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4243 | ||
4c476991 JB |
4244 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
4245 | local_state_change); | |
636a5d36 JM |
4246 | } |
4247 | ||
dd5b4cc7 FF |
4248 | static bool |
4249 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
4250 | int mcast_rate[IEEE80211_NUM_BANDS], | |
4251 | int rateval) | |
4252 | { | |
4253 | struct wiphy *wiphy = &rdev->wiphy; | |
4254 | bool found = false; | |
4255 | int band, i; | |
4256 | ||
4257 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
4258 | struct ieee80211_supported_band *sband; | |
4259 | ||
4260 | sband = wiphy->bands[band]; | |
4261 | if (!sband) | |
4262 | continue; | |
4263 | ||
4264 | for (i = 0; i < sband->n_bitrates; i++) { | |
4265 | if (sband->bitrates[i].bitrate == rateval) { | |
4266 | mcast_rate[band] = i + 1; | |
4267 | found = true; | |
4268 | break; | |
4269 | } | |
4270 | } | |
4271 | } | |
4272 | ||
4273 | return found; | |
4274 | } | |
4275 | ||
04a773ad JB |
4276 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
4277 | { | |
4c476991 JB |
4278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4279 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
4280 | struct cfg80211_ibss_params ibss; |
4281 | struct wiphy *wiphy; | |
fffd0934 | 4282 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
4283 | int err; |
4284 | ||
8e30bc55 JB |
4285 | memset(&ibss, 0, sizeof(ibss)); |
4286 | ||
04a773ad JB |
4287 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4288 | return -EINVAL; | |
4289 | ||
4290 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4291 | !info->attrs[NL80211_ATTR_SSID] || | |
4292 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4293 | return -EINVAL; | |
4294 | ||
8e30bc55 JB |
4295 | ibss.beacon_interval = 100; |
4296 | ||
4297 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
4298 | ibss.beacon_interval = | |
4299 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
4300 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
4301 | return -EINVAL; | |
4302 | } | |
4303 | ||
4c476991 JB |
4304 | if (!rdev->ops->join_ibss) |
4305 | return -EOPNOTSUPP; | |
04a773ad | 4306 | |
4c476991 JB |
4307 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
4308 | return -EOPNOTSUPP; | |
04a773ad | 4309 | |
79c97e97 | 4310 | wiphy = &rdev->wiphy; |
04a773ad JB |
4311 | |
4312 | if (info->attrs[NL80211_ATTR_MAC]) | |
4313 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4314 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4315 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4316 | ||
4317 | if (info->attrs[NL80211_ATTR_IE]) { | |
4318 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4319 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4320 | } | |
4321 | ||
4322 | ibss.channel = ieee80211_get_channel(wiphy, | |
4323 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4324 | if (!ibss.channel || | |
4325 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | |
4c476991 JB |
4326 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
4327 | return -EINVAL; | |
04a773ad JB |
4328 | |
4329 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | |
fffd0934 JB |
4330 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
4331 | ||
fbd2c8dc TP |
4332 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4333 | u8 *rates = | |
4334 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4335 | int n_rates = | |
4336 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4337 | struct ieee80211_supported_band *sband = | |
4338 | wiphy->bands[ibss.channel->band]; | |
4339 | int i, j; | |
4340 | ||
4c476991 JB |
4341 | if (n_rates == 0) |
4342 | return -EINVAL; | |
fbd2c8dc TP |
4343 | |
4344 | for (i = 0; i < n_rates; i++) { | |
4345 | int rate = (rates[i] & 0x7f) * 5; | |
4346 | bool found = false; | |
4347 | ||
4348 | for (j = 0; j < sband->n_bitrates; j++) { | |
4349 | if (sband->bitrates[j].bitrate == rate) { | |
4350 | found = true; | |
4351 | ibss.basic_rates |= BIT(j); | |
4352 | break; | |
4353 | } | |
4354 | } | |
4c476991 JB |
4355 | if (!found) |
4356 | return -EINVAL; | |
fbd2c8dc | 4357 | } |
fbd2c8dc | 4358 | } |
dd5b4cc7 FF |
4359 | |
4360 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
4361 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
4362 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
4363 | return -EINVAL; | |
fbd2c8dc | 4364 | |
4c476991 JB |
4365 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4366 | connkeys = nl80211_parse_connkeys(rdev, | |
4367 | info->attrs[NL80211_ATTR_KEYS]); | |
4368 | if (IS_ERR(connkeys)) | |
4369 | return PTR_ERR(connkeys); | |
4370 | } | |
04a773ad | 4371 | |
4c476991 | 4372 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
4373 | if (err) |
4374 | kfree(connkeys); | |
04a773ad JB |
4375 | return err; |
4376 | } | |
4377 | ||
4378 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
4379 | { | |
4c476991 JB |
4380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4381 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 4382 | |
4c476991 JB |
4383 | if (!rdev->ops->leave_ibss) |
4384 | return -EOPNOTSUPP; | |
04a773ad | 4385 | |
4c476991 JB |
4386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
4387 | return -EOPNOTSUPP; | |
04a773ad | 4388 | |
4c476991 | 4389 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
4390 | } |
4391 | ||
aff89a9b JB |
4392 | #ifdef CONFIG_NL80211_TESTMODE |
4393 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
4394 | .name = "testmode", | |
4395 | }; | |
4396 | ||
4397 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
4398 | { | |
4c476991 | 4399 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
4400 | int err; |
4401 | ||
4402 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
4403 | return -EINVAL; | |
4404 | ||
aff89a9b JB |
4405 | err = -EOPNOTSUPP; |
4406 | if (rdev->ops->testmode_cmd) { | |
4407 | rdev->testmode_info = info; | |
4408 | err = rdev->ops->testmode_cmd(&rdev->wiphy, | |
4409 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | |
4410 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
4411 | rdev->testmode_info = NULL; | |
4412 | } | |
4413 | ||
aff89a9b JB |
4414 | return err; |
4415 | } | |
4416 | ||
71063f0e WYG |
4417 | static int nl80211_testmode_dump(struct sk_buff *skb, |
4418 | struct netlink_callback *cb) | |
4419 | { | |
4420 | struct cfg80211_registered_device *dev; | |
4421 | int err; | |
4422 | long phy_idx; | |
4423 | void *data = NULL; | |
4424 | int data_len = 0; | |
4425 | ||
4426 | if (cb->args[0]) { | |
4427 | /* | |
4428 | * 0 is a valid index, but not valid for args[0], | |
4429 | * so we need to offset by 1. | |
4430 | */ | |
4431 | phy_idx = cb->args[0] - 1; | |
4432 | } else { | |
4433 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
4434 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
4435 | nl80211_policy); | |
4436 | if (err) | |
4437 | return err; | |
4438 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) | |
4439 | return -EINVAL; | |
4440 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); | |
4441 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) | |
4442 | cb->args[1] = | |
4443 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
4444 | } | |
4445 | ||
4446 | if (cb->args[1]) { | |
4447 | data = nla_data((void *)cb->args[1]); | |
4448 | data_len = nla_len((void *)cb->args[1]); | |
4449 | } | |
4450 | ||
4451 | mutex_lock(&cfg80211_mutex); | |
4452 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); | |
4453 | if (!dev) { | |
4454 | mutex_unlock(&cfg80211_mutex); | |
4455 | return -ENOENT; | |
4456 | } | |
4457 | cfg80211_lock_rdev(dev); | |
4458 | mutex_unlock(&cfg80211_mutex); | |
4459 | ||
4460 | if (!dev->ops->testmode_dump) { | |
4461 | err = -EOPNOTSUPP; | |
4462 | goto out_err; | |
4463 | } | |
4464 | ||
4465 | while (1) { | |
4466 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, | |
4467 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4468 | NL80211_CMD_TESTMODE); | |
4469 | struct nlattr *tmdata; | |
4470 | ||
4471 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { | |
4472 | genlmsg_cancel(skb, hdr); | |
4473 | break; | |
4474 | } | |
4475 | ||
4476 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
4477 | if (!tmdata) { | |
4478 | genlmsg_cancel(skb, hdr); | |
4479 | break; | |
4480 | } | |
4481 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, | |
4482 | data, data_len); | |
4483 | nla_nest_end(skb, tmdata); | |
4484 | ||
4485 | if (err == -ENOBUFS || err == -ENOENT) { | |
4486 | genlmsg_cancel(skb, hdr); | |
4487 | break; | |
4488 | } else if (err) { | |
4489 | genlmsg_cancel(skb, hdr); | |
4490 | goto out_err; | |
4491 | } | |
4492 | ||
4493 | genlmsg_end(skb, hdr); | |
4494 | } | |
4495 | ||
4496 | err = skb->len; | |
4497 | /* see above */ | |
4498 | cb->args[0] = phy_idx + 1; | |
4499 | out_err: | |
4500 | cfg80211_unlock_rdev(dev); | |
4501 | return err; | |
4502 | } | |
4503 | ||
aff89a9b JB |
4504 | static struct sk_buff * |
4505 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
4506 | int approxlen, u32 pid, u32 seq, gfp_t gfp) | |
4507 | { | |
4508 | struct sk_buff *skb; | |
4509 | void *hdr; | |
4510 | struct nlattr *data; | |
4511 | ||
4512 | skb = nlmsg_new(approxlen + 100, gfp); | |
4513 | if (!skb) | |
4514 | return NULL; | |
4515 | ||
4516 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); | |
4517 | if (!hdr) { | |
4518 | kfree_skb(skb); | |
4519 | return NULL; | |
4520 | } | |
4521 | ||
4522 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
4523 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
4524 | ||
4525 | ((void **)skb->cb)[0] = rdev; | |
4526 | ((void **)skb->cb)[1] = hdr; | |
4527 | ((void **)skb->cb)[2] = data; | |
4528 | ||
4529 | return skb; | |
4530 | ||
4531 | nla_put_failure: | |
4532 | kfree_skb(skb); | |
4533 | return NULL; | |
4534 | } | |
4535 | ||
4536 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
4537 | int approxlen) | |
4538 | { | |
4539 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4540 | ||
4541 | if (WARN_ON(!rdev->testmode_info)) | |
4542 | return NULL; | |
4543 | ||
4544 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
4545 | rdev->testmode_info->snd_pid, | |
4546 | rdev->testmode_info->snd_seq, | |
4547 | GFP_KERNEL); | |
4548 | } | |
4549 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
4550 | ||
4551 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
4552 | { | |
4553 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
4554 | void *hdr = ((void **)skb->cb)[1]; | |
4555 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4556 | ||
4557 | if (WARN_ON(!rdev->testmode_info)) { | |
4558 | kfree_skb(skb); | |
4559 | return -EINVAL; | |
4560 | } | |
4561 | ||
4562 | nla_nest_end(skb, data); | |
4563 | genlmsg_end(skb, hdr); | |
4564 | return genlmsg_reply(skb, rdev->testmode_info); | |
4565 | } | |
4566 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
4567 | ||
4568 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
4569 | int approxlen, gfp_t gfp) | |
4570 | { | |
4571 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4572 | ||
4573 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
4574 | } | |
4575 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
4576 | ||
4577 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
4578 | { | |
4579 | void *hdr = ((void **)skb->cb)[1]; | |
4580 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4581 | ||
4582 | nla_nest_end(skb, data); | |
4583 | genlmsg_end(skb, hdr); | |
4584 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
4585 | } | |
4586 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
4587 | #endif | |
4588 | ||
b23aa676 SO |
4589 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
4590 | { | |
4c476991 JB |
4591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4592 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
4593 | struct cfg80211_connect_params connect; |
4594 | struct wiphy *wiphy; | |
fffd0934 | 4595 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
4596 | int err; |
4597 | ||
4598 | memset(&connect, 0, sizeof(connect)); | |
4599 | ||
4600 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4601 | return -EINVAL; | |
4602 | ||
4603 | if (!info->attrs[NL80211_ATTR_SSID] || | |
4604 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4605 | return -EINVAL; | |
4606 | ||
4607 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
4608 | connect.auth_type = | |
4609 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
4610 | if (!nl80211_valid_auth_type(connect.auth_type)) | |
4611 | return -EINVAL; | |
4612 | } else | |
4613 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
4614 | ||
4615 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
4616 | ||
c0692b8f | 4617 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 4618 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
4619 | if (err) |
4620 | return err; | |
b23aa676 | 4621 | |
074ac8df | 4622 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4623 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4624 | return -EOPNOTSUPP; | |
b23aa676 | 4625 | |
79c97e97 | 4626 | wiphy = &rdev->wiphy; |
b23aa676 | 4627 | |
b23aa676 SO |
4628 | if (info->attrs[NL80211_ATTR_MAC]) |
4629 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4630 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4631 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4632 | ||
4633 | if (info->attrs[NL80211_ATTR_IE]) { | |
4634 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4635 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4636 | } | |
4637 | ||
4638 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
4639 | connect.channel = | |
4640 | ieee80211_get_channel(wiphy, | |
4641 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4642 | if (!connect.channel || | |
4c476991 JB |
4643 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
4644 | return -EINVAL; | |
b23aa676 SO |
4645 | } |
4646 | ||
fffd0934 JB |
4647 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4648 | connkeys = nl80211_parse_connkeys(rdev, | |
4649 | info->attrs[NL80211_ATTR_KEYS]); | |
4c476991 JB |
4650 | if (IS_ERR(connkeys)) |
4651 | return PTR_ERR(connkeys); | |
fffd0934 JB |
4652 | } |
4653 | ||
4654 | err = cfg80211_connect(rdev, dev, &connect, connkeys); | |
fffd0934 JB |
4655 | if (err) |
4656 | kfree(connkeys); | |
b23aa676 SO |
4657 | return err; |
4658 | } | |
4659 | ||
4660 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
4661 | { | |
4c476991 JB |
4662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4663 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
4664 | u16 reason; |
4665 | ||
4666 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4667 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
4668 | else | |
4669 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4670 | ||
4671 | if (reason == 0) | |
4672 | return -EINVAL; | |
4673 | ||
074ac8df | 4674 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4675 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4676 | return -EOPNOTSUPP; | |
b23aa676 | 4677 | |
4c476991 | 4678 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
4679 | } |
4680 | ||
463d0183 JB |
4681 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
4682 | { | |
4c476991 | 4683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
4684 | struct net *net; |
4685 | int err; | |
4686 | u32 pid; | |
4687 | ||
4688 | if (!info->attrs[NL80211_ATTR_PID]) | |
4689 | return -EINVAL; | |
4690 | ||
4691 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
4692 | ||
463d0183 | 4693 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
4694 | if (IS_ERR(net)) |
4695 | return PTR_ERR(net); | |
463d0183 JB |
4696 | |
4697 | err = 0; | |
4698 | ||
4699 | /* check if anything to do */ | |
4c476991 JB |
4700 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
4701 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 4702 | |
463d0183 | 4703 | put_net(net); |
463d0183 JB |
4704 | return err; |
4705 | } | |
4706 | ||
67fbb16b SO |
4707 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
4708 | { | |
4c476991 | 4709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
4710 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
4711 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 4712 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
4713 | struct cfg80211_pmksa pmksa; |
4714 | ||
4715 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
4716 | ||
4717 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4718 | return -EINVAL; | |
4719 | ||
4720 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
4721 | return -EINVAL; | |
4722 | ||
67fbb16b SO |
4723 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
4724 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4725 | ||
074ac8df | 4726 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4727 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4728 | return -EOPNOTSUPP; | |
67fbb16b SO |
4729 | |
4730 | switch (info->genlhdr->cmd) { | |
4731 | case NL80211_CMD_SET_PMKSA: | |
4732 | rdev_ops = rdev->ops->set_pmksa; | |
4733 | break; | |
4734 | case NL80211_CMD_DEL_PMKSA: | |
4735 | rdev_ops = rdev->ops->del_pmksa; | |
4736 | break; | |
4737 | default: | |
4738 | WARN_ON(1); | |
4739 | break; | |
4740 | } | |
4741 | ||
4c476991 JB |
4742 | if (!rdev_ops) |
4743 | return -EOPNOTSUPP; | |
67fbb16b | 4744 | |
4c476991 | 4745 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
4746 | } |
4747 | ||
4748 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
4749 | { | |
4c476991 JB |
4750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4751 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 4752 | |
074ac8df | 4753 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4754 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4755 | return -EOPNOTSUPP; | |
67fbb16b | 4756 | |
4c476991 JB |
4757 | if (!rdev->ops->flush_pmksa) |
4758 | return -EOPNOTSUPP; | |
67fbb16b | 4759 | |
4c476991 | 4760 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
67fbb16b SO |
4761 | } |
4762 | ||
9588bbd5 JM |
4763 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
4764 | struct genl_info *info) | |
4765 | { | |
4c476991 JB |
4766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4767 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 JM |
4768 | struct ieee80211_channel *chan; |
4769 | struct sk_buff *msg; | |
4770 | void *hdr; | |
4771 | u64 cookie; | |
4772 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
4773 | u32 freq, duration; | |
4774 | int err; | |
4775 | ||
4776 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4777 | !info->attrs[NL80211_ATTR_DURATION]) | |
4778 | return -EINVAL; | |
4779 | ||
4780 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
4781 | ||
4782 | /* | |
4783 | * We should be on that channel for at least one jiffie, | |
4784 | * and more than 5 seconds seems excessive. | |
4785 | */ | |
a293911d JB |
4786 | if (!duration || !msecs_to_jiffies(duration) || |
4787 | duration > rdev->wiphy.max_remain_on_channel_duration) | |
9588bbd5 JM |
4788 | return -EINVAL; |
4789 | ||
4c476991 JB |
4790 | if (!rdev->ops->remain_on_channel) |
4791 | return -EOPNOTSUPP; | |
9588bbd5 | 4792 | |
9588bbd5 JM |
4793 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
4794 | channel_type = nla_get_u32( | |
4795 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
4796 | if (channel_type != NL80211_CHAN_NO_HT && | |
4797 | channel_type != NL80211_CHAN_HT20 && | |
4798 | channel_type != NL80211_CHAN_HT40PLUS && | |
4c476991 JB |
4799 | channel_type != NL80211_CHAN_HT40MINUS) |
4800 | return -EINVAL; | |
9588bbd5 JM |
4801 | } |
4802 | ||
4803 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
4804 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
4805 | if (chan == NULL) |
4806 | return -EINVAL; | |
9588bbd5 JM |
4807 | |
4808 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
4809 | if (!msg) |
4810 | return -ENOMEM; | |
9588bbd5 JM |
4811 | |
4812 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
4813 | NL80211_CMD_REMAIN_ON_CHANNEL); | |
4814 | ||
4815 | if (IS_ERR(hdr)) { | |
4816 | err = PTR_ERR(hdr); | |
4817 | goto free_msg; | |
4818 | } | |
4819 | ||
4820 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, | |
4821 | channel_type, duration, &cookie); | |
4822 | ||
4823 | if (err) | |
4824 | goto free_msg; | |
4825 | ||
4826 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
4827 | ||
4828 | genlmsg_end(msg, hdr); | |
4c476991 JB |
4829 | |
4830 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
4831 | |
4832 | nla_put_failure: | |
4833 | err = -ENOBUFS; | |
4834 | free_msg: | |
4835 | nlmsg_free(msg); | |
9588bbd5 JM |
4836 | return err; |
4837 | } | |
4838 | ||
4839 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
4840 | struct genl_info *info) | |
4841 | { | |
4c476991 JB |
4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4843 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 | 4844 | u64 cookie; |
9588bbd5 JM |
4845 | |
4846 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
4847 | return -EINVAL; | |
4848 | ||
4c476991 JB |
4849 | if (!rdev->ops->cancel_remain_on_channel) |
4850 | return -EOPNOTSUPP; | |
9588bbd5 | 4851 | |
9588bbd5 JM |
4852 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
4853 | ||
4c476991 | 4854 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
9588bbd5 JM |
4855 | } |
4856 | ||
13ae75b1 JM |
4857 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
4858 | u8 *rates, u8 rates_len) | |
4859 | { | |
4860 | u8 i; | |
4861 | u32 mask = 0; | |
4862 | ||
4863 | for (i = 0; i < rates_len; i++) { | |
4864 | int rate = (rates[i] & 0x7f) * 5; | |
4865 | int ridx; | |
4866 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
4867 | struct ieee80211_rate *srate = | |
4868 | &sband->bitrates[ridx]; | |
4869 | if (rate == srate->bitrate) { | |
4870 | mask |= 1 << ridx; | |
4871 | break; | |
4872 | } | |
4873 | } | |
4874 | if (ridx == sband->n_bitrates) | |
4875 | return 0; /* rate not found */ | |
4876 | } | |
4877 | ||
4878 | return mask; | |
4879 | } | |
4880 | ||
b54452b0 | 4881 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
4882 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
4883 | .len = NL80211_MAX_SUPP_RATES }, | |
4884 | }; | |
4885 | ||
4886 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
4887 | struct genl_info *info) | |
4888 | { | |
4889 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 4890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 4891 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
4892 | int rem, i; |
4893 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
4894 | struct nlattr *tx_rates; |
4895 | struct ieee80211_supported_band *sband; | |
4896 | ||
4897 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
4898 | return -EINVAL; | |
4899 | ||
4c476991 JB |
4900 | if (!rdev->ops->set_bitrate_mask) |
4901 | return -EOPNOTSUPP; | |
13ae75b1 JM |
4902 | |
4903 | memset(&mask, 0, sizeof(mask)); | |
4904 | /* Default to all rates enabled */ | |
4905 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
4906 | sband = rdev->wiphy.bands[i]; | |
4907 | mask.control[i].legacy = | |
4908 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
4909 | } | |
4910 | ||
4911 | /* | |
4912 | * The nested attribute uses enum nl80211_band as the index. This maps | |
4913 | * directly to the enum ieee80211_band values used in cfg80211. | |
4914 | */ | |
4915 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) | |
4916 | { | |
4917 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
4918 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
4919 | return -EINVAL; | |
13ae75b1 | 4920 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
4921 | if (sband == NULL) |
4922 | return -EINVAL; | |
13ae75b1 JM |
4923 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
4924 | nla_len(tx_rates), nl80211_txattr_policy); | |
4925 | if (tb[NL80211_TXRATE_LEGACY]) { | |
4926 | mask.control[band].legacy = rateset_to_mask( | |
4927 | sband, | |
4928 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
4929 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
4c476991 JB |
4930 | if (mask.control[band].legacy == 0) |
4931 | return -EINVAL; | |
13ae75b1 JM |
4932 | } |
4933 | } | |
4934 | ||
4c476991 | 4935 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
13ae75b1 JM |
4936 | } |
4937 | ||
2e161f78 | 4938 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 4939 | { |
4c476991 JB |
4940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4941 | struct net_device *dev = info->user_ptr[1]; | |
2e161f78 | 4942 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
4943 | |
4944 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
4945 | return -EINVAL; | |
4946 | ||
2e161f78 JB |
4947 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
4948 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 4949 | |
9d38d85d | 4950 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 4951 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
4952 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
4953 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4954 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 4955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4956 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4957 | return -EOPNOTSUPP; | |
026331c4 JM |
4958 | |
4959 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
4960 | if (!rdev->ops->mgmt_tx) |
4961 | return -EOPNOTSUPP; | |
026331c4 | 4962 | |
4c476991 | 4963 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
2e161f78 | 4964 | frame_type, |
026331c4 JM |
4965 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
4966 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
4967 | } |
4968 | ||
2e161f78 | 4969 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 4970 | { |
4c476991 JB |
4971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4972 | struct net_device *dev = info->user_ptr[1]; | |
026331c4 JM |
4973 | struct ieee80211_channel *chan; |
4974 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
252aa631 | 4975 | bool channel_type_valid = false; |
026331c4 JM |
4976 | u32 freq; |
4977 | int err; | |
4978 | void *hdr; | |
4979 | u64 cookie; | |
4980 | struct sk_buff *msg; | |
f7ca38df JB |
4981 | unsigned int wait = 0; |
4982 | bool offchan; | |
026331c4 JM |
4983 | |
4984 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
4985 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
4986 | return -EINVAL; | |
4987 | ||
4c476991 JB |
4988 | if (!rdev->ops->mgmt_tx) |
4989 | return -EOPNOTSUPP; | |
026331c4 | 4990 | |
9d38d85d | 4991 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 4992 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
4993 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
4994 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 4996 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4997 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4998 | return -EOPNOTSUPP; | |
026331c4 | 4999 | |
f7ca38df JB |
5000 | if (info->attrs[NL80211_ATTR_DURATION]) { |
5001 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
5002 | return -EINVAL; | |
5003 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
5004 | } | |
5005 | ||
026331c4 JM |
5006 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
5007 | channel_type = nla_get_u32( | |
5008 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
5009 | if (channel_type != NL80211_CHAN_NO_HT && | |
5010 | channel_type != NL80211_CHAN_HT20 && | |
5011 | channel_type != NL80211_CHAN_HT40PLUS && | |
4c476991 JB |
5012 | channel_type != NL80211_CHAN_HT40MINUS) |
5013 | return -EINVAL; | |
252aa631 | 5014 | channel_type_valid = true; |
026331c4 JM |
5015 | } |
5016 | ||
f7ca38df JB |
5017 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
5018 | ||
026331c4 JM |
5019 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
5020 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
5021 | if (chan == NULL) |
5022 | return -EINVAL; | |
026331c4 JM |
5023 | |
5024 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5025 | if (!msg) |
5026 | return -ENOMEM; | |
026331c4 JM |
5027 | |
5028 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2e161f78 | 5029 | NL80211_CMD_FRAME); |
026331c4 JM |
5030 | |
5031 | if (IS_ERR(hdr)) { | |
5032 | err = PTR_ERR(hdr); | |
5033 | goto free_msg; | |
5034 | } | |
f7ca38df JB |
5035 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
5036 | channel_type_valid, wait, | |
2e161f78 JB |
5037 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
5038 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
5039 | &cookie); | |
026331c4 JM |
5040 | if (err) |
5041 | goto free_msg; | |
5042 | ||
5043 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
5044 | ||
5045 | genlmsg_end(msg, hdr); | |
4c476991 | 5046 | return genlmsg_reply(msg, info); |
026331c4 JM |
5047 | |
5048 | nla_put_failure: | |
5049 | err = -ENOBUFS; | |
5050 | free_msg: | |
5051 | nlmsg_free(msg); | |
026331c4 JM |
5052 | return err; |
5053 | } | |
5054 | ||
f7ca38df JB |
5055 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
5056 | { | |
5057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5058 | struct net_device *dev = info->user_ptr[1]; | |
5059 | u64 cookie; | |
5060 | ||
5061 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
5062 | return -EINVAL; | |
5063 | ||
5064 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
5065 | return -EOPNOTSUPP; | |
5066 | ||
5067 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | |
5068 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
5069 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && | |
5070 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5071 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
5072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5073 | return -EOPNOTSUPP; | |
5074 | ||
5075 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
5076 | ||
5077 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); | |
5078 | } | |
5079 | ||
ffb9eb3d KV |
5080 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
5081 | { | |
4c476991 | 5082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 5083 | struct wireless_dev *wdev; |
4c476991 | 5084 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
5085 | u8 ps_state; |
5086 | bool state; | |
5087 | int err; | |
5088 | ||
4c476991 JB |
5089 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
5090 | return -EINVAL; | |
ffb9eb3d KV |
5091 | |
5092 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
5093 | ||
4c476991 JB |
5094 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
5095 | return -EINVAL; | |
ffb9eb3d KV |
5096 | |
5097 | wdev = dev->ieee80211_ptr; | |
5098 | ||
4c476991 JB |
5099 | if (!rdev->ops->set_power_mgmt) |
5100 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
5101 | |
5102 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
5103 | ||
5104 | if (state == wdev->ps) | |
4c476991 | 5105 | return 0; |
ffb9eb3d | 5106 | |
4c476991 JB |
5107 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
5108 | wdev->ps_timeout); | |
5109 | if (!err) | |
5110 | wdev->ps = state; | |
ffb9eb3d KV |
5111 | return err; |
5112 | } | |
5113 | ||
5114 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
5115 | { | |
4c476991 | 5116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
5117 | enum nl80211_ps_state ps_state; |
5118 | struct wireless_dev *wdev; | |
4c476991 | 5119 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
5120 | struct sk_buff *msg; |
5121 | void *hdr; | |
5122 | int err; | |
5123 | ||
ffb9eb3d KV |
5124 | wdev = dev->ieee80211_ptr; |
5125 | ||
4c476991 JB |
5126 | if (!rdev->ops->set_power_mgmt) |
5127 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
5128 | |
5129 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5130 | if (!msg) |
5131 | return -ENOMEM; | |
ffb9eb3d KV |
5132 | |
5133 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5134 | NL80211_CMD_GET_POWER_SAVE); | |
5135 | if (!hdr) { | |
4c476991 | 5136 | err = -ENOBUFS; |
ffb9eb3d KV |
5137 | goto free_msg; |
5138 | } | |
5139 | ||
5140 | if (wdev->ps) | |
5141 | ps_state = NL80211_PS_ENABLED; | |
5142 | else | |
5143 | ps_state = NL80211_PS_DISABLED; | |
5144 | ||
5145 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); | |
5146 | ||
5147 | genlmsg_end(msg, hdr); | |
4c476991 | 5148 | return genlmsg_reply(msg, info); |
ffb9eb3d | 5149 | |
4c476991 | 5150 | nla_put_failure: |
ffb9eb3d | 5151 | err = -ENOBUFS; |
4c476991 | 5152 | free_msg: |
ffb9eb3d | 5153 | nlmsg_free(msg); |
ffb9eb3d KV |
5154 | return err; |
5155 | } | |
5156 | ||
d6dc1a38 JO |
5157 | static struct nla_policy |
5158 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
5159 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
5160 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
5161 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
5162 | }; | |
5163 | ||
5164 | static int nl80211_set_cqm_rssi(struct genl_info *info, | |
5165 | s32 threshold, u32 hysteresis) | |
5166 | { | |
4c476991 | 5167 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 5168 | struct wireless_dev *wdev; |
4c476991 | 5169 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
5170 | |
5171 | if (threshold > 0) | |
5172 | return -EINVAL; | |
5173 | ||
d6dc1a38 JO |
5174 | wdev = dev->ieee80211_ptr; |
5175 | ||
4c476991 JB |
5176 | if (!rdev->ops->set_cqm_rssi_config) |
5177 | return -EOPNOTSUPP; | |
d6dc1a38 | 5178 | |
074ac8df | 5179 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5180 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5181 | return -EOPNOTSUPP; | |
d6dc1a38 | 5182 | |
4c476991 JB |
5183 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
5184 | threshold, hysteresis); | |
d6dc1a38 JO |
5185 | } |
5186 | ||
5187 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
5188 | { | |
5189 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
5190 | struct nlattr *cqm; | |
5191 | int err; | |
5192 | ||
5193 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
5194 | if (!cqm) { | |
5195 | err = -EINVAL; | |
5196 | goto out; | |
5197 | } | |
5198 | ||
5199 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
5200 | nl80211_attr_cqm_policy); | |
5201 | if (err) | |
5202 | goto out; | |
5203 | ||
5204 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
5205 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
5206 | s32 threshold; | |
5207 | u32 hysteresis; | |
5208 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
5209 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
5210 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
5211 | } else | |
5212 | err = -EINVAL; | |
5213 | ||
5214 | out: | |
5215 | return err; | |
5216 | } | |
5217 | ||
29cbe68c JB |
5218 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
5219 | { | |
5220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5221 | struct net_device *dev = info->user_ptr[1]; | |
5222 | struct mesh_config cfg; | |
c80d545d | 5223 | struct mesh_setup setup; |
29cbe68c JB |
5224 | int err; |
5225 | ||
5226 | /* start with default */ | |
5227 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 5228 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 5229 | |
24bdd9f4 | 5230 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 5231 | /* and parse parameters if given */ |
24bdd9f4 | 5232 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
5233 | if (err) |
5234 | return err; | |
5235 | } | |
5236 | ||
5237 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
5238 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
5239 | return -EINVAL; | |
5240 | ||
c80d545d JC |
5241 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
5242 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
5243 | ||
5244 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { | |
5245 | /* parse additional setup parameters if given */ | |
5246 | err = nl80211_parse_mesh_setup(info, &setup); | |
5247 | if (err) | |
5248 | return err; | |
5249 | } | |
5250 | ||
5251 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); | |
29cbe68c JB |
5252 | } |
5253 | ||
5254 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
5255 | { | |
5256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5257 | struct net_device *dev = info->user_ptr[1]; | |
5258 | ||
5259 | return cfg80211_leave_mesh(rdev, dev); | |
5260 | } | |
5261 | ||
ff1b6e69 JB |
5262 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
5263 | { | |
5264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5265 | struct sk_buff *msg; | |
5266 | void *hdr; | |
5267 | ||
5268 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
5269 | return -EOPNOTSUPP; | |
5270 | ||
5271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5272 | if (!msg) | |
5273 | return -ENOMEM; | |
5274 | ||
5275 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5276 | NL80211_CMD_GET_WOWLAN); | |
5277 | if (!hdr) | |
5278 | goto nla_put_failure; | |
5279 | ||
5280 | if (rdev->wowlan) { | |
5281 | struct nlattr *nl_wowlan; | |
5282 | ||
5283 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
5284 | if (!nl_wowlan) | |
5285 | goto nla_put_failure; | |
5286 | ||
5287 | if (rdev->wowlan->any) | |
5288 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); | |
5289 | if (rdev->wowlan->disconnect) | |
5290 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); | |
5291 | if (rdev->wowlan->magic_pkt) | |
5292 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); | |
77dbbb13 JB |
5293 | if (rdev->wowlan->gtk_rekey_failure) |
5294 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); | |
5295 | if (rdev->wowlan->eap_identity_req) | |
5296 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); | |
5297 | if (rdev->wowlan->four_way_handshake) | |
5298 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); | |
5299 | if (rdev->wowlan->rfkill_release) | |
5300 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); | |
ff1b6e69 JB |
5301 | if (rdev->wowlan->n_patterns) { |
5302 | struct nlattr *nl_pats, *nl_pat; | |
5303 | int i, pat_len; | |
5304 | ||
5305 | nl_pats = nla_nest_start(msg, | |
5306 | NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
5307 | if (!nl_pats) | |
5308 | goto nla_put_failure; | |
5309 | ||
5310 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
5311 | nl_pat = nla_nest_start(msg, i + 1); | |
5312 | if (!nl_pat) | |
5313 | goto nla_put_failure; | |
5314 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
5315 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
5316 | DIV_ROUND_UP(pat_len, 8), | |
5317 | rdev->wowlan->patterns[i].mask); | |
5318 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
5319 | pat_len, | |
5320 | rdev->wowlan->patterns[i].pattern); | |
5321 | nla_nest_end(msg, nl_pat); | |
5322 | } | |
5323 | nla_nest_end(msg, nl_pats); | |
5324 | } | |
5325 | ||
5326 | nla_nest_end(msg, nl_wowlan); | |
5327 | } | |
5328 | ||
5329 | genlmsg_end(msg, hdr); | |
5330 | return genlmsg_reply(msg, info); | |
5331 | ||
5332 | nla_put_failure: | |
5333 | nlmsg_free(msg); | |
5334 | return -ENOBUFS; | |
5335 | } | |
5336 | ||
5337 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | |
5338 | { | |
5339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5340 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
5341 | struct cfg80211_wowlan no_triggers = {}; | |
5342 | struct cfg80211_wowlan new_triggers = {}; | |
5343 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; | |
5344 | int err, i; | |
5345 | ||
5346 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
5347 | return -EOPNOTSUPP; | |
5348 | ||
5349 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) | |
5350 | goto no_triggers; | |
5351 | ||
5352 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
5353 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
5354 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
5355 | nl80211_wowlan_policy); | |
5356 | if (err) | |
5357 | return err; | |
5358 | ||
5359 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
5360 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
5361 | return -EINVAL; | |
5362 | new_triggers.any = true; | |
5363 | } | |
5364 | ||
5365 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
5366 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
5367 | return -EINVAL; | |
5368 | new_triggers.disconnect = true; | |
5369 | } | |
5370 | ||
5371 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
5372 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
5373 | return -EINVAL; | |
5374 | new_triggers.magic_pkt = true; | |
5375 | } | |
5376 | ||
77dbbb13 JB |
5377 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
5378 | return -EINVAL; | |
5379 | ||
5380 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
5381 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
5382 | return -EINVAL; | |
5383 | new_triggers.gtk_rekey_failure = true; | |
5384 | } | |
5385 | ||
5386 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
5387 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
5388 | return -EINVAL; | |
5389 | new_triggers.eap_identity_req = true; | |
5390 | } | |
5391 | ||
5392 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
5393 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
5394 | return -EINVAL; | |
5395 | new_triggers.four_way_handshake = true; | |
5396 | } | |
5397 | ||
5398 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
5399 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
5400 | return -EINVAL; | |
5401 | new_triggers.rfkill_release = true; | |
5402 | } | |
5403 | ||
ff1b6e69 JB |
5404 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
5405 | struct nlattr *pat; | |
5406 | int n_patterns = 0; | |
5407 | int rem, pat_len, mask_len; | |
5408 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; | |
5409 | ||
5410 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
5411 | rem) | |
5412 | n_patterns++; | |
5413 | if (n_patterns > wowlan->n_patterns) | |
5414 | return -EINVAL; | |
5415 | ||
5416 | new_triggers.patterns = kcalloc(n_patterns, | |
5417 | sizeof(new_triggers.patterns[0]), | |
5418 | GFP_KERNEL); | |
5419 | if (!new_triggers.patterns) | |
5420 | return -ENOMEM; | |
5421 | ||
5422 | new_triggers.n_patterns = n_patterns; | |
5423 | i = 0; | |
5424 | ||
5425 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
5426 | rem) { | |
5427 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
5428 | nla_data(pat), nla_len(pat), NULL); | |
5429 | err = -EINVAL; | |
5430 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
5431 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
5432 | goto error; | |
5433 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
5434 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
5435 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
5436 | mask_len) | |
5437 | goto error; | |
5438 | if (pat_len > wowlan->pattern_max_len || | |
5439 | pat_len < wowlan->pattern_min_len) | |
5440 | goto error; | |
5441 | ||
5442 | new_triggers.patterns[i].mask = | |
5443 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
5444 | if (!new_triggers.patterns[i].mask) { | |
5445 | err = -ENOMEM; | |
5446 | goto error; | |
5447 | } | |
5448 | new_triggers.patterns[i].pattern = | |
5449 | new_triggers.patterns[i].mask + mask_len; | |
5450 | memcpy(new_triggers.patterns[i].mask, | |
5451 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
5452 | mask_len); | |
5453 | new_triggers.patterns[i].pattern_len = pat_len; | |
5454 | memcpy(new_triggers.patterns[i].pattern, | |
5455 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
5456 | pat_len); | |
5457 | i++; | |
5458 | } | |
5459 | } | |
5460 | ||
5461 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { | |
5462 | struct cfg80211_wowlan *ntrig; | |
5463 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), | |
5464 | GFP_KERNEL); | |
5465 | if (!ntrig) { | |
5466 | err = -ENOMEM; | |
5467 | goto error; | |
5468 | } | |
5469 | cfg80211_rdev_free_wowlan(rdev); | |
5470 | rdev->wowlan = ntrig; | |
5471 | } else { | |
5472 | no_triggers: | |
5473 | cfg80211_rdev_free_wowlan(rdev); | |
5474 | rdev->wowlan = NULL; | |
5475 | } | |
5476 | ||
5477 | return 0; | |
5478 | error: | |
5479 | for (i = 0; i < new_triggers.n_patterns; i++) | |
5480 | kfree(new_triggers.patterns[i].mask); | |
5481 | kfree(new_triggers.patterns); | |
5482 | return err; | |
5483 | } | |
5484 | ||
e5497d76 JB |
5485 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
5486 | { | |
5487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5488 | struct net_device *dev = info->user_ptr[1]; | |
5489 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5490 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
5491 | struct cfg80211_gtk_rekey_data rekey_data; | |
5492 | int err; | |
5493 | ||
5494 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
5495 | return -EINVAL; | |
5496 | ||
5497 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
5498 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
5499 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
5500 | nl80211_rekey_policy); | |
5501 | if (err) | |
5502 | return err; | |
5503 | ||
5504 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
5505 | return -ERANGE; | |
5506 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
5507 | return -ERANGE; | |
5508 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
5509 | return -ERANGE; | |
5510 | ||
5511 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
5512 | NL80211_KEK_LEN); | |
5513 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
5514 | NL80211_KCK_LEN); | |
5515 | memcpy(rekey_data.replay_ctr, | |
5516 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
5517 | NL80211_REPLAY_CTR_LEN); | |
5518 | ||
5519 | wdev_lock(wdev); | |
5520 | if (!wdev->current_bss) { | |
5521 | err = -ENOTCONN; | |
5522 | goto out; | |
5523 | } | |
5524 | ||
5525 | if (!rdev->ops->set_rekey_data) { | |
5526 | err = -EOPNOTSUPP; | |
5527 | goto out; | |
5528 | } | |
5529 | ||
5530 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); | |
5531 | out: | |
5532 | wdev_unlock(wdev); | |
5533 | return err; | |
5534 | } | |
5535 | ||
4c476991 JB |
5536 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
5537 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
5538 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
5539 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
5540 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
5541 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
5542 | |
5543 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
5544 | struct genl_info *info) | |
5545 | { | |
5546 | struct cfg80211_registered_device *rdev; | |
5547 | struct net_device *dev; | |
5548 | int err; | |
5549 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | |
5550 | ||
5551 | if (rtnl) | |
5552 | rtnl_lock(); | |
5553 | ||
5554 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
5555 | rdev = cfg80211_get_dev_from_info(info); | |
5556 | if (IS_ERR(rdev)) { | |
5557 | if (rtnl) | |
5558 | rtnl_unlock(); | |
5559 | return PTR_ERR(rdev); | |
5560 | } | |
5561 | info->user_ptr[0] = rdev; | |
5562 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | |
5563 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
5564 | if (err) { | |
5565 | if (rtnl) | |
5566 | rtnl_unlock(); | |
5567 | return err; | |
5568 | } | |
41265714 JB |
5569 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
5570 | !netif_running(dev)) { | |
d537f5fd JB |
5571 | cfg80211_unlock_rdev(rdev); |
5572 | dev_put(dev); | |
41265714 JB |
5573 | if (rtnl) |
5574 | rtnl_unlock(); | |
5575 | return -ENETDOWN; | |
5576 | } | |
4c476991 JB |
5577 | info->user_ptr[0] = rdev; |
5578 | info->user_ptr[1] = dev; | |
5579 | } | |
5580 | ||
5581 | return 0; | |
5582 | } | |
5583 | ||
5584 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
5585 | struct genl_info *info) | |
5586 | { | |
5587 | if (info->user_ptr[0]) | |
5588 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
5589 | if (info->user_ptr[1]) | |
5590 | dev_put(info->user_ptr[1]); | |
5591 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | |
5592 | rtnl_unlock(); | |
5593 | } | |
5594 | ||
55682965 JB |
5595 | static struct genl_ops nl80211_ops[] = { |
5596 | { | |
5597 | .cmd = NL80211_CMD_GET_WIPHY, | |
5598 | .doit = nl80211_get_wiphy, | |
5599 | .dumpit = nl80211_dump_wiphy, | |
5600 | .policy = nl80211_policy, | |
5601 | /* can be retrieved by unprivileged users */ | |
4c476991 | 5602 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
5603 | }, |
5604 | { | |
5605 | .cmd = NL80211_CMD_SET_WIPHY, | |
5606 | .doit = nl80211_set_wiphy, | |
5607 | .policy = nl80211_policy, | |
5608 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 5609 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
5610 | }, |
5611 | { | |
5612 | .cmd = NL80211_CMD_GET_INTERFACE, | |
5613 | .doit = nl80211_get_interface, | |
5614 | .dumpit = nl80211_dump_interface, | |
5615 | .policy = nl80211_policy, | |
5616 | /* can be retrieved by unprivileged users */ | |
4c476991 | 5617 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
55682965 JB |
5618 | }, |
5619 | { | |
5620 | .cmd = NL80211_CMD_SET_INTERFACE, | |
5621 | .doit = nl80211_set_interface, | |
5622 | .policy = nl80211_policy, | |
5623 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5624 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5625 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
5626 | }, |
5627 | { | |
5628 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
5629 | .doit = nl80211_new_interface, | |
5630 | .policy = nl80211_policy, | |
5631 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5632 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
5633 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
5634 | }, |
5635 | { | |
5636 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
5637 | .doit = nl80211_del_interface, | |
5638 | .policy = nl80211_policy, | |
41ade00f | 5639 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
5640 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5641 | NL80211_FLAG_NEED_RTNL, | |
41ade00f JB |
5642 | }, |
5643 | { | |
5644 | .cmd = NL80211_CMD_GET_KEY, | |
5645 | .doit = nl80211_get_key, | |
5646 | .policy = nl80211_policy, | |
5647 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5648 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5649 | NL80211_FLAG_NEED_RTNL, | |
41ade00f JB |
5650 | }, |
5651 | { | |
5652 | .cmd = NL80211_CMD_SET_KEY, | |
5653 | .doit = nl80211_set_key, | |
5654 | .policy = nl80211_policy, | |
5655 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5656 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5657 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
5658 | }, |
5659 | { | |
5660 | .cmd = NL80211_CMD_NEW_KEY, | |
5661 | .doit = nl80211_new_key, | |
5662 | .policy = nl80211_policy, | |
5663 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5664 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5665 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
5666 | }, |
5667 | { | |
5668 | .cmd = NL80211_CMD_DEL_KEY, | |
5669 | .doit = nl80211_del_key, | |
5670 | .policy = nl80211_policy, | |
55682965 | 5671 | .flags = GENL_ADMIN_PERM, |
41265714 | 5672 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5673 | NL80211_FLAG_NEED_RTNL, |
55682965 | 5674 | }, |
ed1b6cc7 JB |
5675 | { |
5676 | .cmd = NL80211_CMD_SET_BEACON, | |
5677 | .policy = nl80211_policy, | |
5678 | .flags = GENL_ADMIN_PERM, | |
5679 | .doit = nl80211_addset_beacon, | |
4c476991 JB |
5680 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5681 | NL80211_FLAG_NEED_RTNL, | |
ed1b6cc7 JB |
5682 | }, |
5683 | { | |
5684 | .cmd = NL80211_CMD_NEW_BEACON, | |
5685 | .policy = nl80211_policy, | |
5686 | .flags = GENL_ADMIN_PERM, | |
5687 | .doit = nl80211_addset_beacon, | |
4c476991 JB |
5688 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5689 | NL80211_FLAG_NEED_RTNL, | |
ed1b6cc7 JB |
5690 | }, |
5691 | { | |
5692 | .cmd = NL80211_CMD_DEL_BEACON, | |
5693 | .policy = nl80211_policy, | |
5694 | .flags = GENL_ADMIN_PERM, | |
5695 | .doit = nl80211_del_beacon, | |
4c476991 JB |
5696 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5697 | NL80211_FLAG_NEED_RTNL, | |
ed1b6cc7 | 5698 | }, |
5727ef1b JB |
5699 | { |
5700 | .cmd = NL80211_CMD_GET_STATION, | |
5701 | .doit = nl80211_get_station, | |
2ec600d6 | 5702 | .dumpit = nl80211_dump_station, |
5727ef1b | 5703 | .policy = nl80211_policy, |
4c476991 JB |
5704 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5705 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
5706 | }, |
5707 | { | |
5708 | .cmd = NL80211_CMD_SET_STATION, | |
5709 | .doit = nl80211_set_station, | |
5710 | .policy = nl80211_policy, | |
5711 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5712 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5713 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
5714 | }, |
5715 | { | |
5716 | .cmd = NL80211_CMD_NEW_STATION, | |
5717 | .doit = nl80211_new_station, | |
5718 | .policy = nl80211_policy, | |
5719 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5720 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5721 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
5722 | }, |
5723 | { | |
5724 | .cmd = NL80211_CMD_DEL_STATION, | |
5725 | .doit = nl80211_del_station, | |
5726 | .policy = nl80211_policy, | |
2ec600d6 | 5727 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
5728 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5729 | NL80211_FLAG_NEED_RTNL, | |
2ec600d6 LCC |
5730 | }, |
5731 | { | |
5732 | .cmd = NL80211_CMD_GET_MPATH, | |
5733 | .doit = nl80211_get_mpath, | |
5734 | .dumpit = nl80211_dump_mpath, | |
5735 | .policy = nl80211_policy, | |
5736 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5737 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5738 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
5739 | }, |
5740 | { | |
5741 | .cmd = NL80211_CMD_SET_MPATH, | |
5742 | .doit = nl80211_set_mpath, | |
5743 | .policy = nl80211_policy, | |
5744 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5745 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5746 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
5747 | }, |
5748 | { | |
5749 | .cmd = NL80211_CMD_NEW_MPATH, | |
5750 | .doit = nl80211_new_mpath, | |
5751 | .policy = nl80211_policy, | |
5752 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5754 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
5755 | }, |
5756 | { | |
5757 | .cmd = NL80211_CMD_DEL_MPATH, | |
5758 | .doit = nl80211_del_mpath, | |
5759 | .policy = nl80211_policy, | |
9f1ba906 | 5760 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
5761 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5762 | NL80211_FLAG_NEED_RTNL, | |
9f1ba906 JM |
5763 | }, |
5764 | { | |
5765 | .cmd = NL80211_CMD_SET_BSS, | |
5766 | .doit = nl80211_set_bss, | |
5767 | .policy = nl80211_policy, | |
b2e1b302 | 5768 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
5769 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5770 | NL80211_FLAG_NEED_RTNL, | |
b2e1b302 | 5771 | }, |
f130347c LR |
5772 | { |
5773 | .cmd = NL80211_CMD_GET_REG, | |
5774 | .doit = nl80211_get_reg, | |
5775 | .policy = nl80211_policy, | |
5776 | /* can be retrieved by unprivileged users */ | |
5777 | }, | |
b2e1b302 LR |
5778 | { |
5779 | .cmd = NL80211_CMD_SET_REG, | |
5780 | .doit = nl80211_set_reg, | |
5781 | .policy = nl80211_policy, | |
5782 | .flags = GENL_ADMIN_PERM, | |
5783 | }, | |
5784 | { | |
5785 | .cmd = NL80211_CMD_REQ_SET_REG, | |
5786 | .doit = nl80211_req_set_reg, | |
5787 | .policy = nl80211_policy, | |
93da9cc1 | 5788 | .flags = GENL_ADMIN_PERM, |
5789 | }, | |
5790 | { | |
24bdd9f4 JC |
5791 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
5792 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 5793 | .policy = nl80211_policy, |
5794 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
5795 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5796 | NL80211_FLAG_NEED_RTNL, | |
93da9cc1 | 5797 | }, |
5798 | { | |
24bdd9f4 JC |
5799 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
5800 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 5801 | .policy = nl80211_policy, |
9aed3cc1 | 5802 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 5803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5804 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 5805 | }, |
2a519311 JB |
5806 | { |
5807 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
5808 | .doit = nl80211_trigger_scan, | |
5809 | .policy = nl80211_policy, | |
5810 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5812 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
5813 | }, |
5814 | { | |
5815 | .cmd = NL80211_CMD_GET_SCAN, | |
5816 | .policy = nl80211_policy, | |
5817 | .dumpit = nl80211_dump_scan, | |
5818 | }, | |
807f8a8c LC |
5819 | { |
5820 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
5821 | .doit = nl80211_start_sched_scan, | |
5822 | .policy = nl80211_policy, | |
5823 | .flags = GENL_ADMIN_PERM, | |
5824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5825 | NL80211_FLAG_NEED_RTNL, | |
5826 | }, | |
5827 | { | |
5828 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
5829 | .doit = nl80211_stop_sched_scan, | |
5830 | .policy = nl80211_policy, | |
5831 | .flags = GENL_ADMIN_PERM, | |
5832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5833 | NL80211_FLAG_NEED_RTNL, | |
5834 | }, | |
636a5d36 JM |
5835 | { |
5836 | .cmd = NL80211_CMD_AUTHENTICATE, | |
5837 | .doit = nl80211_authenticate, | |
5838 | .policy = nl80211_policy, | |
5839 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5840 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5841 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
5842 | }, |
5843 | { | |
5844 | .cmd = NL80211_CMD_ASSOCIATE, | |
5845 | .doit = nl80211_associate, | |
5846 | .policy = nl80211_policy, | |
5847 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5848 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5849 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
5850 | }, |
5851 | { | |
5852 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
5853 | .doit = nl80211_deauthenticate, | |
5854 | .policy = nl80211_policy, | |
5855 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5856 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5857 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
5858 | }, |
5859 | { | |
5860 | .cmd = NL80211_CMD_DISASSOCIATE, | |
5861 | .doit = nl80211_disassociate, | |
5862 | .policy = nl80211_policy, | |
5863 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5864 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5865 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 5866 | }, |
04a773ad JB |
5867 | { |
5868 | .cmd = NL80211_CMD_JOIN_IBSS, | |
5869 | .doit = nl80211_join_ibss, | |
5870 | .policy = nl80211_policy, | |
5871 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5872 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5873 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
5874 | }, |
5875 | { | |
5876 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
5877 | .doit = nl80211_leave_ibss, | |
5878 | .policy = nl80211_policy, | |
5879 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5880 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5881 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 5882 | }, |
aff89a9b JB |
5883 | #ifdef CONFIG_NL80211_TESTMODE |
5884 | { | |
5885 | .cmd = NL80211_CMD_TESTMODE, | |
5886 | .doit = nl80211_testmode_do, | |
71063f0e | 5887 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
5888 | .policy = nl80211_policy, |
5889 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5890 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
5891 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
5892 | }, |
5893 | #endif | |
b23aa676 SO |
5894 | { |
5895 | .cmd = NL80211_CMD_CONNECT, | |
5896 | .doit = nl80211_connect, | |
5897 | .policy = nl80211_policy, | |
5898 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5899 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5900 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
5901 | }, |
5902 | { | |
5903 | .cmd = NL80211_CMD_DISCONNECT, | |
5904 | .doit = nl80211_disconnect, | |
5905 | .policy = nl80211_policy, | |
5906 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5908 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 5909 | }, |
463d0183 JB |
5910 | { |
5911 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
5912 | .doit = nl80211_wiphy_netns, | |
5913 | .policy = nl80211_policy, | |
5914 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5915 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
5916 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 5917 | }, |
61fa713c HS |
5918 | { |
5919 | .cmd = NL80211_CMD_GET_SURVEY, | |
5920 | .policy = nl80211_policy, | |
5921 | .dumpit = nl80211_dump_survey, | |
5922 | }, | |
67fbb16b SO |
5923 | { |
5924 | .cmd = NL80211_CMD_SET_PMKSA, | |
5925 | .doit = nl80211_setdel_pmksa, | |
5926 | .policy = nl80211_policy, | |
5927 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5928 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5929 | NL80211_FLAG_NEED_RTNL, | |
67fbb16b SO |
5930 | }, |
5931 | { | |
5932 | .cmd = NL80211_CMD_DEL_PMKSA, | |
5933 | .doit = nl80211_setdel_pmksa, | |
5934 | .policy = nl80211_policy, | |
5935 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5936 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5937 | NL80211_FLAG_NEED_RTNL, | |
67fbb16b SO |
5938 | }, |
5939 | { | |
5940 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
5941 | .doit = nl80211_flush_pmksa, | |
5942 | .policy = nl80211_policy, | |
5943 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5944 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5945 | NL80211_FLAG_NEED_RTNL, | |
67fbb16b | 5946 | }, |
9588bbd5 JM |
5947 | { |
5948 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
5949 | .doit = nl80211_remain_on_channel, | |
5950 | .policy = nl80211_policy, | |
5951 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5952 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5953 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
5954 | }, |
5955 | { | |
5956 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
5957 | .doit = nl80211_cancel_remain_on_channel, | |
5958 | .policy = nl80211_policy, | |
5959 | .flags = GENL_ADMIN_PERM, | |
41265714 | 5960 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5961 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 5962 | }, |
13ae75b1 JM |
5963 | { |
5964 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
5965 | .doit = nl80211_set_tx_bitrate_mask, | |
5966 | .policy = nl80211_policy, | |
5967 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5968 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5969 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 5970 | }, |
026331c4 | 5971 | { |
2e161f78 JB |
5972 | .cmd = NL80211_CMD_REGISTER_FRAME, |
5973 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
5974 | .policy = nl80211_policy, |
5975 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
5976 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
5977 | NL80211_FLAG_NEED_RTNL, | |
026331c4 JM |
5978 | }, |
5979 | { | |
2e161f78 JB |
5980 | .cmd = NL80211_CMD_FRAME, |
5981 | .doit = nl80211_tx_mgmt, | |
026331c4 | 5982 | .policy = nl80211_policy, |
f7ca38df JB |
5983 | .flags = GENL_ADMIN_PERM, |
5984 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5985 | NL80211_FLAG_NEED_RTNL, | |
5986 | }, | |
5987 | { | |
5988 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
5989 | .doit = nl80211_tx_mgmt_cancel_wait, | |
5990 | .policy = nl80211_policy, | |
026331c4 | 5991 | .flags = GENL_ADMIN_PERM, |
41265714 | 5992 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 5993 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 5994 | }, |
ffb9eb3d KV |
5995 | { |
5996 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
5997 | .doit = nl80211_set_power_save, | |
5998 | .policy = nl80211_policy, | |
5999 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6000 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6001 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
6002 | }, |
6003 | { | |
6004 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
6005 | .doit = nl80211_get_power_save, | |
6006 | .policy = nl80211_policy, | |
6007 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
6008 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6009 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 6010 | }, |
d6dc1a38 JO |
6011 | { |
6012 | .cmd = NL80211_CMD_SET_CQM, | |
6013 | .doit = nl80211_set_cqm, | |
6014 | .policy = nl80211_policy, | |
6015 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6016 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6017 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 6018 | }, |
f444de05 JB |
6019 | { |
6020 | .cmd = NL80211_CMD_SET_CHANNEL, | |
6021 | .doit = nl80211_set_channel, | |
6022 | .policy = nl80211_policy, | |
6023 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6024 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6025 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 6026 | }, |
e8347eba BJ |
6027 | { |
6028 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
6029 | .doit = nl80211_set_wds_peer, | |
6030 | .policy = nl80211_policy, | |
6031 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
6032 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6033 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 6034 | }, |
29cbe68c JB |
6035 | { |
6036 | .cmd = NL80211_CMD_JOIN_MESH, | |
6037 | .doit = nl80211_join_mesh, | |
6038 | .policy = nl80211_policy, | |
6039 | .flags = GENL_ADMIN_PERM, | |
6040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6041 | NL80211_FLAG_NEED_RTNL, | |
6042 | }, | |
6043 | { | |
6044 | .cmd = NL80211_CMD_LEAVE_MESH, | |
6045 | .doit = nl80211_leave_mesh, | |
6046 | .policy = nl80211_policy, | |
6047 | .flags = GENL_ADMIN_PERM, | |
6048 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6049 | NL80211_FLAG_NEED_RTNL, | |
6050 | }, | |
ff1b6e69 JB |
6051 | { |
6052 | .cmd = NL80211_CMD_GET_WOWLAN, | |
6053 | .doit = nl80211_get_wowlan, | |
6054 | .policy = nl80211_policy, | |
6055 | /* can be retrieved by unprivileged users */ | |
6056 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6057 | NL80211_FLAG_NEED_RTNL, | |
6058 | }, | |
6059 | { | |
6060 | .cmd = NL80211_CMD_SET_WOWLAN, | |
6061 | .doit = nl80211_set_wowlan, | |
6062 | .policy = nl80211_policy, | |
6063 | .flags = GENL_ADMIN_PERM, | |
6064 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6065 | NL80211_FLAG_NEED_RTNL, | |
6066 | }, | |
e5497d76 JB |
6067 | { |
6068 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
6069 | .doit = nl80211_set_rekey_data, | |
6070 | .policy = nl80211_policy, | |
6071 | .flags = GENL_ADMIN_PERM, | |
6072 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6073 | NL80211_FLAG_NEED_RTNL, | |
6074 | }, | |
55682965 | 6075 | }; |
9588bbd5 | 6076 | |
6039f6d2 JM |
6077 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
6078 | .name = "mlme", | |
6079 | }; | |
55682965 JB |
6080 | |
6081 | /* multicast groups */ | |
6082 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
6083 | .name = "config", | |
6084 | }; | |
2a519311 JB |
6085 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
6086 | .name = "scan", | |
6087 | }; | |
73d54c9e LR |
6088 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
6089 | .name = "regulatory", | |
6090 | }; | |
55682965 JB |
6091 | |
6092 | /* notification functions */ | |
6093 | ||
6094 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
6095 | { | |
6096 | struct sk_buff *msg; | |
6097 | ||
fd2120ca | 6098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
6099 | if (!msg) |
6100 | return; | |
6101 | ||
6102 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
6103 | nlmsg_free(msg); | |
6104 | return; | |
6105 | } | |
6106 | ||
463d0183 JB |
6107 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6108 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
6109 | } |
6110 | ||
362a415d JB |
6111 | static int nl80211_add_scan_req(struct sk_buff *msg, |
6112 | struct cfg80211_registered_device *rdev) | |
6113 | { | |
6114 | struct cfg80211_scan_request *req = rdev->scan_req; | |
6115 | struct nlattr *nest; | |
6116 | int i; | |
6117 | ||
667503dd JB |
6118 | ASSERT_RDEV_LOCK(rdev); |
6119 | ||
362a415d JB |
6120 | if (WARN_ON(!req)) |
6121 | return 0; | |
6122 | ||
6123 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
6124 | if (!nest) | |
6125 | goto nla_put_failure; | |
6126 | for (i = 0; i < req->n_ssids; i++) | |
6127 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); | |
6128 | nla_nest_end(msg, nest); | |
6129 | ||
6130 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
6131 | if (!nest) | |
6132 | goto nla_put_failure; | |
6133 | for (i = 0; i < req->n_channels; i++) | |
6134 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); | |
6135 | nla_nest_end(msg, nest); | |
6136 | ||
6137 | if (req->ie) | |
6138 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); | |
6139 | ||
6140 | return 0; | |
6141 | nla_put_failure: | |
6142 | return -ENOBUFS; | |
6143 | } | |
6144 | ||
a538e2d5 JB |
6145 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
6146 | struct cfg80211_registered_device *rdev, | |
6147 | struct net_device *netdev, | |
6148 | u32 pid, u32 seq, int flags, | |
6149 | u32 cmd) | |
2a519311 JB |
6150 | { |
6151 | void *hdr; | |
6152 | ||
6153 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
6154 | if (!hdr) | |
6155 | return -1; | |
6156 | ||
b5850a7a | 6157 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
2a519311 JB |
6158 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
6159 | ||
362a415d JB |
6160 | /* ignore errors and send incomplete event anyway */ |
6161 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
6162 | |
6163 | return genlmsg_end(msg, hdr); | |
6164 | ||
6165 | nla_put_failure: | |
6166 | genlmsg_cancel(msg, hdr); | |
6167 | return -EMSGSIZE; | |
6168 | } | |
6169 | ||
807f8a8c LC |
6170 | static int |
6171 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
6172 | struct cfg80211_registered_device *rdev, | |
6173 | struct net_device *netdev, | |
6174 | u32 pid, u32 seq, int flags, u32 cmd) | |
6175 | { | |
6176 | void *hdr; | |
6177 | ||
6178 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
6179 | if (!hdr) | |
6180 | return -1; | |
6181 | ||
6182 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6183 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6184 | ||
6185 | return genlmsg_end(msg, hdr); | |
6186 | ||
6187 | nla_put_failure: | |
6188 | genlmsg_cancel(msg, hdr); | |
6189 | return -EMSGSIZE; | |
6190 | } | |
6191 | ||
a538e2d5 JB |
6192 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
6193 | struct net_device *netdev) | |
6194 | { | |
6195 | struct sk_buff *msg; | |
6196 | ||
6197 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
6198 | if (!msg) | |
6199 | return; | |
6200 | ||
6201 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
6202 | NL80211_CMD_TRIGGER_SCAN) < 0) { | |
6203 | nlmsg_free(msg); | |
6204 | return; | |
6205 | } | |
6206 | ||
463d0183 JB |
6207 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6208 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
6209 | } |
6210 | ||
2a519311 JB |
6211 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
6212 | struct net_device *netdev) | |
6213 | { | |
6214 | struct sk_buff *msg; | |
6215 | ||
fd2120ca | 6216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
6217 | if (!msg) |
6218 | return; | |
6219 | ||
a538e2d5 JB |
6220 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
6221 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 JB |
6222 | nlmsg_free(msg); |
6223 | return; | |
6224 | } | |
6225 | ||
463d0183 JB |
6226 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6227 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
6228 | } |
6229 | ||
6230 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
6231 | struct net_device *netdev) | |
6232 | { | |
6233 | struct sk_buff *msg; | |
6234 | ||
fd2120ca | 6235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
6236 | if (!msg) |
6237 | return; | |
6238 | ||
a538e2d5 JB |
6239 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
6240 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
2a519311 JB |
6241 | nlmsg_free(msg); |
6242 | return; | |
6243 | } | |
6244 | ||
463d0183 JB |
6245 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6246 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
6247 | } |
6248 | ||
807f8a8c LC |
6249 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
6250 | struct net_device *netdev) | |
6251 | { | |
6252 | struct sk_buff *msg; | |
6253 | ||
6254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6255 | if (!msg) | |
6256 | return; | |
6257 | ||
6258 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
6259 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
6260 | nlmsg_free(msg); | |
6261 | return; | |
6262 | } | |
6263 | ||
6264 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6265 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
6266 | } | |
6267 | ||
6268 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
6269 | struct net_device *netdev, u32 cmd) | |
6270 | { | |
6271 | struct sk_buff *msg; | |
6272 | ||
6273 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
6274 | if (!msg) | |
6275 | return; | |
6276 | ||
6277 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
6278 | nlmsg_free(msg); | |
6279 | return; | |
6280 | } | |
6281 | ||
6282 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6283 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
6284 | } | |
6285 | ||
73d54c9e LR |
6286 | /* |
6287 | * This can happen on global regulatory changes or device specific settings | |
6288 | * based on custom world regulatory domains. | |
6289 | */ | |
6290 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
6291 | { | |
6292 | struct sk_buff *msg; | |
6293 | void *hdr; | |
6294 | ||
fd2120ca | 6295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
6296 | if (!msg) |
6297 | return; | |
6298 | ||
6299 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
6300 | if (!hdr) { | |
6301 | nlmsg_free(msg); | |
6302 | return; | |
6303 | } | |
6304 | ||
6305 | /* Userspace can always count this one always being set */ | |
6306 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); | |
6307 | ||
6308 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') | |
6309 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6310 | NL80211_REGDOM_TYPE_WORLD); | |
6311 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') | |
6312 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6313 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); | |
6314 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
6315 | request->intersect) | |
6316 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6317 | NL80211_REGDOM_TYPE_INTERSECTION); | |
6318 | else { | |
6319 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6320 | NL80211_REGDOM_TYPE_COUNTRY); | |
6321 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); | |
6322 | } | |
6323 | ||
6324 | if (wiphy_idx_valid(request->wiphy_idx)) | |
6325 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); | |
6326 | ||
6327 | if (genlmsg_end(msg, hdr) < 0) { | |
6328 | nlmsg_free(msg); | |
6329 | return; | |
6330 | } | |
6331 | ||
bc43b28c | 6332 | rcu_read_lock(); |
463d0183 | 6333 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
6334 | GFP_ATOMIC); |
6335 | rcu_read_unlock(); | |
73d54c9e LR |
6336 | |
6337 | return; | |
6338 | ||
6339 | nla_put_failure: | |
6340 | genlmsg_cancel(msg, hdr); | |
6341 | nlmsg_free(msg); | |
6342 | } | |
6343 | ||
6039f6d2 JM |
6344 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
6345 | struct net_device *netdev, | |
6346 | const u8 *buf, size_t len, | |
e6d6e342 | 6347 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
6348 | { |
6349 | struct sk_buff *msg; | |
6350 | void *hdr; | |
6351 | ||
e6d6e342 | 6352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
6353 | if (!msg) |
6354 | return; | |
6355 | ||
6356 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
6357 | if (!hdr) { | |
6358 | nlmsg_free(msg); | |
6359 | return; | |
6360 | } | |
6361 | ||
6362 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6363 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6364 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
6365 | ||
6366 | if (genlmsg_end(msg, hdr) < 0) { | |
6367 | nlmsg_free(msg); | |
6368 | return; | |
6369 | } | |
6370 | ||
463d0183 JB |
6371 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6372 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
6373 | return; |
6374 | ||
6375 | nla_put_failure: | |
6376 | genlmsg_cancel(msg, hdr); | |
6377 | nlmsg_free(msg); | |
6378 | } | |
6379 | ||
6380 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
6381 | struct net_device *netdev, const u8 *buf, |
6382 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
6383 | { |
6384 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 6385 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
6386 | } |
6387 | ||
6388 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
6389 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 6390 | size_t len, gfp_t gfp) |
6039f6d2 | 6391 | { |
e6d6e342 JB |
6392 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
6393 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
6394 | } |
6395 | ||
53b46b84 | 6396 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
6397 | struct net_device *netdev, const u8 *buf, |
6398 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
6399 | { |
6400 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 6401 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
6402 | } |
6403 | ||
53b46b84 JM |
6404 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
6405 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 6406 | size_t len, gfp_t gfp) |
6039f6d2 JM |
6407 | { |
6408 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 6409 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
6410 | } |
6411 | ||
cf4e594e JM |
6412 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
6413 | struct net_device *netdev, const u8 *buf, | |
6414 | size_t len, gfp_t gfp) | |
6415 | { | |
6416 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
6417 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); | |
6418 | } | |
6419 | ||
6420 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, | |
6421 | struct net_device *netdev, const u8 *buf, | |
6422 | size_t len, gfp_t gfp) | |
6423 | { | |
6424 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
6425 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); | |
6426 | } | |
6427 | ||
1b06bb40 LR |
6428 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
6429 | struct net_device *netdev, int cmd, | |
e6d6e342 | 6430 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
6431 | { |
6432 | struct sk_buff *msg; | |
6433 | void *hdr; | |
6434 | ||
e6d6e342 | 6435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
6436 | if (!msg) |
6437 | return; | |
6438 | ||
6439 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
6440 | if (!hdr) { | |
6441 | nlmsg_free(msg); | |
6442 | return; | |
6443 | } | |
6444 | ||
6445 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6446 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6447 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); | |
6448 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
6449 | ||
6450 | if (genlmsg_end(msg, hdr) < 0) { | |
6451 | nlmsg_free(msg); | |
6452 | return; | |
6453 | } | |
6454 | ||
463d0183 JB |
6455 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6456 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
6457 | return; |
6458 | ||
6459 | nla_put_failure: | |
6460 | genlmsg_cancel(msg, hdr); | |
6461 | nlmsg_free(msg); | |
6462 | } | |
6463 | ||
6464 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
6465 | struct net_device *netdev, const u8 *addr, |
6466 | gfp_t gfp) | |
1965c853 JM |
6467 | { |
6468 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 6469 | addr, gfp); |
1965c853 JM |
6470 | } |
6471 | ||
6472 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
6473 | struct net_device *netdev, const u8 *addr, |
6474 | gfp_t gfp) | |
1965c853 | 6475 | { |
e6d6e342 JB |
6476 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
6477 | addr, gfp); | |
1965c853 JM |
6478 | } |
6479 | ||
b23aa676 SO |
6480 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
6481 | struct net_device *netdev, const u8 *bssid, | |
6482 | const u8 *req_ie, size_t req_ie_len, | |
6483 | const u8 *resp_ie, size_t resp_ie_len, | |
6484 | u16 status, gfp_t gfp) | |
6485 | { | |
6486 | struct sk_buff *msg; | |
6487 | void *hdr; | |
6488 | ||
6489 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6490 | if (!msg) | |
6491 | return; | |
6492 | ||
6493 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
6494 | if (!hdr) { | |
6495 | nlmsg_free(msg); | |
6496 | return; | |
6497 | } | |
6498 | ||
6499 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6500 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6501 | if (bssid) | |
6502 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
6503 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); | |
6504 | if (req_ie) | |
6505 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
6506 | if (resp_ie) | |
6507 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
6508 | ||
6509 | if (genlmsg_end(msg, hdr) < 0) { | |
6510 | nlmsg_free(msg); | |
6511 | return; | |
6512 | } | |
6513 | ||
463d0183 JB |
6514 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6515 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
6516 | return; |
6517 | ||
6518 | nla_put_failure: | |
6519 | genlmsg_cancel(msg, hdr); | |
6520 | nlmsg_free(msg); | |
6521 | ||
6522 | } | |
6523 | ||
6524 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
6525 | struct net_device *netdev, const u8 *bssid, | |
6526 | const u8 *req_ie, size_t req_ie_len, | |
6527 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
6528 | { | |
6529 | struct sk_buff *msg; | |
6530 | void *hdr; | |
6531 | ||
6532 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6533 | if (!msg) | |
6534 | return; | |
6535 | ||
6536 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
6537 | if (!hdr) { | |
6538 | nlmsg_free(msg); | |
6539 | return; | |
6540 | } | |
6541 | ||
6542 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6543 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6544 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
6545 | if (req_ie) | |
6546 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
6547 | if (resp_ie) | |
6548 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
6549 | ||
6550 | if (genlmsg_end(msg, hdr) < 0) { | |
6551 | nlmsg_free(msg); | |
6552 | return; | |
6553 | } | |
6554 | ||
463d0183 JB |
6555 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6556 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
6557 | return; |
6558 | ||
6559 | nla_put_failure: | |
6560 | genlmsg_cancel(msg, hdr); | |
6561 | nlmsg_free(msg); | |
6562 | ||
6563 | } | |
6564 | ||
6565 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
6566 | struct net_device *netdev, u16 reason, | |
667503dd | 6567 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
6568 | { |
6569 | struct sk_buff *msg; | |
6570 | void *hdr; | |
6571 | ||
667503dd | 6572 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
b23aa676 SO |
6573 | if (!msg) |
6574 | return; | |
6575 | ||
6576 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
6577 | if (!hdr) { | |
6578 | nlmsg_free(msg); | |
6579 | return; | |
6580 | } | |
6581 | ||
6582 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6583 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6584 | if (from_ap && reason) | |
6585 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); | |
6586 | if (from_ap) | |
6587 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); | |
6588 | if (ie) | |
6589 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); | |
6590 | ||
6591 | if (genlmsg_end(msg, hdr) < 0) { | |
6592 | nlmsg_free(msg); | |
6593 | return; | |
6594 | } | |
6595 | ||
463d0183 JB |
6596 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6597 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
6598 | return; |
6599 | ||
6600 | nla_put_failure: | |
6601 | genlmsg_cancel(msg, hdr); | |
6602 | nlmsg_free(msg); | |
6603 | ||
6604 | } | |
6605 | ||
04a773ad JB |
6606 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
6607 | struct net_device *netdev, const u8 *bssid, | |
6608 | gfp_t gfp) | |
6609 | { | |
6610 | struct sk_buff *msg; | |
6611 | void *hdr; | |
6612 | ||
fd2120ca | 6613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
6614 | if (!msg) |
6615 | return; | |
6616 | ||
6617 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
6618 | if (!hdr) { | |
6619 | nlmsg_free(msg); | |
6620 | return; | |
6621 | } | |
6622 | ||
6623 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6624 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6625 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
6626 | ||
6627 | if (genlmsg_end(msg, hdr) < 0) { | |
6628 | nlmsg_free(msg); | |
6629 | return; | |
6630 | } | |
6631 | ||
463d0183 JB |
6632 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6633 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
6634 | return; |
6635 | ||
6636 | nla_put_failure: | |
6637 | genlmsg_cancel(msg, hdr); | |
6638 | nlmsg_free(msg); | |
6639 | } | |
6640 | ||
c93b5e71 JC |
6641 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
6642 | struct net_device *netdev, | |
6643 | const u8 *macaddr, const u8* ie, u8 ie_len, | |
6644 | gfp_t gfp) | |
6645 | { | |
6646 | struct sk_buff *msg; | |
6647 | void *hdr; | |
6648 | ||
6649 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6650 | if (!msg) | |
6651 | return; | |
6652 | ||
6653 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
6654 | if (!hdr) { | |
6655 | nlmsg_free(msg); | |
6656 | return; | |
6657 | } | |
6658 | ||
6659 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6660 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6661 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); | |
6662 | if (ie_len && ie) | |
6663 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); | |
6664 | ||
6665 | if (genlmsg_end(msg, hdr) < 0) { | |
6666 | nlmsg_free(msg); | |
6667 | return; | |
6668 | } | |
6669 | ||
6670 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6671 | nl80211_mlme_mcgrp.id, gfp); | |
6672 | return; | |
6673 | ||
6674 | nla_put_failure: | |
6675 | genlmsg_cancel(msg, hdr); | |
6676 | nlmsg_free(msg); | |
6677 | } | |
6678 | ||
a3b8b056 JM |
6679 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
6680 | struct net_device *netdev, const u8 *addr, | |
6681 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 6682 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
6683 | { |
6684 | struct sk_buff *msg; | |
6685 | void *hdr; | |
6686 | ||
e6d6e342 | 6687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
6688 | if (!msg) |
6689 | return; | |
6690 | ||
6691 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
6692 | if (!hdr) { | |
6693 | nlmsg_free(msg); | |
6694 | return; | |
6695 | } | |
6696 | ||
6697 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6698 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6699 | if (addr) | |
6700 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
6701 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); | |
a66b98db AN |
6702 | if (key_id != -1) |
6703 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | |
a3b8b056 JM |
6704 | if (tsc) |
6705 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); | |
6706 | ||
6707 | if (genlmsg_end(msg, hdr) < 0) { | |
6708 | nlmsg_free(msg); | |
6709 | return; | |
6710 | } | |
6711 | ||
463d0183 JB |
6712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6713 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
6714 | return; |
6715 | ||
6716 | nla_put_failure: | |
6717 | genlmsg_cancel(msg, hdr); | |
6718 | nlmsg_free(msg); | |
6719 | } | |
6720 | ||
6bad8766 LR |
6721 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
6722 | struct ieee80211_channel *channel_before, | |
6723 | struct ieee80211_channel *channel_after) | |
6724 | { | |
6725 | struct sk_buff *msg; | |
6726 | void *hdr; | |
6727 | struct nlattr *nl_freq; | |
6728 | ||
fd2120ca | 6729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
6730 | if (!msg) |
6731 | return; | |
6732 | ||
6733 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
6734 | if (!hdr) { | |
6735 | nlmsg_free(msg); | |
6736 | return; | |
6737 | } | |
6738 | ||
6739 | /* | |
6740 | * Since we are applying the beacon hint to a wiphy we know its | |
6741 | * wiphy_idx is valid | |
6742 | */ | |
6743 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); | |
6744 | ||
6745 | /* Before */ | |
6746 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
6747 | if (!nl_freq) | |
6748 | goto nla_put_failure; | |
6749 | if (nl80211_msg_put_channel(msg, channel_before)) | |
6750 | goto nla_put_failure; | |
6751 | nla_nest_end(msg, nl_freq); | |
6752 | ||
6753 | /* After */ | |
6754 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
6755 | if (!nl_freq) | |
6756 | goto nla_put_failure; | |
6757 | if (nl80211_msg_put_channel(msg, channel_after)) | |
6758 | goto nla_put_failure; | |
6759 | nla_nest_end(msg, nl_freq); | |
6760 | ||
6761 | if (genlmsg_end(msg, hdr) < 0) { | |
6762 | nlmsg_free(msg); | |
6763 | return; | |
6764 | } | |
6765 | ||
463d0183 JB |
6766 | rcu_read_lock(); |
6767 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
6768 | GFP_ATOMIC); | |
6769 | rcu_read_unlock(); | |
6bad8766 LR |
6770 | |
6771 | return; | |
6772 | ||
6773 | nla_put_failure: | |
6774 | genlmsg_cancel(msg, hdr); | |
6775 | nlmsg_free(msg); | |
6776 | } | |
6777 | ||
9588bbd5 JM |
6778 | static void nl80211_send_remain_on_chan_event( |
6779 | int cmd, struct cfg80211_registered_device *rdev, | |
6780 | struct net_device *netdev, u64 cookie, | |
6781 | struct ieee80211_channel *chan, | |
6782 | enum nl80211_channel_type channel_type, | |
6783 | unsigned int duration, gfp_t gfp) | |
6784 | { | |
6785 | struct sk_buff *msg; | |
6786 | void *hdr; | |
6787 | ||
6788 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6789 | if (!msg) | |
6790 | return; | |
6791 | ||
6792 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
6793 | if (!hdr) { | |
6794 | nlmsg_free(msg); | |
6795 | return; | |
6796 | } | |
6797 | ||
6798 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6799 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6800 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); | |
6801 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); | |
6802 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
6803 | ||
6804 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) | |
6805 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
6806 | ||
6807 | if (genlmsg_end(msg, hdr) < 0) { | |
6808 | nlmsg_free(msg); | |
6809 | return; | |
6810 | } | |
6811 | ||
6812 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6813 | nl80211_mlme_mcgrp.id, gfp); | |
6814 | return; | |
6815 | ||
6816 | nla_put_failure: | |
6817 | genlmsg_cancel(msg, hdr); | |
6818 | nlmsg_free(msg); | |
6819 | } | |
6820 | ||
6821 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
6822 | struct net_device *netdev, u64 cookie, | |
6823 | struct ieee80211_channel *chan, | |
6824 | enum nl80211_channel_type channel_type, | |
6825 | unsigned int duration, gfp_t gfp) | |
6826 | { | |
6827 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
6828 | rdev, netdev, cookie, chan, | |
6829 | channel_type, duration, gfp); | |
6830 | } | |
6831 | ||
6832 | void nl80211_send_remain_on_channel_cancel( | |
6833 | struct cfg80211_registered_device *rdev, struct net_device *netdev, | |
6834 | u64 cookie, struct ieee80211_channel *chan, | |
6835 | enum nl80211_channel_type channel_type, gfp_t gfp) | |
6836 | { | |
6837 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
6838 | rdev, netdev, cookie, chan, | |
6839 | channel_type, 0, gfp); | |
6840 | } | |
6841 | ||
98b62183 JB |
6842 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
6843 | struct net_device *dev, const u8 *mac_addr, | |
6844 | struct station_info *sinfo, gfp_t gfp) | |
6845 | { | |
6846 | struct sk_buff *msg; | |
6847 | ||
6848 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6849 | if (!msg) | |
6850 | return; | |
6851 | ||
6852 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { | |
6853 | nlmsg_free(msg); | |
6854 | return; | |
6855 | } | |
6856 | ||
6857 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6858 | nl80211_mlme_mcgrp.id, gfp); | |
6859 | } | |
6860 | ||
ec15e68b JM |
6861 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
6862 | struct net_device *dev, const u8 *mac_addr, | |
6863 | gfp_t gfp) | |
6864 | { | |
6865 | struct sk_buff *msg; | |
6866 | void *hdr; | |
6867 | ||
6868 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6869 | if (!msg) | |
6870 | return; | |
6871 | ||
6872 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
6873 | if (!hdr) { | |
6874 | nlmsg_free(msg); | |
6875 | return; | |
6876 | } | |
6877 | ||
6878 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
6879 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
6880 | ||
6881 | if (genlmsg_end(msg, hdr) < 0) { | |
6882 | nlmsg_free(msg); | |
6883 | return; | |
6884 | } | |
6885 | ||
6886 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6887 | nl80211_mlme_mcgrp.id, gfp); | |
6888 | return; | |
6889 | ||
6890 | nla_put_failure: | |
6891 | genlmsg_cancel(msg, hdr); | |
6892 | nlmsg_free(msg); | |
6893 | } | |
6894 | ||
2e161f78 JB |
6895 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
6896 | struct net_device *netdev, u32 nlpid, | |
6897 | int freq, const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 JM |
6898 | { |
6899 | struct sk_buff *msg; | |
6900 | void *hdr; | |
6901 | int err; | |
6902 | ||
6903 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6904 | if (!msg) | |
6905 | return -ENOMEM; | |
6906 | ||
2e161f78 | 6907 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
6908 | if (!hdr) { |
6909 | nlmsg_free(msg); | |
6910 | return -ENOMEM; | |
6911 | } | |
6912 | ||
6913 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6914 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6915 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
6916 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
6917 | ||
6918 | err = genlmsg_end(msg, hdr); | |
6919 | if (err < 0) { | |
6920 | nlmsg_free(msg); | |
6921 | return err; | |
6922 | } | |
6923 | ||
6924 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
6925 | if (err < 0) | |
6926 | return err; | |
6927 | return 0; | |
6928 | ||
6929 | nla_put_failure: | |
6930 | genlmsg_cancel(msg, hdr); | |
6931 | nlmsg_free(msg); | |
6932 | return -ENOBUFS; | |
6933 | } | |
6934 | ||
2e161f78 JB |
6935 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
6936 | struct net_device *netdev, u64 cookie, | |
6937 | const u8 *buf, size_t len, bool ack, | |
6938 | gfp_t gfp) | |
026331c4 JM |
6939 | { |
6940 | struct sk_buff *msg; | |
6941 | void *hdr; | |
6942 | ||
6943 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6944 | if (!msg) | |
6945 | return; | |
6946 | ||
2e161f78 | 6947 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
6948 | if (!hdr) { |
6949 | nlmsg_free(msg); | |
6950 | return; | |
6951 | } | |
6952 | ||
6953 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6954 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6955 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
6956 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
6957 | if (ack) | |
6958 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); | |
6959 | ||
6960 | if (genlmsg_end(msg, hdr) < 0) { | |
6961 | nlmsg_free(msg); | |
6962 | return; | |
6963 | } | |
6964 | ||
6965 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
6966 | return; | |
6967 | ||
6968 | nla_put_failure: | |
6969 | genlmsg_cancel(msg, hdr); | |
6970 | nlmsg_free(msg); | |
6971 | } | |
6972 | ||
d6dc1a38 JO |
6973 | void |
6974 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |
6975 | struct net_device *netdev, | |
6976 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
6977 | gfp_t gfp) | |
6978 | { | |
6979 | struct sk_buff *msg; | |
6980 | struct nlattr *pinfoattr; | |
6981 | void *hdr; | |
6982 | ||
6983 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6984 | if (!msg) | |
6985 | return; | |
6986 | ||
6987 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
6988 | if (!hdr) { | |
6989 | nlmsg_free(msg); | |
6990 | return; | |
6991 | } | |
6992 | ||
6993 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6994 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6995 | ||
6996 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
6997 | if (!pinfoattr) | |
6998 | goto nla_put_failure; | |
6999 | ||
7000 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
7001 | rssi_event); | |
7002 | ||
7003 | nla_nest_end(msg, pinfoattr); | |
7004 | ||
7005 | if (genlmsg_end(msg, hdr) < 0) { | |
7006 | nlmsg_free(msg); | |
7007 | return; | |
7008 | } | |
7009 | ||
7010 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7011 | nl80211_mlme_mcgrp.id, gfp); | |
7012 | return; | |
7013 | ||
7014 | nla_put_failure: | |
7015 | genlmsg_cancel(msg, hdr); | |
7016 | nlmsg_free(msg); | |
7017 | } | |
7018 | ||
e5497d76 JB |
7019 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
7020 | struct net_device *netdev, const u8 *bssid, | |
7021 | const u8 *replay_ctr, gfp_t gfp) | |
7022 | { | |
7023 | struct sk_buff *msg; | |
7024 | struct nlattr *rekey_attr; | |
7025 | void *hdr; | |
7026 | ||
7027 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7028 | if (!msg) | |
7029 | return; | |
7030 | ||
7031 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
7032 | if (!hdr) { | |
7033 | nlmsg_free(msg); | |
7034 | return; | |
7035 | } | |
7036 | ||
7037 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7038 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7039 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
7040 | ||
7041 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
7042 | if (!rekey_attr) | |
7043 | goto nla_put_failure; | |
7044 | ||
7045 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, | |
7046 | NL80211_REPLAY_CTR_LEN, replay_ctr); | |
7047 | ||
7048 | nla_nest_end(msg, rekey_attr); | |
7049 | ||
7050 | if (genlmsg_end(msg, hdr) < 0) { | |
7051 | nlmsg_free(msg); | |
7052 | return; | |
7053 | } | |
7054 | ||
7055 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7056 | nl80211_mlme_mcgrp.id, gfp); | |
7057 | return; | |
7058 | ||
7059 | nla_put_failure: | |
7060 | genlmsg_cancel(msg, hdr); | |
7061 | nlmsg_free(msg); | |
7062 | } | |
7063 | ||
c063dbf5 JB |
7064 | void |
7065 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, | |
7066 | struct net_device *netdev, const u8 *peer, | |
7067 | u32 num_packets, gfp_t gfp) | |
7068 | { | |
7069 | struct sk_buff *msg; | |
7070 | struct nlattr *pinfoattr; | |
7071 | void *hdr; | |
7072 | ||
7073 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7074 | if (!msg) | |
7075 | return; | |
7076 | ||
7077 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
7078 | if (!hdr) { | |
7079 | nlmsg_free(msg); | |
7080 | return; | |
7081 | } | |
7082 | ||
7083 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7084 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7085 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); | |
7086 | ||
7087 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
7088 | if (!pinfoattr) | |
7089 | goto nla_put_failure; | |
7090 | ||
7091 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); | |
7092 | ||
7093 | nla_nest_end(msg, pinfoattr); | |
7094 | ||
7095 | if (genlmsg_end(msg, hdr) < 0) { | |
7096 | nlmsg_free(msg); | |
7097 | return; | |
7098 | } | |
7099 | ||
7100 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7101 | nl80211_mlme_mcgrp.id, gfp); | |
7102 | return; | |
7103 | ||
7104 | nla_put_failure: | |
7105 | genlmsg_cancel(msg, hdr); | |
7106 | nlmsg_free(msg); | |
7107 | } | |
7108 | ||
026331c4 JM |
7109 | static int nl80211_netlink_notify(struct notifier_block * nb, |
7110 | unsigned long state, | |
7111 | void *_notify) | |
7112 | { | |
7113 | struct netlink_notify *notify = _notify; | |
7114 | struct cfg80211_registered_device *rdev; | |
7115 | struct wireless_dev *wdev; | |
7116 | ||
7117 | if (state != NETLINK_URELEASE) | |
7118 | return NOTIFY_DONE; | |
7119 | ||
7120 | rcu_read_lock(); | |
7121 | ||
7122 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) | |
7123 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) | |
2e161f78 | 7124 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
026331c4 JM |
7125 | |
7126 | rcu_read_unlock(); | |
7127 | ||
7128 | return NOTIFY_DONE; | |
7129 | } | |
7130 | ||
7131 | static struct notifier_block nl80211_netlink_notifier = { | |
7132 | .notifier_call = nl80211_netlink_notify, | |
7133 | }; | |
7134 | ||
55682965 JB |
7135 | /* initialisation/exit functions */ |
7136 | ||
7137 | int nl80211_init(void) | |
7138 | { | |
0d63cbb5 | 7139 | int err; |
55682965 | 7140 | |
0d63cbb5 MM |
7141 | err = genl_register_family_with_ops(&nl80211_fam, |
7142 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
7143 | if (err) |
7144 | return err; | |
7145 | ||
55682965 JB |
7146 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
7147 | if (err) | |
7148 | goto err_out; | |
7149 | ||
2a519311 JB |
7150 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
7151 | if (err) | |
7152 | goto err_out; | |
7153 | ||
73d54c9e LR |
7154 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
7155 | if (err) | |
7156 | goto err_out; | |
7157 | ||
6039f6d2 JM |
7158 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
7159 | if (err) | |
7160 | goto err_out; | |
7161 | ||
aff89a9b JB |
7162 | #ifdef CONFIG_NL80211_TESTMODE |
7163 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
7164 | if (err) | |
7165 | goto err_out; | |
7166 | #endif | |
7167 | ||
026331c4 JM |
7168 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
7169 | if (err) | |
7170 | goto err_out; | |
7171 | ||
55682965 JB |
7172 | return 0; |
7173 | err_out: | |
7174 | genl_unregister_family(&nl80211_fam); | |
7175 | return err; | |
7176 | } | |
7177 | ||
7178 | void nl80211_exit(void) | |
7179 | { | |
026331c4 | 7180 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
7181 | genl_unregister_family(&nl80211_fam); |
7182 | } |