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 | */ |
463d0183 | 2488 | static int get_vlan(struct genl_info *info, |
5727ef1b JB |
2489 | struct cfg80211_registered_device *rdev, |
2490 | struct net_device **vlan) | |
2491 | { | |
463d0183 | 2492 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
5727ef1b JB |
2493 | *vlan = NULL; |
2494 | ||
2495 | if (vlanattr) { | |
463d0183 JB |
2496 | *vlan = dev_get_by_index(genl_info_net(info), |
2497 | nla_get_u32(vlanattr)); | |
5727ef1b JB |
2498 | if (!*vlan) |
2499 | return -ENODEV; | |
2500 | if (!(*vlan)->ieee80211_ptr) | |
2501 | return -EINVAL; | |
2502 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) | |
2503 | return -EINVAL; | |
c258d2de FF |
2504 | if (!netif_running(*vlan)) |
2505 | return -ENETDOWN; | |
5727ef1b JB |
2506 | } |
2507 | return 0; | |
2508 | } | |
2509 | ||
2510 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
2511 | { | |
4c476991 | 2512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2513 | int err; |
4c476991 | 2514 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2515 | struct station_parameters params; |
2516 | u8 *mac_addr = NULL; | |
2517 | ||
2518 | memset(¶ms, 0, sizeof(params)); | |
2519 | ||
2520 | params.listen_interval = -1; | |
57cf8043 | 2521 | params.plink_state = -1; |
5727ef1b JB |
2522 | |
2523 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
2524 | return -EINVAL; | |
2525 | ||
2526 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2527 | return -EINVAL; | |
2528 | ||
2529 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2530 | ||
2531 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
2532 | params.supported_rates = | |
2533 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2534 | params.supported_rates_len = | |
2535 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2536 | } | |
2537 | ||
2538 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
2539 | params.listen_interval = | |
2540 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
2541 | ||
36aedc90 JM |
2542 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2543 | params.ht_capa = | |
2544 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
2545 | ||
eccb8e8f | 2546 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2547 | return -EINVAL; |
2548 | ||
2ec600d6 LCC |
2549 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2550 | params.plink_action = | |
2551 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2552 | ||
9c3990aa JC |
2553 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
2554 | params.plink_state = | |
2555 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | |
2556 | ||
463d0183 | 2557 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2558 | if (err) |
034d655e | 2559 | goto out; |
a97f4424 JB |
2560 | |
2561 | /* validate settings */ | |
2562 | err = 0; | |
2563 | ||
2564 | switch (dev->ieee80211_ptr->iftype) { | |
2565 | case NL80211_IFTYPE_AP: | |
2566 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 2567 | case NL80211_IFTYPE_P2P_GO: |
a97f4424 JB |
2568 | /* disallow mesh-specific things */ |
2569 | if (params.plink_action) | |
2570 | err = -EINVAL; | |
2571 | break; | |
074ac8df | 2572 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 2573 | case NL80211_IFTYPE_STATION: |
07ba55d7 | 2574 | /* disallow things sta doesn't support */ |
a97f4424 JB |
2575 | if (params.plink_action) |
2576 | err = -EINVAL; | |
2577 | if (params.vlan) | |
2578 | err = -EINVAL; | |
07ba55d7 AN |
2579 | if (params.supported_rates && |
2580 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
a97f4424 JB |
2581 | err = -EINVAL; |
2582 | if (params.ht_capa) | |
2583 | err = -EINVAL; | |
2584 | if (params.listen_interval >= 0) | |
2585 | err = -EINVAL; | |
07ba55d7 AN |
2586 | if (params.sta_flags_mask & |
2587 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2588 | BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
2589 | err = -EINVAL; | |
2590 | /* can't change the TDLS bit */ | |
2591 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && | |
2592 | (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
a97f4424 JB |
2593 | err = -EINVAL; |
2594 | break; | |
2595 | case NL80211_IFTYPE_MESH_POINT: | |
2596 | /* disallow things mesh doesn't support */ | |
2597 | if (params.vlan) | |
2598 | err = -EINVAL; | |
2599 | if (params.ht_capa) | |
2600 | err = -EINVAL; | |
2601 | if (params.listen_interval >= 0) | |
2602 | err = -EINVAL; | |
b39c48fa JC |
2603 | if (params.sta_flags_mask & |
2604 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
8429828e | 2605 | BIT(NL80211_STA_FLAG_MFP) | |
b39c48fa | 2606 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
a97f4424 JB |
2607 | err = -EINVAL; |
2608 | break; | |
2609 | default: | |
2610 | err = -EINVAL; | |
034d655e JB |
2611 | } |
2612 | ||
5727ef1b JB |
2613 | if (err) |
2614 | goto out; | |
2615 | ||
79c97e97 | 2616 | if (!rdev->ops->change_station) { |
5727ef1b JB |
2617 | err = -EOPNOTSUPP; |
2618 | goto out; | |
2619 | } | |
2620 | ||
79c97e97 | 2621 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2622 | |
2623 | out: | |
2624 | if (params.vlan) | |
2625 | dev_put(params.vlan); | |
3b85875a | 2626 | |
5727ef1b JB |
2627 | return err; |
2628 | } | |
2629 | ||
c75786c9 EP |
2630 | static struct nla_policy |
2631 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
2632 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
2633 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
2634 | }; | |
2635 | ||
5727ef1b JB |
2636 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
2637 | { | |
4c476991 | 2638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2639 | int err; |
4c476991 | 2640 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2641 | struct station_parameters params; |
2642 | u8 *mac_addr = NULL; | |
2643 | ||
2644 | memset(¶ms, 0, sizeof(params)); | |
2645 | ||
2646 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2647 | return -EINVAL; | |
2648 | ||
5727ef1b JB |
2649 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
2650 | return -EINVAL; | |
2651 | ||
2652 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
2653 | return -EINVAL; | |
2654 | ||
0e956c13 TLSC |
2655 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
2656 | return -EINVAL; | |
2657 | ||
5727ef1b JB |
2658 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2659 | params.supported_rates = | |
2660 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2661 | params.supported_rates_len = | |
2662 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2663 | params.listen_interval = | |
2664 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 2665 | |
0e956c13 TLSC |
2666 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
2667 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
2668 | return -EINVAL; | |
51b50fbe | 2669 | |
36aedc90 JM |
2670 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2671 | params.ht_capa = | |
2672 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 2673 | |
96b78dff JC |
2674 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2675 | params.plink_action = | |
2676 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2677 | ||
eccb8e8f | 2678 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2679 | return -EINVAL; |
2680 | ||
c75786c9 | 2681 | /* parse WME attributes if sta is WME capable */ |
cedb5412 | 2682 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
cd32984f | 2683 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
c75786c9 EP |
2684 | info->attrs[NL80211_ATTR_STA_WME]) { |
2685 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; | |
2686 | struct nlattr *nla; | |
2687 | ||
2688 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
2689 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
2690 | nl80211_sta_wme_policy); | |
2691 | if (err) | |
2692 | return err; | |
2693 | ||
2694 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
2695 | params.uapsd_queues = | |
2696 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4319e193 JB |
2697 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
2698 | return -EINVAL; | |
c75786c9 EP |
2699 | |
2700 | if (tb[NL80211_STA_WME_MAX_SP]) | |
2701 | params.max_sp = | |
2702 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4319e193 JB |
2703 | |
2704 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
2705 | return -EINVAL; | |
3b9ce80c JB |
2706 | |
2707 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
c75786c9 EP |
2708 | } |
2709 | ||
0e956c13 | 2710 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
074ac8df | 2711 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
96b78dff | 2712 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
07ba55d7 AN |
2713 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO && |
2714 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) | |
2715 | return -EINVAL; | |
2716 | ||
2717 | /* | |
2718 | * Only managed stations can add TDLS peers, and only when the | |
2719 | * wiphy supports external TDLS setup. | |
2720 | */ | |
2721 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION && | |
2722 | !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && | |
2723 | (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
2724 | (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))) | |
4c476991 | 2725 | return -EINVAL; |
0e956c13 | 2726 | |
463d0183 | 2727 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2728 | if (err) |
e80cf853 | 2729 | goto out; |
a97f4424 JB |
2730 | |
2731 | /* validate settings */ | |
2732 | err = 0; | |
2733 | ||
79c97e97 | 2734 | if (!rdev->ops->add_station) { |
5727ef1b JB |
2735 | err = -EOPNOTSUPP; |
2736 | goto out; | |
2737 | } | |
2738 | ||
79c97e97 | 2739 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2740 | |
2741 | out: | |
2742 | if (params.vlan) | |
2743 | dev_put(params.vlan); | |
5727ef1b JB |
2744 | return err; |
2745 | } | |
2746 | ||
2747 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
2748 | { | |
4c476991 JB |
2749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2750 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
2751 | u8 *mac_addr = NULL; |
2752 | ||
2753 | if (info->attrs[NL80211_ATTR_MAC]) | |
2754 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2755 | ||
e80cf853 | 2756 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 2757 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 2758 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
2759 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2760 | return -EINVAL; | |
5727ef1b | 2761 | |
4c476991 JB |
2762 | if (!rdev->ops->del_station) |
2763 | return -EOPNOTSUPP; | |
3b85875a | 2764 | |
4c476991 | 2765 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
5727ef1b JB |
2766 | } |
2767 | ||
2ec600d6 LCC |
2768 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
2769 | int flags, struct net_device *dev, | |
2770 | u8 *dst, u8 *next_hop, | |
2771 | struct mpath_info *pinfo) | |
2772 | { | |
2773 | void *hdr; | |
2774 | struct nlattr *pinfoattr; | |
2775 | ||
2776 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2777 | if (!hdr) | |
2778 | return -1; | |
2779 | ||
2780 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2781 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
2782 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); | |
2783 | ||
f5ea9120 JB |
2784 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
2785 | ||
2ec600d6 LCC |
2786 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
2787 | if (!pinfoattr) | |
2788 | goto nla_put_failure; | |
2789 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) | |
2790 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
2791 | pinfo->frame_qlen); | |
d19b3bf6 RP |
2792 | if (pinfo->filled & MPATH_INFO_SN) |
2793 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, | |
2794 | pinfo->sn); | |
2ec600d6 LCC |
2795 | if (pinfo->filled & MPATH_INFO_METRIC) |
2796 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, | |
2797 | pinfo->metric); | |
2798 | if (pinfo->filled & MPATH_INFO_EXPTIME) | |
2799 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, | |
2800 | pinfo->exptime); | |
2801 | if (pinfo->filled & MPATH_INFO_FLAGS) | |
2802 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, | |
2803 | pinfo->flags); | |
2804 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) | |
2805 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
2806 | pinfo->discovery_timeout); | |
2807 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) | |
2808 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
2809 | pinfo->discovery_retries); | |
2810 | ||
2811 | nla_nest_end(msg, pinfoattr); | |
2812 | ||
2813 | return genlmsg_end(msg, hdr); | |
2814 | ||
2815 | nla_put_failure: | |
bc3ed28c TG |
2816 | genlmsg_cancel(msg, hdr); |
2817 | return -EMSGSIZE; | |
2ec600d6 LCC |
2818 | } |
2819 | ||
2820 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 2821 | struct netlink_callback *cb) |
2ec600d6 | 2822 | { |
2ec600d6 LCC |
2823 | struct mpath_info pinfo; |
2824 | struct cfg80211_registered_device *dev; | |
bba95fef | 2825 | struct net_device *netdev; |
2ec600d6 LCC |
2826 | u8 dst[ETH_ALEN]; |
2827 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 2828 | int path_idx = cb->args[1]; |
2ec600d6 | 2829 | int err; |
2ec600d6 | 2830 | |
67748893 JB |
2831 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
2832 | if (err) | |
2833 | return err; | |
bba95fef JB |
2834 | |
2835 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 2836 | err = -EOPNOTSUPP; |
bba95fef JB |
2837 | goto out_err; |
2838 | } | |
2839 | ||
eec60b03 JM |
2840 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2841 | err = -EOPNOTSUPP; | |
0448b5fc | 2842 | goto out_err; |
eec60b03 JM |
2843 | } |
2844 | ||
bba95fef JB |
2845 | while (1) { |
2846 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
2847 | dst, next_hop, &pinfo); | |
2848 | if (err == -ENOENT) | |
2ec600d6 | 2849 | break; |
bba95fef | 2850 | if (err) |
3b85875a | 2851 | goto out_err; |
2ec600d6 | 2852 | |
bba95fef JB |
2853 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
2854 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
2855 | netdev, dst, next_hop, | |
2856 | &pinfo) < 0) | |
2857 | goto out; | |
2ec600d6 | 2858 | |
bba95fef | 2859 | path_idx++; |
2ec600d6 | 2860 | } |
2ec600d6 | 2861 | |
2ec600d6 | 2862 | |
bba95fef JB |
2863 | out: |
2864 | cb->args[1] = path_idx; | |
2865 | err = skb->len; | |
bba95fef | 2866 | out_err: |
67748893 | 2867 | nl80211_finish_netdev_dump(dev); |
bba95fef | 2868 | return err; |
2ec600d6 LCC |
2869 | } |
2870 | ||
2871 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
2872 | { | |
4c476991 | 2873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2874 | int err; |
4c476991 | 2875 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
2876 | struct mpath_info pinfo; |
2877 | struct sk_buff *msg; | |
2878 | u8 *dst = NULL; | |
2879 | u8 next_hop[ETH_ALEN]; | |
2880 | ||
2881 | memset(&pinfo, 0, sizeof(pinfo)); | |
2882 | ||
2883 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2884 | return -EINVAL; | |
2885 | ||
2886 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2887 | ||
4c476991 JB |
2888 | if (!rdev->ops->get_mpath) |
2889 | return -EOPNOTSUPP; | |
2ec600d6 | 2890 | |
4c476991 JB |
2891 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2892 | return -EOPNOTSUPP; | |
eec60b03 | 2893 | |
79c97e97 | 2894 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 | 2895 | if (err) |
4c476991 | 2896 | return err; |
2ec600d6 | 2897 | |
fd2120ca | 2898 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 2899 | if (!msg) |
4c476991 | 2900 | return -ENOMEM; |
2ec600d6 LCC |
2901 | |
2902 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
4c476991 JB |
2903 | dev, dst, next_hop, &pinfo) < 0) { |
2904 | nlmsg_free(msg); | |
2905 | return -ENOBUFS; | |
2906 | } | |
3b85875a | 2907 | |
4c476991 | 2908 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
2909 | } |
2910 | ||
2911 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
2912 | { | |
4c476991 JB |
2913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2914 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
2915 | u8 *dst = NULL; |
2916 | u8 *next_hop = NULL; | |
2917 | ||
2918 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2919 | return -EINVAL; | |
2920 | ||
2921 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2922 | return -EINVAL; | |
2923 | ||
2924 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2925 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2926 | ||
4c476991 JB |
2927 | if (!rdev->ops->change_mpath) |
2928 | return -EOPNOTSUPP; | |
35a8efe1 | 2929 | |
4c476991 JB |
2930 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2931 | return -EOPNOTSUPP; | |
2ec600d6 | 2932 | |
4c476991 | 2933 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 | 2934 | } |
4c476991 | 2935 | |
2ec600d6 LCC |
2936 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
2937 | { | |
4c476991 JB |
2938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2939 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
2940 | u8 *dst = NULL; |
2941 | u8 *next_hop = NULL; | |
2942 | ||
2943 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2944 | return -EINVAL; | |
2945 | ||
2946 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2947 | return -EINVAL; | |
2948 | ||
2949 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2950 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2951 | ||
4c476991 JB |
2952 | if (!rdev->ops->add_mpath) |
2953 | return -EOPNOTSUPP; | |
35a8efe1 | 2954 | |
4c476991 JB |
2955 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2956 | return -EOPNOTSUPP; | |
2ec600d6 | 2957 | |
4c476991 | 2958 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
2959 | } |
2960 | ||
2961 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
2962 | { | |
4c476991 JB |
2963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2964 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
2965 | u8 *dst = NULL; |
2966 | ||
2967 | if (info->attrs[NL80211_ATTR_MAC]) | |
2968 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2969 | ||
4c476991 JB |
2970 | if (!rdev->ops->del_mpath) |
2971 | return -EOPNOTSUPP; | |
3b85875a | 2972 | |
4c476991 | 2973 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2ec600d6 LCC |
2974 | } |
2975 | ||
9f1ba906 JM |
2976 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
2977 | { | |
4c476991 JB |
2978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2979 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
2980 | struct bss_parameters params; |
2981 | ||
2982 | memset(¶ms, 0, sizeof(params)); | |
2983 | /* default to not changing parameters */ | |
2984 | params.use_cts_prot = -1; | |
2985 | params.use_short_preamble = -1; | |
2986 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 2987 | params.ap_isolate = -1; |
50b12f59 | 2988 | params.ht_opmode = -1; |
9f1ba906 JM |
2989 | |
2990 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
2991 | params.use_cts_prot = | |
2992 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
2993 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
2994 | params.use_short_preamble = | |
2995 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
2996 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
2997 | params.use_short_slot_time = | |
2998 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
2999 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
3000 | params.basic_rates = | |
3001 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3002 | params.basic_rates_len = | |
3003 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3004 | } | |
fd8aaaf3 FF |
3005 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
3006 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
3007 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
3008 | params.ht_opmode = | |
3009 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 3010 | |
4c476991 JB |
3011 | if (!rdev->ops->change_bss) |
3012 | return -EOPNOTSUPP; | |
9f1ba906 | 3013 | |
074ac8df | 3014 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
3015 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
3016 | return -EOPNOTSUPP; | |
3b85875a | 3017 | |
4c476991 | 3018 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
9f1ba906 JM |
3019 | } |
3020 | ||
b54452b0 | 3021 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
3022 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
3023 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
3024 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
3025 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
3026 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
3027 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
3028 | }; | |
3029 | ||
3030 | static int parse_reg_rule(struct nlattr *tb[], | |
3031 | struct ieee80211_reg_rule *reg_rule) | |
3032 | { | |
3033 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
3034 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
3035 | ||
3036 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
3037 | return -EINVAL; | |
3038 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
3039 | return -EINVAL; | |
3040 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
3041 | return -EINVAL; | |
3042 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
3043 | return -EINVAL; | |
3044 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
3045 | return -EINVAL; | |
3046 | ||
3047 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
3048 | ||
3049 | freq_range->start_freq_khz = | |
3050 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
3051 | freq_range->end_freq_khz = | |
3052 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
3053 | freq_range->max_bandwidth_khz = | |
3054 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
3055 | ||
3056 | power_rule->max_eirp = | |
3057 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
3058 | ||
3059 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
3060 | power_rule->max_antenna_gain = | |
3061 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
3062 | ||
3063 | return 0; | |
3064 | } | |
3065 | ||
3066 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
3067 | { | |
3068 | int r; | |
3069 | char *data = NULL; | |
3070 | ||
80778f18 LR |
3071 | /* |
3072 | * You should only get this when cfg80211 hasn't yet initialized | |
3073 | * completely when built-in to the kernel right between the time | |
3074 | * window between nl80211_init() and regulatory_init(), if that is | |
3075 | * even possible. | |
3076 | */ | |
3077 | mutex_lock(&cfg80211_mutex); | |
3078 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
3079 | mutex_unlock(&cfg80211_mutex); |
3080 | return -EINPROGRESS; | |
80778f18 | 3081 | } |
fe33eb39 | 3082 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 3083 | |
fe33eb39 LR |
3084 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
3085 | return -EINVAL; | |
b2e1b302 LR |
3086 | |
3087 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3088 | ||
fe33eb39 LR |
3089 | r = regulatory_hint_user(data); |
3090 | ||
b2e1b302 LR |
3091 | return r; |
3092 | } | |
3093 | ||
24bdd9f4 | 3094 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 3095 | struct genl_info *info) |
93da9cc1 | 3096 | { |
4c476991 | 3097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3098 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
3099 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
3100 | struct mesh_config cur_params; | |
3101 | int err = 0; | |
93da9cc1 | 3102 | void *hdr; |
3103 | struct nlattr *pinfoattr; | |
3104 | struct sk_buff *msg; | |
3105 | ||
29cbe68c JB |
3106 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3107 | return -EOPNOTSUPP; | |
3108 | ||
24bdd9f4 | 3109 | if (!rdev->ops->get_mesh_config) |
4c476991 | 3110 | return -EOPNOTSUPP; |
f3f92586 | 3111 | |
29cbe68c JB |
3112 | wdev_lock(wdev); |
3113 | /* If not connected, get default parameters */ | |
3114 | if (!wdev->mesh_id_len) | |
3115 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
3116 | else | |
24bdd9f4 | 3117 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3118 | &cur_params); |
3119 | wdev_unlock(wdev); | |
3120 | ||
93da9cc1 | 3121 | if (err) |
4c476991 | 3122 | return err; |
93da9cc1 | 3123 | |
3124 | /* Draw up a netlink message to send back */ | |
fd2120ca | 3125 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3126 | if (!msg) |
3127 | return -ENOMEM; | |
93da9cc1 | 3128 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
24bdd9f4 | 3129 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 3130 | if (!hdr) |
efe1cf0c | 3131 | goto out; |
24bdd9f4 | 3132 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 3133 | if (!pinfoattr) |
3134 | goto nla_put_failure; | |
3135 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
3136 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
3137 | cur_params.dot11MeshRetryTimeout); | |
3138 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
3139 | cur_params.dot11MeshConfirmTimeout); | |
3140 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
3141 | cur_params.dot11MeshHoldingTimeout); | |
3142 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
3143 | cur_params.dot11MeshMaxPeerLinks); | |
3144 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
3145 | cur_params.dot11MeshMaxRetries); | |
3146 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | |
3147 | cur_params.dot11MeshTTL); | |
45904f21 JC |
3148 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
3149 | cur_params.element_ttl); | |
93da9cc1 | 3150 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
3151 | cur_params.auto_open_plinks); | |
3152 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
3153 | cur_params.dot11MeshHWMPmaxPREQretries); | |
3154 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
3155 | cur_params.path_refresh_time); | |
3156 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
3157 | cur_params.min_discovery_timeout); | |
3158 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3159 | cur_params.dot11MeshHWMPactivePathTimeout); | |
3160 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
3161 | cur_params.dot11MeshHWMPpreqMinInterval); | |
3162 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3163 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); | |
63c5723b RP |
3164 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
3165 | cur_params.dot11MeshHWMPRootMode); | |
0507e159 JC |
3166 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
3167 | cur_params.dot11MeshHWMPRannInterval); | |
16dd7267 JC |
3168 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
3169 | cur_params.dot11MeshGateAnnouncementProtocol); | |
93da9cc1 | 3170 | nla_nest_end(msg, pinfoattr); |
3171 | genlmsg_end(msg, hdr); | |
4c476991 | 3172 | return genlmsg_reply(msg, info); |
93da9cc1 | 3173 | |
3b85875a | 3174 | nla_put_failure: |
93da9cc1 | 3175 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 3176 | out: |
d080e275 | 3177 | nlmsg_free(msg); |
4c476991 | 3178 | return -ENOBUFS; |
93da9cc1 | 3179 | } |
3180 | ||
b54452b0 | 3181 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 3182 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
3183 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
3184 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
3185 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
3186 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
3187 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 3188 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 3189 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
3190 | ||
3191 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | |
3192 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
3193 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
3194 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
3195 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
3196 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | |
699403db | 3197 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 3198 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 3199 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
93da9cc1 | 3200 | }; |
3201 | ||
c80d545d JC |
3202 | static const struct nla_policy |
3203 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
3204 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, | |
3205 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 3206 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
581a8b0f | 3207 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
c80d545d | 3208 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 3209 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
3210 | }; |
3211 | ||
24bdd9f4 | 3212 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
3213 | struct mesh_config *cfg, |
3214 | u32 *mask_out) | |
93da9cc1 | 3215 | { |
93da9cc1 | 3216 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 3217 | u32 mask = 0; |
93da9cc1 | 3218 | |
bd90fdcc JB |
3219 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
3220 | do {\ | |
3221 | if (table[attr_num]) {\ | |
3222 | cfg->param = nla_fn(table[attr_num]); \ | |
3223 | mask |= (1 << (attr_num - 1)); \ | |
3224 | } \ | |
3225 | } while (0);\ | |
3226 | ||
3227 | ||
24bdd9f4 | 3228 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 3229 | return -EINVAL; |
3230 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 3231 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 3232 | nl80211_meshconf_params_policy)) |
93da9cc1 | 3233 | return -EINVAL; |
3234 | ||
93da9cc1 | 3235 | /* This makes sure that there aren't more than 32 mesh config |
3236 | * parameters (otherwise our bitfield scheme would not work.) */ | |
3237 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
3238 | ||
3239 | /* Fill in the params struct */ | |
93da9cc1 | 3240 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
3241 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
3242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | |
3243 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | |
3244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | |
3245 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | |
3246 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | |
3247 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | |
3248 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | |
3249 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
3250 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | |
3251 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | |
45904f21 JC |
3252 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
3253 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); | |
93da9cc1 | 3254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
3255 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | |
3256 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | |
3257 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
3258 | nla_get_u8); | |
3259 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | |
3260 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | |
3261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | |
3262 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
3263 | nla_get_u16); | |
3264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | |
3265 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3266 | nla_get_u32); | |
3267 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | |
3268 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
3269 | nla_get_u16); | |
3270 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
3271 | dot11MeshHWMPnetDiameterTraversalTime, | |
3272 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3273 | nla_get_u16); | |
63c5723b RP |
3274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3275 | dot11MeshHWMPRootMode, mask, | |
3276 | NL80211_MESHCONF_HWMP_ROOTMODE, | |
3277 | nla_get_u8); | |
0507e159 JC |
3278 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3279 | dot11MeshHWMPRannInterval, mask, | |
3280 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
3281 | nla_get_u16); | |
16dd7267 JC |
3282 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3283 | dot11MeshGateAnnouncementProtocol, mask, | |
3284 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
3285 | nla_get_u8); | |
bd90fdcc JB |
3286 | if (mask_out) |
3287 | *mask_out = mask; | |
c80d545d | 3288 | |
bd90fdcc JB |
3289 | return 0; |
3290 | ||
3291 | #undef FILL_IN_MESH_PARAM_IF_SET | |
3292 | } | |
3293 | ||
c80d545d JC |
3294 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
3295 | struct mesh_setup *setup) | |
3296 | { | |
3297 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | |
3298 | ||
3299 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
3300 | return -EINVAL; | |
3301 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
3302 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
3303 | nl80211_mesh_setup_params_policy)) | |
3304 | return -EINVAL; | |
3305 | ||
3306 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) | |
3307 | setup->path_sel_proto = | |
3308 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
3309 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
3310 | IEEE80211_PATH_PROTOCOL_HWMP; | |
3311 | ||
3312 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
3313 | setup->path_metric = | |
3314 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
3315 | IEEE80211_PATH_METRIC_VENDOR : | |
3316 | IEEE80211_PATH_METRIC_AIRTIME; | |
3317 | ||
581a8b0f JC |
3318 | |
3319 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 3320 | struct nlattr *ieattr = |
581a8b0f | 3321 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
3322 | if (!is_valid_ie_attr(ieattr)) |
3323 | return -EINVAL; | |
581a8b0f JC |
3324 | setup->ie = nla_data(ieattr); |
3325 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 3326 | } |
b130e5ce JC |
3327 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
3328 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
c80d545d JC |
3329 | |
3330 | return 0; | |
3331 | } | |
3332 | ||
24bdd9f4 | 3333 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 3334 | struct genl_info *info) |
bd90fdcc JB |
3335 | { |
3336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3337 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 3338 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
3339 | struct mesh_config cfg; |
3340 | u32 mask; | |
3341 | int err; | |
3342 | ||
29cbe68c JB |
3343 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3344 | return -EOPNOTSUPP; | |
3345 | ||
24bdd9f4 | 3346 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
3347 | return -EOPNOTSUPP; |
3348 | ||
24bdd9f4 | 3349 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
3350 | if (err) |
3351 | return err; | |
3352 | ||
29cbe68c JB |
3353 | wdev_lock(wdev); |
3354 | if (!wdev->mesh_id_len) | |
3355 | err = -ENOLINK; | |
3356 | ||
3357 | if (!err) | |
24bdd9f4 | 3358 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3359 | mask, &cfg); |
3360 | ||
3361 | wdev_unlock(wdev); | |
3362 | ||
3363 | return err; | |
93da9cc1 | 3364 | } |
3365 | ||
f130347c LR |
3366 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
3367 | { | |
3368 | struct sk_buff *msg; | |
3369 | void *hdr = NULL; | |
3370 | struct nlattr *nl_reg_rules; | |
3371 | unsigned int i; | |
3372 | int err = -EINVAL; | |
3373 | ||
a1794390 | 3374 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
3375 | |
3376 | if (!cfg80211_regdomain) | |
3377 | goto out; | |
3378 | ||
fd2120ca | 3379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
3380 | if (!msg) { |
3381 | err = -ENOBUFS; | |
3382 | goto out; | |
3383 | } | |
3384 | ||
3385 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
3386 | NL80211_CMD_GET_REG); | |
3387 | if (!hdr) | |
efe1cf0c | 3388 | goto put_failure; |
f130347c LR |
3389 | |
3390 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, | |
3391 | cfg80211_regdomain->alpha2); | |
8b60b078 LR |
3392 | if (cfg80211_regdomain->dfs_region) |
3393 | NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION, | |
3394 | cfg80211_regdomain->dfs_region); | |
f130347c LR |
3395 | |
3396 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
3397 | if (!nl_reg_rules) | |
3398 | goto nla_put_failure; | |
3399 | ||
3400 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
3401 | struct nlattr *nl_reg_rule; | |
3402 | const struct ieee80211_reg_rule *reg_rule; | |
3403 | const struct ieee80211_freq_range *freq_range; | |
3404 | const struct ieee80211_power_rule *power_rule; | |
3405 | ||
3406 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
3407 | freq_range = ®_rule->freq_range; | |
3408 | power_rule = ®_rule->power_rule; | |
3409 | ||
3410 | nl_reg_rule = nla_nest_start(msg, i); | |
3411 | if (!nl_reg_rule) | |
3412 | goto nla_put_failure; | |
3413 | ||
3414 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, | |
3415 | reg_rule->flags); | |
3416 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
3417 | freq_range->start_freq_khz); | |
3418 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
3419 | freq_range->end_freq_khz); | |
3420 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
3421 | freq_range->max_bandwidth_khz); | |
3422 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
3423 | power_rule->max_antenna_gain); | |
3424 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
3425 | power_rule->max_eirp); | |
3426 | ||
3427 | nla_nest_end(msg, nl_reg_rule); | |
3428 | } | |
3429 | ||
3430 | nla_nest_end(msg, nl_reg_rules); | |
3431 | ||
3432 | genlmsg_end(msg, hdr); | |
134e6375 | 3433 | err = genlmsg_reply(msg, info); |
f130347c LR |
3434 | goto out; |
3435 | ||
3436 | nla_put_failure: | |
3437 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 3438 | put_failure: |
d080e275 | 3439 | nlmsg_free(msg); |
f130347c LR |
3440 | err = -EMSGSIZE; |
3441 | out: | |
a1794390 | 3442 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
3443 | return err; |
3444 | } | |
3445 | ||
b2e1b302 LR |
3446 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
3447 | { | |
3448 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
3449 | struct nlattr *nl_reg_rule; | |
3450 | char *alpha2 = NULL; | |
3451 | int rem_reg_rules = 0, r = 0; | |
3452 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 3453 | u8 dfs_region = 0; |
b2e1b302 LR |
3454 | struct ieee80211_regdomain *rd = NULL; |
3455 | ||
3456 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
3457 | return -EINVAL; | |
3458 | ||
3459 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
3460 | return -EINVAL; | |
3461 | ||
3462 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3463 | ||
8b60b078 LR |
3464 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
3465 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
3466 | ||
b2e1b302 LR |
3467 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
3468 | rem_reg_rules) { | |
3469 | num_rules++; | |
3470 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 3471 | return -EINVAL; |
b2e1b302 LR |
3472 | } |
3473 | ||
61405e97 LR |
3474 | mutex_lock(&cfg80211_mutex); |
3475 | ||
d0e18f83 LR |
3476 | if (!reg_is_valid_request(alpha2)) { |
3477 | r = -EINVAL; | |
3478 | goto bad_reg; | |
3479 | } | |
b2e1b302 LR |
3480 | |
3481 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
3482 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
3483 | ||
3484 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
d0e18f83 LR |
3485 | if (!rd) { |
3486 | r = -ENOMEM; | |
3487 | goto bad_reg; | |
3488 | } | |
b2e1b302 LR |
3489 | |
3490 | rd->n_reg_rules = num_rules; | |
3491 | rd->alpha2[0] = alpha2[0]; | |
3492 | rd->alpha2[1] = alpha2[1]; | |
3493 | ||
8b60b078 LR |
3494 | /* |
3495 | * Disable DFS master mode if the DFS region was | |
3496 | * not supported or known on this kernel. | |
3497 | */ | |
3498 | if (reg_supported_dfs_region(dfs_region)) | |
3499 | rd->dfs_region = dfs_region; | |
3500 | ||
b2e1b302 LR |
3501 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
3502 | rem_reg_rules) { | |
3503 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
3504 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
3505 | reg_rule_policy); | |
3506 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
3507 | if (r) | |
3508 | goto bad_reg; | |
3509 | ||
3510 | rule_idx++; | |
3511 | ||
d0e18f83 LR |
3512 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
3513 | r = -EINVAL; | |
b2e1b302 | 3514 | goto bad_reg; |
d0e18f83 | 3515 | } |
b2e1b302 LR |
3516 | } |
3517 | ||
3518 | BUG_ON(rule_idx != num_rules); | |
3519 | ||
b2e1b302 | 3520 | r = set_regdom(rd); |
61405e97 | 3521 | |
a1794390 | 3522 | mutex_unlock(&cfg80211_mutex); |
d0e18f83 | 3523 | |
b2e1b302 LR |
3524 | return r; |
3525 | ||
d2372b31 | 3526 | bad_reg: |
61405e97 | 3527 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 3528 | kfree(rd); |
d0e18f83 | 3529 | return r; |
b2e1b302 LR |
3530 | } |
3531 | ||
83f5e2cf JB |
3532 | static int validate_scan_freqs(struct nlattr *freqs) |
3533 | { | |
3534 | struct nlattr *attr1, *attr2; | |
3535 | int n_channels = 0, tmp1, tmp2; | |
3536 | ||
3537 | nla_for_each_nested(attr1, freqs, tmp1) { | |
3538 | n_channels++; | |
3539 | /* | |
3540 | * Some hardware has a limited channel list for | |
3541 | * scanning, and it is pretty much nonsensical | |
3542 | * to scan for a channel twice, so disallow that | |
3543 | * and don't require drivers to check that the | |
3544 | * channel list they get isn't longer than what | |
3545 | * they can scan, as long as they can scan all | |
3546 | * the channels they registered at once. | |
3547 | */ | |
3548 | nla_for_each_nested(attr2, freqs, tmp2) | |
3549 | if (attr1 != attr2 && | |
3550 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
3551 | return 0; | |
3552 | } | |
3553 | ||
3554 | return n_channels; | |
3555 | } | |
3556 | ||
2a519311 JB |
3557 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
3558 | { | |
4c476991 JB |
3559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3560 | struct net_device *dev = info->user_ptr[1]; | |
2a519311 | 3561 | struct cfg80211_scan_request *request; |
2a519311 JB |
3562 | struct nlattr *attr; |
3563 | struct wiphy *wiphy; | |
83f5e2cf | 3564 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 3565 | size_t ie_len; |
2a519311 | 3566 | |
f4a11bb0 JB |
3567 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3568 | return -EINVAL; | |
3569 | ||
79c97e97 | 3570 | wiphy = &rdev->wiphy; |
2a519311 | 3571 | |
4c476991 JB |
3572 | if (!rdev->ops->scan) |
3573 | return -EOPNOTSUPP; | |
2a519311 | 3574 | |
4c476991 JB |
3575 | if (rdev->scan_req) |
3576 | return -EBUSY; | |
2a519311 JB |
3577 | |
3578 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
3579 | n_channels = validate_scan_freqs( |
3580 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
3581 | if (!n_channels) |
3582 | return -EINVAL; | |
2a519311 | 3583 | } else { |
34850ab2 | 3584 | enum ieee80211_band band; |
83f5e2cf JB |
3585 | n_channels = 0; |
3586 | ||
2a519311 JB |
3587 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
3588 | if (wiphy->bands[band]) | |
3589 | n_channels += wiphy->bands[band]->n_channels; | |
3590 | } | |
3591 | ||
3592 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
3593 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
3594 | n_ssids++; | |
3595 | ||
4c476991 JB |
3596 | if (n_ssids > wiphy->max_scan_ssids) |
3597 | return -EINVAL; | |
2a519311 | 3598 | |
70692ad2 JM |
3599 | if (info->attrs[NL80211_ATTR_IE]) |
3600 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3601 | else | |
3602 | ie_len = 0; | |
3603 | ||
4c476991 JB |
3604 | if (ie_len > wiphy->max_scan_ie_len) |
3605 | return -EINVAL; | |
18a83659 | 3606 | |
2a519311 | 3607 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
3608 | + sizeof(*request->ssids) * n_ssids |
3609 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 3610 | + ie_len, GFP_KERNEL); |
4c476991 JB |
3611 | if (!request) |
3612 | return -ENOMEM; | |
2a519311 | 3613 | |
2a519311 | 3614 | if (n_ssids) |
5ba63533 | 3615 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 3616 | request->n_ssids = n_ssids; |
70692ad2 JM |
3617 | if (ie_len) { |
3618 | if (request->ssids) | |
3619 | request->ie = (void *)(request->ssids + n_ssids); | |
3620 | else | |
3621 | request->ie = (void *)(request->channels + n_channels); | |
3622 | } | |
2a519311 | 3623 | |
584991dc | 3624 | i = 0; |
2a519311 JB |
3625 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3626 | /* user specified, bail out if channel not found */ | |
2a519311 | 3627 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
3628 | struct ieee80211_channel *chan; |
3629 | ||
3630 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3631 | ||
3632 | if (!chan) { | |
2a519311 JB |
3633 | err = -EINVAL; |
3634 | goto out_free; | |
3635 | } | |
584991dc JB |
3636 | |
3637 | /* ignore disabled channels */ | |
3638 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3639 | continue; | |
3640 | ||
3641 | request->channels[i] = chan; | |
2a519311 JB |
3642 | i++; |
3643 | } | |
3644 | } else { | |
34850ab2 JB |
3645 | enum ieee80211_band band; |
3646 | ||
2a519311 | 3647 | /* all channels */ |
2a519311 JB |
3648 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
3649 | int j; | |
3650 | if (!wiphy->bands[band]) | |
3651 | continue; | |
3652 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
3653 | struct ieee80211_channel *chan; |
3654 | ||
3655 | chan = &wiphy->bands[band]->channels[j]; | |
3656 | ||
3657 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3658 | continue; | |
3659 | ||
3660 | request->channels[i] = chan; | |
2a519311 JB |
3661 | i++; |
3662 | } | |
3663 | } | |
3664 | } | |
3665 | ||
584991dc JB |
3666 | if (!i) { |
3667 | err = -EINVAL; | |
3668 | goto out_free; | |
3669 | } | |
3670 | ||
3671 | request->n_channels = i; | |
3672 | ||
2a519311 JB |
3673 | i = 0; |
3674 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3675 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 3676 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
3677 | err = -EINVAL; |
3678 | goto out_free; | |
3679 | } | |
57a27e1d | 3680 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 3681 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
3682 | i++; |
3683 | } | |
3684 | } | |
3685 | ||
70692ad2 JM |
3686 | if (info->attrs[NL80211_ATTR_IE]) { |
3687 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
3688 | memcpy((void *)request->ie, |
3689 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
3690 | request->ie_len); |
3691 | } | |
3692 | ||
34850ab2 | 3693 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
3694 | if (wiphy->bands[i]) |
3695 | request->rates[i] = | |
3696 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
3697 | |
3698 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
3699 | nla_for_each_nested(attr, | |
3700 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
3701 | tmp) { | |
3702 | enum ieee80211_band band = nla_type(attr); | |
3703 | ||
84404623 | 3704 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
3705 | err = -EINVAL; |
3706 | goto out_free; | |
3707 | } | |
3708 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
3709 | nla_data(attr), | |
3710 | nla_len(attr), | |
3711 | &request->rates[band]); | |
3712 | if (err) | |
3713 | goto out_free; | |
3714 | } | |
3715 | } | |
3716 | ||
e9f935e3 RM |
3717 | request->no_cck = |
3718 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
3719 | ||
463d0183 | 3720 | request->dev = dev; |
79c97e97 | 3721 | request->wiphy = &rdev->wiphy; |
2a519311 | 3722 | |
79c97e97 JB |
3723 | rdev->scan_req = request; |
3724 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | |
2a519311 | 3725 | |
463d0183 | 3726 | if (!err) { |
79c97e97 | 3727 | nl80211_send_scan_start(rdev, dev); |
463d0183 | 3728 | dev_hold(dev); |
4c476991 | 3729 | } else { |
2a519311 | 3730 | out_free: |
79c97e97 | 3731 | rdev->scan_req = NULL; |
2a519311 JB |
3732 | kfree(request); |
3733 | } | |
3b85875a | 3734 | |
2a519311 JB |
3735 | return err; |
3736 | } | |
3737 | ||
807f8a8c LC |
3738 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
3739 | struct genl_info *info) | |
3740 | { | |
3741 | struct cfg80211_sched_scan_request *request; | |
3742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3743 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
3744 | struct nlattr *attr; |
3745 | struct wiphy *wiphy; | |
a1f1c21c | 3746 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 3747 | u32 interval; |
807f8a8c LC |
3748 | enum ieee80211_band band; |
3749 | size_t ie_len; | |
a1f1c21c | 3750 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
3751 | |
3752 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
3753 | !rdev->ops->sched_scan_start) | |
3754 | return -EOPNOTSUPP; | |
3755 | ||
3756 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
3757 | return -EINVAL; | |
3758 | ||
bbe6ad6d LC |
3759 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
3760 | return -EINVAL; | |
3761 | ||
3762 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
3763 | if (interval == 0) | |
3764 | return -EINVAL; | |
3765 | ||
807f8a8c LC |
3766 | wiphy = &rdev->wiphy; |
3767 | ||
3768 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
3769 | n_channels = validate_scan_freqs( | |
3770 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
3771 | if (!n_channels) | |
3772 | return -EINVAL; | |
3773 | } else { | |
3774 | n_channels = 0; | |
3775 | ||
3776 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
3777 | if (wiphy->bands[band]) | |
3778 | n_channels += wiphy->bands[band]->n_channels; | |
3779 | } | |
3780 | ||
3781 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
3782 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
3783 | tmp) | |
3784 | n_ssids++; | |
3785 | ||
93b6aa69 | 3786 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
3787 | return -EINVAL; |
3788 | ||
a1f1c21c LC |
3789 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
3790 | nla_for_each_nested(attr, | |
3791 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
3792 | tmp) | |
3793 | n_match_sets++; | |
3794 | ||
3795 | if (n_match_sets > wiphy->max_match_sets) | |
3796 | return -EINVAL; | |
3797 | ||
807f8a8c LC |
3798 | if (info->attrs[NL80211_ATTR_IE]) |
3799 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3800 | else | |
3801 | ie_len = 0; | |
3802 | ||
5a865bad | 3803 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
3804 | return -EINVAL; |
3805 | ||
c10841ca LC |
3806 | mutex_lock(&rdev->sched_scan_mtx); |
3807 | ||
3808 | if (rdev->sched_scan_req) { | |
3809 | err = -EINPROGRESS; | |
3810 | goto out; | |
3811 | } | |
3812 | ||
807f8a8c | 3813 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 3814 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 3815 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 3816 | + sizeof(*request->channels) * n_channels |
807f8a8c | 3817 | + ie_len, GFP_KERNEL); |
c10841ca LC |
3818 | if (!request) { |
3819 | err = -ENOMEM; | |
3820 | goto out; | |
3821 | } | |
807f8a8c LC |
3822 | |
3823 | if (n_ssids) | |
3824 | request->ssids = (void *)&request->channels[n_channels]; | |
3825 | request->n_ssids = n_ssids; | |
3826 | if (ie_len) { | |
3827 | if (request->ssids) | |
3828 | request->ie = (void *)(request->ssids + n_ssids); | |
3829 | else | |
3830 | request->ie = (void *)(request->channels + n_channels); | |
3831 | } | |
3832 | ||
a1f1c21c LC |
3833 | if (n_match_sets) { |
3834 | if (request->ie) | |
3835 | request->match_sets = (void *)(request->ie + ie_len); | |
3836 | else if (request->ssids) | |
3837 | request->match_sets = | |
3838 | (void *)(request->ssids + n_ssids); | |
3839 | else | |
3840 | request->match_sets = | |
3841 | (void *)(request->channels + n_channels); | |
3842 | } | |
3843 | request->n_match_sets = n_match_sets; | |
3844 | ||
807f8a8c LC |
3845 | i = 0; |
3846 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
3847 | /* user specified, bail out if channel not found */ | |
3848 | nla_for_each_nested(attr, | |
3849 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
3850 | tmp) { | |
3851 | struct ieee80211_channel *chan; | |
3852 | ||
3853 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3854 | ||
3855 | if (!chan) { | |
3856 | err = -EINVAL; | |
3857 | goto out_free; | |
3858 | } | |
3859 | ||
3860 | /* ignore disabled channels */ | |
3861 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3862 | continue; | |
3863 | ||
3864 | request->channels[i] = chan; | |
3865 | i++; | |
3866 | } | |
3867 | } else { | |
3868 | /* all channels */ | |
3869 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
3870 | int j; | |
3871 | if (!wiphy->bands[band]) | |
3872 | continue; | |
3873 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
3874 | struct ieee80211_channel *chan; | |
3875 | ||
3876 | chan = &wiphy->bands[band]->channels[j]; | |
3877 | ||
3878 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3879 | continue; | |
3880 | ||
3881 | request->channels[i] = chan; | |
3882 | i++; | |
3883 | } | |
3884 | } | |
3885 | } | |
3886 | ||
3887 | if (!i) { | |
3888 | err = -EINVAL; | |
3889 | goto out_free; | |
3890 | } | |
3891 | ||
3892 | request->n_channels = i; | |
3893 | ||
3894 | i = 0; | |
3895 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3896 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
3897 | tmp) { | |
57a27e1d | 3898 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
3899 | err = -EINVAL; |
3900 | goto out_free; | |
3901 | } | |
57a27e1d | 3902 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
3903 | memcpy(request->ssids[i].ssid, nla_data(attr), |
3904 | nla_len(attr)); | |
807f8a8c LC |
3905 | i++; |
3906 | } | |
3907 | } | |
3908 | ||
a1f1c21c LC |
3909 | i = 0; |
3910 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
3911 | nla_for_each_nested(attr, | |
3912 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
3913 | tmp) { | |
3914 | struct nlattr *ssid; | |
3915 | ||
3916 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
3917 | nla_data(attr), nla_len(attr), | |
3918 | nl80211_match_policy); | |
3919 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; | |
3920 | if (ssid) { | |
3921 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
3922 | err = -EINVAL; | |
3923 | goto out_free; | |
3924 | } | |
3925 | memcpy(request->match_sets[i].ssid.ssid, | |
3926 | nla_data(ssid), nla_len(ssid)); | |
3927 | request->match_sets[i].ssid.ssid_len = | |
3928 | nla_len(ssid); | |
3929 | } | |
3930 | i++; | |
3931 | } | |
3932 | } | |
3933 | ||
807f8a8c LC |
3934 | if (info->attrs[NL80211_ATTR_IE]) { |
3935 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3936 | memcpy((void *)request->ie, | |
3937 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
3938 | request->ie_len); | |
3939 | } | |
3940 | ||
3941 | request->dev = dev; | |
3942 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 3943 | request->interval = interval; |
807f8a8c LC |
3944 | |
3945 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); | |
3946 | if (!err) { | |
3947 | rdev->sched_scan_req = request; | |
3948 | nl80211_send_sched_scan(rdev, dev, | |
3949 | NL80211_CMD_START_SCHED_SCAN); | |
3950 | goto out; | |
3951 | } | |
3952 | ||
3953 | out_free: | |
3954 | kfree(request); | |
3955 | out: | |
c10841ca | 3956 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
3957 | return err; |
3958 | } | |
3959 | ||
3960 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
3961 | struct genl_info *info) | |
3962 | { | |
3963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 3964 | int err; |
807f8a8c LC |
3965 | |
3966 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
3967 | !rdev->ops->sched_scan_stop) | |
3968 | return -EOPNOTSUPP; | |
3969 | ||
c10841ca LC |
3970 | mutex_lock(&rdev->sched_scan_mtx); |
3971 | err = __cfg80211_stop_sched_scan(rdev, false); | |
3972 | mutex_unlock(&rdev->sched_scan_mtx); | |
3973 | ||
3974 | return err; | |
807f8a8c LC |
3975 | } |
3976 | ||
9720bb3a JB |
3977 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
3978 | u32 seq, int flags, | |
2a519311 | 3979 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
3980 | struct wireless_dev *wdev, |
3981 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 3982 | { |
48ab905d | 3983 | struct cfg80211_bss *res = &intbss->pub; |
2a519311 JB |
3984 | void *hdr; |
3985 | struct nlattr *bss; | |
48ab905d JB |
3986 | int i; |
3987 | ||
3988 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 3989 | |
9720bb3a | 3990 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
2a519311 JB |
3991 | NL80211_CMD_NEW_SCAN_RESULTS); |
3992 | if (!hdr) | |
3993 | return -1; | |
3994 | ||
9720bb3a JB |
3995 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
3996 | ||
f5ea9120 | 3997 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
48ab905d | 3998 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
2a519311 JB |
3999 | |
4000 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
4001 | if (!bss) | |
4002 | goto nla_put_failure; | |
4003 | if (!is_zero_ether_addr(res->bssid)) | |
4004 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); | |
4005 | if (res->information_elements && res->len_information_elements) | |
4006 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
4007 | res->len_information_elements, | |
4008 | res->information_elements); | |
34a6eddb JM |
4009 | if (res->beacon_ies && res->len_beacon_ies && |
4010 | res->beacon_ies != res->information_elements) | |
4011 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, | |
4012 | res->len_beacon_ies, res->beacon_ies); | |
2a519311 JB |
4013 | if (res->tsf) |
4014 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); | |
4015 | if (res->beacon_interval) | |
4016 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); | |
4017 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); | |
4018 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); | |
7c89606e HS |
4019 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
4020 | jiffies_to_msecs(jiffies - intbss->ts)); | |
2a519311 | 4021 | |
77965c97 | 4022 | switch (rdev->wiphy.signal_type) { |
2a519311 JB |
4023 | case CFG80211_SIGNAL_TYPE_MBM: |
4024 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); | |
4025 | break; | |
4026 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
4027 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); | |
4028 | break; | |
4029 | default: | |
4030 | break; | |
4031 | } | |
4032 | ||
48ab905d | 4033 | switch (wdev->iftype) { |
074ac8df | 4034 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d JB |
4035 | case NL80211_IFTYPE_STATION: |
4036 | if (intbss == wdev->current_bss) | |
4037 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
4038 | NL80211_BSS_STATUS_ASSOCIATED); | |
4039 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
4040 | if (intbss != wdev->auth_bsses[i]) | |
4041 | continue; | |
4042 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
4043 | NL80211_BSS_STATUS_AUTHENTICATED); | |
4044 | break; | |
4045 | } | |
4046 | break; | |
4047 | case NL80211_IFTYPE_ADHOC: | |
4048 | if (intbss == wdev->current_bss) | |
4049 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
4050 | NL80211_BSS_STATUS_IBSS_JOINED); | |
4051 | break; | |
4052 | default: | |
4053 | break; | |
4054 | } | |
4055 | ||
2a519311 JB |
4056 | nla_nest_end(msg, bss); |
4057 | ||
4058 | return genlmsg_end(msg, hdr); | |
4059 | ||
4060 | nla_put_failure: | |
4061 | genlmsg_cancel(msg, hdr); | |
4062 | return -EMSGSIZE; | |
4063 | } | |
4064 | ||
4065 | static int nl80211_dump_scan(struct sk_buff *skb, | |
4066 | struct netlink_callback *cb) | |
4067 | { | |
48ab905d JB |
4068 | struct cfg80211_registered_device *rdev; |
4069 | struct net_device *dev; | |
2a519311 | 4070 | struct cfg80211_internal_bss *scan; |
48ab905d | 4071 | struct wireless_dev *wdev; |
2a519311 JB |
4072 | int start = cb->args[1], idx = 0; |
4073 | int err; | |
4074 | ||
67748893 JB |
4075 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
4076 | if (err) | |
4077 | return err; | |
2a519311 | 4078 | |
48ab905d | 4079 | wdev = dev->ieee80211_ptr; |
2a519311 | 4080 | |
48ab905d JB |
4081 | wdev_lock(wdev); |
4082 | spin_lock_bh(&rdev->bss_lock); | |
4083 | cfg80211_bss_expire(rdev); | |
4084 | ||
9720bb3a JB |
4085 | cb->seq = rdev->bss_generation; |
4086 | ||
48ab905d | 4087 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
4088 | if (++idx <= start) |
4089 | continue; | |
9720bb3a | 4090 | if (nl80211_send_bss(skb, cb, |
2a519311 | 4091 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 4092 | rdev, wdev, scan) < 0) { |
2a519311 | 4093 | idx--; |
67748893 | 4094 | break; |
2a519311 JB |
4095 | } |
4096 | } | |
4097 | ||
48ab905d JB |
4098 | spin_unlock_bh(&rdev->bss_lock); |
4099 | wdev_unlock(wdev); | |
2a519311 JB |
4100 | |
4101 | cb->args[1] = idx; | |
67748893 | 4102 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 4103 | |
67748893 | 4104 | return skb->len; |
2a519311 JB |
4105 | } |
4106 | ||
61fa713c HS |
4107 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
4108 | int flags, struct net_device *dev, | |
4109 | struct survey_info *survey) | |
4110 | { | |
4111 | void *hdr; | |
4112 | struct nlattr *infoattr; | |
4113 | ||
61fa713c HS |
4114 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
4115 | NL80211_CMD_NEW_SURVEY_RESULTS); | |
4116 | if (!hdr) | |
4117 | return -ENOMEM; | |
4118 | ||
4119 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
4120 | ||
4121 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
4122 | if (!infoattr) | |
4123 | goto nla_put_failure; | |
4124 | ||
4125 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
4126 | survey->channel->center_freq); | |
4127 | if (survey->filled & SURVEY_INFO_NOISE_DBM) | |
4128 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, | |
4129 | survey->noise); | |
17e5a808 FF |
4130 | if (survey->filled & SURVEY_INFO_IN_USE) |
4131 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); | |
8610c29a FF |
4132 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
4133 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
4134 | survey->channel_time); | |
4135 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) | |
4136 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
4137 | survey->channel_time_busy); | |
4138 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) | |
4139 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
4140 | survey->channel_time_ext_busy); | |
4141 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) | |
4142 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
4143 | survey->channel_time_rx); | |
4144 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) | |
4145 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
4146 | survey->channel_time_tx); | |
61fa713c HS |
4147 | |
4148 | nla_nest_end(msg, infoattr); | |
4149 | ||
4150 | return genlmsg_end(msg, hdr); | |
4151 | ||
4152 | nla_put_failure: | |
4153 | genlmsg_cancel(msg, hdr); | |
4154 | return -EMSGSIZE; | |
4155 | } | |
4156 | ||
4157 | static int nl80211_dump_survey(struct sk_buff *skb, | |
4158 | struct netlink_callback *cb) | |
4159 | { | |
4160 | struct survey_info survey; | |
4161 | struct cfg80211_registered_device *dev; | |
4162 | struct net_device *netdev; | |
61fa713c HS |
4163 | int survey_idx = cb->args[1]; |
4164 | int res; | |
4165 | ||
67748893 JB |
4166 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
4167 | if (res) | |
4168 | return res; | |
61fa713c HS |
4169 | |
4170 | if (!dev->ops->dump_survey) { | |
4171 | res = -EOPNOTSUPP; | |
4172 | goto out_err; | |
4173 | } | |
4174 | ||
4175 | while (1) { | |
180cdc79 LR |
4176 | struct ieee80211_channel *chan; |
4177 | ||
61fa713c HS |
4178 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
4179 | &survey); | |
4180 | if (res == -ENOENT) | |
4181 | break; | |
4182 | if (res) | |
4183 | goto out_err; | |
4184 | ||
180cdc79 LR |
4185 | /* Survey without a channel doesn't make sense */ |
4186 | if (!survey.channel) { | |
4187 | res = -EINVAL; | |
4188 | goto out; | |
4189 | } | |
4190 | ||
4191 | chan = ieee80211_get_channel(&dev->wiphy, | |
4192 | survey.channel->center_freq); | |
4193 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
4194 | survey_idx++; | |
4195 | continue; | |
4196 | } | |
4197 | ||
61fa713c HS |
4198 | if (nl80211_send_survey(skb, |
4199 | NETLINK_CB(cb->skb).pid, | |
4200 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4201 | netdev, | |
4202 | &survey) < 0) | |
4203 | goto out; | |
4204 | survey_idx++; | |
4205 | } | |
4206 | ||
4207 | out: | |
4208 | cb->args[1] = survey_idx; | |
4209 | res = skb->len; | |
4210 | out_err: | |
67748893 | 4211 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
4212 | return res; |
4213 | } | |
4214 | ||
255e737e JM |
4215 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
4216 | { | |
b23aa676 SO |
4217 | return auth_type <= NL80211_AUTHTYPE_MAX; |
4218 | } | |
4219 | ||
4220 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | |
4221 | { | |
4222 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
4223 | NL80211_WPA_VERSION_2)); | |
4224 | } | |
4225 | ||
636a5d36 JM |
4226 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
4227 | { | |
4c476991 JB |
4228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4229 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 JB |
4230 | struct ieee80211_channel *chan; |
4231 | const u8 *bssid, *ssid, *ie = NULL; | |
4232 | int err, ssid_len, ie_len = 0; | |
4233 | enum nl80211_auth_type auth_type; | |
fffd0934 | 4234 | struct key_parse key; |
d5cdfacb | 4235 | bool local_state_change; |
636a5d36 | 4236 | |
f4a11bb0 JB |
4237 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4238 | return -EINVAL; | |
4239 | ||
4240 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4241 | return -EINVAL; | |
4242 | ||
1778092e JM |
4243 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
4244 | return -EINVAL; | |
4245 | ||
19957bb3 JB |
4246 | if (!info->attrs[NL80211_ATTR_SSID]) |
4247 | return -EINVAL; | |
4248 | ||
4249 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
4250 | return -EINVAL; | |
4251 | ||
fffd0934 JB |
4252 | err = nl80211_parse_key(info, &key); |
4253 | if (err) | |
4254 | return err; | |
4255 | ||
4256 | if (key.idx >= 0) { | |
e31b8213 JB |
4257 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
4258 | return -EINVAL; | |
fffd0934 JB |
4259 | if (!key.p.key || !key.p.key_len) |
4260 | return -EINVAL; | |
4261 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
4262 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
4263 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
4264 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
4265 | return -EINVAL; | |
4266 | if (key.idx > 4) | |
4267 | return -EINVAL; | |
4268 | } else { | |
4269 | key.p.key_len = 0; | |
4270 | key.p.key = NULL; | |
4271 | } | |
4272 | ||
afea0b7a JB |
4273 | if (key.idx >= 0) { |
4274 | int i; | |
4275 | bool ok = false; | |
4276 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
4277 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
4278 | ok = true; | |
4279 | break; | |
4280 | } | |
4281 | } | |
4c476991 JB |
4282 | if (!ok) |
4283 | return -EINVAL; | |
afea0b7a JB |
4284 | } |
4285 | ||
4c476991 JB |
4286 | if (!rdev->ops->auth) |
4287 | return -EOPNOTSUPP; | |
636a5d36 | 4288 | |
074ac8df | 4289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4291 | return -EOPNOTSUPP; | |
eec60b03 | 4292 | |
19957bb3 | 4293 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 4294 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 4295 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
4296 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4297 | return -EINVAL; | |
636a5d36 | 4298 | |
19957bb3 JB |
4299 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4300 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4301 | |
4302 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4303 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4304 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4305 | } |
4306 | ||
19957bb3 | 4307 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
4c476991 JB |
4308 | if (!nl80211_valid_auth_type(auth_type)) |
4309 | return -EINVAL; | |
636a5d36 | 4310 | |
d5cdfacb JM |
4311 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4312 | ||
4c476991 JB |
4313 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
4314 | ssid, ssid_len, ie, ie_len, | |
4315 | key.p.key, key.p.key_len, key.idx, | |
4316 | local_state_change); | |
636a5d36 JM |
4317 | } |
4318 | ||
c0692b8f JB |
4319 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
4320 | struct genl_info *info, | |
3dc27d25 JB |
4321 | struct cfg80211_crypto_settings *settings, |
4322 | int cipher_limit) | |
b23aa676 | 4323 | { |
c0b2bbd8 JB |
4324 | memset(settings, 0, sizeof(*settings)); |
4325 | ||
b23aa676 SO |
4326 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
4327 | ||
c0692b8f JB |
4328 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
4329 | u16 proto; | |
4330 | proto = nla_get_u16( | |
4331 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
4332 | settings->control_port_ethertype = cpu_to_be16(proto); | |
4333 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
4334 | proto != ETH_P_PAE) | |
4335 | return -EINVAL; | |
4336 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
4337 | settings->control_port_no_encrypt = true; | |
4338 | } else | |
4339 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
4340 | ||
b23aa676 SO |
4341 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
4342 | void *data; | |
4343 | int len, i; | |
4344 | ||
4345 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4346 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4347 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
4348 | ||
4349 | if (len % sizeof(u32)) | |
4350 | return -EINVAL; | |
4351 | ||
3dc27d25 | 4352 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
4353 | return -EINVAL; |
4354 | ||
4355 | memcpy(settings->ciphers_pairwise, data, len); | |
4356 | ||
4357 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
4358 | if (!cfg80211_supported_cipher_suite( |
4359 | &rdev->wiphy, | |
b23aa676 SO |
4360 | settings->ciphers_pairwise[i])) |
4361 | return -EINVAL; | |
4362 | } | |
4363 | ||
4364 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
4365 | settings->cipher_group = | |
4366 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
4367 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
4368 | settings->cipher_group)) | |
b23aa676 SO |
4369 | return -EINVAL; |
4370 | } | |
4371 | ||
4372 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
4373 | settings->wpa_versions = | |
4374 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
4375 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
4376 | return -EINVAL; | |
4377 | } | |
4378 | ||
4379 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
4380 | void *data; | |
6d30240e | 4381 | int len; |
b23aa676 SO |
4382 | |
4383 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4384 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4385 | settings->n_akm_suites = len / sizeof(u32); | |
4386 | ||
4387 | if (len % sizeof(u32)) | |
4388 | return -EINVAL; | |
4389 | ||
1b9ca027 JM |
4390 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
4391 | return -EINVAL; | |
4392 | ||
b23aa676 | 4393 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
4394 | } |
4395 | ||
4396 | return 0; | |
4397 | } | |
4398 | ||
636a5d36 JM |
4399 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
4400 | { | |
4c476991 JB |
4401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4402 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4403 | struct cfg80211_crypto_settings crypto; |
f444de05 | 4404 | struct ieee80211_channel *chan; |
3e5d7649 | 4405 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
4406 | int err, ssid_len, ie_len = 0; |
4407 | bool use_mfp = false; | |
636a5d36 | 4408 | |
f4a11bb0 JB |
4409 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4410 | return -EINVAL; | |
4411 | ||
4412 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
4413 | !info->attrs[NL80211_ATTR_SSID] || |
4414 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
4415 | return -EINVAL; |
4416 | ||
4c476991 JB |
4417 | if (!rdev->ops->assoc) |
4418 | return -EOPNOTSUPP; | |
636a5d36 | 4419 | |
074ac8df | 4420 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4421 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4422 | return -EOPNOTSUPP; | |
eec60b03 | 4423 | |
19957bb3 | 4424 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4425 | |
19957bb3 JB |
4426 | chan = ieee80211_get_channel(&rdev->wiphy, |
4427 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
4428 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4429 | return -EINVAL; | |
636a5d36 | 4430 | |
19957bb3 JB |
4431 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4432 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4433 | |
4434 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4435 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4436 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4437 | } |
4438 | ||
dc6382ce | 4439 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 4440 | enum nl80211_mfp mfp = |
dc6382ce | 4441 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 4442 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 4443 | use_mfp = true; |
4c476991 JB |
4444 | else if (mfp != NL80211_MFP_NO) |
4445 | return -EINVAL; | |
dc6382ce JM |
4446 | } |
4447 | ||
3e5d7649 JB |
4448 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
4449 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
4450 | ||
c0692b8f | 4451 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 4452 | if (!err) |
3e5d7649 JB |
4453 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
4454 | ssid, ssid_len, ie, ie_len, use_mfp, | |
19957bb3 | 4455 | &crypto); |
636a5d36 | 4456 | |
636a5d36 JM |
4457 | return err; |
4458 | } | |
4459 | ||
4460 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
4461 | { | |
4c476991 JB |
4462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4463 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4464 | const u8 *ie = NULL, *bssid; |
4c476991 | 4465 | int ie_len = 0; |
19957bb3 | 4466 | u16 reason_code; |
d5cdfacb | 4467 | bool local_state_change; |
636a5d36 | 4468 | |
f4a11bb0 JB |
4469 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4470 | return -EINVAL; | |
4471 | ||
4472 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4473 | return -EINVAL; | |
4474 | ||
4475 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4476 | return -EINVAL; | |
4477 | ||
4c476991 JB |
4478 | if (!rdev->ops->deauth) |
4479 | return -EOPNOTSUPP; | |
636a5d36 | 4480 | |
074ac8df | 4481 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4482 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4483 | return -EOPNOTSUPP; | |
eec60b03 | 4484 | |
19957bb3 | 4485 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4486 | |
19957bb3 JB |
4487 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
4488 | if (reason_code == 0) { | |
f4a11bb0 | 4489 | /* Reason Code 0 is reserved */ |
4c476991 | 4490 | return -EINVAL; |
255e737e | 4491 | } |
636a5d36 JM |
4492 | |
4493 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4494 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4495 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4496 | } |
4497 | ||
d5cdfacb JM |
4498 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4499 | ||
4c476991 JB |
4500 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
4501 | local_state_change); | |
636a5d36 JM |
4502 | } |
4503 | ||
4504 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
4505 | { | |
4c476991 JB |
4506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4507 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4508 | const u8 *ie = NULL, *bssid; |
4c476991 | 4509 | int ie_len = 0; |
19957bb3 | 4510 | u16 reason_code; |
d5cdfacb | 4511 | bool local_state_change; |
636a5d36 | 4512 | |
f4a11bb0 JB |
4513 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4514 | return -EINVAL; | |
4515 | ||
4516 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4517 | return -EINVAL; | |
4518 | ||
4519 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4520 | return -EINVAL; | |
4521 | ||
4c476991 JB |
4522 | if (!rdev->ops->disassoc) |
4523 | return -EOPNOTSUPP; | |
636a5d36 | 4524 | |
074ac8df | 4525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4527 | return -EOPNOTSUPP; | |
eec60b03 | 4528 | |
19957bb3 | 4529 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4530 | |
19957bb3 JB |
4531 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
4532 | if (reason_code == 0) { | |
f4a11bb0 | 4533 | /* Reason Code 0 is reserved */ |
4c476991 | 4534 | return -EINVAL; |
255e737e | 4535 | } |
636a5d36 JM |
4536 | |
4537 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4538 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4539 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4540 | } |
4541 | ||
d5cdfacb JM |
4542 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4543 | ||
4c476991 JB |
4544 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
4545 | local_state_change); | |
636a5d36 JM |
4546 | } |
4547 | ||
dd5b4cc7 FF |
4548 | static bool |
4549 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
4550 | int mcast_rate[IEEE80211_NUM_BANDS], | |
4551 | int rateval) | |
4552 | { | |
4553 | struct wiphy *wiphy = &rdev->wiphy; | |
4554 | bool found = false; | |
4555 | int band, i; | |
4556 | ||
4557 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
4558 | struct ieee80211_supported_band *sband; | |
4559 | ||
4560 | sband = wiphy->bands[band]; | |
4561 | if (!sband) | |
4562 | continue; | |
4563 | ||
4564 | for (i = 0; i < sband->n_bitrates; i++) { | |
4565 | if (sband->bitrates[i].bitrate == rateval) { | |
4566 | mcast_rate[band] = i + 1; | |
4567 | found = true; | |
4568 | break; | |
4569 | } | |
4570 | } | |
4571 | } | |
4572 | ||
4573 | return found; | |
4574 | } | |
4575 | ||
04a773ad JB |
4576 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
4577 | { | |
4c476991 JB |
4578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4579 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
4580 | struct cfg80211_ibss_params ibss; |
4581 | struct wiphy *wiphy; | |
fffd0934 | 4582 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
4583 | int err; |
4584 | ||
8e30bc55 JB |
4585 | memset(&ibss, 0, sizeof(ibss)); |
4586 | ||
04a773ad JB |
4587 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4588 | return -EINVAL; | |
4589 | ||
4590 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4591 | !info->attrs[NL80211_ATTR_SSID] || | |
4592 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4593 | return -EINVAL; | |
4594 | ||
8e30bc55 JB |
4595 | ibss.beacon_interval = 100; |
4596 | ||
4597 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
4598 | ibss.beacon_interval = | |
4599 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
4600 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
4601 | return -EINVAL; | |
4602 | } | |
4603 | ||
4c476991 JB |
4604 | if (!rdev->ops->join_ibss) |
4605 | return -EOPNOTSUPP; | |
04a773ad | 4606 | |
4c476991 JB |
4607 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
4608 | return -EOPNOTSUPP; | |
04a773ad | 4609 | |
79c97e97 | 4610 | wiphy = &rdev->wiphy; |
04a773ad | 4611 | |
39193498 | 4612 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 4613 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
4614 | |
4615 | if (!is_valid_ether_addr(ibss.bssid)) | |
4616 | return -EINVAL; | |
4617 | } | |
04a773ad JB |
4618 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4619 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4620 | ||
4621 | if (info->attrs[NL80211_ATTR_IE]) { | |
4622 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4623 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4624 | } | |
4625 | ||
4626 | ibss.channel = ieee80211_get_channel(wiphy, | |
4627 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4628 | if (!ibss.channel || | |
4629 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | |
4c476991 JB |
4630 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
4631 | return -EINVAL; | |
04a773ad JB |
4632 | |
4633 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | |
fffd0934 JB |
4634 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
4635 | ||
fbd2c8dc TP |
4636 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4637 | u8 *rates = | |
4638 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4639 | int n_rates = | |
4640 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4641 | struct ieee80211_supported_band *sband = | |
4642 | wiphy->bands[ibss.channel->band]; | |
34850ab2 | 4643 | int err; |
fbd2c8dc | 4644 | |
34850ab2 JB |
4645 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
4646 | &ibss.basic_rates); | |
4647 | if (err) | |
4648 | return err; | |
fbd2c8dc | 4649 | } |
dd5b4cc7 FF |
4650 | |
4651 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
4652 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
4653 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
4654 | return -EINVAL; | |
fbd2c8dc | 4655 | |
4c476991 JB |
4656 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4657 | connkeys = nl80211_parse_connkeys(rdev, | |
4658 | info->attrs[NL80211_ATTR_KEYS]); | |
4659 | if (IS_ERR(connkeys)) | |
4660 | return PTR_ERR(connkeys); | |
4661 | } | |
04a773ad | 4662 | |
4c476991 | 4663 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
4664 | if (err) |
4665 | kfree(connkeys); | |
04a773ad JB |
4666 | return err; |
4667 | } | |
4668 | ||
4669 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
4670 | { | |
4c476991 JB |
4671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4672 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 4673 | |
4c476991 JB |
4674 | if (!rdev->ops->leave_ibss) |
4675 | return -EOPNOTSUPP; | |
04a773ad | 4676 | |
4c476991 JB |
4677 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
4678 | return -EOPNOTSUPP; | |
04a773ad | 4679 | |
4c476991 | 4680 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
4681 | } |
4682 | ||
aff89a9b JB |
4683 | #ifdef CONFIG_NL80211_TESTMODE |
4684 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
4685 | .name = "testmode", | |
4686 | }; | |
4687 | ||
4688 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
4689 | { | |
4c476991 | 4690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
4691 | int err; |
4692 | ||
4693 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
4694 | return -EINVAL; | |
4695 | ||
aff89a9b JB |
4696 | err = -EOPNOTSUPP; |
4697 | if (rdev->ops->testmode_cmd) { | |
4698 | rdev->testmode_info = info; | |
4699 | err = rdev->ops->testmode_cmd(&rdev->wiphy, | |
4700 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | |
4701 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
4702 | rdev->testmode_info = NULL; | |
4703 | } | |
4704 | ||
aff89a9b JB |
4705 | return err; |
4706 | } | |
4707 | ||
71063f0e WYG |
4708 | static int nl80211_testmode_dump(struct sk_buff *skb, |
4709 | struct netlink_callback *cb) | |
4710 | { | |
4711 | struct cfg80211_registered_device *dev; | |
4712 | int err; | |
4713 | long phy_idx; | |
4714 | void *data = NULL; | |
4715 | int data_len = 0; | |
4716 | ||
4717 | if (cb->args[0]) { | |
4718 | /* | |
4719 | * 0 is a valid index, but not valid for args[0], | |
4720 | * so we need to offset by 1. | |
4721 | */ | |
4722 | phy_idx = cb->args[0] - 1; | |
4723 | } else { | |
4724 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
4725 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
4726 | nl80211_policy); | |
4727 | if (err) | |
4728 | return err; | |
4729 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) | |
4730 | return -EINVAL; | |
4731 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); | |
4732 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) | |
4733 | cb->args[1] = | |
4734 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
4735 | } | |
4736 | ||
4737 | if (cb->args[1]) { | |
4738 | data = nla_data((void *)cb->args[1]); | |
4739 | data_len = nla_len((void *)cb->args[1]); | |
4740 | } | |
4741 | ||
4742 | mutex_lock(&cfg80211_mutex); | |
4743 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); | |
4744 | if (!dev) { | |
4745 | mutex_unlock(&cfg80211_mutex); | |
4746 | return -ENOENT; | |
4747 | } | |
4748 | cfg80211_lock_rdev(dev); | |
4749 | mutex_unlock(&cfg80211_mutex); | |
4750 | ||
4751 | if (!dev->ops->testmode_dump) { | |
4752 | err = -EOPNOTSUPP; | |
4753 | goto out_err; | |
4754 | } | |
4755 | ||
4756 | while (1) { | |
4757 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, | |
4758 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4759 | NL80211_CMD_TESTMODE); | |
4760 | struct nlattr *tmdata; | |
4761 | ||
4762 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { | |
4763 | genlmsg_cancel(skb, hdr); | |
4764 | break; | |
4765 | } | |
4766 | ||
4767 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
4768 | if (!tmdata) { | |
4769 | genlmsg_cancel(skb, hdr); | |
4770 | break; | |
4771 | } | |
4772 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, | |
4773 | data, data_len); | |
4774 | nla_nest_end(skb, tmdata); | |
4775 | ||
4776 | if (err == -ENOBUFS || err == -ENOENT) { | |
4777 | genlmsg_cancel(skb, hdr); | |
4778 | break; | |
4779 | } else if (err) { | |
4780 | genlmsg_cancel(skb, hdr); | |
4781 | goto out_err; | |
4782 | } | |
4783 | ||
4784 | genlmsg_end(skb, hdr); | |
4785 | } | |
4786 | ||
4787 | err = skb->len; | |
4788 | /* see above */ | |
4789 | cb->args[0] = phy_idx + 1; | |
4790 | out_err: | |
4791 | cfg80211_unlock_rdev(dev); | |
4792 | return err; | |
4793 | } | |
4794 | ||
aff89a9b JB |
4795 | static struct sk_buff * |
4796 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
4797 | int approxlen, u32 pid, u32 seq, gfp_t gfp) | |
4798 | { | |
4799 | struct sk_buff *skb; | |
4800 | void *hdr; | |
4801 | struct nlattr *data; | |
4802 | ||
4803 | skb = nlmsg_new(approxlen + 100, gfp); | |
4804 | if (!skb) | |
4805 | return NULL; | |
4806 | ||
4807 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); | |
4808 | if (!hdr) { | |
4809 | kfree_skb(skb); | |
4810 | return NULL; | |
4811 | } | |
4812 | ||
4813 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
4814 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
4815 | ||
4816 | ((void **)skb->cb)[0] = rdev; | |
4817 | ((void **)skb->cb)[1] = hdr; | |
4818 | ((void **)skb->cb)[2] = data; | |
4819 | ||
4820 | return skb; | |
4821 | ||
4822 | nla_put_failure: | |
4823 | kfree_skb(skb); | |
4824 | return NULL; | |
4825 | } | |
4826 | ||
4827 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
4828 | int approxlen) | |
4829 | { | |
4830 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4831 | ||
4832 | if (WARN_ON(!rdev->testmode_info)) | |
4833 | return NULL; | |
4834 | ||
4835 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
4836 | rdev->testmode_info->snd_pid, | |
4837 | rdev->testmode_info->snd_seq, | |
4838 | GFP_KERNEL); | |
4839 | } | |
4840 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
4841 | ||
4842 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
4843 | { | |
4844 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
4845 | void *hdr = ((void **)skb->cb)[1]; | |
4846 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4847 | ||
4848 | if (WARN_ON(!rdev->testmode_info)) { | |
4849 | kfree_skb(skb); | |
4850 | return -EINVAL; | |
4851 | } | |
4852 | ||
4853 | nla_nest_end(skb, data); | |
4854 | genlmsg_end(skb, hdr); | |
4855 | return genlmsg_reply(skb, rdev->testmode_info); | |
4856 | } | |
4857 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
4858 | ||
4859 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
4860 | int approxlen, gfp_t gfp) | |
4861 | { | |
4862 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4863 | ||
4864 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
4865 | } | |
4866 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
4867 | ||
4868 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
4869 | { | |
4870 | void *hdr = ((void **)skb->cb)[1]; | |
4871 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4872 | ||
4873 | nla_nest_end(skb, data); | |
4874 | genlmsg_end(skb, hdr); | |
4875 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
4876 | } | |
4877 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
4878 | #endif | |
4879 | ||
b23aa676 SO |
4880 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
4881 | { | |
4c476991 JB |
4882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4883 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
4884 | struct cfg80211_connect_params connect; |
4885 | struct wiphy *wiphy; | |
fffd0934 | 4886 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
4887 | int err; |
4888 | ||
4889 | memset(&connect, 0, sizeof(connect)); | |
4890 | ||
4891 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4892 | return -EINVAL; | |
4893 | ||
4894 | if (!info->attrs[NL80211_ATTR_SSID] || | |
4895 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4896 | return -EINVAL; | |
4897 | ||
4898 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
4899 | connect.auth_type = | |
4900 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
4901 | if (!nl80211_valid_auth_type(connect.auth_type)) | |
4902 | return -EINVAL; | |
4903 | } else | |
4904 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
4905 | ||
4906 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
4907 | ||
c0692b8f | 4908 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 4909 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
4910 | if (err) |
4911 | return err; | |
b23aa676 | 4912 | |
074ac8df | 4913 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4914 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4915 | return -EOPNOTSUPP; | |
b23aa676 | 4916 | |
79c97e97 | 4917 | wiphy = &rdev->wiphy; |
b23aa676 | 4918 | |
b23aa676 SO |
4919 | if (info->attrs[NL80211_ATTR_MAC]) |
4920 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4921 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4922 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4923 | ||
4924 | if (info->attrs[NL80211_ATTR_IE]) { | |
4925 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4926 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4927 | } | |
4928 | ||
4929 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
4930 | connect.channel = | |
4931 | ieee80211_get_channel(wiphy, | |
4932 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4933 | if (!connect.channel || | |
4c476991 JB |
4934 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
4935 | return -EINVAL; | |
b23aa676 SO |
4936 | } |
4937 | ||
fffd0934 JB |
4938 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4939 | connkeys = nl80211_parse_connkeys(rdev, | |
4940 | info->attrs[NL80211_ATTR_KEYS]); | |
4c476991 JB |
4941 | if (IS_ERR(connkeys)) |
4942 | return PTR_ERR(connkeys); | |
fffd0934 JB |
4943 | } |
4944 | ||
4945 | err = cfg80211_connect(rdev, dev, &connect, connkeys); | |
fffd0934 JB |
4946 | if (err) |
4947 | kfree(connkeys); | |
b23aa676 SO |
4948 | return err; |
4949 | } | |
4950 | ||
4951 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
4952 | { | |
4c476991 JB |
4953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4954 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
4955 | u16 reason; |
4956 | ||
4957 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4958 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
4959 | else | |
4960 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4961 | ||
4962 | if (reason == 0) | |
4963 | return -EINVAL; | |
4964 | ||
074ac8df | 4965 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4967 | return -EOPNOTSUPP; | |
b23aa676 | 4968 | |
4c476991 | 4969 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
4970 | } |
4971 | ||
463d0183 JB |
4972 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
4973 | { | |
4c476991 | 4974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
4975 | struct net *net; |
4976 | int err; | |
4977 | u32 pid; | |
4978 | ||
4979 | if (!info->attrs[NL80211_ATTR_PID]) | |
4980 | return -EINVAL; | |
4981 | ||
4982 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
4983 | ||
463d0183 | 4984 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
4985 | if (IS_ERR(net)) |
4986 | return PTR_ERR(net); | |
463d0183 JB |
4987 | |
4988 | err = 0; | |
4989 | ||
4990 | /* check if anything to do */ | |
4c476991 JB |
4991 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
4992 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 4993 | |
463d0183 | 4994 | put_net(net); |
463d0183 JB |
4995 | return err; |
4996 | } | |
4997 | ||
67fbb16b SO |
4998 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
4999 | { | |
4c476991 | 5000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
5001 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
5002 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 5003 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
5004 | struct cfg80211_pmksa pmksa; |
5005 | ||
5006 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
5007 | ||
5008 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5009 | return -EINVAL; | |
5010 | ||
5011 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
5012 | return -EINVAL; | |
5013 | ||
67fbb16b SO |
5014 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
5015 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5016 | ||
074ac8df | 5017 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5018 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5019 | return -EOPNOTSUPP; | |
67fbb16b SO |
5020 | |
5021 | switch (info->genlhdr->cmd) { | |
5022 | case NL80211_CMD_SET_PMKSA: | |
5023 | rdev_ops = rdev->ops->set_pmksa; | |
5024 | break; | |
5025 | case NL80211_CMD_DEL_PMKSA: | |
5026 | rdev_ops = rdev->ops->del_pmksa; | |
5027 | break; | |
5028 | default: | |
5029 | WARN_ON(1); | |
5030 | break; | |
5031 | } | |
5032 | ||
4c476991 JB |
5033 | if (!rdev_ops) |
5034 | return -EOPNOTSUPP; | |
67fbb16b | 5035 | |
4c476991 | 5036 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
5037 | } |
5038 | ||
5039 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
5040 | { | |
4c476991 JB |
5041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5042 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 5043 | |
074ac8df | 5044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5046 | return -EOPNOTSUPP; | |
67fbb16b | 5047 | |
4c476991 JB |
5048 | if (!rdev->ops->flush_pmksa) |
5049 | return -EOPNOTSUPP; | |
67fbb16b | 5050 | |
4c476991 | 5051 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
67fbb16b SO |
5052 | } |
5053 | ||
109086ce AN |
5054 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
5055 | { | |
5056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5057 | struct net_device *dev = info->user_ptr[1]; | |
5058 | u8 action_code, dialog_token; | |
5059 | u16 status_code; | |
5060 | u8 *peer; | |
5061 | ||
5062 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
5063 | !rdev->ops->tdls_mgmt) | |
5064 | return -EOPNOTSUPP; | |
5065 | ||
5066 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
5067 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
5068 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
5069 | !info->attrs[NL80211_ATTR_IE] || | |
5070 | !info->attrs[NL80211_ATTR_MAC]) | |
5071 | return -EINVAL; | |
5072 | ||
5073 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5074 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
5075 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
5076 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
5077 | ||
5078 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, | |
5079 | dialog_token, status_code, | |
5080 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5081 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
5082 | } | |
5083 | ||
5084 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
5085 | { | |
5086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5087 | struct net_device *dev = info->user_ptr[1]; | |
5088 | enum nl80211_tdls_operation operation; | |
5089 | u8 *peer; | |
5090 | ||
5091 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
5092 | !rdev->ops->tdls_oper) | |
5093 | return -EOPNOTSUPP; | |
5094 | ||
5095 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
5096 | !info->attrs[NL80211_ATTR_MAC]) | |
5097 | return -EINVAL; | |
5098 | ||
5099 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
5100 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5101 | ||
5102 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); | |
5103 | } | |
5104 | ||
9588bbd5 JM |
5105 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
5106 | struct genl_info *info) | |
5107 | { | |
4c476991 JB |
5108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5109 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 JM |
5110 | struct ieee80211_channel *chan; |
5111 | struct sk_buff *msg; | |
5112 | void *hdr; | |
5113 | u64 cookie; | |
5114 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
5115 | u32 freq, duration; | |
5116 | int err; | |
5117 | ||
5118 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5119 | !info->attrs[NL80211_ATTR_DURATION]) | |
5120 | return -EINVAL; | |
5121 | ||
5122 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
5123 | ||
5124 | /* | |
5125 | * We should be on that channel for at least one jiffie, | |
5126 | * and more than 5 seconds seems excessive. | |
5127 | */ | |
a293911d JB |
5128 | if (!duration || !msecs_to_jiffies(duration) || |
5129 | duration > rdev->wiphy.max_remain_on_channel_duration) | |
9588bbd5 JM |
5130 | return -EINVAL; |
5131 | ||
7c4ef712 JB |
5132 | if (!rdev->ops->remain_on_channel || |
5133 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
4c476991 | 5134 | return -EOPNOTSUPP; |
9588bbd5 | 5135 | |
9588bbd5 JM |
5136 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
5137 | channel_type = nla_get_u32( | |
5138 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
5139 | if (channel_type != NL80211_CHAN_NO_HT && | |
5140 | channel_type != NL80211_CHAN_HT20 && | |
5141 | channel_type != NL80211_CHAN_HT40PLUS && | |
4c476991 JB |
5142 | channel_type != NL80211_CHAN_HT40MINUS) |
5143 | return -EINVAL; | |
9588bbd5 JM |
5144 | } |
5145 | ||
5146 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
5147 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
5148 | if (chan == NULL) |
5149 | return -EINVAL; | |
9588bbd5 JM |
5150 | |
5151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5152 | if (!msg) |
5153 | return -ENOMEM; | |
9588bbd5 JM |
5154 | |
5155 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5156 | NL80211_CMD_REMAIN_ON_CHANNEL); | |
5157 | ||
5158 | if (IS_ERR(hdr)) { | |
5159 | err = PTR_ERR(hdr); | |
5160 | goto free_msg; | |
5161 | } | |
5162 | ||
5163 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, | |
5164 | channel_type, duration, &cookie); | |
5165 | ||
5166 | if (err) | |
5167 | goto free_msg; | |
5168 | ||
5169 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
5170 | ||
5171 | genlmsg_end(msg, hdr); | |
4c476991 JB |
5172 | |
5173 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
5174 | |
5175 | nla_put_failure: | |
5176 | err = -ENOBUFS; | |
5177 | free_msg: | |
5178 | nlmsg_free(msg); | |
9588bbd5 JM |
5179 | return err; |
5180 | } | |
5181 | ||
5182 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
5183 | struct genl_info *info) | |
5184 | { | |
4c476991 JB |
5185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5186 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 | 5187 | u64 cookie; |
9588bbd5 JM |
5188 | |
5189 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
5190 | return -EINVAL; | |
5191 | ||
4c476991 JB |
5192 | if (!rdev->ops->cancel_remain_on_channel) |
5193 | return -EOPNOTSUPP; | |
9588bbd5 | 5194 | |
9588bbd5 JM |
5195 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
5196 | ||
4c476991 | 5197 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
9588bbd5 JM |
5198 | } |
5199 | ||
13ae75b1 JM |
5200 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
5201 | u8 *rates, u8 rates_len) | |
5202 | { | |
5203 | u8 i; | |
5204 | u32 mask = 0; | |
5205 | ||
5206 | for (i = 0; i < rates_len; i++) { | |
5207 | int rate = (rates[i] & 0x7f) * 5; | |
5208 | int ridx; | |
5209 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
5210 | struct ieee80211_rate *srate = | |
5211 | &sband->bitrates[ridx]; | |
5212 | if (rate == srate->bitrate) { | |
5213 | mask |= 1 << ridx; | |
5214 | break; | |
5215 | } | |
5216 | } | |
5217 | if (ridx == sband->n_bitrates) | |
5218 | return 0; /* rate not found */ | |
5219 | } | |
5220 | ||
5221 | return mask; | |
5222 | } | |
5223 | ||
b54452b0 | 5224 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
5225 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
5226 | .len = NL80211_MAX_SUPP_RATES }, | |
5227 | }; | |
5228 | ||
5229 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
5230 | struct genl_info *info) | |
5231 | { | |
5232 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 5233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 5234 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
5235 | int rem, i; |
5236 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
5237 | struct nlattr *tx_rates; |
5238 | struct ieee80211_supported_band *sband; | |
5239 | ||
5240 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
5241 | return -EINVAL; | |
5242 | ||
4c476991 JB |
5243 | if (!rdev->ops->set_bitrate_mask) |
5244 | return -EOPNOTSUPP; | |
13ae75b1 JM |
5245 | |
5246 | memset(&mask, 0, sizeof(mask)); | |
5247 | /* Default to all rates enabled */ | |
5248 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
5249 | sband = rdev->wiphy.bands[i]; | |
5250 | mask.control[i].legacy = | |
5251 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
5252 | } | |
5253 | ||
5254 | /* | |
5255 | * The nested attribute uses enum nl80211_band as the index. This maps | |
5256 | * directly to the enum ieee80211_band values used in cfg80211. | |
5257 | */ | |
5258 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) | |
5259 | { | |
5260 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
5261 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
5262 | return -EINVAL; | |
13ae75b1 | 5263 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
5264 | if (sband == NULL) |
5265 | return -EINVAL; | |
13ae75b1 JM |
5266 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
5267 | nla_len(tx_rates), nl80211_txattr_policy); | |
5268 | if (tb[NL80211_TXRATE_LEGACY]) { | |
5269 | mask.control[band].legacy = rateset_to_mask( | |
5270 | sband, | |
5271 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
5272 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
4c476991 JB |
5273 | if (mask.control[band].legacy == 0) |
5274 | return -EINVAL; | |
13ae75b1 JM |
5275 | } |
5276 | } | |
5277 | ||
4c476991 | 5278 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
13ae75b1 JM |
5279 | } |
5280 | ||
2e161f78 | 5281 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 5282 | { |
4c476991 JB |
5283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5284 | struct net_device *dev = info->user_ptr[1]; | |
2e161f78 | 5285 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
5286 | |
5287 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
5288 | return -EINVAL; | |
5289 | ||
2e161f78 JB |
5290 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
5291 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 5292 | |
9d38d85d | 5293 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 5294 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
5295 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
5296 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5297 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 5298 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5299 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5300 | return -EOPNOTSUPP; | |
026331c4 JM |
5301 | |
5302 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
5303 | if (!rdev->ops->mgmt_tx) |
5304 | return -EOPNOTSUPP; | |
026331c4 | 5305 | |
4c476991 | 5306 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
2e161f78 | 5307 | frame_type, |
026331c4 JM |
5308 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
5309 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
5310 | } |
5311 | ||
2e161f78 | 5312 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 5313 | { |
4c476991 JB |
5314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5315 | struct net_device *dev = info->user_ptr[1]; | |
026331c4 JM |
5316 | struct ieee80211_channel *chan; |
5317 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
252aa631 | 5318 | bool channel_type_valid = false; |
026331c4 JM |
5319 | u32 freq; |
5320 | int err; | |
d64d373f | 5321 | void *hdr = NULL; |
026331c4 | 5322 | u64 cookie; |
e247bd90 | 5323 | struct sk_buff *msg = NULL; |
f7ca38df | 5324 | unsigned int wait = 0; |
e247bd90 JB |
5325 | bool offchan, no_cck, dont_wait_for_ack; |
5326 | ||
5327 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 JM |
5328 | |
5329 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
5330 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5331 | return -EINVAL; | |
5332 | ||
4c476991 JB |
5333 | if (!rdev->ops->mgmt_tx) |
5334 | return -EOPNOTSUPP; | |
026331c4 | 5335 | |
9d38d85d | 5336 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 5337 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
5338 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
5339 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5340 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 5341 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5342 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5343 | return -EOPNOTSUPP; | |
026331c4 | 5344 | |
f7ca38df | 5345 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 5346 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
5347 | return -EINVAL; |
5348 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
5349 | } | |
5350 | ||
026331c4 JM |
5351 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
5352 | channel_type = nla_get_u32( | |
5353 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
5354 | if (channel_type != NL80211_CHAN_NO_HT && | |
5355 | channel_type != NL80211_CHAN_HT20 && | |
5356 | channel_type != NL80211_CHAN_HT40PLUS && | |
4c476991 JB |
5357 | channel_type != NL80211_CHAN_HT40MINUS) |
5358 | return -EINVAL; | |
252aa631 | 5359 | channel_type_valid = true; |
026331c4 JM |
5360 | } |
5361 | ||
f7ca38df JB |
5362 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
5363 | ||
7c4ef712 JB |
5364 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
5365 | return -EINVAL; | |
5366 | ||
e9f935e3 RM |
5367 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
5368 | ||
026331c4 JM |
5369 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
5370 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
5371 | if (chan == NULL) |
5372 | return -EINVAL; | |
026331c4 | 5373 | |
e247bd90 JB |
5374 | if (!dont_wait_for_ack) { |
5375 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5376 | if (!msg) | |
5377 | return -ENOMEM; | |
026331c4 | 5378 | |
e247bd90 JB |
5379 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
5380 | NL80211_CMD_FRAME); | |
026331c4 | 5381 | |
e247bd90 JB |
5382 | if (IS_ERR(hdr)) { |
5383 | err = PTR_ERR(hdr); | |
5384 | goto free_msg; | |
5385 | } | |
026331c4 | 5386 | } |
e247bd90 | 5387 | |
f7ca38df JB |
5388 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
5389 | channel_type_valid, wait, | |
2e161f78 JB |
5390 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
5391 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 5392 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
5393 | if (err) |
5394 | goto free_msg; | |
5395 | ||
e247bd90 JB |
5396 | if (msg) { |
5397 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
026331c4 | 5398 | |
e247bd90 JB |
5399 | genlmsg_end(msg, hdr); |
5400 | return genlmsg_reply(msg, info); | |
5401 | } | |
5402 | ||
5403 | return 0; | |
026331c4 JM |
5404 | |
5405 | nla_put_failure: | |
5406 | err = -ENOBUFS; | |
5407 | free_msg: | |
5408 | nlmsg_free(msg); | |
026331c4 JM |
5409 | return err; |
5410 | } | |
5411 | ||
f7ca38df JB |
5412 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
5413 | { | |
5414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5415 | struct net_device *dev = info->user_ptr[1]; | |
5416 | u64 cookie; | |
5417 | ||
5418 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
5419 | return -EINVAL; | |
5420 | ||
5421 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
5422 | return -EOPNOTSUPP; | |
5423 | ||
5424 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | |
5425 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
5426 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && | |
5427 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5428 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
5429 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5430 | return -EOPNOTSUPP; | |
5431 | ||
5432 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
5433 | ||
5434 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); | |
5435 | } | |
5436 | ||
ffb9eb3d KV |
5437 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
5438 | { | |
4c476991 | 5439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 5440 | struct wireless_dev *wdev; |
4c476991 | 5441 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
5442 | u8 ps_state; |
5443 | bool state; | |
5444 | int err; | |
5445 | ||
4c476991 JB |
5446 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
5447 | return -EINVAL; | |
ffb9eb3d KV |
5448 | |
5449 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
5450 | ||
4c476991 JB |
5451 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
5452 | return -EINVAL; | |
ffb9eb3d KV |
5453 | |
5454 | wdev = dev->ieee80211_ptr; | |
5455 | ||
4c476991 JB |
5456 | if (!rdev->ops->set_power_mgmt) |
5457 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
5458 | |
5459 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
5460 | ||
5461 | if (state == wdev->ps) | |
4c476991 | 5462 | return 0; |
ffb9eb3d | 5463 | |
4c476991 JB |
5464 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
5465 | wdev->ps_timeout); | |
5466 | if (!err) | |
5467 | wdev->ps = state; | |
ffb9eb3d KV |
5468 | return err; |
5469 | } | |
5470 | ||
5471 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
5472 | { | |
4c476991 | 5473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
5474 | enum nl80211_ps_state ps_state; |
5475 | struct wireless_dev *wdev; | |
4c476991 | 5476 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
5477 | struct sk_buff *msg; |
5478 | void *hdr; | |
5479 | int err; | |
5480 | ||
ffb9eb3d KV |
5481 | wdev = dev->ieee80211_ptr; |
5482 | ||
4c476991 JB |
5483 | if (!rdev->ops->set_power_mgmt) |
5484 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
5485 | |
5486 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5487 | if (!msg) |
5488 | return -ENOMEM; | |
ffb9eb3d KV |
5489 | |
5490 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5491 | NL80211_CMD_GET_POWER_SAVE); | |
5492 | if (!hdr) { | |
4c476991 | 5493 | err = -ENOBUFS; |
ffb9eb3d KV |
5494 | goto free_msg; |
5495 | } | |
5496 | ||
5497 | if (wdev->ps) | |
5498 | ps_state = NL80211_PS_ENABLED; | |
5499 | else | |
5500 | ps_state = NL80211_PS_DISABLED; | |
5501 | ||
5502 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); | |
5503 | ||
5504 | genlmsg_end(msg, hdr); | |
4c476991 | 5505 | return genlmsg_reply(msg, info); |
ffb9eb3d | 5506 | |
4c476991 | 5507 | nla_put_failure: |
ffb9eb3d | 5508 | err = -ENOBUFS; |
4c476991 | 5509 | free_msg: |
ffb9eb3d | 5510 | nlmsg_free(msg); |
ffb9eb3d KV |
5511 | return err; |
5512 | } | |
5513 | ||
d6dc1a38 JO |
5514 | static struct nla_policy |
5515 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
5516 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
5517 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
5518 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
5519 | }; | |
5520 | ||
5521 | static int nl80211_set_cqm_rssi(struct genl_info *info, | |
5522 | s32 threshold, u32 hysteresis) | |
5523 | { | |
4c476991 | 5524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 5525 | struct wireless_dev *wdev; |
4c476991 | 5526 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
5527 | |
5528 | if (threshold > 0) | |
5529 | return -EINVAL; | |
5530 | ||
d6dc1a38 JO |
5531 | wdev = dev->ieee80211_ptr; |
5532 | ||
4c476991 JB |
5533 | if (!rdev->ops->set_cqm_rssi_config) |
5534 | return -EOPNOTSUPP; | |
d6dc1a38 | 5535 | |
074ac8df | 5536 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5537 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5538 | return -EOPNOTSUPP; | |
d6dc1a38 | 5539 | |
4c476991 JB |
5540 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
5541 | threshold, hysteresis); | |
d6dc1a38 JO |
5542 | } |
5543 | ||
5544 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
5545 | { | |
5546 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
5547 | struct nlattr *cqm; | |
5548 | int err; | |
5549 | ||
5550 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
5551 | if (!cqm) { | |
5552 | err = -EINVAL; | |
5553 | goto out; | |
5554 | } | |
5555 | ||
5556 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
5557 | nl80211_attr_cqm_policy); | |
5558 | if (err) | |
5559 | goto out; | |
5560 | ||
5561 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
5562 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
5563 | s32 threshold; | |
5564 | u32 hysteresis; | |
5565 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
5566 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
5567 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
5568 | } else | |
5569 | err = -EINVAL; | |
5570 | ||
5571 | out: | |
5572 | return err; | |
5573 | } | |
5574 | ||
29cbe68c JB |
5575 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
5576 | { | |
5577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5578 | struct net_device *dev = info->user_ptr[1]; | |
5579 | struct mesh_config cfg; | |
c80d545d | 5580 | struct mesh_setup setup; |
29cbe68c JB |
5581 | int err; |
5582 | ||
5583 | /* start with default */ | |
5584 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 5585 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 5586 | |
24bdd9f4 | 5587 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 5588 | /* and parse parameters if given */ |
24bdd9f4 | 5589 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
5590 | if (err) |
5591 | return err; | |
5592 | } | |
5593 | ||
5594 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
5595 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
5596 | return -EINVAL; | |
5597 | ||
c80d545d JC |
5598 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
5599 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
5600 | ||
5601 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { | |
5602 | /* parse additional setup parameters if given */ | |
5603 | err = nl80211_parse_mesh_setup(info, &setup); | |
5604 | if (err) | |
5605 | return err; | |
5606 | } | |
5607 | ||
5608 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); | |
29cbe68c JB |
5609 | } |
5610 | ||
5611 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
5612 | { | |
5613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5614 | struct net_device *dev = info->user_ptr[1]; | |
5615 | ||
5616 | return cfg80211_leave_mesh(rdev, dev); | |
5617 | } | |
5618 | ||
ff1b6e69 JB |
5619 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
5620 | { | |
5621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5622 | struct sk_buff *msg; | |
5623 | void *hdr; | |
5624 | ||
5625 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
5626 | return -EOPNOTSUPP; | |
5627 | ||
5628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5629 | if (!msg) | |
5630 | return -ENOMEM; | |
5631 | ||
5632 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5633 | NL80211_CMD_GET_WOWLAN); | |
5634 | if (!hdr) | |
5635 | goto nla_put_failure; | |
5636 | ||
5637 | if (rdev->wowlan) { | |
5638 | struct nlattr *nl_wowlan; | |
5639 | ||
5640 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
5641 | if (!nl_wowlan) | |
5642 | goto nla_put_failure; | |
5643 | ||
5644 | if (rdev->wowlan->any) | |
5645 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); | |
5646 | if (rdev->wowlan->disconnect) | |
5647 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); | |
5648 | if (rdev->wowlan->magic_pkt) | |
5649 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); | |
77dbbb13 JB |
5650 | if (rdev->wowlan->gtk_rekey_failure) |
5651 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); | |
5652 | if (rdev->wowlan->eap_identity_req) | |
5653 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); | |
5654 | if (rdev->wowlan->four_way_handshake) | |
5655 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); | |
5656 | if (rdev->wowlan->rfkill_release) | |
5657 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); | |
ff1b6e69 JB |
5658 | if (rdev->wowlan->n_patterns) { |
5659 | struct nlattr *nl_pats, *nl_pat; | |
5660 | int i, pat_len; | |
5661 | ||
5662 | nl_pats = nla_nest_start(msg, | |
5663 | NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
5664 | if (!nl_pats) | |
5665 | goto nla_put_failure; | |
5666 | ||
5667 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
5668 | nl_pat = nla_nest_start(msg, i + 1); | |
5669 | if (!nl_pat) | |
5670 | goto nla_put_failure; | |
5671 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
5672 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
5673 | DIV_ROUND_UP(pat_len, 8), | |
5674 | rdev->wowlan->patterns[i].mask); | |
5675 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
5676 | pat_len, | |
5677 | rdev->wowlan->patterns[i].pattern); | |
5678 | nla_nest_end(msg, nl_pat); | |
5679 | } | |
5680 | nla_nest_end(msg, nl_pats); | |
5681 | } | |
5682 | ||
5683 | nla_nest_end(msg, nl_wowlan); | |
5684 | } | |
5685 | ||
5686 | genlmsg_end(msg, hdr); | |
5687 | return genlmsg_reply(msg, info); | |
5688 | ||
5689 | nla_put_failure: | |
5690 | nlmsg_free(msg); | |
5691 | return -ENOBUFS; | |
5692 | } | |
5693 | ||
5694 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | |
5695 | { | |
5696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5697 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
5698 | struct cfg80211_wowlan no_triggers = {}; | |
5699 | struct cfg80211_wowlan new_triggers = {}; | |
5700 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; | |
5701 | int err, i; | |
5702 | ||
5703 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
5704 | return -EOPNOTSUPP; | |
5705 | ||
5706 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) | |
5707 | goto no_triggers; | |
5708 | ||
5709 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
5710 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
5711 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
5712 | nl80211_wowlan_policy); | |
5713 | if (err) | |
5714 | return err; | |
5715 | ||
5716 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
5717 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
5718 | return -EINVAL; | |
5719 | new_triggers.any = true; | |
5720 | } | |
5721 | ||
5722 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
5723 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
5724 | return -EINVAL; | |
5725 | new_triggers.disconnect = true; | |
5726 | } | |
5727 | ||
5728 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
5729 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
5730 | return -EINVAL; | |
5731 | new_triggers.magic_pkt = true; | |
5732 | } | |
5733 | ||
77dbbb13 JB |
5734 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
5735 | return -EINVAL; | |
5736 | ||
5737 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
5738 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
5739 | return -EINVAL; | |
5740 | new_triggers.gtk_rekey_failure = true; | |
5741 | } | |
5742 | ||
5743 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
5744 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
5745 | return -EINVAL; | |
5746 | new_triggers.eap_identity_req = true; | |
5747 | } | |
5748 | ||
5749 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
5750 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
5751 | return -EINVAL; | |
5752 | new_triggers.four_way_handshake = true; | |
5753 | } | |
5754 | ||
5755 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
5756 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
5757 | return -EINVAL; | |
5758 | new_triggers.rfkill_release = true; | |
5759 | } | |
5760 | ||
ff1b6e69 JB |
5761 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
5762 | struct nlattr *pat; | |
5763 | int n_patterns = 0; | |
5764 | int rem, pat_len, mask_len; | |
5765 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; | |
5766 | ||
5767 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
5768 | rem) | |
5769 | n_patterns++; | |
5770 | if (n_patterns > wowlan->n_patterns) | |
5771 | return -EINVAL; | |
5772 | ||
5773 | new_triggers.patterns = kcalloc(n_patterns, | |
5774 | sizeof(new_triggers.patterns[0]), | |
5775 | GFP_KERNEL); | |
5776 | if (!new_triggers.patterns) | |
5777 | return -ENOMEM; | |
5778 | ||
5779 | new_triggers.n_patterns = n_patterns; | |
5780 | i = 0; | |
5781 | ||
5782 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
5783 | rem) { | |
5784 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
5785 | nla_data(pat), nla_len(pat), NULL); | |
5786 | err = -EINVAL; | |
5787 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
5788 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
5789 | goto error; | |
5790 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
5791 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
5792 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
5793 | mask_len) | |
5794 | goto error; | |
5795 | if (pat_len > wowlan->pattern_max_len || | |
5796 | pat_len < wowlan->pattern_min_len) | |
5797 | goto error; | |
5798 | ||
5799 | new_triggers.patterns[i].mask = | |
5800 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
5801 | if (!new_triggers.patterns[i].mask) { | |
5802 | err = -ENOMEM; | |
5803 | goto error; | |
5804 | } | |
5805 | new_triggers.patterns[i].pattern = | |
5806 | new_triggers.patterns[i].mask + mask_len; | |
5807 | memcpy(new_triggers.patterns[i].mask, | |
5808 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
5809 | mask_len); | |
5810 | new_triggers.patterns[i].pattern_len = pat_len; | |
5811 | memcpy(new_triggers.patterns[i].pattern, | |
5812 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
5813 | pat_len); | |
5814 | i++; | |
5815 | } | |
5816 | } | |
5817 | ||
5818 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { | |
5819 | struct cfg80211_wowlan *ntrig; | |
5820 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), | |
5821 | GFP_KERNEL); | |
5822 | if (!ntrig) { | |
5823 | err = -ENOMEM; | |
5824 | goto error; | |
5825 | } | |
5826 | cfg80211_rdev_free_wowlan(rdev); | |
5827 | rdev->wowlan = ntrig; | |
5828 | } else { | |
5829 | no_triggers: | |
5830 | cfg80211_rdev_free_wowlan(rdev); | |
5831 | rdev->wowlan = NULL; | |
5832 | } | |
5833 | ||
5834 | return 0; | |
5835 | error: | |
5836 | for (i = 0; i < new_triggers.n_patterns; i++) | |
5837 | kfree(new_triggers.patterns[i].mask); | |
5838 | kfree(new_triggers.patterns); | |
5839 | return err; | |
5840 | } | |
5841 | ||
e5497d76 JB |
5842 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
5843 | { | |
5844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5845 | struct net_device *dev = info->user_ptr[1]; | |
5846 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5847 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
5848 | struct cfg80211_gtk_rekey_data rekey_data; | |
5849 | int err; | |
5850 | ||
5851 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
5852 | return -EINVAL; | |
5853 | ||
5854 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
5855 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
5856 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
5857 | nl80211_rekey_policy); | |
5858 | if (err) | |
5859 | return err; | |
5860 | ||
5861 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
5862 | return -ERANGE; | |
5863 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
5864 | return -ERANGE; | |
5865 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
5866 | return -ERANGE; | |
5867 | ||
5868 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
5869 | NL80211_KEK_LEN); | |
5870 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
5871 | NL80211_KCK_LEN); | |
5872 | memcpy(rekey_data.replay_ctr, | |
5873 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
5874 | NL80211_REPLAY_CTR_LEN); | |
5875 | ||
5876 | wdev_lock(wdev); | |
5877 | if (!wdev->current_bss) { | |
5878 | err = -ENOTCONN; | |
5879 | goto out; | |
5880 | } | |
5881 | ||
5882 | if (!rdev->ops->set_rekey_data) { | |
5883 | err = -EOPNOTSUPP; | |
5884 | goto out; | |
5885 | } | |
5886 | ||
5887 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); | |
5888 | out: | |
5889 | wdev_unlock(wdev); | |
5890 | return err; | |
5891 | } | |
5892 | ||
28946da7 JB |
5893 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
5894 | struct genl_info *info) | |
5895 | { | |
5896 | struct net_device *dev = info->user_ptr[1]; | |
5897 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5898 | ||
5899 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
5900 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
5901 | return -EINVAL; | |
5902 | ||
5903 | if (wdev->ap_unexpected_nlpid) | |
5904 | return -EBUSY; | |
5905 | ||
5906 | wdev->ap_unexpected_nlpid = info->snd_pid; | |
5907 | return 0; | |
5908 | } | |
5909 | ||
7f6cf311 JB |
5910 | static int nl80211_probe_client(struct sk_buff *skb, |
5911 | struct genl_info *info) | |
5912 | { | |
5913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5914 | struct net_device *dev = info->user_ptr[1]; | |
5915 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5916 | struct sk_buff *msg; | |
5917 | void *hdr; | |
5918 | const u8 *addr; | |
5919 | u64 cookie; | |
5920 | int err; | |
5921 | ||
5922 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
5923 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
5924 | return -EOPNOTSUPP; | |
5925 | ||
5926 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5927 | return -EINVAL; | |
5928 | ||
5929 | if (!rdev->ops->probe_client) | |
5930 | return -EOPNOTSUPP; | |
5931 | ||
5932 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5933 | if (!msg) | |
5934 | return -ENOMEM; | |
5935 | ||
5936 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5937 | NL80211_CMD_PROBE_CLIENT); | |
5938 | ||
5939 | if (IS_ERR(hdr)) { | |
5940 | err = PTR_ERR(hdr); | |
5941 | goto free_msg; | |
5942 | } | |
5943 | ||
5944 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5945 | ||
5946 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); | |
5947 | if (err) | |
5948 | goto free_msg; | |
5949 | ||
5950 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
5951 | ||
5952 | genlmsg_end(msg, hdr); | |
5953 | ||
5954 | return genlmsg_reply(msg, info); | |
5955 | ||
5956 | nla_put_failure: | |
5957 | err = -ENOBUFS; | |
5958 | free_msg: | |
5959 | nlmsg_free(msg); | |
5960 | return err; | |
5961 | } | |
5962 | ||
5e760230 JB |
5963 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
5964 | { | |
5965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5966 | ||
5967 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
5968 | return -EOPNOTSUPP; | |
5969 | ||
5970 | if (rdev->ap_beacons_nlpid) | |
5971 | return -EBUSY; | |
5972 | ||
5973 | rdev->ap_beacons_nlpid = info->snd_pid; | |
5974 | ||
5975 | return 0; | |
5976 | } | |
5977 | ||
4c476991 JB |
5978 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
5979 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
5980 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
5981 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
5982 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
5983 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
5984 | |
5985 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
5986 | struct genl_info *info) | |
5987 | { | |
5988 | struct cfg80211_registered_device *rdev; | |
5989 | struct net_device *dev; | |
5990 | int err; | |
5991 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | |
5992 | ||
5993 | if (rtnl) | |
5994 | rtnl_lock(); | |
5995 | ||
5996 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
5997 | rdev = cfg80211_get_dev_from_info(info); | |
5998 | if (IS_ERR(rdev)) { | |
5999 | if (rtnl) | |
6000 | rtnl_unlock(); | |
6001 | return PTR_ERR(rdev); | |
6002 | } | |
6003 | info->user_ptr[0] = rdev; | |
6004 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | |
6005 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
6006 | if (err) { | |
6007 | if (rtnl) | |
6008 | rtnl_unlock(); | |
6009 | return err; | |
6010 | } | |
41265714 JB |
6011 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
6012 | !netif_running(dev)) { | |
d537f5fd JB |
6013 | cfg80211_unlock_rdev(rdev); |
6014 | dev_put(dev); | |
41265714 JB |
6015 | if (rtnl) |
6016 | rtnl_unlock(); | |
6017 | return -ENETDOWN; | |
6018 | } | |
4c476991 JB |
6019 | info->user_ptr[0] = rdev; |
6020 | info->user_ptr[1] = dev; | |
6021 | } | |
6022 | ||
6023 | return 0; | |
6024 | } | |
6025 | ||
6026 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
6027 | struct genl_info *info) | |
6028 | { | |
6029 | if (info->user_ptr[0]) | |
6030 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
6031 | if (info->user_ptr[1]) | |
6032 | dev_put(info->user_ptr[1]); | |
6033 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | |
6034 | rtnl_unlock(); | |
6035 | } | |
6036 | ||
55682965 JB |
6037 | static struct genl_ops nl80211_ops[] = { |
6038 | { | |
6039 | .cmd = NL80211_CMD_GET_WIPHY, | |
6040 | .doit = nl80211_get_wiphy, | |
6041 | .dumpit = nl80211_dump_wiphy, | |
6042 | .policy = nl80211_policy, | |
6043 | /* can be retrieved by unprivileged users */ | |
4c476991 | 6044 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
6045 | }, |
6046 | { | |
6047 | .cmd = NL80211_CMD_SET_WIPHY, | |
6048 | .doit = nl80211_set_wiphy, | |
6049 | .policy = nl80211_policy, | |
6050 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 6051 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
6052 | }, |
6053 | { | |
6054 | .cmd = NL80211_CMD_GET_INTERFACE, | |
6055 | .doit = nl80211_get_interface, | |
6056 | .dumpit = nl80211_dump_interface, | |
6057 | .policy = nl80211_policy, | |
6058 | /* can be retrieved by unprivileged users */ | |
4c476991 | 6059 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
55682965 JB |
6060 | }, |
6061 | { | |
6062 | .cmd = NL80211_CMD_SET_INTERFACE, | |
6063 | .doit = nl80211_set_interface, | |
6064 | .policy = nl80211_policy, | |
6065 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6066 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6067 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
6068 | }, |
6069 | { | |
6070 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
6071 | .doit = nl80211_new_interface, | |
6072 | .policy = nl80211_policy, | |
6073 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6074 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6075 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
6076 | }, |
6077 | { | |
6078 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
6079 | .doit = nl80211_del_interface, | |
6080 | .policy = nl80211_policy, | |
41ade00f | 6081 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
6082 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6083 | NL80211_FLAG_NEED_RTNL, | |
41ade00f JB |
6084 | }, |
6085 | { | |
6086 | .cmd = NL80211_CMD_GET_KEY, | |
6087 | .doit = nl80211_get_key, | |
6088 | .policy = nl80211_policy, | |
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_SET_KEY, | |
6095 | .doit = nl80211_set_key, | |
6096 | .policy = nl80211_policy, | |
6097 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6098 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6099 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6100 | }, |
6101 | { | |
6102 | .cmd = NL80211_CMD_NEW_KEY, | |
6103 | .doit = nl80211_new_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_DEL_KEY, | |
6111 | .doit = nl80211_del_key, | |
6112 | .policy = nl80211_policy, | |
55682965 | 6113 | .flags = GENL_ADMIN_PERM, |
41265714 | 6114 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6115 | NL80211_FLAG_NEED_RTNL, |
55682965 | 6116 | }, |
ed1b6cc7 JB |
6117 | { |
6118 | .cmd = NL80211_CMD_SET_BEACON, | |
6119 | .policy = nl80211_policy, | |
6120 | .flags = GENL_ADMIN_PERM, | |
6121 | .doit = nl80211_addset_beacon, | |
4c476991 JB |
6122 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6123 | NL80211_FLAG_NEED_RTNL, | |
ed1b6cc7 JB |
6124 | }, |
6125 | { | |
6126 | .cmd = NL80211_CMD_NEW_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_DEL_BEACON, | |
6135 | .policy = nl80211_policy, | |
6136 | .flags = GENL_ADMIN_PERM, | |
6137 | .doit = nl80211_del_beacon, | |
4c476991 JB |
6138 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6139 | NL80211_FLAG_NEED_RTNL, | |
ed1b6cc7 | 6140 | }, |
5727ef1b JB |
6141 | { |
6142 | .cmd = NL80211_CMD_GET_STATION, | |
6143 | .doit = nl80211_get_station, | |
2ec600d6 | 6144 | .dumpit = nl80211_dump_station, |
5727ef1b | 6145 | .policy = nl80211_policy, |
4c476991 JB |
6146 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6147 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
6148 | }, |
6149 | { | |
6150 | .cmd = NL80211_CMD_SET_STATION, | |
6151 | .doit = nl80211_set_station, | |
6152 | .policy = nl80211_policy, | |
6153 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6154 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6155 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
6156 | }, |
6157 | { | |
6158 | .cmd = NL80211_CMD_NEW_STATION, | |
6159 | .doit = nl80211_new_station, | |
6160 | .policy = nl80211_policy, | |
6161 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6162 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6163 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
6164 | }, |
6165 | { | |
6166 | .cmd = NL80211_CMD_DEL_STATION, | |
6167 | .doit = nl80211_del_station, | |
6168 | .policy = nl80211_policy, | |
2ec600d6 | 6169 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
6170 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6171 | NL80211_FLAG_NEED_RTNL, | |
2ec600d6 LCC |
6172 | }, |
6173 | { | |
6174 | .cmd = NL80211_CMD_GET_MPATH, | |
6175 | .doit = nl80211_get_mpath, | |
6176 | .dumpit = nl80211_dump_mpath, | |
6177 | .policy = nl80211_policy, | |
6178 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6179 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6180 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6181 | }, |
6182 | { | |
6183 | .cmd = NL80211_CMD_SET_MPATH, | |
6184 | .doit = nl80211_set_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_NEW_MPATH, | |
6192 | .doit = nl80211_new_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_DEL_MPATH, | |
6200 | .doit = nl80211_del_mpath, | |
6201 | .policy = nl80211_policy, | |
9f1ba906 | 6202 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
6203 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6204 | NL80211_FLAG_NEED_RTNL, | |
9f1ba906 JM |
6205 | }, |
6206 | { | |
6207 | .cmd = NL80211_CMD_SET_BSS, | |
6208 | .doit = nl80211_set_bss, | |
6209 | .policy = nl80211_policy, | |
b2e1b302 | 6210 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
6211 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6212 | NL80211_FLAG_NEED_RTNL, | |
b2e1b302 | 6213 | }, |
f130347c LR |
6214 | { |
6215 | .cmd = NL80211_CMD_GET_REG, | |
6216 | .doit = nl80211_get_reg, | |
6217 | .policy = nl80211_policy, | |
6218 | /* can be retrieved by unprivileged users */ | |
6219 | }, | |
b2e1b302 LR |
6220 | { |
6221 | .cmd = NL80211_CMD_SET_REG, | |
6222 | .doit = nl80211_set_reg, | |
6223 | .policy = nl80211_policy, | |
6224 | .flags = GENL_ADMIN_PERM, | |
6225 | }, | |
6226 | { | |
6227 | .cmd = NL80211_CMD_REQ_SET_REG, | |
6228 | .doit = nl80211_req_set_reg, | |
6229 | .policy = nl80211_policy, | |
93da9cc1 | 6230 | .flags = GENL_ADMIN_PERM, |
6231 | }, | |
6232 | { | |
24bdd9f4 JC |
6233 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
6234 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 6235 | .policy = nl80211_policy, |
6236 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
6237 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6238 | NL80211_FLAG_NEED_RTNL, | |
93da9cc1 | 6239 | }, |
6240 | { | |
24bdd9f4 JC |
6241 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
6242 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 6243 | .policy = nl80211_policy, |
9aed3cc1 | 6244 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 6245 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6246 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 6247 | }, |
2a519311 JB |
6248 | { |
6249 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
6250 | .doit = nl80211_trigger_scan, | |
6251 | .policy = nl80211_policy, | |
6252 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6253 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6254 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
6255 | }, |
6256 | { | |
6257 | .cmd = NL80211_CMD_GET_SCAN, | |
6258 | .policy = nl80211_policy, | |
6259 | .dumpit = nl80211_dump_scan, | |
6260 | }, | |
807f8a8c LC |
6261 | { |
6262 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
6263 | .doit = nl80211_start_sched_scan, | |
6264 | .policy = nl80211_policy, | |
6265 | .flags = GENL_ADMIN_PERM, | |
6266 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6267 | NL80211_FLAG_NEED_RTNL, | |
6268 | }, | |
6269 | { | |
6270 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
6271 | .doit = nl80211_stop_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 | }, | |
636a5d36 JM |
6277 | { |
6278 | .cmd = NL80211_CMD_AUTHENTICATE, | |
6279 | .doit = nl80211_authenticate, | |
6280 | .policy = nl80211_policy, | |
6281 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6282 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6283 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6284 | }, |
6285 | { | |
6286 | .cmd = NL80211_CMD_ASSOCIATE, | |
6287 | .doit = nl80211_associate, | |
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_DEAUTHENTICATE, | |
6295 | .doit = nl80211_deauthenticate, | |
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_DISASSOCIATE, | |
6303 | .doit = nl80211_disassociate, | |
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 | 6308 | }, |
04a773ad JB |
6309 | { |
6310 | .cmd = NL80211_CMD_JOIN_IBSS, | |
6311 | .doit = nl80211_join_ibss, | |
6312 | .policy = nl80211_policy, | |
6313 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6315 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
6316 | }, |
6317 | { | |
6318 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
6319 | .doit = nl80211_leave_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 | 6324 | }, |
aff89a9b JB |
6325 | #ifdef CONFIG_NL80211_TESTMODE |
6326 | { | |
6327 | .cmd = NL80211_CMD_TESTMODE, | |
6328 | .doit = nl80211_testmode_do, | |
71063f0e | 6329 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
6330 | .policy = nl80211_policy, |
6331 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6332 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6333 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
6334 | }, |
6335 | #endif | |
b23aa676 SO |
6336 | { |
6337 | .cmd = NL80211_CMD_CONNECT, | |
6338 | .doit = nl80211_connect, | |
6339 | .policy = nl80211_policy, | |
6340 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6342 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
6343 | }, |
6344 | { | |
6345 | .cmd = NL80211_CMD_DISCONNECT, | |
6346 | .doit = nl80211_disconnect, | |
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 | 6351 | }, |
463d0183 JB |
6352 | { |
6353 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
6354 | .doit = nl80211_wiphy_netns, | |
6355 | .policy = nl80211_policy, | |
6356 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6357 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6358 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 6359 | }, |
61fa713c HS |
6360 | { |
6361 | .cmd = NL80211_CMD_GET_SURVEY, | |
6362 | .policy = nl80211_policy, | |
6363 | .dumpit = nl80211_dump_survey, | |
6364 | }, | |
67fbb16b SO |
6365 | { |
6366 | .cmd = NL80211_CMD_SET_PMKSA, | |
6367 | .doit = nl80211_setdel_pmksa, | |
6368 | .policy = nl80211_policy, | |
6369 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6370 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6371 | NL80211_FLAG_NEED_RTNL, | |
67fbb16b SO |
6372 | }, |
6373 | { | |
6374 | .cmd = NL80211_CMD_DEL_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_FLUSH_PMKSA, | |
6383 | .doit = nl80211_flush_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 | 6388 | }, |
9588bbd5 JM |
6389 | { |
6390 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
6391 | .doit = nl80211_remain_on_channel, | |
6392 | .policy = nl80211_policy, | |
6393 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6395 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
6396 | }, |
6397 | { | |
6398 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
6399 | .doit = nl80211_cancel_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 | 6404 | }, |
13ae75b1 JM |
6405 | { |
6406 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
6407 | .doit = nl80211_set_tx_bitrate_mask, | |
6408 | .policy = nl80211_policy, | |
6409 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6410 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6411 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 6412 | }, |
026331c4 | 6413 | { |
2e161f78 JB |
6414 | .cmd = NL80211_CMD_REGISTER_FRAME, |
6415 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
6416 | .policy = nl80211_policy, |
6417 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6418 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6419 | NL80211_FLAG_NEED_RTNL, | |
026331c4 JM |
6420 | }, |
6421 | { | |
2e161f78 JB |
6422 | .cmd = NL80211_CMD_FRAME, |
6423 | .doit = nl80211_tx_mgmt, | |
026331c4 | 6424 | .policy = nl80211_policy, |
f7ca38df JB |
6425 | .flags = GENL_ADMIN_PERM, |
6426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6427 | NL80211_FLAG_NEED_RTNL, | |
6428 | }, | |
6429 | { | |
6430 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
6431 | .doit = nl80211_tx_mgmt_cancel_wait, | |
6432 | .policy = nl80211_policy, | |
026331c4 | 6433 | .flags = GENL_ADMIN_PERM, |
41265714 | 6434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6435 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 6436 | }, |
ffb9eb3d KV |
6437 | { |
6438 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
6439 | .doit = nl80211_set_power_save, | |
6440 | .policy = nl80211_policy, | |
6441 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6442 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6443 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
6444 | }, |
6445 | { | |
6446 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
6447 | .doit = nl80211_get_power_save, | |
6448 | .policy = nl80211_policy, | |
6449 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
6450 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6451 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 6452 | }, |
d6dc1a38 JO |
6453 | { |
6454 | .cmd = NL80211_CMD_SET_CQM, | |
6455 | .doit = nl80211_set_cqm, | |
6456 | .policy = nl80211_policy, | |
6457 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6458 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6459 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 6460 | }, |
f444de05 JB |
6461 | { |
6462 | .cmd = NL80211_CMD_SET_CHANNEL, | |
6463 | .doit = nl80211_set_channel, | |
6464 | .policy = nl80211_policy, | |
6465 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6466 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6467 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 6468 | }, |
e8347eba BJ |
6469 | { |
6470 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
6471 | .doit = nl80211_set_wds_peer, | |
6472 | .policy = nl80211_policy, | |
6473 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
6474 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6475 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 6476 | }, |
29cbe68c JB |
6477 | { |
6478 | .cmd = NL80211_CMD_JOIN_MESH, | |
6479 | .doit = nl80211_join_mesh, | |
6480 | .policy = nl80211_policy, | |
6481 | .flags = GENL_ADMIN_PERM, | |
6482 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6483 | NL80211_FLAG_NEED_RTNL, | |
6484 | }, | |
6485 | { | |
6486 | .cmd = NL80211_CMD_LEAVE_MESH, | |
6487 | .doit = nl80211_leave_mesh, | |
6488 | .policy = nl80211_policy, | |
6489 | .flags = GENL_ADMIN_PERM, | |
6490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6491 | NL80211_FLAG_NEED_RTNL, | |
6492 | }, | |
ff1b6e69 JB |
6493 | { |
6494 | .cmd = NL80211_CMD_GET_WOWLAN, | |
6495 | .doit = nl80211_get_wowlan, | |
6496 | .policy = nl80211_policy, | |
6497 | /* can be retrieved by unprivileged users */ | |
6498 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6499 | NL80211_FLAG_NEED_RTNL, | |
6500 | }, | |
6501 | { | |
6502 | .cmd = NL80211_CMD_SET_WOWLAN, | |
6503 | .doit = nl80211_set_wowlan, | |
6504 | .policy = nl80211_policy, | |
6505 | .flags = GENL_ADMIN_PERM, | |
6506 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6507 | NL80211_FLAG_NEED_RTNL, | |
6508 | }, | |
e5497d76 JB |
6509 | { |
6510 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
6511 | .doit = nl80211_set_rekey_data, | |
6512 | .policy = nl80211_policy, | |
6513 | .flags = GENL_ADMIN_PERM, | |
6514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6515 | NL80211_FLAG_NEED_RTNL, | |
6516 | }, | |
109086ce AN |
6517 | { |
6518 | .cmd = NL80211_CMD_TDLS_MGMT, | |
6519 | .doit = nl80211_tdls_mgmt, | |
6520 | .policy = nl80211_policy, | |
6521 | .flags = GENL_ADMIN_PERM, | |
6522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6523 | NL80211_FLAG_NEED_RTNL, | |
6524 | }, | |
6525 | { | |
6526 | .cmd = NL80211_CMD_TDLS_OPER, | |
6527 | .doit = nl80211_tdls_oper, | |
6528 | .policy = nl80211_policy, | |
6529 | .flags = GENL_ADMIN_PERM, | |
6530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6531 | NL80211_FLAG_NEED_RTNL, | |
6532 | }, | |
28946da7 JB |
6533 | { |
6534 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
6535 | .doit = nl80211_register_unexpected_frame, | |
6536 | .policy = nl80211_policy, | |
6537 | .flags = GENL_ADMIN_PERM, | |
6538 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
6539 | NL80211_FLAG_NEED_RTNL, | |
6540 | }, | |
7f6cf311 JB |
6541 | { |
6542 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
6543 | .doit = nl80211_probe_client, | |
6544 | .policy = nl80211_policy, | |
6545 | .flags = GENL_ADMIN_PERM, | |
6546 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
6547 | NL80211_FLAG_NEED_RTNL, | |
6548 | }, | |
5e760230 JB |
6549 | { |
6550 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
6551 | .doit = nl80211_register_beacons, | |
6552 | .policy = nl80211_policy, | |
6553 | .flags = GENL_ADMIN_PERM, | |
6554 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6555 | NL80211_FLAG_NEED_RTNL, | |
6556 | }, | |
55682965 | 6557 | }; |
9588bbd5 | 6558 | |
6039f6d2 JM |
6559 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
6560 | .name = "mlme", | |
6561 | }; | |
55682965 JB |
6562 | |
6563 | /* multicast groups */ | |
6564 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
6565 | .name = "config", | |
6566 | }; | |
2a519311 JB |
6567 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
6568 | .name = "scan", | |
6569 | }; | |
73d54c9e LR |
6570 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
6571 | .name = "regulatory", | |
6572 | }; | |
55682965 JB |
6573 | |
6574 | /* notification functions */ | |
6575 | ||
6576 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
6577 | { | |
6578 | struct sk_buff *msg; | |
6579 | ||
fd2120ca | 6580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
6581 | if (!msg) |
6582 | return; | |
6583 | ||
6584 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
6585 | nlmsg_free(msg); | |
6586 | return; | |
6587 | } | |
6588 | ||
463d0183 JB |
6589 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6590 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
6591 | } |
6592 | ||
362a415d JB |
6593 | static int nl80211_add_scan_req(struct sk_buff *msg, |
6594 | struct cfg80211_registered_device *rdev) | |
6595 | { | |
6596 | struct cfg80211_scan_request *req = rdev->scan_req; | |
6597 | struct nlattr *nest; | |
6598 | int i; | |
6599 | ||
667503dd JB |
6600 | ASSERT_RDEV_LOCK(rdev); |
6601 | ||
362a415d JB |
6602 | if (WARN_ON(!req)) |
6603 | return 0; | |
6604 | ||
6605 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
6606 | if (!nest) | |
6607 | goto nla_put_failure; | |
6608 | for (i = 0; i < req->n_ssids; i++) | |
6609 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); | |
6610 | nla_nest_end(msg, nest); | |
6611 | ||
6612 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
6613 | if (!nest) | |
6614 | goto nla_put_failure; | |
6615 | for (i = 0; i < req->n_channels; i++) | |
6616 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); | |
6617 | nla_nest_end(msg, nest); | |
6618 | ||
6619 | if (req->ie) | |
6620 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); | |
6621 | ||
6622 | return 0; | |
6623 | nla_put_failure: | |
6624 | return -ENOBUFS; | |
6625 | } | |
6626 | ||
a538e2d5 JB |
6627 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
6628 | struct cfg80211_registered_device *rdev, | |
6629 | struct net_device *netdev, | |
6630 | u32 pid, u32 seq, int flags, | |
6631 | u32 cmd) | |
2a519311 JB |
6632 | { |
6633 | void *hdr; | |
6634 | ||
6635 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
6636 | if (!hdr) | |
6637 | return -1; | |
6638 | ||
b5850a7a | 6639 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
2a519311 JB |
6640 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
6641 | ||
362a415d JB |
6642 | /* ignore errors and send incomplete event anyway */ |
6643 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
6644 | |
6645 | return genlmsg_end(msg, hdr); | |
6646 | ||
6647 | nla_put_failure: | |
6648 | genlmsg_cancel(msg, hdr); | |
6649 | return -EMSGSIZE; | |
6650 | } | |
6651 | ||
807f8a8c LC |
6652 | static int |
6653 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
6654 | struct cfg80211_registered_device *rdev, | |
6655 | struct net_device *netdev, | |
6656 | u32 pid, u32 seq, int flags, u32 cmd) | |
6657 | { | |
6658 | void *hdr; | |
6659 | ||
6660 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
6661 | if (!hdr) | |
6662 | return -1; | |
6663 | ||
6664 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6665 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6666 | ||
6667 | return genlmsg_end(msg, hdr); | |
6668 | ||
6669 | nla_put_failure: | |
6670 | genlmsg_cancel(msg, hdr); | |
6671 | return -EMSGSIZE; | |
6672 | } | |
6673 | ||
a538e2d5 JB |
6674 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
6675 | struct net_device *netdev) | |
6676 | { | |
6677 | struct sk_buff *msg; | |
6678 | ||
6679 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
6680 | if (!msg) | |
6681 | return; | |
6682 | ||
6683 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
6684 | NL80211_CMD_TRIGGER_SCAN) < 0) { | |
6685 | nlmsg_free(msg); | |
6686 | return; | |
6687 | } | |
6688 | ||
463d0183 JB |
6689 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6690 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
6691 | } |
6692 | ||
2a519311 JB |
6693 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
6694 | struct net_device *netdev) | |
6695 | { | |
6696 | struct sk_buff *msg; | |
6697 | ||
fd2120ca | 6698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
6699 | if (!msg) |
6700 | return; | |
6701 | ||
a538e2d5 JB |
6702 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
6703 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 JB |
6704 | nlmsg_free(msg); |
6705 | return; | |
6706 | } | |
6707 | ||
463d0183 JB |
6708 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6709 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
6710 | } |
6711 | ||
6712 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
6713 | struct net_device *netdev) | |
6714 | { | |
6715 | struct sk_buff *msg; | |
6716 | ||
fd2120ca | 6717 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
6718 | if (!msg) |
6719 | return; | |
6720 | ||
a538e2d5 JB |
6721 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
6722 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
2a519311 JB |
6723 | nlmsg_free(msg); |
6724 | return; | |
6725 | } | |
6726 | ||
463d0183 JB |
6727 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6728 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
6729 | } |
6730 | ||
807f8a8c LC |
6731 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
6732 | struct net_device *netdev) | |
6733 | { | |
6734 | struct sk_buff *msg; | |
6735 | ||
6736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6737 | if (!msg) | |
6738 | return; | |
6739 | ||
6740 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
6741 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
6742 | nlmsg_free(msg); | |
6743 | return; | |
6744 | } | |
6745 | ||
6746 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6747 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
6748 | } | |
6749 | ||
6750 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
6751 | struct net_device *netdev, u32 cmd) | |
6752 | { | |
6753 | struct sk_buff *msg; | |
6754 | ||
6755 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
6756 | if (!msg) | |
6757 | return; | |
6758 | ||
6759 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
6760 | nlmsg_free(msg); | |
6761 | return; | |
6762 | } | |
6763 | ||
6764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6765 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
6766 | } | |
6767 | ||
73d54c9e LR |
6768 | /* |
6769 | * This can happen on global regulatory changes or device specific settings | |
6770 | * based on custom world regulatory domains. | |
6771 | */ | |
6772 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
6773 | { | |
6774 | struct sk_buff *msg; | |
6775 | void *hdr; | |
6776 | ||
fd2120ca | 6777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
6778 | if (!msg) |
6779 | return; | |
6780 | ||
6781 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
6782 | if (!hdr) { | |
6783 | nlmsg_free(msg); | |
6784 | return; | |
6785 | } | |
6786 | ||
6787 | /* Userspace can always count this one always being set */ | |
6788 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); | |
6789 | ||
6790 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') | |
6791 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6792 | NL80211_REGDOM_TYPE_WORLD); | |
6793 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') | |
6794 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6795 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); | |
6796 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
6797 | request->intersect) | |
6798 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6799 | NL80211_REGDOM_TYPE_INTERSECTION); | |
6800 | else { | |
6801 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
6802 | NL80211_REGDOM_TYPE_COUNTRY); | |
6803 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); | |
6804 | } | |
6805 | ||
6806 | if (wiphy_idx_valid(request->wiphy_idx)) | |
6807 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); | |
6808 | ||
3b7b72ee | 6809 | genlmsg_end(msg, hdr); |
73d54c9e | 6810 | |
bc43b28c | 6811 | rcu_read_lock(); |
463d0183 | 6812 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
6813 | GFP_ATOMIC); |
6814 | rcu_read_unlock(); | |
73d54c9e LR |
6815 | |
6816 | return; | |
6817 | ||
6818 | nla_put_failure: | |
6819 | genlmsg_cancel(msg, hdr); | |
6820 | nlmsg_free(msg); | |
6821 | } | |
6822 | ||
6039f6d2 JM |
6823 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
6824 | struct net_device *netdev, | |
6825 | const u8 *buf, size_t len, | |
e6d6e342 | 6826 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
6827 | { |
6828 | struct sk_buff *msg; | |
6829 | void *hdr; | |
6830 | ||
e6d6e342 | 6831 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
6832 | if (!msg) |
6833 | return; | |
6834 | ||
6835 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
6836 | if (!hdr) { | |
6837 | nlmsg_free(msg); | |
6838 | return; | |
6839 | } | |
6840 | ||
6841 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6842 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6843 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
6844 | ||
3b7b72ee | 6845 | genlmsg_end(msg, hdr); |
6039f6d2 | 6846 | |
463d0183 JB |
6847 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6848 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
6849 | return; |
6850 | ||
6851 | nla_put_failure: | |
6852 | genlmsg_cancel(msg, hdr); | |
6853 | nlmsg_free(msg); | |
6854 | } | |
6855 | ||
6856 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
6857 | struct net_device *netdev, const u8 *buf, |
6858 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
6859 | { |
6860 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 6861 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
6862 | } |
6863 | ||
6864 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
6865 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 6866 | size_t len, gfp_t gfp) |
6039f6d2 | 6867 | { |
e6d6e342 JB |
6868 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
6869 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
6870 | } |
6871 | ||
53b46b84 | 6872 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
6873 | struct net_device *netdev, const u8 *buf, |
6874 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
6875 | { |
6876 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 6877 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
6878 | } |
6879 | ||
53b46b84 JM |
6880 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
6881 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 6882 | size_t len, gfp_t gfp) |
6039f6d2 JM |
6883 | { |
6884 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 6885 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
6886 | } |
6887 | ||
cf4e594e JM |
6888 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
6889 | struct net_device *netdev, const u8 *buf, | |
6890 | size_t len, gfp_t gfp) | |
6891 | { | |
6892 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
6893 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); | |
6894 | } | |
6895 | ||
6896 | void nl80211_send_unprot_disassoc(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_DISASSOCIATE, gfp); | |
6902 | } | |
6903 | ||
1b06bb40 LR |
6904 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
6905 | struct net_device *netdev, int cmd, | |
e6d6e342 | 6906 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
6907 | { |
6908 | struct sk_buff *msg; | |
6909 | void *hdr; | |
6910 | ||
e6d6e342 | 6911 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
6912 | if (!msg) |
6913 | return; | |
6914 | ||
6915 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
6916 | if (!hdr) { | |
6917 | nlmsg_free(msg); | |
6918 | return; | |
6919 | } | |
6920 | ||
6921 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6922 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6923 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); | |
6924 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
6925 | ||
3b7b72ee | 6926 | genlmsg_end(msg, hdr); |
1965c853 | 6927 | |
463d0183 JB |
6928 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6929 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
6930 | return; |
6931 | ||
6932 | nla_put_failure: | |
6933 | genlmsg_cancel(msg, hdr); | |
6934 | nlmsg_free(msg); | |
6935 | } | |
6936 | ||
6937 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
6938 | struct net_device *netdev, const u8 *addr, |
6939 | gfp_t gfp) | |
1965c853 JM |
6940 | { |
6941 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 6942 | addr, gfp); |
1965c853 JM |
6943 | } |
6944 | ||
6945 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
6946 | struct net_device *netdev, const u8 *addr, |
6947 | gfp_t gfp) | |
1965c853 | 6948 | { |
e6d6e342 JB |
6949 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
6950 | addr, gfp); | |
1965c853 JM |
6951 | } |
6952 | ||
b23aa676 SO |
6953 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
6954 | struct net_device *netdev, const u8 *bssid, | |
6955 | const u8 *req_ie, size_t req_ie_len, | |
6956 | const u8 *resp_ie, size_t resp_ie_len, | |
6957 | u16 status, gfp_t gfp) | |
6958 | { | |
6959 | struct sk_buff *msg; | |
6960 | void *hdr; | |
6961 | ||
6962 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6963 | if (!msg) | |
6964 | return; | |
6965 | ||
6966 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
6967 | if (!hdr) { | |
6968 | nlmsg_free(msg); | |
6969 | return; | |
6970 | } | |
6971 | ||
6972 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6973 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6974 | if (bssid) | |
6975 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
6976 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); | |
6977 | if (req_ie) | |
6978 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
6979 | if (resp_ie) | |
6980 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
6981 | ||
3b7b72ee | 6982 | genlmsg_end(msg, hdr); |
b23aa676 | 6983 | |
463d0183 JB |
6984 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6985 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
6986 | return; |
6987 | ||
6988 | nla_put_failure: | |
6989 | genlmsg_cancel(msg, hdr); | |
6990 | nlmsg_free(msg); | |
6991 | ||
6992 | } | |
6993 | ||
6994 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
6995 | struct net_device *netdev, const u8 *bssid, | |
6996 | const u8 *req_ie, size_t req_ie_len, | |
6997 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
6998 | { | |
6999 | struct sk_buff *msg; | |
7000 | void *hdr; | |
7001 | ||
7002 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7003 | if (!msg) | |
7004 | return; | |
7005 | ||
7006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
7007 | if (!hdr) { | |
7008 | nlmsg_free(msg); | |
7009 | return; | |
7010 | } | |
7011 | ||
7012 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7013 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7014 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
7015 | if (req_ie) | |
7016 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
7017 | if (resp_ie) | |
7018 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
7019 | ||
3b7b72ee | 7020 | genlmsg_end(msg, hdr); |
b23aa676 | 7021 | |
463d0183 JB |
7022 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7023 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
7024 | return; |
7025 | ||
7026 | nla_put_failure: | |
7027 | genlmsg_cancel(msg, hdr); | |
7028 | nlmsg_free(msg); | |
7029 | ||
7030 | } | |
7031 | ||
7032 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
7033 | struct net_device *netdev, u16 reason, | |
667503dd | 7034 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
7035 | { |
7036 | struct sk_buff *msg; | |
7037 | void *hdr; | |
7038 | ||
667503dd | 7039 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
b23aa676 SO |
7040 | if (!msg) |
7041 | return; | |
7042 | ||
7043 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
7044 | if (!hdr) { | |
7045 | nlmsg_free(msg); | |
7046 | return; | |
7047 | } | |
7048 | ||
7049 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7050 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7051 | if (from_ap && reason) | |
7052 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); | |
7053 | if (from_ap) | |
7054 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); | |
7055 | if (ie) | |
7056 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); | |
7057 | ||
3b7b72ee | 7058 | genlmsg_end(msg, hdr); |
b23aa676 | 7059 | |
463d0183 JB |
7060 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7061 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
7062 | return; |
7063 | ||
7064 | nla_put_failure: | |
7065 | genlmsg_cancel(msg, hdr); | |
7066 | nlmsg_free(msg); | |
7067 | ||
7068 | } | |
7069 | ||
04a773ad JB |
7070 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
7071 | struct net_device *netdev, const u8 *bssid, | |
7072 | gfp_t gfp) | |
7073 | { | |
7074 | struct sk_buff *msg; | |
7075 | void *hdr; | |
7076 | ||
fd2120ca | 7077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
7078 | if (!msg) |
7079 | return; | |
7080 | ||
7081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
7082 | if (!hdr) { | |
7083 | nlmsg_free(msg); | |
7084 | return; | |
7085 | } | |
7086 | ||
7087 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7088 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7089 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
7090 | ||
3b7b72ee | 7091 | genlmsg_end(msg, hdr); |
04a773ad | 7092 | |
463d0183 JB |
7093 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7094 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
7095 | return; |
7096 | ||
7097 | nla_put_failure: | |
7098 | genlmsg_cancel(msg, hdr); | |
7099 | nlmsg_free(msg); | |
7100 | } | |
7101 | ||
c93b5e71 JC |
7102 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
7103 | struct net_device *netdev, | |
7104 | const u8 *macaddr, const u8* ie, u8 ie_len, | |
7105 | gfp_t gfp) | |
7106 | { | |
7107 | struct sk_buff *msg; | |
7108 | void *hdr; | |
7109 | ||
7110 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7111 | if (!msg) | |
7112 | return; | |
7113 | ||
7114 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
7115 | if (!hdr) { | |
7116 | nlmsg_free(msg); | |
7117 | return; | |
7118 | } | |
7119 | ||
7120 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7121 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7122 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); | |
7123 | if (ie_len && ie) | |
7124 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); | |
7125 | ||
3b7b72ee | 7126 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
7127 | |
7128 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7129 | nl80211_mlme_mcgrp.id, gfp); | |
7130 | return; | |
7131 | ||
7132 | nla_put_failure: | |
7133 | genlmsg_cancel(msg, hdr); | |
7134 | nlmsg_free(msg); | |
7135 | } | |
7136 | ||
a3b8b056 JM |
7137 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
7138 | struct net_device *netdev, const u8 *addr, | |
7139 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 7140 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
7141 | { |
7142 | struct sk_buff *msg; | |
7143 | void *hdr; | |
7144 | ||
e6d6e342 | 7145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
7146 | if (!msg) |
7147 | return; | |
7148 | ||
7149 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
7150 | if (!hdr) { | |
7151 | nlmsg_free(msg); | |
7152 | return; | |
7153 | } | |
7154 | ||
7155 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7156 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7157 | if (addr) | |
7158 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
7159 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); | |
a66b98db AN |
7160 | if (key_id != -1) |
7161 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | |
a3b8b056 JM |
7162 | if (tsc) |
7163 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); | |
7164 | ||
3b7b72ee | 7165 | genlmsg_end(msg, hdr); |
a3b8b056 | 7166 | |
463d0183 JB |
7167 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7168 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
7169 | return; |
7170 | ||
7171 | nla_put_failure: | |
7172 | genlmsg_cancel(msg, hdr); | |
7173 | nlmsg_free(msg); | |
7174 | } | |
7175 | ||
6bad8766 LR |
7176 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
7177 | struct ieee80211_channel *channel_before, | |
7178 | struct ieee80211_channel *channel_after) | |
7179 | { | |
7180 | struct sk_buff *msg; | |
7181 | void *hdr; | |
7182 | struct nlattr *nl_freq; | |
7183 | ||
fd2120ca | 7184 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
7185 | if (!msg) |
7186 | return; | |
7187 | ||
7188 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
7189 | if (!hdr) { | |
7190 | nlmsg_free(msg); | |
7191 | return; | |
7192 | } | |
7193 | ||
7194 | /* | |
7195 | * Since we are applying the beacon hint to a wiphy we know its | |
7196 | * wiphy_idx is valid | |
7197 | */ | |
7198 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); | |
7199 | ||
7200 | /* Before */ | |
7201 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
7202 | if (!nl_freq) | |
7203 | goto nla_put_failure; | |
7204 | if (nl80211_msg_put_channel(msg, channel_before)) | |
7205 | goto nla_put_failure; | |
7206 | nla_nest_end(msg, nl_freq); | |
7207 | ||
7208 | /* After */ | |
7209 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
7210 | if (!nl_freq) | |
7211 | goto nla_put_failure; | |
7212 | if (nl80211_msg_put_channel(msg, channel_after)) | |
7213 | goto nla_put_failure; | |
7214 | nla_nest_end(msg, nl_freq); | |
7215 | ||
3b7b72ee | 7216 | genlmsg_end(msg, hdr); |
6bad8766 | 7217 | |
463d0183 JB |
7218 | rcu_read_lock(); |
7219 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
7220 | GFP_ATOMIC); | |
7221 | rcu_read_unlock(); | |
6bad8766 LR |
7222 | |
7223 | return; | |
7224 | ||
7225 | nla_put_failure: | |
7226 | genlmsg_cancel(msg, hdr); | |
7227 | nlmsg_free(msg); | |
7228 | } | |
7229 | ||
9588bbd5 JM |
7230 | static void nl80211_send_remain_on_chan_event( |
7231 | int cmd, struct cfg80211_registered_device *rdev, | |
7232 | struct net_device *netdev, u64 cookie, | |
7233 | struct ieee80211_channel *chan, | |
7234 | enum nl80211_channel_type channel_type, | |
7235 | unsigned int duration, gfp_t gfp) | |
7236 | { | |
7237 | struct sk_buff *msg; | |
7238 | void *hdr; | |
7239 | ||
7240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7241 | if (!msg) | |
7242 | return; | |
7243 | ||
7244 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7245 | if (!hdr) { | |
7246 | nlmsg_free(msg); | |
7247 | return; | |
7248 | } | |
7249 | ||
7250 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7251 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7252 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); | |
7253 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); | |
7254 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
7255 | ||
7256 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) | |
7257 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
7258 | ||
3b7b72ee | 7259 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
7260 | |
7261 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7262 | nl80211_mlme_mcgrp.id, gfp); | |
7263 | return; | |
7264 | ||
7265 | nla_put_failure: | |
7266 | genlmsg_cancel(msg, hdr); | |
7267 | nlmsg_free(msg); | |
7268 | } | |
7269 | ||
7270 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
7271 | struct net_device *netdev, u64 cookie, | |
7272 | struct ieee80211_channel *chan, | |
7273 | enum nl80211_channel_type channel_type, | |
7274 | unsigned int duration, gfp_t gfp) | |
7275 | { | |
7276 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
7277 | rdev, netdev, cookie, chan, | |
7278 | channel_type, duration, gfp); | |
7279 | } | |
7280 | ||
7281 | void nl80211_send_remain_on_channel_cancel( | |
7282 | struct cfg80211_registered_device *rdev, struct net_device *netdev, | |
7283 | u64 cookie, struct ieee80211_channel *chan, | |
7284 | enum nl80211_channel_type channel_type, gfp_t gfp) | |
7285 | { | |
7286 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
7287 | rdev, netdev, cookie, chan, | |
7288 | channel_type, 0, gfp); | |
7289 | } | |
7290 | ||
98b62183 JB |
7291 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
7292 | struct net_device *dev, const u8 *mac_addr, | |
7293 | struct station_info *sinfo, gfp_t gfp) | |
7294 | { | |
7295 | struct sk_buff *msg; | |
7296 | ||
7297 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7298 | if (!msg) | |
7299 | return; | |
7300 | ||
7301 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { | |
7302 | nlmsg_free(msg); | |
7303 | return; | |
7304 | } | |
7305 | ||
7306 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7307 | nl80211_mlme_mcgrp.id, gfp); | |
7308 | } | |
7309 | ||
ec15e68b JM |
7310 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
7311 | struct net_device *dev, const u8 *mac_addr, | |
7312 | gfp_t gfp) | |
7313 | { | |
7314 | struct sk_buff *msg; | |
7315 | void *hdr; | |
7316 | ||
7317 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7318 | if (!msg) | |
7319 | return; | |
7320 | ||
7321 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
7322 | if (!hdr) { | |
7323 | nlmsg_free(msg); | |
7324 | return; | |
7325 | } | |
7326 | ||
7327 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
7328 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
7329 | ||
3b7b72ee | 7330 | genlmsg_end(msg, hdr); |
ec15e68b JM |
7331 | |
7332 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7333 | nl80211_mlme_mcgrp.id, gfp); | |
7334 | return; | |
7335 | ||
7336 | nla_put_failure: | |
7337 | genlmsg_cancel(msg, hdr); | |
7338 | nlmsg_free(msg); | |
7339 | } | |
7340 | ||
b92ab5d8 JB |
7341 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
7342 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
7343 | { |
7344 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7345 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
7346 | struct sk_buff *msg; | |
7347 | void *hdr; | |
7348 | int err; | |
7349 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); | |
7350 | ||
7351 | if (!nlpid) | |
7352 | return false; | |
7353 | ||
7354 | msg = nlmsg_new(100, gfp); | |
7355 | if (!msg) | |
7356 | return true; | |
7357 | ||
b92ab5d8 | 7358 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
7359 | if (!hdr) { |
7360 | nlmsg_free(msg); | |
7361 | return true; | |
7362 | } | |
7363 | ||
7364 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7365 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
7366 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
7367 | ||
7368 | err = genlmsg_end(msg, hdr); | |
7369 | if (err < 0) { | |
7370 | nlmsg_free(msg); | |
7371 | return true; | |
7372 | } | |
7373 | ||
7374 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
7375 | return true; | |
7376 | ||
7377 | nla_put_failure: | |
7378 | genlmsg_cancel(msg, hdr); | |
7379 | nlmsg_free(msg); | |
7380 | return true; | |
7381 | } | |
7382 | ||
b92ab5d8 JB |
7383 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
7384 | { | |
7385 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
7386 | addr, gfp); | |
7387 | } | |
7388 | ||
7389 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, | |
7390 | const u8 *addr, gfp_t gfp) | |
7391 | { | |
7392 | return __nl80211_unexpected_frame(dev, | |
7393 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
7394 | addr, gfp); | |
7395 | } | |
7396 | ||
2e161f78 JB |
7397 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
7398 | struct net_device *netdev, u32 nlpid, | |
7399 | int freq, const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 JM |
7400 | { |
7401 | struct sk_buff *msg; | |
7402 | void *hdr; | |
026331c4 JM |
7403 | |
7404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7405 | if (!msg) | |
7406 | return -ENOMEM; | |
7407 | ||
2e161f78 | 7408 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
7409 | if (!hdr) { |
7410 | nlmsg_free(msg); | |
7411 | return -ENOMEM; | |
7412 | } | |
7413 | ||
7414 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7415 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7416 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
7417 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
7418 | ||
3b7b72ee | 7419 | genlmsg_end(msg, hdr); |
026331c4 | 7420 | |
3b7b72ee | 7421 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
026331c4 JM |
7422 | |
7423 | nla_put_failure: | |
7424 | genlmsg_cancel(msg, hdr); | |
7425 | nlmsg_free(msg); | |
7426 | return -ENOBUFS; | |
7427 | } | |
7428 | ||
2e161f78 JB |
7429 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
7430 | struct net_device *netdev, u64 cookie, | |
7431 | const u8 *buf, size_t len, bool ack, | |
7432 | gfp_t gfp) | |
026331c4 JM |
7433 | { |
7434 | struct sk_buff *msg; | |
7435 | void *hdr; | |
7436 | ||
7437 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7438 | if (!msg) | |
7439 | return; | |
7440 | ||
2e161f78 | 7441 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
7442 | if (!hdr) { |
7443 | nlmsg_free(msg); | |
7444 | return; | |
7445 | } | |
7446 | ||
7447 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7448 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7449 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
7450 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
7451 | if (ack) | |
7452 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); | |
7453 | ||
3b7b72ee | 7454 | genlmsg_end(msg, hdr); |
026331c4 JM |
7455 | |
7456 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
7457 | return; | |
7458 | ||
7459 | nla_put_failure: | |
7460 | genlmsg_cancel(msg, hdr); | |
7461 | nlmsg_free(msg); | |
7462 | } | |
7463 | ||
d6dc1a38 JO |
7464 | void |
7465 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |
7466 | struct net_device *netdev, | |
7467 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
7468 | gfp_t gfp) | |
7469 | { | |
7470 | struct sk_buff *msg; | |
7471 | struct nlattr *pinfoattr; | |
7472 | void *hdr; | |
7473 | ||
7474 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7475 | if (!msg) | |
7476 | return; | |
7477 | ||
7478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
7479 | if (!hdr) { | |
7480 | nlmsg_free(msg); | |
7481 | return; | |
7482 | } | |
7483 | ||
7484 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7485 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7486 | ||
7487 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
7488 | if (!pinfoattr) | |
7489 | goto nla_put_failure; | |
7490 | ||
7491 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
7492 | rssi_event); | |
7493 | ||
7494 | nla_nest_end(msg, pinfoattr); | |
7495 | ||
3b7b72ee | 7496 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
7497 | |
7498 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7499 | nl80211_mlme_mcgrp.id, gfp); | |
7500 | return; | |
7501 | ||
7502 | nla_put_failure: | |
7503 | genlmsg_cancel(msg, hdr); | |
7504 | nlmsg_free(msg); | |
7505 | } | |
7506 | ||
e5497d76 JB |
7507 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
7508 | struct net_device *netdev, const u8 *bssid, | |
7509 | const u8 *replay_ctr, gfp_t gfp) | |
7510 | { | |
7511 | struct sk_buff *msg; | |
7512 | struct nlattr *rekey_attr; | |
7513 | void *hdr; | |
7514 | ||
7515 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7516 | if (!msg) | |
7517 | return; | |
7518 | ||
7519 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
7520 | if (!hdr) { | |
7521 | nlmsg_free(msg); | |
7522 | return; | |
7523 | } | |
7524 | ||
7525 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7526 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7527 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
7528 | ||
7529 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
7530 | if (!rekey_attr) | |
7531 | goto nla_put_failure; | |
7532 | ||
7533 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, | |
7534 | NL80211_REPLAY_CTR_LEN, replay_ctr); | |
7535 | ||
7536 | nla_nest_end(msg, rekey_attr); | |
7537 | ||
3b7b72ee | 7538 | genlmsg_end(msg, hdr); |
e5497d76 JB |
7539 | |
7540 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7541 | nl80211_mlme_mcgrp.id, gfp); | |
7542 | return; | |
7543 | ||
7544 | nla_put_failure: | |
7545 | genlmsg_cancel(msg, hdr); | |
7546 | nlmsg_free(msg); | |
7547 | } | |
7548 | ||
c9df56b4 JM |
7549 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
7550 | struct net_device *netdev, int index, | |
7551 | const u8 *bssid, bool preauth, gfp_t gfp) | |
7552 | { | |
7553 | struct sk_buff *msg; | |
7554 | struct nlattr *attr; | |
7555 | void *hdr; | |
7556 | ||
7557 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7558 | if (!msg) | |
7559 | return; | |
7560 | ||
7561 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
7562 | if (!hdr) { | |
7563 | nlmsg_free(msg); | |
7564 | return; | |
7565 | } | |
7566 | ||
7567 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7568 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7569 | ||
7570 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
7571 | if (!attr) | |
7572 | goto nla_put_failure; | |
7573 | ||
7574 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); | |
7575 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); | |
7576 | if (preauth) | |
7577 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); | |
7578 | ||
7579 | nla_nest_end(msg, attr); | |
7580 | ||
3b7b72ee | 7581 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
7582 | |
7583 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7584 | nl80211_mlme_mcgrp.id, gfp); | |
7585 | return; | |
7586 | ||
7587 | nla_put_failure: | |
7588 | genlmsg_cancel(msg, hdr); | |
7589 | nlmsg_free(msg); | |
7590 | } | |
7591 | ||
c063dbf5 JB |
7592 | void |
7593 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, | |
7594 | struct net_device *netdev, const u8 *peer, | |
7595 | u32 num_packets, gfp_t gfp) | |
7596 | { | |
7597 | struct sk_buff *msg; | |
7598 | struct nlattr *pinfoattr; | |
7599 | void *hdr; | |
7600 | ||
7601 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7602 | if (!msg) | |
7603 | return; | |
7604 | ||
7605 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
7606 | if (!hdr) { | |
7607 | nlmsg_free(msg); | |
7608 | return; | |
7609 | } | |
7610 | ||
7611 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7612 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
7613 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); | |
7614 | ||
7615 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
7616 | if (!pinfoattr) | |
7617 | goto nla_put_failure; | |
7618 | ||
7619 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); | |
7620 | ||
7621 | nla_nest_end(msg, pinfoattr); | |
7622 | ||
3b7b72ee | 7623 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
7624 | |
7625 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7626 | nl80211_mlme_mcgrp.id, gfp); | |
7627 | return; | |
7628 | ||
7629 | nla_put_failure: | |
7630 | genlmsg_cancel(msg, hdr); | |
7631 | nlmsg_free(msg); | |
7632 | } | |
7633 | ||
7f6cf311 JB |
7634 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
7635 | u64 cookie, bool acked, gfp_t gfp) | |
7636 | { | |
7637 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7638 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
7639 | struct sk_buff *msg; | |
7640 | void *hdr; | |
7641 | int err; | |
7642 | ||
7643 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7644 | if (!msg) | |
7645 | return; | |
7646 | ||
7647 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
7648 | if (!hdr) { | |
7649 | nlmsg_free(msg); | |
7650 | return; | |
7651 | } | |
7652 | ||
7653 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7654 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
7655 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
7656 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
7657 | if (acked) | |
7658 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); | |
7659 | ||
7660 | err = genlmsg_end(msg, hdr); | |
7661 | if (err < 0) { | |
7662 | nlmsg_free(msg); | |
7663 | return; | |
7664 | } | |
7665 | ||
7666 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7667 | nl80211_mlme_mcgrp.id, gfp); | |
7668 | return; | |
7669 | ||
7670 | nla_put_failure: | |
7671 | genlmsg_cancel(msg, hdr); | |
7672 | nlmsg_free(msg); | |
7673 | } | |
7674 | EXPORT_SYMBOL(cfg80211_probe_status); | |
7675 | ||
5e760230 JB |
7676 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
7677 | const u8 *frame, size_t len, | |
7678 | int freq, gfp_t gfp) | |
7679 | { | |
7680 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
7681 | struct sk_buff *msg; | |
7682 | void *hdr; | |
7683 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); | |
7684 | ||
7685 | if (!nlpid) | |
7686 | return; | |
7687 | ||
7688 | msg = nlmsg_new(len + 100, gfp); | |
7689 | if (!msg) | |
7690 | return; | |
7691 | ||
7692 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | |
7693 | if (!hdr) { | |
7694 | nlmsg_free(msg); | |
7695 | return; | |
7696 | } | |
7697 | ||
7698 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
7699 | if (freq) | |
7700 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
7701 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); | |
7702 | ||
7703 | genlmsg_end(msg, hdr); | |
7704 | ||
7705 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
7706 | return; | |
7707 | ||
7708 | nla_put_failure: | |
7709 | genlmsg_cancel(msg, hdr); | |
7710 | nlmsg_free(msg); | |
7711 | } | |
7712 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
7713 | ||
026331c4 JM |
7714 | static int nl80211_netlink_notify(struct notifier_block * nb, |
7715 | unsigned long state, | |
7716 | void *_notify) | |
7717 | { | |
7718 | struct netlink_notify *notify = _notify; | |
7719 | struct cfg80211_registered_device *rdev; | |
7720 | struct wireless_dev *wdev; | |
7721 | ||
7722 | if (state != NETLINK_URELEASE) | |
7723 | return NOTIFY_DONE; | |
7724 | ||
7725 | rcu_read_lock(); | |
7726 | ||
5e760230 | 7727 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
026331c4 | 7728 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
2e161f78 | 7729 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
5e760230 JB |
7730 | if (rdev->ap_beacons_nlpid == notify->pid) |
7731 | rdev->ap_beacons_nlpid = 0; | |
7732 | } | |
026331c4 JM |
7733 | |
7734 | rcu_read_unlock(); | |
7735 | ||
7736 | return NOTIFY_DONE; | |
7737 | } | |
7738 | ||
7739 | static struct notifier_block nl80211_netlink_notifier = { | |
7740 | .notifier_call = nl80211_netlink_notify, | |
7741 | }; | |
7742 | ||
55682965 JB |
7743 | /* initialisation/exit functions */ |
7744 | ||
7745 | int nl80211_init(void) | |
7746 | { | |
0d63cbb5 | 7747 | int err; |
55682965 | 7748 | |
0d63cbb5 MM |
7749 | err = genl_register_family_with_ops(&nl80211_fam, |
7750 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
7751 | if (err) |
7752 | return err; | |
7753 | ||
55682965 JB |
7754 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
7755 | if (err) | |
7756 | goto err_out; | |
7757 | ||
2a519311 JB |
7758 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
7759 | if (err) | |
7760 | goto err_out; | |
7761 | ||
73d54c9e LR |
7762 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
7763 | if (err) | |
7764 | goto err_out; | |
7765 | ||
6039f6d2 JM |
7766 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
7767 | if (err) | |
7768 | goto err_out; | |
7769 | ||
aff89a9b JB |
7770 | #ifdef CONFIG_NL80211_TESTMODE |
7771 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
7772 | if (err) | |
7773 | goto err_out; | |
7774 | #endif | |
7775 | ||
026331c4 JM |
7776 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
7777 | if (err) | |
7778 | goto err_out; | |
7779 | ||
55682965 JB |
7780 | return 0; |
7781 | err_out: | |
7782 | genl_unregister_family(&nl80211_fam); | |
7783 | return err; | |
7784 | } | |
7785 | ||
7786 | void nl80211_exit(void) | |
7787 | { | |
026331c4 | 7788 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
7789 | genl_unregister_family(&nl80211_fam); |
7790 | } |