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