]>
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> |
2a0e047e | 22 | #include <net/inet_connection_sock.h> |
55682965 JB |
23 | #include "core.h" |
24 | #include "nl80211.h" | |
b2e1b302 | 25 | #include "reg.h" |
e35e4d28 | 26 | #include "rdev-ops.h" |
55682965 | 27 | |
5fb628e9 JM |
28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
29 | struct genl_info *info, | |
30 | struct cfg80211_crypto_settings *settings, | |
31 | int cipher_limit); | |
32 | ||
f84f771d | 33 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 34 | struct genl_info *info); |
f84f771d | 35 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
36 | struct genl_info *info); |
37 | ||
55682965 JB |
38 | /* the netlink family */ |
39 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
42 | .hdrsize = 0, /* no private header */ | |
43 | .version = 1, /* no particular meaning now */ | |
55682965 | 44 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 45 | .netnsok = true, |
4c476991 JB |
46 | .pre_doit = nl80211_pre_doit, |
47 | .post_doit = nl80211_post_doit, | |
55682965 JB |
48 | }; |
49 | ||
2a94fe48 JB |
50 | /* multicast groups */ |
51 | enum nl80211_multicast_groups { | |
52 | NL80211_MCGRP_CONFIG, | |
53 | NL80211_MCGRP_SCAN, | |
54 | NL80211_MCGRP_REGULATORY, | |
55 | NL80211_MCGRP_MLME, | |
567ffc35 | 56 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
57 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
58 | }; | |
59 | ||
60 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
61 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, | |
62 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, | |
63 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, | |
64 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, | |
567ffc35 | 65 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
2a94fe48 JB |
66 | #ifdef CONFIG_NL80211_TESTMODE |
67 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } | |
68 | #endif | |
69 | }; | |
70 | ||
89a54e48 JB |
71 | /* returns ERR_PTR values */ |
72 | static struct wireless_dev * | |
73 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 74 | { |
89a54e48 JB |
75 | struct cfg80211_registered_device *rdev; |
76 | struct wireless_dev *result = NULL; | |
77 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
78 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
79 | u64 wdev_id; | |
80 | int wiphy_idx = -1; | |
81 | int ifidx = -1; | |
55682965 | 82 | |
5fe231e8 | 83 | ASSERT_RTNL(); |
55682965 | 84 | |
89a54e48 JB |
85 | if (!have_ifidx && !have_wdev_id) |
86 | return ERR_PTR(-EINVAL); | |
55682965 | 87 | |
89a54e48 JB |
88 | if (have_ifidx) |
89 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
90 | if (have_wdev_id) { | |
91 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
92 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
93 | } |
94 | ||
89a54e48 JB |
95 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
96 | struct wireless_dev *wdev; | |
97 | ||
98 | if (wiphy_net(&rdev->wiphy) != netns) | |
99 | continue; | |
100 | ||
101 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
102 | continue; | |
103 | ||
89a54e48 JB |
104 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
105 | if (have_ifidx && wdev->netdev && | |
106 | wdev->netdev->ifindex == ifidx) { | |
107 | result = wdev; | |
108 | break; | |
109 | } | |
110 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
111 | result = wdev; | |
112 | break; | |
113 | } | |
114 | } | |
89a54e48 JB |
115 | |
116 | if (result) | |
117 | break; | |
118 | } | |
119 | ||
120 | if (result) | |
121 | return result; | |
122 | return ERR_PTR(-ENODEV); | |
55682965 JB |
123 | } |
124 | ||
a9455408 | 125 | static struct cfg80211_registered_device * |
878d9ec7 | 126 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 127 | { |
7fee4778 JB |
128 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
129 | struct net_device *netdev; | |
a9455408 | 130 | |
5fe231e8 | 131 | ASSERT_RTNL(); |
a9455408 | 132 | |
878d9ec7 | 133 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
134 | !attrs[NL80211_ATTR_IFINDEX] && |
135 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
136 | return ERR_PTR(-EINVAL); |
137 | ||
878d9ec7 | 138 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 139 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 140 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 141 | |
89a54e48 JB |
142 | if (attrs[NL80211_ATTR_WDEV]) { |
143 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
144 | struct wireless_dev *wdev; | |
145 | bool found = false; | |
146 | ||
147 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
148 | if (tmp) { | |
149 | /* make sure wdev exists */ | |
89a54e48 JB |
150 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
151 | if (wdev->identifier != (u32)wdev_id) | |
152 | continue; | |
153 | found = true; | |
154 | break; | |
155 | } | |
89a54e48 JB |
156 | |
157 | if (!found) | |
158 | tmp = NULL; | |
159 | ||
160 | if (rdev && tmp != rdev) | |
161 | return ERR_PTR(-EINVAL); | |
162 | rdev = tmp; | |
163 | } | |
164 | } | |
165 | ||
878d9ec7 JB |
166 | if (attrs[NL80211_ATTR_IFINDEX]) { |
167 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 168 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
169 | if (netdev) { |
170 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
171 | tmp = wiphy_to_rdev( |
172 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
173 | else |
174 | tmp = NULL; | |
175 | ||
7fee4778 JB |
176 | /* not wireless device -- return error */ |
177 | if (!tmp) | |
178 | return ERR_PTR(-EINVAL); | |
179 | ||
180 | /* mismatch -- return error */ | |
181 | if (rdev && tmp != rdev) | |
182 | return ERR_PTR(-EINVAL); | |
183 | ||
184 | rdev = tmp; | |
a9455408 | 185 | } |
a9455408 | 186 | } |
a9455408 | 187 | |
4f7eff10 JB |
188 | if (!rdev) |
189 | return ERR_PTR(-ENODEV); | |
a9455408 | 190 | |
4f7eff10 JB |
191 | if (netns != wiphy_net(&rdev->wiphy)) |
192 | return ERR_PTR(-ENODEV); | |
193 | ||
194 | return rdev; | |
a9455408 JB |
195 | } |
196 | ||
197 | /* | |
198 | * This function returns a pointer to the driver | |
199 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
200 | * |
201 | * The result of this can be a PTR_ERR and hence must | |
202 | * be checked with IS_ERR() for errors. | |
203 | */ | |
204 | static struct cfg80211_registered_device * | |
4f7eff10 | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 206 | { |
5fe231e8 | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
208 | } |
209 | ||
55682965 | 210 | /* policy for the attributes */ |
b54452b0 | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 214 | .len = 20-1 }, |
31888487 | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 216 | |
72bdcf34 | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
222 | ||
b9a5f8ca JM |
223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
228 | |
229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 232 | |
e007b857 EP |
233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 235 | |
b9454e83 | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
238 | .len = WLAN_MAX_KEY_LEN }, | |
239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
244 | |
245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
248 | .len = IEEE80211_MAX_DATA_LEN }, | |
249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
255 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 262 | |
b2e1b302 LR |
263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
265 | ||
9f1ba906 JM |
266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
270 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 272 | |
24bdd9f4 | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 275 | |
6c739419 | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
277 | |
278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
280 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
283 | |
284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
285 | .len = IEEE80211_MAX_SSID_LEN }, | |
286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
291 | [NL80211_ATTR_STA_FLAGS2] = { |
292 | .len = sizeof(struct nl80211_sta_flag_update), | |
293 | }, | |
3f77316c | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
303 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
308 | .len = IEEE80211_MAX_DATA_LEN }, | |
309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
329 | .len = IEEE80211_MAX_DATA_LEN }, | |
330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 340 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 341 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
342 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
343 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 344 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
345 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
346 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
347 | .len = NL80211_HT_CAPABILITY_LEN | |
348 | }, | |
1d9d9213 | 349 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 350 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 351 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 352 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 353 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 354 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 355 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 356 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
357 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
358 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
359 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
360 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
361 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
362 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 363 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
364 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
365 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
366 | .len = NL80211_VHT_CAPABILITY_LEN, | |
367 | }, | |
355199e0 JM |
368 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
369 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
370 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 371 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
372 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
373 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
374 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
375 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
376 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
377 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 379 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 380 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
381 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
382 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
383 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
384 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
385 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
386 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
387 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 388 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
78f22b6a | 389 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 390 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
55682965 JB |
391 | }; |
392 | ||
e31b8213 | 393 | /* policy for the key attributes */ |
b54452b0 | 394 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 395 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
396 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
397 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 398 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
399 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
400 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 401 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
402 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
403 | }; | |
404 | ||
405 | /* policy for the key default flags */ | |
406 | static const struct nla_policy | |
407 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
408 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
409 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
410 | }; |
411 | ||
ff1b6e69 JB |
412 | /* policy for WoWLAN attributes */ |
413 | static const struct nla_policy | |
414 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
415 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
416 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
417 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
418 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
419 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
420 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
421 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
422 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
423 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
424 | }; | |
425 | ||
426 | static const struct nla_policy | |
427 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
428 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
429 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
430 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
431 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
432 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
433 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
434 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
435 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
436 | }, | |
437 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
438 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
439 | }, | |
440 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
441 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
442 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
443 | }; |
444 | ||
be29b99a AK |
445 | /* policy for coalesce rule attributes */ |
446 | static const struct nla_policy | |
447 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
448 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
449 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
450 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
451 | }; | |
452 | ||
e5497d76 JB |
453 | /* policy for GTK rekey offload attributes */ |
454 | static const struct nla_policy | |
455 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
456 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
457 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
458 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
459 | }; | |
460 | ||
a1f1c21c LC |
461 | static const struct nla_policy |
462 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 463 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 464 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 465 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
466 | }; |
467 | ||
97990a06 JB |
468 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
469 | struct netlink_callback *cb, | |
470 | struct cfg80211_registered_device **rdev, | |
471 | struct wireless_dev **wdev) | |
a043897a | 472 | { |
97990a06 | 473 | int err; |
a043897a | 474 | |
97990a06 | 475 | rtnl_lock(); |
a043897a | 476 | |
97990a06 JB |
477 | if (!cb->args[0]) { |
478 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
479 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
480 | nl80211_policy); | |
481 | if (err) | |
482 | goto out_unlock; | |
67748893 | 483 | |
97990a06 JB |
484 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
485 | nl80211_fam.attrbuf); | |
486 | if (IS_ERR(*wdev)) { | |
487 | err = PTR_ERR(*wdev); | |
488 | goto out_unlock; | |
489 | } | |
f26cbf40 | 490 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
491 | /* 0 is the first index - add 1 to parse only once */ |
492 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
493 | cb->args[1] = (*wdev)->identifier; |
494 | } else { | |
c319d50b JB |
495 | /* subtract the 1 again here */ |
496 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 497 | struct wireless_dev *tmp; |
67748893 | 498 | |
97990a06 JB |
499 | if (!wiphy) { |
500 | err = -ENODEV; | |
501 | goto out_unlock; | |
502 | } | |
f26cbf40 | 503 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 504 | *wdev = NULL; |
67748893 | 505 | |
97990a06 JB |
506 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
507 | if (tmp->identifier == cb->args[1]) { | |
508 | *wdev = tmp; | |
509 | break; | |
510 | } | |
511 | } | |
67748893 | 512 | |
97990a06 JB |
513 | if (!*wdev) { |
514 | err = -ENODEV; | |
515 | goto out_unlock; | |
516 | } | |
67748893 JB |
517 | } |
518 | ||
67748893 | 519 | return 0; |
97990a06 | 520 | out_unlock: |
67748893 JB |
521 | rtnl_unlock(); |
522 | return err; | |
523 | } | |
524 | ||
97990a06 | 525 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 526 | { |
67748893 JB |
527 | rtnl_unlock(); |
528 | } | |
529 | ||
f4a11bb0 JB |
530 | /* IE validation */ |
531 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
532 | { | |
533 | const u8 *pos; | |
534 | int len; | |
535 | ||
536 | if (!attr) | |
537 | return true; | |
538 | ||
539 | pos = nla_data(attr); | |
540 | len = nla_len(attr); | |
541 | ||
542 | while (len) { | |
543 | u8 elemlen; | |
544 | ||
545 | if (len < 2) | |
546 | return false; | |
547 | len -= 2; | |
548 | ||
549 | elemlen = pos[1]; | |
550 | if (elemlen > len) | |
551 | return false; | |
552 | ||
553 | len -= elemlen; | |
554 | pos += 2 + elemlen; | |
555 | } | |
556 | ||
557 | return true; | |
558 | } | |
559 | ||
55682965 | 560 | /* message building helper */ |
15e47304 | 561 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
562 | int flags, u8 cmd) |
563 | { | |
564 | /* since there is no private header just add the generic one */ | |
15e47304 | 565 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
566 | } |
567 | ||
5dab3b8a | 568 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
569 | struct ieee80211_channel *chan, |
570 | bool large) | |
5dab3b8a | 571 | { |
ea077c1c RL |
572 | /* Some channels must be completely excluded from the |
573 | * list to protect old user-space tools from breaking | |
574 | */ | |
575 | if (!large && chan->flags & | |
576 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
577 | return 0; | |
578 | ||
9360ffd1 DM |
579 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
580 | chan->center_freq)) | |
581 | goto nla_put_failure; | |
5dab3b8a | 582 | |
9360ffd1 DM |
583 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
584 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
585 | goto nla_put_failure; | |
8fe02e16 LR |
586 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
587 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
588 | goto nla_put_failure; | |
589 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
590 | goto nla_put_failure; | |
591 | } | |
cdc89b97 JB |
592 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
593 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
594 | goto nla_put_failure; | |
595 | if (large) { | |
596 | u32 time; | |
597 | ||
598 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
599 | ||
600 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
601 | chan->dfs_state)) | |
602 | goto nla_put_failure; | |
603 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
604 | time)) | |
605 | goto nla_put_failure; | |
089027e5 JD |
606 | if (nla_put_u32(msg, |
607 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
608 | chan->dfs_cac_ms)) | |
609 | goto nla_put_failure; | |
cdc89b97 JB |
610 | } |
611 | } | |
5dab3b8a | 612 | |
fe1abafd JB |
613 | if (large) { |
614 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
615 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
616 | goto nla_put_failure; | |
617 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
618 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
619 | goto nla_put_failure; | |
620 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
622 | goto nla_put_failure; | |
623 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
624 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
625 | goto nla_put_failure; | |
570dbde1 DS |
626 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
627 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
628 | goto nla_put_failure; | |
629 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
630 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
631 | goto nla_put_failure; | |
ea077c1c RL |
632 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
633 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
634 | goto nla_put_failure; | |
635 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
637 | goto nla_put_failure; | |
fe1abafd JB |
638 | } |
639 | ||
9360ffd1 DM |
640 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
641 | DBM_TO_MBM(chan->max_power))) | |
642 | goto nla_put_failure; | |
5dab3b8a LR |
643 | |
644 | return 0; | |
645 | ||
646 | nla_put_failure: | |
647 | return -ENOBUFS; | |
648 | } | |
649 | ||
55682965 JB |
650 | /* netlink command implementations */ |
651 | ||
b9454e83 JB |
652 | struct key_parse { |
653 | struct key_params p; | |
654 | int idx; | |
e31b8213 | 655 | int type; |
b9454e83 | 656 | bool def, defmgmt; |
dbd2fd65 | 657 | bool def_uni, def_multi; |
b9454e83 JB |
658 | }; |
659 | ||
660 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
661 | { | |
662 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
663 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
664 | nl80211_key_policy); | |
665 | if (err) | |
666 | return err; | |
667 | ||
668 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
669 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
670 | ||
dbd2fd65 JB |
671 | if (k->def) { |
672 | k->def_uni = true; | |
673 | k->def_multi = true; | |
674 | } | |
675 | if (k->defmgmt) | |
676 | k->def_multi = true; | |
677 | ||
b9454e83 JB |
678 | if (tb[NL80211_KEY_IDX]) |
679 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
680 | ||
681 | if (tb[NL80211_KEY_DATA]) { | |
682 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
683 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
684 | } | |
685 | ||
686 | if (tb[NL80211_KEY_SEQ]) { | |
687 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
688 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
689 | } | |
690 | ||
691 | if (tb[NL80211_KEY_CIPHER]) | |
692 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
693 | ||
e31b8213 JB |
694 | if (tb[NL80211_KEY_TYPE]) { |
695 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
696 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
697 | return -EINVAL; | |
698 | } | |
699 | ||
dbd2fd65 JB |
700 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
701 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
702 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
703 | tb[NL80211_KEY_DEFAULT_TYPES], | |
704 | nl80211_key_default_policy); | |
dbd2fd65 JB |
705 | if (err) |
706 | return err; | |
707 | ||
708 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
709 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
710 | } | |
711 | ||
b9454e83 JB |
712 | return 0; |
713 | } | |
714 | ||
715 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
716 | { | |
717 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
718 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
719 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
720 | } | |
721 | ||
722 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
723 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
724 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
725 | } | |
726 | ||
727 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
728 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
729 | ||
730 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
731 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
732 | ||
733 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
734 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
735 | ||
dbd2fd65 JB |
736 | if (k->def) { |
737 | k->def_uni = true; | |
738 | k->def_multi = true; | |
739 | } | |
740 | if (k->defmgmt) | |
741 | k->def_multi = true; | |
742 | ||
e31b8213 JB |
743 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
744 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
745 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
746 | return -EINVAL; | |
747 | } | |
748 | ||
dbd2fd65 JB |
749 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
750 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
751 | int err = nla_parse_nested( | |
752 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
753 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
754 | nl80211_key_default_policy); | |
755 | if (err) | |
756 | return err; | |
757 | ||
758 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
759 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
760 | } | |
761 | ||
b9454e83 JB |
762 | return 0; |
763 | } | |
764 | ||
765 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
766 | { | |
767 | int err; | |
768 | ||
769 | memset(k, 0, sizeof(*k)); | |
770 | k->idx = -1; | |
e31b8213 | 771 | k->type = -1; |
b9454e83 JB |
772 | |
773 | if (info->attrs[NL80211_ATTR_KEY]) | |
774 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
775 | else | |
776 | err = nl80211_parse_key_old(info, k); | |
777 | ||
778 | if (err) | |
779 | return err; | |
780 | ||
781 | if (k->def && k->defmgmt) | |
782 | return -EINVAL; | |
783 | ||
dbd2fd65 JB |
784 | if (k->defmgmt) { |
785 | if (k->def_uni || !k->def_multi) | |
786 | return -EINVAL; | |
787 | } | |
788 | ||
b9454e83 JB |
789 | if (k->idx != -1) { |
790 | if (k->defmgmt) { | |
791 | if (k->idx < 4 || k->idx > 5) | |
792 | return -EINVAL; | |
793 | } else if (k->def) { | |
794 | if (k->idx < 0 || k->idx > 3) | |
795 | return -EINVAL; | |
796 | } else { | |
797 | if (k->idx < 0 || k->idx > 5) | |
798 | return -EINVAL; | |
799 | } | |
800 | } | |
801 | ||
802 | return 0; | |
803 | } | |
804 | ||
fffd0934 JB |
805 | static struct cfg80211_cached_keys * |
806 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 807 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
808 | { |
809 | struct key_parse parse; | |
810 | struct nlattr *key; | |
811 | struct cfg80211_cached_keys *result; | |
812 | int rem, err, def = 0; | |
813 | ||
814 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
815 | if (!result) | |
816 | return ERR_PTR(-ENOMEM); | |
817 | ||
818 | result->def = -1; | |
819 | result->defmgmt = -1; | |
820 | ||
821 | nla_for_each_nested(key, keys, rem) { | |
822 | memset(&parse, 0, sizeof(parse)); | |
823 | parse.idx = -1; | |
824 | ||
825 | err = nl80211_parse_key_new(key, &parse); | |
826 | if (err) | |
827 | goto error; | |
828 | err = -EINVAL; | |
829 | if (!parse.p.key) | |
830 | goto error; | |
831 | if (parse.idx < 0 || parse.idx > 4) | |
832 | goto error; | |
833 | if (parse.def) { | |
834 | if (def) | |
835 | goto error; | |
836 | def = 1; | |
837 | result->def = parse.idx; | |
dbd2fd65 JB |
838 | if (!parse.def_uni || !parse.def_multi) |
839 | goto error; | |
fffd0934 JB |
840 | } else if (parse.defmgmt) |
841 | goto error; | |
842 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 843 | parse.idx, false, NULL); |
fffd0934 JB |
844 | if (err) |
845 | goto error; | |
846 | result->params[parse.idx].cipher = parse.p.cipher; | |
847 | result->params[parse.idx].key_len = parse.p.key_len; | |
848 | result->params[parse.idx].key = result->data[parse.idx]; | |
849 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
850 | |
851 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
852 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
853 | if (no_ht) | |
854 | *no_ht = true; | |
855 | } | |
fffd0934 JB |
856 | } |
857 | ||
858 | return result; | |
859 | error: | |
860 | kfree(result); | |
861 | return ERR_PTR(err); | |
862 | } | |
863 | ||
864 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
865 | { | |
866 | ASSERT_WDEV_LOCK(wdev); | |
867 | ||
fffd0934 JB |
868 | switch (wdev->iftype) { |
869 | case NL80211_IFTYPE_AP: | |
870 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 871 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 872 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
873 | break; |
874 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 875 | case NL80211_IFTYPE_STATION: |
074ac8df | 876 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 877 | if (!wdev->current_bss) |
fffd0934 JB |
878 | return -ENOLINK; |
879 | break; | |
880 | default: | |
881 | return -EINVAL; | |
882 | } | |
883 | ||
884 | return 0; | |
885 | } | |
886 | ||
664834de JM |
887 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
888 | struct nlattr *tb) | |
889 | { | |
890 | struct ieee80211_channel *chan; | |
891 | ||
892 | if (tb == NULL) | |
893 | return NULL; | |
894 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
895 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
896 | return NULL; | |
897 | return chan; | |
898 | } | |
899 | ||
7527a782 JB |
900 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
901 | { | |
902 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
903 | int i; | |
904 | ||
905 | if (!nl_modes) | |
906 | goto nla_put_failure; | |
907 | ||
908 | i = 0; | |
909 | while (ifmodes) { | |
9360ffd1 DM |
910 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
911 | goto nla_put_failure; | |
7527a782 JB |
912 | ifmodes >>= 1; |
913 | i++; | |
914 | } | |
915 | ||
916 | nla_nest_end(msg, nl_modes); | |
917 | return 0; | |
918 | ||
919 | nla_put_failure: | |
920 | return -ENOBUFS; | |
921 | } | |
922 | ||
923 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
924 | struct sk_buff *msg, |
925 | bool large) | |
7527a782 JB |
926 | { |
927 | struct nlattr *nl_combis; | |
928 | int i, j; | |
929 | ||
930 | nl_combis = nla_nest_start(msg, | |
931 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
932 | if (!nl_combis) | |
933 | goto nla_put_failure; | |
934 | ||
935 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
936 | const struct ieee80211_iface_combination *c; | |
937 | struct nlattr *nl_combi, *nl_limits; | |
938 | ||
939 | c = &wiphy->iface_combinations[i]; | |
940 | ||
941 | nl_combi = nla_nest_start(msg, i + 1); | |
942 | if (!nl_combi) | |
943 | goto nla_put_failure; | |
944 | ||
945 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
946 | if (!nl_limits) | |
947 | goto nla_put_failure; | |
948 | ||
949 | for (j = 0; j < c->n_limits; j++) { | |
950 | struct nlattr *nl_limit; | |
951 | ||
952 | nl_limit = nla_nest_start(msg, j + 1); | |
953 | if (!nl_limit) | |
954 | goto nla_put_failure; | |
9360ffd1 DM |
955 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
956 | c->limits[j].max)) | |
957 | goto nla_put_failure; | |
7527a782 JB |
958 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
959 | c->limits[j].types)) | |
960 | goto nla_put_failure; | |
961 | nla_nest_end(msg, nl_limit); | |
962 | } | |
963 | ||
964 | nla_nest_end(msg, nl_limits); | |
965 | ||
9360ffd1 DM |
966 | if (c->beacon_int_infra_match && |
967 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
968 | goto nla_put_failure; | |
969 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
970 | c->num_different_channels) || | |
971 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
972 | c->max_interfaces)) | |
973 | goto nla_put_failure; | |
cdc89b97 | 974 | if (large && |
8c48b50a FF |
975 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
976 | c->radar_detect_widths) || | |
977 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
978 | c->radar_detect_regions))) | |
cdc89b97 | 979 | goto nla_put_failure; |
7527a782 JB |
980 | |
981 | nla_nest_end(msg, nl_combi); | |
982 | } | |
983 | ||
984 | nla_nest_end(msg, nl_combis); | |
985 | ||
986 | return 0; | |
987 | nla_put_failure: | |
988 | return -ENOBUFS; | |
989 | } | |
990 | ||
3713b4e3 | 991 | #ifdef CONFIG_PM |
b56cf720 JB |
992 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
993 | struct sk_buff *msg) | |
994 | { | |
964dc9e2 | 995 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
996 | struct nlattr *nl_tcp; |
997 | ||
998 | if (!tcp) | |
999 | return 0; | |
1000 | ||
1001 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1002 | if (!nl_tcp) | |
1003 | return -ENOBUFS; | |
1004 | ||
1005 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1006 | tcp->data_payload_max)) | |
1007 | return -ENOBUFS; | |
1008 | ||
1009 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1010 | tcp->data_payload_max)) | |
1011 | return -ENOBUFS; | |
1012 | ||
1013 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1014 | return -ENOBUFS; | |
1015 | ||
1016 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1017 | sizeof(*tcp->tok), tcp->tok)) | |
1018 | return -ENOBUFS; | |
1019 | ||
1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1021 | tcp->data_interval_max)) | |
1022 | return -ENOBUFS; | |
1023 | ||
1024 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1025 | tcp->wake_payload_max)) | |
1026 | return -ENOBUFS; | |
1027 | ||
1028 | nla_nest_end(msg, nl_tcp); | |
1029 | return 0; | |
1030 | } | |
1031 | ||
3713b4e3 | 1032 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1033 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1034 | bool large) |
55682965 | 1035 | { |
3713b4e3 | 1036 | struct nlattr *nl_wowlan; |
55682965 | 1037 | |
1b8ec87a | 1038 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1039 | return 0; |
55682965 | 1040 | |
3713b4e3 JB |
1041 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1042 | if (!nl_wowlan) | |
1043 | return -ENOBUFS; | |
9360ffd1 | 1044 | |
1b8ec87a | 1045 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1046 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1047 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1049 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1050 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1051 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1052 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1053 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1055 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1056 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1057 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1058 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1059 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1061 | return -ENOBUFS; | |
9360ffd1 | 1062 | |
1b8ec87a | 1063 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1064 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1065 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1066 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1067 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1068 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1069 | }; |
9360ffd1 | 1070 | |
3713b4e3 JB |
1071 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1072 | sizeof(pat), &pat)) | |
1073 | return -ENOBUFS; | |
1074 | } | |
9360ffd1 | 1075 | |
1b8ec87a | 1076 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1077 | return -ENOBUFS; |
1078 | ||
3713b4e3 | 1079 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1080 | |
3713b4e3 JB |
1081 | return 0; |
1082 | } | |
1083 | #endif | |
9360ffd1 | 1084 | |
be29b99a | 1085 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1086 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1087 | { |
1088 | struct nl80211_coalesce_rule_support rule; | |
1089 | ||
1b8ec87a | 1090 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1091 | return 0; |
1092 | ||
1b8ec87a ZG |
1093 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1094 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1095 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1096 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1097 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1098 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1099 | |
1100 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1101 | return -ENOBUFS; | |
1102 | ||
1103 | return 0; | |
1104 | } | |
1105 | ||
3713b4e3 JB |
1106 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1107 | struct ieee80211_supported_band *sband) | |
1108 | { | |
1109 | struct nlattr *nl_rates, *nl_rate; | |
1110 | struct ieee80211_rate *rate; | |
1111 | int i; | |
87bbbe22 | 1112 | |
3713b4e3 JB |
1113 | /* add HT info */ |
1114 | if (sband->ht_cap.ht_supported && | |
1115 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1116 | sizeof(sband->ht_cap.mcs), | |
1117 | &sband->ht_cap.mcs) || | |
1118 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1119 | sband->ht_cap.cap) || | |
1120 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1121 | sband->ht_cap.ampdu_factor) || | |
1122 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1123 | sband->ht_cap.ampdu_density))) | |
1124 | return -ENOBUFS; | |
afe0cbf8 | 1125 | |
3713b4e3 JB |
1126 | /* add VHT info */ |
1127 | if (sband->vht_cap.vht_supported && | |
1128 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1129 | sizeof(sband->vht_cap.vht_mcs), | |
1130 | &sband->vht_cap.vht_mcs) || | |
1131 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1132 | sband->vht_cap.cap))) | |
1133 | return -ENOBUFS; | |
f59ac048 | 1134 | |
3713b4e3 JB |
1135 | /* add bitrates */ |
1136 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1137 | if (!nl_rates) | |
1138 | return -ENOBUFS; | |
ee688b00 | 1139 | |
3713b4e3 JB |
1140 | for (i = 0; i < sband->n_bitrates; i++) { |
1141 | nl_rate = nla_nest_start(msg, i); | |
1142 | if (!nl_rate) | |
1143 | return -ENOBUFS; | |
ee688b00 | 1144 | |
3713b4e3 JB |
1145 | rate = &sband->bitrates[i]; |
1146 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1147 | rate->bitrate)) | |
1148 | return -ENOBUFS; | |
1149 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1150 | nla_put_flag(msg, | |
1151 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1152 | return -ENOBUFS; | |
ee688b00 | 1153 | |
3713b4e3 JB |
1154 | nla_nest_end(msg, nl_rate); |
1155 | } | |
d51626df | 1156 | |
3713b4e3 | 1157 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1158 | |
3713b4e3 JB |
1159 | return 0; |
1160 | } | |
ee688b00 | 1161 | |
3713b4e3 JB |
1162 | static int |
1163 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1164 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1165 | { | |
1166 | u16 stypes; | |
1167 | struct nlattr *nl_ftypes, *nl_ifs; | |
1168 | enum nl80211_iftype ift; | |
1169 | int i; | |
ee688b00 | 1170 | |
3713b4e3 JB |
1171 | if (!mgmt_stypes) |
1172 | return 0; | |
5dab3b8a | 1173 | |
3713b4e3 JB |
1174 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1175 | if (!nl_ifs) | |
1176 | return -ENOBUFS; | |
e2f367f2 | 1177 | |
3713b4e3 JB |
1178 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1179 | nl_ftypes = nla_nest_start(msg, ift); | |
1180 | if (!nl_ftypes) | |
1181 | return -ENOBUFS; | |
1182 | i = 0; | |
1183 | stypes = mgmt_stypes[ift].tx; | |
1184 | while (stypes) { | |
1185 | if ((stypes & 1) && | |
1186 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1187 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1188 | return -ENOBUFS; | |
1189 | stypes >>= 1; | |
1190 | i++; | |
ee688b00 | 1191 | } |
3713b4e3 JB |
1192 | nla_nest_end(msg, nl_ftypes); |
1193 | } | |
ee688b00 | 1194 | |
3713b4e3 | 1195 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1196 | |
3713b4e3 JB |
1197 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1198 | if (!nl_ifs) | |
1199 | return -ENOBUFS; | |
ee688b00 | 1200 | |
3713b4e3 JB |
1201 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1202 | nl_ftypes = nla_nest_start(msg, ift); | |
1203 | if (!nl_ftypes) | |
1204 | return -ENOBUFS; | |
1205 | i = 0; | |
1206 | stypes = mgmt_stypes[ift].rx; | |
1207 | while (stypes) { | |
1208 | if ((stypes & 1) && | |
1209 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1210 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1211 | return -ENOBUFS; | |
1212 | stypes >>= 1; | |
1213 | i++; | |
1214 | } | |
1215 | nla_nest_end(msg, nl_ftypes); | |
1216 | } | |
1217 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1218 | |
3713b4e3 JB |
1219 | return 0; |
1220 | } | |
ee688b00 | 1221 | |
86e8cf98 JB |
1222 | struct nl80211_dump_wiphy_state { |
1223 | s64 filter_wiphy; | |
1224 | long start; | |
1225 | long split_start, band_start, chan_start; | |
1226 | bool split; | |
1227 | }; | |
1228 | ||
1b8ec87a | 1229 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1230 | enum nl80211_commands cmd, |
3713b4e3 | 1231 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1232 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1233 | { |
1234 | void *hdr; | |
1235 | struct nlattr *nl_bands, *nl_band; | |
1236 | struct nlattr *nl_freqs, *nl_freq; | |
1237 | struct nlattr *nl_cmds; | |
1238 | enum ieee80211_band band; | |
1239 | struct ieee80211_channel *chan; | |
1240 | int i; | |
1241 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1242 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1243 | u32 features; |
ee688b00 | 1244 | |
3bb20556 | 1245 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1246 | if (!hdr) |
1247 | return -ENOBUFS; | |
ee688b00 | 1248 | |
86e8cf98 JB |
1249 | if (WARN_ON(!state)) |
1250 | return -EINVAL; | |
ee688b00 | 1251 | |
1b8ec87a | 1252 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1253 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1254 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1255 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1256 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1257 | goto nla_put_failure; |
1258 | ||
3bb20556 JB |
1259 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1260 | goto finish; | |
1261 | ||
86e8cf98 | 1262 | switch (state->split_start) { |
3713b4e3 JB |
1263 | case 0: |
1264 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1265 | rdev->wiphy.retry_short) || |
3713b4e3 | 1266 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1267 | rdev->wiphy.retry_long) || |
3713b4e3 | 1268 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1269 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1270 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1271 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1272 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1273 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1274 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1275 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1276 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1277 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1278 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1279 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1280 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1281 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1282 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1283 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1284 | goto nla_put_failure; |
3713b4e3 | 1285 | |
1b8ec87a | 1286 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1287 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1288 | goto nla_put_failure; |
1b8ec87a | 1289 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1290 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1291 | goto nla_put_failure; | |
1b8ec87a | 1292 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1293 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1294 | goto nla_put_failure; | |
1b8ec87a | 1295 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1296 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1297 | goto nla_put_failure; | |
1b8ec87a | 1298 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1299 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1300 | goto nla_put_failure; | |
1b8ec87a | 1301 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1302 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1303 | goto nla_put_failure; |
86e8cf98 JB |
1304 | state->split_start++; |
1305 | if (state->split) | |
3713b4e3 JB |
1306 | break; |
1307 | case 1: | |
1308 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1309 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1310 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1311 | goto nla_put_failure; |
4745fc09 | 1312 | |
3713b4e3 | 1313 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1314 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1315 | goto nla_put_failure; |
b23aa676 | 1316 | |
1b8ec87a | 1317 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1318 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1319 | goto nla_put_failure; |
b23aa676 | 1320 | |
3713b4e3 | 1321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1322 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1323 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1324 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1325 | goto nla_put_failure; |
b23aa676 | 1326 | |
1b8ec87a | 1327 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1328 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1329 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1330 | goto nla_put_failure; |
8fdc621d | 1331 | |
1b8ec87a ZG |
1332 | if ((rdev->wiphy.available_antennas_tx || |
1333 | rdev->wiphy.available_antennas_rx) && | |
1334 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1335 | u32 tx_ant = 0, rx_ant = 0; |
1336 | int res; | |
1b8ec87a | 1337 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1338 | if (!res) { |
1339 | if (nla_put_u32(msg, | |
1340 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1341 | tx_ant) || | |
1342 | nla_put_u32(msg, | |
1343 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1344 | rx_ant)) | |
1345 | goto nla_put_failure; | |
1346 | } | |
1347 | } | |
a293911d | 1348 | |
86e8cf98 JB |
1349 | state->split_start++; |
1350 | if (state->split) | |
3713b4e3 JB |
1351 | break; |
1352 | case 2: | |
1353 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1354 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1355 | goto nla_put_failure; |
86e8cf98 JB |
1356 | state->split_start++; |
1357 | if (state->split) | |
3713b4e3 JB |
1358 | break; |
1359 | case 3: | |
1360 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1361 | if (!nl_bands) | |
1362 | goto nla_put_failure; | |
f7ca38df | 1363 | |
86e8cf98 JB |
1364 | for (band = state->band_start; |
1365 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1366 | struct ieee80211_supported_band *sband; |
2e161f78 | 1367 | |
1b8ec87a | 1368 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1369 | |
3713b4e3 JB |
1370 | if (!sband) |
1371 | continue; | |
1372 | ||
1373 | nl_band = nla_nest_start(msg, band); | |
1374 | if (!nl_band) | |
2e161f78 | 1375 | goto nla_put_failure; |
3713b4e3 | 1376 | |
86e8cf98 | 1377 | switch (state->chan_start) { |
3713b4e3 JB |
1378 | case 0: |
1379 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1380 | goto nla_put_failure; |
86e8cf98 JB |
1381 | state->chan_start++; |
1382 | if (state->split) | |
3713b4e3 JB |
1383 | break; |
1384 | default: | |
1385 | /* add frequencies */ | |
1386 | nl_freqs = nla_nest_start( | |
1387 | msg, NL80211_BAND_ATTR_FREQS); | |
1388 | if (!nl_freqs) | |
1389 | goto nla_put_failure; | |
1390 | ||
86e8cf98 | 1391 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1392 | i < sband->n_channels; |
1393 | i++) { | |
1394 | nl_freq = nla_nest_start(msg, i); | |
1395 | if (!nl_freq) | |
1396 | goto nla_put_failure; | |
1397 | ||
1398 | chan = &sband->channels[i]; | |
1399 | ||
86e8cf98 JB |
1400 | if (nl80211_msg_put_channel( |
1401 | msg, chan, | |
1402 | state->split)) | |
3713b4e3 JB |
1403 | goto nla_put_failure; |
1404 | ||
1405 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1406 | if (state->split) |
3713b4e3 JB |
1407 | break; |
1408 | } | |
1409 | if (i < sband->n_channels) | |
86e8cf98 | 1410 | state->chan_start = i + 2; |
3713b4e3 | 1411 | else |
86e8cf98 | 1412 | state->chan_start = 0; |
3713b4e3 JB |
1413 | nla_nest_end(msg, nl_freqs); |
1414 | } | |
1415 | ||
1416 | nla_nest_end(msg, nl_band); | |
1417 | ||
86e8cf98 | 1418 | if (state->split) { |
3713b4e3 | 1419 | /* start again here */ |
86e8cf98 | 1420 | if (state->chan_start) |
3713b4e3 JB |
1421 | band--; |
1422 | break; | |
2e161f78 | 1423 | } |
2e161f78 | 1424 | } |
3713b4e3 | 1425 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1426 | |
3713b4e3 | 1427 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1428 | state->band_start = band + 1; |
3713b4e3 | 1429 | else |
86e8cf98 | 1430 | state->band_start = 0; |
74b70a4e | 1431 | |
3713b4e3 | 1432 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1433 | if (state->band_start == 0 && state->chan_start == 0) |
1434 | state->split_start++; | |
1435 | if (state->split) | |
3713b4e3 JB |
1436 | break; |
1437 | case 4: | |
1438 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1439 | if (!nl_cmds) | |
2e161f78 JB |
1440 | goto nla_put_failure; |
1441 | ||
3713b4e3 JB |
1442 | i = 0; |
1443 | #define CMD(op, n) \ | |
1444 | do { \ | |
1b8ec87a | 1445 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1446 | i++; \ |
1447 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1448 | goto nla_put_failure; \ | |
1449 | } \ | |
1450 | } while (0) | |
1451 | ||
1452 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1453 | CMD(change_virtual_intf, SET_INTERFACE); | |
1454 | CMD(add_key, NEW_KEY); | |
1455 | CMD(start_ap, START_AP); | |
1456 | CMD(add_station, NEW_STATION); | |
1457 | CMD(add_mpath, NEW_MPATH); | |
1458 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1459 | CMD(change_bss, SET_BSS); | |
1460 | CMD(auth, AUTHENTICATE); | |
1461 | CMD(assoc, ASSOCIATE); | |
1462 | CMD(deauth, DEAUTHENTICATE); | |
1463 | CMD(disassoc, DISASSOCIATE); | |
1464 | CMD(join_ibss, JOIN_IBSS); | |
1465 | CMD(join_mesh, JOIN_MESH); | |
1466 | CMD(set_pmksa, SET_PMKSA); | |
1467 | CMD(del_pmksa, DEL_PMKSA); | |
1468 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1469 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1470 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1471 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1472 | CMD(mgmt_tx, FRAME); | |
1473 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1474 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1475 | i++; |
1476 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1477 | goto nla_put_failure; |
2e161f78 | 1478 | } |
1b8ec87a ZG |
1479 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1480 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1481 | i++; |
1482 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1483 | goto nla_put_failure; | |
1484 | } | |
1485 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1487 | CMD(tdls_mgmt, TDLS_MGMT); |
1488 | CMD(tdls_oper, TDLS_OPER); | |
1489 | } | |
1b8ec87a | 1490 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1491 | CMD(sched_scan_start, START_SCHED_SCAN); |
1492 | CMD(probe_client, PROBE_CLIENT); | |
1493 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1494 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1495 | i++; |
1496 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1497 | goto nla_put_failure; | |
1498 | } | |
1499 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1500 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1501 | #ifdef CONFIG_NL80211_TESTMODE |
1502 | CMD(testmode_cmd, TESTMODE); | |
1503 | #endif | |
86e8cf98 | 1504 | if (state->split) { |
5de17984 AS |
1505 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1506 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1507 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1508 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1509 | CMD(set_qos_map, SET_QOS_MAP); |
5de17984 | 1510 | } |
02df00eb | 1511 | /* add into the if now */ |
3713b4e3 | 1512 | #undef CMD |
ff1b6e69 | 1513 | |
1b8ec87a | 1514 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1515 | i++; |
1516 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1517 | goto nla_put_failure; |
ff1b6e69 JB |
1518 | } |
1519 | ||
1b8ec87a | 1520 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1521 | i++; |
1522 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1523 | goto nla_put_failure; | |
1524 | } | |
1525 | ||
1526 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1527 | state->split_start++; |
1528 | if (state->split) | |
3713b4e3 JB |
1529 | break; |
1530 | case 5: | |
1b8ec87a ZG |
1531 | if (rdev->ops->remain_on_channel && |
1532 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1533 | nla_put_u32(msg, |
1534 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1535 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1536 | goto nla_put_failure; |
1537 | ||
1b8ec87a | 1538 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1539 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1540 | goto nla_put_failure; | |
1541 | ||
1542 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1543 | goto nla_put_failure; | |
86e8cf98 JB |
1544 | state->split_start++; |
1545 | if (state->split) | |
3713b4e3 JB |
1546 | break; |
1547 | case 6: | |
1548 | #ifdef CONFIG_PM | |
1b8ec87a | 1549 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1550 | goto nla_put_failure; |
86e8cf98 JB |
1551 | state->split_start++; |
1552 | if (state->split) | |
3713b4e3 JB |
1553 | break; |
1554 | #else | |
86e8cf98 | 1555 | state->split_start++; |
dfb89c56 | 1556 | #endif |
3713b4e3 JB |
1557 | case 7: |
1558 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1559 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1560 | goto nla_put_failure; |
ff1b6e69 | 1561 | |
1b8ec87a | 1562 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1563 | state->split)) |
3713b4e3 | 1564 | goto nla_put_failure; |
7527a782 | 1565 | |
86e8cf98 JB |
1566 | state->split_start++; |
1567 | if (state->split) | |
3713b4e3 JB |
1568 | break; |
1569 | case 8: | |
1b8ec87a | 1570 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1571 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1572 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1573 | goto nla_put_failure; |
7527a782 | 1574 | |
1b8ec87a | 1575 | features = rdev->wiphy.features; |
fe1abafd JB |
1576 | /* |
1577 | * We can only add the per-channel limit information if the | |
1578 | * dump is split, otherwise it makes it too big. Therefore | |
1579 | * only advertise it in that case. | |
1580 | */ | |
86e8cf98 | 1581 | if (state->split) |
fe1abafd JB |
1582 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1583 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1584 | goto nla_put_failure; |
562a7480 | 1585 | |
1b8ec87a | 1586 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1587 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1588 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1589 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1590 | goto nla_put_failure; |
1f074bd8 | 1591 | |
1b8ec87a ZG |
1592 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1593 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1594 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1595 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1596 | goto nla_put_failure; |
7e7c8926 | 1597 | |
3713b4e3 JB |
1598 | /* |
1599 | * Any information below this point is only available to | |
1600 | * applications that can deal with it being split. This | |
1601 | * helps ensure that newly added capabilities don't break | |
1602 | * older tools by overrunning their buffers. | |
1603 | * | |
1604 | * We still increment split_start so that in the split | |
1605 | * case we'll continue with more data in the next round, | |
1606 | * but break unconditionally so unsplit data stops here. | |
1607 | */ | |
86e8cf98 | 1608 | state->split_start++; |
3713b4e3 JB |
1609 | break; |
1610 | case 9: | |
1b8ec87a | 1611 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1612 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1613 | rdev->wiphy.extended_capabilities_len, |
1614 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1615 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1616 | rdev->wiphy.extended_capabilities_len, |
1617 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1618 | goto nla_put_failure; |
a50df0c4 | 1619 | |
1b8ec87a | 1620 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1621 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1622 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1623 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1624 | goto nla_put_failure; |
1625 | ||
be29b99a AK |
1626 | state->split_start++; |
1627 | break; | |
1628 | case 10: | |
1b8ec87a | 1629 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1630 | goto nla_put_failure; |
1631 | ||
1b8ec87a | 1632 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1633 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1634 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1635 | goto nla_put_failure; | |
b43504cf | 1636 | |
1b8ec87a | 1637 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1638 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1639 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1640 | goto nla_put_failure; |
1641 | ||
ad7e718c JB |
1642 | state->split_start++; |
1643 | break; | |
1644 | case 11: | |
1b8ec87a | 1645 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1646 | const struct nl80211_vendor_cmd_info *info; |
1647 | struct nlattr *nested; | |
1648 | ||
1649 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1650 | if (!nested) | |
1651 | goto nla_put_failure; | |
1652 | ||
1b8ec87a ZG |
1653 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1654 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1655 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1656 | goto nla_put_failure; | |
1657 | } | |
1658 | nla_nest_end(msg, nested); | |
1659 | } | |
1660 | ||
1b8ec87a | 1661 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1662 | const struct nl80211_vendor_cmd_info *info; |
1663 | struct nlattr *nested; | |
ad7e718c | 1664 | |
567ffc35 JB |
1665 | nested = nla_nest_start(msg, |
1666 | NL80211_ATTR_VENDOR_EVENTS); | |
1667 | if (!nested) | |
ad7e718c | 1668 | goto nla_put_failure; |
567ffc35 | 1669 | |
1b8ec87a ZG |
1670 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1671 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1672 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1673 | goto nla_put_failure; | |
1674 | } | |
1675 | nla_nest_end(msg, nested); | |
1676 | } | |
9a774c78 AO |
1677 | state->split_start++; |
1678 | break; | |
1679 | case 12: | |
1680 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1681 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1682 | rdev->wiphy.max_num_csa_counters)) | |
1683 | goto nla_put_failure; | |
01e0daa4 | 1684 | |
3713b4e3 | 1685 | /* done */ |
86e8cf98 | 1686 | state->split_start = 0; |
3713b4e3 JB |
1687 | break; |
1688 | } | |
3bb20556 | 1689 | finish: |
55682965 JB |
1690 | return genlmsg_end(msg, hdr); |
1691 | ||
1692 | nla_put_failure: | |
bc3ed28c TG |
1693 | genlmsg_cancel(msg, hdr); |
1694 | return -EMSGSIZE; | |
55682965 JB |
1695 | } |
1696 | ||
86e8cf98 JB |
1697 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1698 | struct netlink_callback *cb, | |
1699 | struct nl80211_dump_wiphy_state *state) | |
1700 | { | |
1701 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1702 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1703 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1704 | /* ignore parse errors for backward compatibility */ | |
1705 | if (ret) | |
1706 | return 0; | |
1707 | ||
1708 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1709 | if (tb[NL80211_ATTR_WIPHY]) | |
1710 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1711 | if (tb[NL80211_ATTR_WDEV]) | |
1712 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1713 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1714 | struct net_device *netdev; | |
1715 | struct cfg80211_registered_device *rdev; | |
1716 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1717 | ||
7f2b8562 | 1718 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1719 | if (!netdev) |
1720 | return -ENODEV; | |
1721 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1722 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1723 | netdev->ieee80211_ptr->wiphy); |
1724 | state->filter_wiphy = rdev->wiphy_idx; | |
1725 | } | |
86e8cf98 JB |
1726 | } |
1727 | ||
1728 | return 0; | |
1729 | } | |
1730 | ||
55682965 JB |
1731 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1732 | { | |
645e77de | 1733 | int idx = 0, ret; |
86e8cf98 | 1734 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1735 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1736 | |
5fe231e8 | 1737 | rtnl_lock(); |
86e8cf98 JB |
1738 | if (!state) { |
1739 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1740 | if (!state) { |
1741 | rtnl_unlock(); | |
86e8cf98 | 1742 | return -ENOMEM; |
3713b4e3 | 1743 | } |
86e8cf98 JB |
1744 | state->filter_wiphy = -1; |
1745 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1746 | if (ret) { | |
1747 | kfree(state); | |
1748 | rtnl_unlock(); | |
1749 | return ret; | |
3713b4e3 | 1750 | } |
86e8cf98 | 1751 | cb->args[0] = (long)state; |
3713b4e3 JB |
1752 | } |
1753 | ||
1b8ec87a ZG |
1754 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1755 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1756 | continue; |
86e8cf98 | 1757 | if (++idx <= state->start) |
55682965 | 1758 | continue; |
86e8cf98 | 1759 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1760 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1761 | continue; |
1762 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1763 | do { | |
3bb20556 JB |
1764 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1765 | skb, | |
3713b4e3 JB |
1766 | NETLINK_CB(cb->skb).portid, |
1767 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1768 | NLM_F_MULTI, state); |
3713b4e3 JB |
1769 | if (ret < 0) { |
1770 | /* | |
1771 | * If sending the wiphy data didn't fit (ENOBUFS | |
1772 | * or EMSGSIZE returned), this SKB is still | |
1773 | * empty (so it's not too big because another | |
1774 | * wiphy dataset is already in the skb) and | |
1775 | * we've not tried to adjust the dump allocation | |
1776 | * yet ... then adjust the alloc size to be | |
1777 | * bigger, and return 1 but with the empty skb. | |
1778 | * This results in an empty message being RX'ed | |
1779 | * in userspace, but that is ignored. | |
1780 | * | |
1781 | * We can then retry with the larger buffer. | |
1782 | */ | |
1783 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1784 | !skb->len && !state->split && |
3713b4e3 JB |
1785 | cb->min_dump_alloc < 4096) { |
1786 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1787 | state->split_start = 0; |
d98cae64 | 1788 | rtnl_unlock(); |
3713b4e3 JB |
1789 | return 1; |
1790 | } | |
1791 | idx--; | |
1792 | break; | |
645e77de | 1793 | } |
86e8cf98 | 1794 | } while (state->split_start > 0); |
3713b4e3 | 1795 | break; |
55682965 | 1796 | } |
5fe231e8 | 1797 | rtnl_unlock(); |
55682965 | 1798 | |
86e8cf98 | 1799 | state->start = idx; |
55682965 JB |
1800 | |
1801 | return skb->len; | |
1802 | } | |
1803 | ||
86e8cf98 JB |
1804 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1805 | { | |
1806 | kfree((void *)cb->args[0]); | |
1807 | return 0; | |
1808 | } | |
1809 | ||
55682965 JB |
1810 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1811 | { | |
1812 | struct sk_buff *msg; | |
1b8ec87a | 1813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1814 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1815 | |
645e77de | 1816 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1817 | if (!msg) |
4c476991 | 1818 | return -ENOMEM; |
55682965 | 1819 | |
3bb20556 JB |
1820 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1821 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1822 | &state) < 0) { |
4c476991 JB |
1823 | nlmsg_free(msg); |
1824 | return -ENOBUFS; | |
1825 | } | |
55682965 | 1826 | |
134e6375 | 1827 | return genlmsg_reply(msg, info); |
55682965 JB |
1828 | } |
1829 | ||
31888487 JM |
1830 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1831 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1832 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1833 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1834 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1835 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1836 | }; | |
1837 | ||
1838 | static int parse_txq_params(struct nlattr *tb[], | |
1839 | struct ieee80211_txq_params *txq_params) | |
1840 | { | |
a3304b0a | 1841 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1842 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1843 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1844 | return -EINVAL; | |
1845 | ||
a3304b0a | 1846 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1847 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1848 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1849 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1850 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1851 | ||
a3304b0a JB |
1852 | if (txq_params->ac >= NL80211_NUM_ACS) |
1853 | return -EINVAL; | |
1854 | ||
31888487 JM |
1855 | return 0; |
1856 | } | |
1857 | ||
f444de05 JB |
1858 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1859 | { | |
1860 | /* | |
cc1d2806 JB |
1861 | * You can only set the channel explicitly for WDS interfaces, |
1862 | * all others have their channel managed via their respective | |
1863 | * "establish a connection" command (connect, join, ...) | |
1864 | * | |
1865 | * For AP/GO and mesh mode, the channel can be set with the | |
1866 | * channel userspace API, but is only stored and passed to the | |
1867 | * low-level driver when the AP starts or the mesh is joined. | |
1868 | * This is for backward compatibility, userspace can also give | |
1869 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1870 | * |
1871 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1872 | * whatever else is going on, so they have their own special |
1873 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1874 | */ |
1875 | return !wdev || | |
1876 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1877 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1878 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1879 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1880 | } |
1881 | ||
683b6d3b JB |
1882 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1883 | struct genl_info *info, | |
1884 | struct cfg80211_chan_def *chandef) | |
1885 | { | |
dbeca2ea | 1886 | u32 control_freq; |
683b6d3b JB |
1887 | |
1888 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1889 | return -EINVAL; | |
1890 | ||
1891 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1892 | ||
1893 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1894 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1895 | chandef->center_freq1 = control_freq; | |
1896 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1897 | |
1898 | /* Primary channel not allowed */ | |
1899 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1900 | return -EINVAL; | |
1901 | ||
3d9d1d66 JB |
1902 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1903 | enum nl80211_channel_type chantype; | |
1904 | ||
1905 | chantype = nla_get_u32( | |
1906 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1907 | ||
1908 | switch (chantype) { | |
1909 | case NL80211_CHAN_NO_HT: | |
1910 | case NL80211_CHAN_HT20: | |
1911 | case NL80211_CHAN_HT40PLUS: | |
1912 | case NL80211_CHAN_HT40MINUS: | |
1913 | cfg80211_chandef_create(chandef, chandef->chan, | |
1914 | chantype); | |
1915 | break; | |
1916 | default: | |
1917 | return -EINVAL; | |
1918 | } | |
1919 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1920 | chandef->width = | |
1921 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1922 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1923 | chandef->center_freq1 = | |
1924 | nla_get_u32( | |
1925 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1926 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1927 | chandef->center_freq2 = | |
1928 | nla_get_u32( | |
1929 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1930 | } | |
1931 | ||
9f5e8f6e | 1932 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1933 | return -EINVAL; |
1934 | ||
9f5e8f6e JB |
1935 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1936 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1937 | return -EINVAL; |
1938 | ||
2f301ab2 SW |
1939 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1940 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1941 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1942 | return -EINVAL; | |
1943 | ||
683b6d3b JB |
1944 | return 0; |
1945 | } | |
1946 | ||
f444de05 | 1947 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1948 | struct net_device *dev, |
f444de05 JB |
1949 | struct genl_info *info) |
1950 | { | |
683b6d3b | 1951 | struct cfg80211_chan_def chandef; |
f444de05 | 1952 | int result; |
e8c9bd5b | 1953 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1954 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1955 | |
e16821bc JM |
1956 | if (dev) |
1957 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1958 | if (!nl80211_can_set_dev_channel(wdev)) |
1959 | return -EOPNOTSUPP; | |
e16821bc JM |
1960 | if (wdev) |
1961 | iftype = wdev->iftype; | |
f444de05 | 1962 | |
683b6d3b JB |
1963 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1964 | if (result) | |
1965 | return result; | |
f444de05 | 1966 | |
e8c9bd5b | 1967 | switch (iftype) { |
aa430da4 JB |
1968 | case NL80211_IFTYPE_AP: |
1969 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 1970 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
1971 | result = -EINVAL; |
1972 | break; | |
1973 | } | |
e16821bc JM |
1974 | if (wdev->beacon_interval) { |
1975 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
1976 | !(rdev->wiphy.features & | |
1977 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
1978 | result = -EBUSY; | |
1979 | break; | |
1980 | } | |
1981 | ||
1982 | /* Only allow dynamic channel width changes */ | |
1983 | if (chandef.chan != wdev->preset_chandef.chan) { | |
1984 | result = -EBUSY; | |
1985 | break; | |
1986 | } | |
1987 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
1988 | if (result) | |
1989 | break; | |
1990 | } | |
683b6d3b | 1991 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1992 | result = 0; |
1993 | break; | |
cc1d2806 | 1994 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1995 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1996 | break; |
e8c9bd5b | 1997 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1998 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1999 | break; |
aa430da4 | 2000 | default: |
e8c9bd5b | 2001 | result = -EINVAL; |
f444de05 | 2002 | } |
f444de05 JB |
2003 | |
2004 | return result; | |
2005 | } | |
2006 | ||
2007 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2008 | { | |
4c476991 JB |
2009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2010 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2011 | |
e16821bc | 2012 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2013 | } |
2014 | ||
e8347eba BJ |
2015 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2016 | { | |
43b19952 JB |
2017 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2018 | struct net_device *dev = info->user_ptr[1]; | |
2019 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2020 | const u8 *bssid; |
e8347eba BJ |
2021 | |
2022 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2023 | return -EINVAL; | |
2024 | ||
43b19952 JB |
2025 | if (netif_running(dev)) |
2026 | return -EBUSY; | |
e8347eba | 2027 | |
43b19952 JB |
2028 | if (!rdev->ops->set_wds_peer) |
2029 | return -EOPNOTSUPP; | |
e8347eba | 2030 | |
43b19952 JB |
2031 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2032 | return -EOPNOTSUPP; | |
e8347eba BJ |
2033 | |
2034 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2035 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2036 | } |
2037 | ||
2038 | ||
55682965 JB |
2039 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2040 | { | |
2041 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2042 | struct net_device *netdev = NULL; |
2043 | struct wireless_dev *wdev; | |
a1e567c8 | 2044 | int result = 0, rem_txq_params = 0; |
31888487 | 2045 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2046 | u32 changed; |
2047 | u8 retry_short = 0, retry_long = 0; | |
2048 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2049 | u8 coverage_class = 0; |
55682965 | 2050 | |
5fe231e8 JB |
2051 | ASSERT_RTNL(); |
2052 | ||
f444de05 JB |
2053 | /* |
2054 | * Try to find the wiphy and netdev. Normally this | |
2055 | * function shouldn't need the netdev, but this is | |
2056 | * done for backward compatibility -- previously | |
2057 | * setting the channel was done per wiphy, but now | |
2058 | * it is per netdev. Previous userland like hostapd | |
2059 | * also passed a netdev to set_wiphy, so that it is | |
2060 | * possible to let that go to the right netdev! | |
2061 | */ | |
4bbf4d56 | 2062 | |
f444de05 JB |
2063 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2064 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2065 | ||
7f2b8562 | 2066 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2067 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2068 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2069 | else |
f444de05 | 2070 | netdev = NULL; |
4bbf4d56 JB |
2071 | } |
2072 | ||
f444de05 | 2073 | if (!netdev) { |
878d9ec7 JB |
2074 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2075 | info->attrs); | |
5fe231e8 | 2076 | if (IS_ERR(rdev)) |
4c476991 | 2077 | return PTR_ERR(rdev); |
f444de05 JB |
2078 | wdev = NULL; |
2079 | netdev = NULL; | |
2080 | result = 0; | |
71fe96bf | 2081 | } else |
f444de05 | 2082 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2083 | |
2084 | /* | |
2085 | * end workaround code, by now the rdev is available | |
2086 | * and locked, and wdev may or may not be NULL. | |
2087 | */ | |
4bbf4d56 JB |
2088 | |
2089 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2090 | result = cfg80211_dev_rename( |
2091 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2092 | |
4bbf4d56 | 2093 | if (result) |
7f2b8562 | 2094 | return result; |
31888487 JM |
2095 | |
2096 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2097 | struct ieee80211_txq_params txq_params; | |
2098 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2099 | ||
7f2b8562 YX |
2100 | if (!rdev->ops->set_txq_params) |
2101 | return -EOPNOTSUPP; | |
31888487 | 2102 | |
7f2b8562 YX |
2103 | if (!netdev) |
2104 | return -EINVAL; | |
f70f01c2 | 2105 | |
133a3ff2 | 2106 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2107 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2108 | return -EINVAL; | |
133a3ff2 | 2109 | |
7f2b8562 YX |
2110 | if (!netif_running(netdev)) |
2111 | return -ENETDOWN; | |
2b5f8b0b | 2112 | |
31888487 JM |
2113 | nla_for_each_nested(nl_txq_params, |
2114 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2115 | rem_txq_params) { | |
ae811e21 JB |
2116 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2117 | nla_data(nl_txq_params), | |
2118 | nla_len(nl_txq_params), | |
2119 | txq_params_policy); | |
2120 | if (result) | |
2121 | return result; | |
31888487 JM |
2122 | result = parse_txq_params(tb, &txq_params); |
2123 | if (result) | |
7f2b8562 | 2124 | return result; |
31888487 | 2125 | |
e35e4d28 HG |
2126 | result = rdev_set_txq_params(rdev, netdev, |
2127 | &txq_params); | |
31888487 | 2128 | if (result) |
7f2b8562 | 2129 | return result; |
31888487 JM |
2130 | } |
2131 | } | |
55682965 | 2132 | |
72bdcf34 | 2133 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2134 | result = __nl80211_set_channel( |
2135 | rdev, | |
2136 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2137 | info); | |
72bdcf34 | 2138 | if (result) |
7f2b8562 | 2139 | return result; |
72bdcf34 JM |
2140 | } |
2141 | ||
98d2ff8b | 2142 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2143 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2144 | enum nl80211_tx_power_setting type; |
2145 | int idx, mbm = 0; | |
2146 | ||
c8442118 JB |
2147 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2148 | txp_wdev = NULL; | |
2149 | ||
7f2b8562 YX |
2150 | if (!rdev->ops->set_tx_power) |
2151 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2152 | |
2153 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2154 | type = nla_get_u32(info->attrs[idx]); | |
2155 | ||
2156 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2157 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2158 | return -EINVAL; | |
98d2ff8b JO |
2159 | |
2160 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2161 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2162 | mbm = nla_get_u32(info->attrs[idx]); | |
2163 | } | |
2164 | ||
c8442118 | 2165 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2166 | if (result) |
7f2b8562 | 2167 | return result; |
98d2ff8b JO |
2168 | } |
2169 | ||
afe0cbf8 BR |
2170 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2171 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2172 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2173 | if ((!rdev->wiphy.available_antennas_tx && |
2174 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2175 | !rdev->ops->set_antenna) |
2176 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2177 | |
2178 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2179 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2180 | ||
a7ffac95 | 2181 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2182 | * available antenna masks, except for the "all" mask */ |
2183 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2184 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2185 | return -EINVAL; | |
a7ffac95 | 2186 | |
7f531e03 BR |
2187 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2188 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2189 | |
e35e4d28 | 2190 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2191 | if (result) |
7f2b8562 | 2192 | return result; |
afe0cbf8 BR |
2193 | } |
2194 | ||
b9a5f8ca JM |
2195 | changed = 0; |
2196 | ||
2197 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2198 | retry_short = nla_get_u8( | |
2199 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2200 | if (retry_short == 0) |
2201 | return -EINVAL; | |
2202 | ||
b9a5f8ca JM |
2203 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2204 | } | |
2205 | ||
2206 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2207 | retry_long = nla_get_u8( | |
2208 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2209 | if (retry_long == 0) |
2210 | return -EINVAL; | |
2211 | ||
b9a5f8ca JM |
2212 | changed |= WIPHY_PARAM_RETRY_LONG; |
2213 | } | |
2214 | ||
2215 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2216 | frag_threshold = nla_get_u32( | |
2217 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2218 | if (frag_threshold < 256) |
2219 | return -EINVAL; | |
2220 | ||
b9a5f8ca JM |
2221 | if (frag_threshold != (u32) -1) { |
2222 | /* | |
2223 | * Fragments (apart from the last one) are required to | |
2224 | * have even length. Make the fragmentation code | |
2225 | * simpler by stripping LSB should someone try to use | |
2226 | * odd threshold value. | |
2227 | */ | |
2228 | frag_threshold &= ~0x1; | |
2229 | } | |
2230 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2231 | } | |
2232 | ||
2233 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2234 | rts_threshold = nla_get_u32( | |
2235 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2236 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2237 | } | |
2238 | ||
81077e82 LT |
2239 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2240 | coverage_class = nla_get_u8( | |
2241 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2242 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2243 | } | |
2244 | ||
b9a5f8ca JM |
2245 | if (changed) { |
2246 | u8 old_retry_short, old_retry_long; | |
2247 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2248 | u8 old_coverage_class; |
b9a5f8ca | 2249 | |
7f2b8562 YX |
2250 | if (!rdev->ops->set_wiphy_params) |
2251 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2252 | |
2253 | old_retry_short = rdev->wiphy.retry_short; | |
2254 | old_retry_long = rdev->wiphy.retry_long; | |
2255 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2256 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2257 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2258 | |
2259 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2260 | rdev->wiphy.retry_short = retry_short; | |
2261 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2262 | rdev->wiphy.retry_long = retry_long; | |
2263 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2264 | rdev->wiphy.frag_threshold = frag_threshold; | |
2265 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2266 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2267 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2268 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2269 | |
e35e4d28 | 2270 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2271 | if (result) { |
2272 | rdev->wiphy.retry_short = old_retry_short; | |
2273 | rdev->wiphy.retry_long = old_retry_long; | |
2274 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2275 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2276 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2277 | } |
2278 | } | |
7f2b8562 | 2279 | return 0; |
55682965 JB |
2280 | } |
2281 | ||
71bbc994 JB |
2282 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2283 | { | |
2284 | return (u64)wdev->identifier | | |
f26cbf40 | 2285 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2286 | } |
55682965 | 2287 | |
683b6d3b | 2288 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2289 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2290 | { |
9f5e8f6e | 2291 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2292 | |
683b6d3b JB |
2293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2294 | chandef->chan->center_freq)) | |
2295 | return -ENOBUFS; | |
3d9d1d66 JB |
2296 | switch (chandef->width) { |
2297 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2298 | case NL80211_CHAN_WIDTH_20: | |
2299 | case NL80211_CHAN_WIDTH_40: | |
2300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2301 | cfg80211_get_chandef_type(chandef))) | |
2302 | return -ENOBUFS; | |
2303 | break; | |
2304 | default: | |
2305 | break; | |
2306 | } | |
2307 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2308 | return -ENOBUFS; | |
2309 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2310 | return -ENOBUFS; | |
2311 | if (chandef->center_freq2 && | |
2312 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2313 | return -ENOBUFS; |
2314 | return 0; | |
2315 | } | |
2316 | ||
15e47304 | 2317 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2318 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2319 | struct wireless_dev *wdev) |
55682965 | 2320 | { |
72fb2abc | 2321 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2322 | void *hdr; |
2323 | ||
15e47304 | 2324 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2325 | if (!hdr) |
2326 | return -1; | |
2327 | ||
72fb2abc JB |
2328 | if (dev && |
2329 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2330 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2331 | goto nla_put_failure; |
2332 | ||
2333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2334 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2335 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2336 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2337 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2338 | rdev->devlist_generation ^ | |
2339 | (cfg80211_rdev_list_generation << 2))) | |
2340 | goto nla_put_failure; | |
f5ea9120 | 2341 | |
5b7ccaf3 | 2342 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2343 | int ret; |
2344 | struct cfg80211_chan_def chandef; | |
2345 | ||
2346 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2347 | if (ret == 0) { | |
2348 | if (nl80211_send_chandef(msg, &chandef)) | |
2349 | goto nla_put_failure; | |
2350 | } | |
d91df0e3 PF |
2351 | } |
2352 | ||
b84e7a05 AQ |
2353 | if (wdev->ssid_len) { |
2354 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2355 | goto nla_put_failure; | |
2356 | } | |
2357 | ||
55682965 JB |
2358 | return genlmsg_end(msg, hdr); |
2359 | ||
2360 | nla_put_failure: | |
bc3ed28c TG |
2361 | genlmsg_cancel(msg, hdr); |
2362 | return -EMSGSIZE; | |
55682965 JB |
2363 | } |
2364 | ||
2365 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2366 | { | |
2367 | int wp_idx = 0; | |
2368 | int if_idx = 0; | |
2369 | int wp_start = cb->args[0]; | |
2370 | int if_start = cb->args[1]; | |
f5ea9120 | 2371 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2372 | struct wireless_dev *wdev; |
2373 | ||
5fe231e8 | 2374 | rtnl_lock(); |
f5ea9120 JB |
2375 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2376 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2377 | continue; |
bba95fef JB |
2378 | if (wp_idx < wp_start) { |
2379 | wp_idx++; | |
55682965 | 2380 | continue; |
bba95fef | 2381 | } |
55682965 JB |
2382 | if_idx = 0; |
2383 | ||
89a54e48 | 2384 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2385 | if (if_idx < if_start) { |
2386 | if_idx++; | |
55682965 | 2387 | continue; |
bba95fef | 2388 | } |
15e47304 | 2389 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2390 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2391 | rdev, wdev) < 0) { |
bba95fef JB |
2392 | goto out; |
2393 | } | |
2394 | if_idx++; | |
55682965 | 2395 | } |
bba95fef JB |
2396 | |
2397 | wp_idx++; | |
55682965 | 2398 | } |
bba95fef | 2399 | out: |
5fe231e8 | 2400 | rtnl_unlock(); |
55682965 JB |
2401 | |
2402 | cb->args[0] = wp_idx; | |
2403 | cb->args[1] = if_idx; | |
2404 | ||
2405 | return skb->len; | |
2406 | } | |
2407 | ||
2408 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2409 | { | |
2410 | struct sk_buff *msg; | |
1b8ec87a | 2411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2412 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2413 | |
fd2120ca | 2414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2415 | if (!msg) |
4c476991 | 2416 | return -ENOMEM; |
55682965 | 2417 | |
15e47304 | 2418 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1b8ec87a | 2419 | rdev, wdev) < 0) { |
4c476991 JB |
2420 | nlmsg_free(msg); |
2421 | return -ENOBUFS; | |
2422 | } | |
55682965 | 2423 | |
134e6375 | 2424 | return genlmsg_reply(msg, info); |
55682965 JB |
2425 | } |
2426 | ||
66f7ac50 MW |
2427 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2428 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2429 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2430 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2431 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2432 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2433 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2434 | }; |
2435 | ||
2436 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2437 | { | |
2438 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2439 | int flag; | |
2440 | ||
2441 | *mntrflags = 0; | |
2442 | ||
2443 | if (!nla) | |
2444 | return -EINVAL; | |
2445 | ||
2446 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2447 | nla, mntr_flags_policy)) | |
2448 | return -EINVAL; | |
2449 | ||
2450 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2451 | if (flags[flag]) | |
2452 | *mntrflags |= (1<<flag); | |
2453 | ||
2454 | return 0; | |
2455 | } | |
2456 | ||
9bc383de | 2457 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2458 | struct net_device *netdev, u8 use_4addr, |
2459 | enum nl80211_iftype iftype) | |
9bc383de | 2460 | { |
ad4bb6f8 | 2461 | if (!use_4addr) { |
f350a0a8 | 2462 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2463 | return -EBUSY; |
9bc383de | 2464 | return 0; |
ad4bb6f8 | 2465 | } |
9bc383de JB |
2466 | |
2467 | switch (iftype) { | |
2468 | case NL80211_IFTYPE_AP_VLAN: | |
2469 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2470 | return 0; | |
2471 | break; | |
2472 | case NL80211_IFTYPE_STATION: | |
2473 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2474 | return 0; | |
2475 | break; | |
2476 | default: | |
2477 | break; | |
2478 | } | |
2479 | ||
2480 | return -EOPNOTSUPP; | |
2481 | } | |
2482 | ||
55682965 JB |
2483 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2484 | { | |
4c476991 | 2485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2486 | struct vif_params params; |
e36d56b6 | 2487 | int err; |
04a773ad | 2488 | enum nl80211_iftype otype, ntype; |
4c476991 | 2489 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2490 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2491 | bool change = false; |
55682965 | 2492 | |
2ec600d6 LCC |
2493 | memset(¶ms, 0, sizeof(params)); |
2494 | ||
04a773ad | 2495 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2496 | |
723b038d | 2497 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2498 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2499 | if (otype != ntype) |
ac7f9cfa | 2500 | change = true; |
4c476991 JB |
2501 | if (ntype > NL80211_IFTYPE_MAX) |
2502 | return -EINVAL; | |
723b038d JB |
2503 | } |
2504 | ||
92ffe055 | 2505 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2506 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2507 | ||
4c476991 JB |
2508 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2509 | return -EINVAL; | |
29cbe68c JB |
2510 | if (netif_running(dev)) |
2511 | return -EBUSY; | |
2512 | ||
2513 | wdev_lock(wdev); | |
2514 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2515 | IEEE80211_MAX_MESH_ID_LEN); | |
2516 | wdev->mesh_id_up_len = | |
2517 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2518 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2519 | wdev->mesh_id_up_len); | |
2520 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2521 | } |
2522 | ||
8b787643 FF |
2523 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2524 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2525 | change = true; | |
ad4bb6f8 | 2526 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2527 | if (err) |
4c476991 | 2528 | return err; |
8b787643 FF |
2529 | } else { |
2530 | params.use_4addr = -1; | |
2531 | } | |
2532 | ||
92ffe055 | 2533 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2534 | if (ntype != NL80211_IFTYPE_MONITOR) |
2535 | return -EINVAL; | |
92ffe055 JB |
2536 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2537 | &_flags); | |
ac7f9cfa | 2538 | if (err) |
4c476991 | 2539 | return err; |
ac7f9cfa JB |
2540 | |
2541 | flags = &_flags; | |
2542 | change = true; | |
92ffe055 | 2543 | } |
3b85875a | 2544 | |
18003297 | 2545 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2546 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2547 | return -EOPNOTSUPP; | |
2548 | ||
ac7f9cfa | 2549 | if (change) |
3d54d255 | 2550 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2551 | else |
2552 | err = 0; | |
60719ffd | 2553 | |
9bc383de JB |
2554 | if (!err && params.use_4addr != -1) |
2555 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2556 | ||
55682965 JB |
2557 | return err; |
2558 | } | |
2559 | ||
2560 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2561 | { | |
4c476991 | 2562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2563 | struct vif_params params; |
84efbb84 | 2564 | struct wireless_dev *wdev; |
1c90f9d4 | 2565 | struct sk_buff *msg; |
55682965 JB |
2566 | int err; |
2567 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2568 | u32 flags; |
55682965 | 2569 | |
78f22b6a JB |
2570 | /* to avoid failing a new interface creation due to pending removal */ |
2571 | cfg80211_destroy_ifaces(rdev); | |
2572 | ||
2ec600d6 LCC |
2573 | memset(¶ms, 0, sizeof(params)); |
2574 | ||
55682965 JB |
2575 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2576 | return -EINVAL; | |
2577 | ||
2578 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2579 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2580 | if (type > NL80211_IFTYPE_MAX) | |
2581 | return -EINVAL; | |
2582 | } | |
2583 | ||
79c97e97 | 2584 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2585 | !(rdev->wiphy.interface_modes & (1 << type))) |
2586 | return -EOPNOTSUPP; | |
55682965 | 2587 | |
1c18f145 AS |
2588 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2589 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2590 | ETH_ALEN); | |
2591 | if (!is_valid_ether_addr(params.macaddr)) | |
2592 | return -EADDRNOTAVAIL; | |
2593 | } | |
2594 | ||
9bc383de | 2595 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2596 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2597 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2598 | if (err) |
4c476991 | 2599 | return err; |
9bc383de | 2600 | } |
8b787643 | 2601 | |
1c90f9d4 JB |
2602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2603 | if (!msg) | |
2604 | return -ENOMEM; | |
2605 | ||
66f7ac50 MW |
2606 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2607 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2608 | &flags); | |
e057d3c3 | 2609 | |
18003297 | 2610 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2611 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2612 | return -EOPNOTSUPP; | |
2613 | ||
e35e4d28 HG |
2614 | wdev = rdev_add_virtual_intf(rdev, |
2615 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2616 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2617 | if (IS_ERR(wdev)) { |
2618 | nlmsg_free(msg); | |
84efbb84 | 2619 | return PTR_ERR(wdev); |
1c90f9d4 | 2620 | } |
2ec600d6 | 2621 | |
78f22b6a JB |
2622 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
2623 | wdev->owner_nlportid = info->snd_portid; | |
2624 | ||
98104fde JB |
2625 | switch (type) { |
2626 | case NL80211_IFTYPE_MESH_POINT: | |
2627 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2628 | break; | |
29cbe68c JB |
2629 | wdev_lock(wdev); |
2630 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2631 | IEEE80211_MAX_MESH_ID_LEN); | |
2632 | wdev->mesh_id_up_len = | |
2633 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2634 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2635 | wdev->mesh_id_up_len); | |
2636 | wdev_unlock(wdev); | |
98104fde JB |
2637 | break; |
2638 | case NL80211_IFTYPE_P2P_DEVICE: | |
2639 | /* | |
2640 | * P2P Device doesn't have a netdev, so doesn't go | |
2641 | * through the netdev notifier and must be added here | |
2642 | */ | |
2643 | mutex_init(&wdev->mtx); | |
2644 | INIT_LIST_HEAD(&wdev->event_list); | |
2645 | spin_lock_init(&wdev->event_lock); | |
2646 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2647 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2648 | ||
98104fde JB |
2649 | wdev->identifier = ++rdev->wdev_id; |
2650 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2651 | rdev->devlist_generation++; | |
98104fde JB |
2652 | break; |
2653 | default: | |
2654 | break; | |
29cbe68c JB |
2655 | } |
2656 | ||
15e47304 | 2657 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2658 | rdev, wdev) < 0) { |
2659 | nlmsg_free(msg); | |
2660 | return -ENOBUFS; | |
2661 | } | |
2662 | ||
2663 | return genlmsg_reply(msg, info); | |
55682965 JB |
2664 | } |
2665 | ||
2666 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2667 | { | |
4c476991 | 2668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2669 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2670 | |
4c476991 JB |
2671 | if (!rdev->ops->del_virtual_intf) |
2672 | return -EOPNOTSUPP; | |
55682965 | 2673 | |
84efbb84 JB |
2674 | /* |
2675 | * If we remove a wireless device without a netdev then clear | |
2676 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2677 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2678 | * since the wdev has been freed, unlike with a netdev where | |
2679 | * we need the dev_put() for the netdev to really be freed. | |
2680 | */ | |
2681 | if (!wdev->netdev) | |
2682 | info->user_ptr[1] = NULL; | |
2683 | ||
e35e4d28 | 2684 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2685 | } |
2686 | ||
1d9d9213 SW |
2687 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2688 | { | |
2689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2690 | struct net_device *dev = info->user_ptr[1]; | |
2691 | u16 noack_map; | |
2692 | ||
2693 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2694 | return -EINVAL; | |
2695 | ||
2696 | if (!rdev->ops->set_noack_map) | |
2697 | return -EOPNOTSUPP; | |
2698 | ||
2699 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2700 | ||
e35e4d28 | 2701 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2702 | } |
2703 | ||
41ade00f JB |
2704 | struct get_key_cookie { |
2705 | struct sk_buff *msg; | |
2706 | int error; | |
b9454e83 | 2707 | int idx; |
41ade00f JB |
2708 | }; |
2709 | ||
2710 | static void get_key_callback(void *c, struct key_params *params) | |
2711 | { | |
b9454e83 | 2712 | struct nlattr *key; |
41ade00f JB |
2713 | struct get_key_cookie *cookie = c; |
2714 | ||
9360ffd1 DM |
2715 | if ((params->key && |
2716 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2717 | params->key_len, params->key)) || | |
2718 | (params->seq && | |
2719 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2720 | params->seq_len, params->seq)) || | |
2721 | (params->cipher && | |
2722 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2723 | params->cipher))) | |
2724 | goto nla_put_failure; | |
41ade00f | 2725 | |
b9454e83 JB |
2726 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2727 | if (!key) | |
2728 | goto nla_put_failure; | |
2729 | ||
9360ffd1 DM |
2730 | if ((params->key && |
2731 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2732 | params->key_len, params->key)) || | |
2733 | (params->seq && | |
2734 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2735 | params->seq_len, params->seq)) || | |
2736 | (params->cipher && | |
2737 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2738 | params->cipher))) | |
2739 | goto nla_put_failure; | |
b9454e83 | 2740 | |
9360ffd1 DM |
2741 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2742 | goto nla_put_failure; | |
b9454e83 JB |
2743 | |
2744 | nla_nest_end(cookie->msg, key); | |
2745 | ||
41ade00f JB |
2746 | return; |
2747 | nla_put_failure: | |
2748 | cookie->error = 1; | |
2749 | } | |
2750 | ||
2751 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2752 | { | |
4c476991 | 2753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2754 | int err; |
4c476991 | 2755 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2756 | u8 key_idx = 0; |
e31b8213 JB |
2757 | const u8 *mac_addr = NULL; |
2758 | bool pairwise; | |
41ade00f JB |
2759 | struct get_key_cookie cookie = { |
2760 | .error = 0, | |
2761 | }; | |
2762 | void *hdr; | |
2763 | struct sk_buff *msg; | |
2764 | ||
2765 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2766 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2767 | ||
3cfcf6ac | 2768 | if (key_idx > 5) |
41ade00f JB |
2769 | return -EINVAL; |
2770 | ||
2771 | if (info->attrs[NL80211_ATTR_MAC]) | |
2772 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2773 | ||
e31b8213 JB |
2774 | pairwise = !!mac_addr; |
2775 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2776 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2777 | if (kt >= NUM_NL80211_KEYTYPES) | |
2778 | return -EINVAL; | |
2779 | if (kt != NL80211_KEYTYPE_GROUP && | |
2780 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2781 | return -EINVAL; | |
2782 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2783 | } | |
2784 | ||
4c476991 JB |
2785 | if (!rdev->ops->get_key) |
2786 | return -EOPNOTSUPP; | |
41ade00f | 2787 | |
fd2120ca | 2788 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2789 | if (!msg) |
2790 | return -ENOMEM; | |
41ade00f | 2791 | |
15e47304 | 2792 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2793 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2794 | if (!hdr) |
9fe271af | 2795 | goto nla_put_failure; |
41ade00f JB |
2796 | |
2797 | cookie.msg = msg; | |
b9454e83 | 2798 | cookie.idx = key_idx; |
41ade00f | 2799 | |
9360ffd1 DM |
2800 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2801 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2802 | goto nla_put_failure; | |
2803 | if (mac_addr && | |
2804 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2805 | goto nla_put_failure; | |
41ade00f | 2806 | |
e31b8213 JB |
2807 | if (pairwise && mac_addr && |
2808 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2809 | return -ENOENT; | |
2810 | ||
e35e4d28 HG |
2811 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2812 | get_key_callback); | |
41ade00f JB |
2813 | |
2814 | if (err) | |
6c95e2a2 | 2815 | goto free_msg; |
41ade00f JB |
2816 | |
2817 | if (cookie.error) | |
2818 | goto nla_put_failure; | |
2819 | ||
2820 | genlmsg_end(msg, hdr); | |
4c476991 | 2821 | return genlmsg_reply(msg, info); |
41ade00f JB |
2822 | |
2823 | nla_put_failure: | |
2824 | err = -ENOBUFS; | |
6c95e2a2 | 2825 | free_msg: |
41ade00f | 2826 | nlmsg_free(msg); |
41ade00f JB |
2827 | return err; |
2828 | } | |
2829 | ||
2830 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2831 | { | |
4c476991 | 2832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2833 | struct key_parse key; |
41ade00f | 2834 | int err; |
4c476991 | 2835 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2836 | |
b9454e83 JB |
2837 | err = nl80211_parse_key(info, &key); |
2838 | if (err) | |
2839 | return err; | |
41ade00f | 2840 | |
b9454e83 | 2841 | if (key.idx < 0) |
41ade00f JB |
2842 | return -EINVAL; |
2843 | ||
b9454e83 JB |
2844 | /* only support setting default key */ |
2845 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2846 | return -EINVAL; |
2847 | ||
dbd2fd65 | 2848 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2849 | |
dbd2fd65 JB |
2850 | if (key.def) { |
2851 | if (!rdev->ops->set_default_key) { | |
2852 | err = -EOPNOTSUPP; | |
2853 | goto out; | |
2854 | } | |
41ade00f | 2855 | |
dbd2fd65 JB |
2856 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2857 | if (err) | |
2858 | goto out; | |
2859 | ||
e35e4d28 | 2860 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2861 | key.def_uni, key.def_multi); |
2862 | ||
2863 | if (err) | |
2864 | goto out; | |
fffd0934 | 2865 | |
3d23e349 | 2866 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2867 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2868 | #endif | |
2869 | } else { | |
2870 | if (key.def_uni || !key.def_multi) { | |
2871 | err = -EINVAL; | |
2872 | goto out; | |
2873 | } | |
2874 | ||
2875 | if (!rdev->ops->set_default_mgmt_key) { | |
2876 | err = -EOPNOTSUPP; | |
2877 | goto out; | |
2878 | } | |
2879 | ||
2880 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2881 | if (err) | |
2882 | goto out; | |
2883 | ||
e35e4d28 | 2884 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2885 | if (err) |
2886 | goto out; | |
2887 | ||
2888 | #ifdef CONFIG_CFG80211_WEXT | |
2889 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2890 | #endif |
dbd2fd65 JB |
2891 | } |
2892 | ||
2893 | out: | |
fffd0934 | 2894 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2895 | |
41ade00f JB |
2896 | return err; |
2897 | } | |
2898 | ||
2899 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2900 | { | |
4c476991 | 2901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2902 | int err; |
4c476991 | 2903 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2904 | struct key_parse key; |
e31b8213 | 2905 | const u8 *mac_addr = NULL; |
41ade00f | 2906 | |
b9454e83 JB |
2907 | err = nl80211_parse_key(info, &key); |
2908 | if (err) | |
2909 | return err; | |
41ade00f | 2910 | |
b9454e83 | 2911 | if (!key.p.key) |
41ade00f JB |
2912 | return -EINVAL; |
2913 | ||
41ade00f JB |
2914 | if (info->attrs[NL80211_ATTR_MAC]) |
2915 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2916 | ||
e31b8213 JB |
2917 | if (key.type == -1) { |
2918 | if (mac_addr) | |
2919 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2920 | else | |
2921 | key.type = NL80211_KEYTYPE_GROUP; | |
2922 | } | |
2923 | ||
2924 | /* for now */ | |
2925 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2926 | key.type != NL80211_KEYTYPE_GROUP) | |
2927 | return -EINVAL; | |
2928 | ||
4c476991 JB |
2929 | if (!rdev->ops->add_key) |
2930 | return -EOPNOTSUPP; | |
25e47c18 | 2931 | |
e31b8213 JB |
2932 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2933 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2934 | mac_addr)) | |
4c476991 | 2935 | return -EINVAL; |
41ade00f | 2936 | |
fffd0934 JB |
2937 | wdev_lock(dev->ieee80211_ptr); |
2938 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2939 | if (!err) | |
e35e4d28 HG |
2940 | err = rdev_add_key(rdev, dev, key.idx, |
2941 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2942 | mac_addr, &key.p); | |
fffd0934 | 2943 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2944 | |
41ade00f JB |
2945 | return err; |
2946 | } | |
2947 | ||
2948 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2949 | { | |
4c476991 | 2950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2951 | int err; |
4c476991 | 2952 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2953 | u8 *mac_addr = NULL; |
b9454e83 | 2954 | struct key_parse key; |
41ade00f | 2955 | |
b9454e83 JB |
2956 | err = nl80211_parse_key(info, &key); |
2957 | if (err) | |
2958 | return err; | |
41ade00f JB |
2959 | |
2960 | if (info->attrs[NL80211_ATTR_MAC]) | |
2961 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2962 | ||
e31b8213 JB |
2963 | if (key.type == -1) { |
2964 | if (mac_addr) | |
2965 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2966 | else | |
2967 | key.type = NL80211_KEYTYPE_GROUP; | |
2968 | } | |
2969 | ||
2970 | /* for now */ | |
2971 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2972 | key.type != NL80211_KEYTYPE_GROUP) | |
2973 | return -EINVAL; | |
2974 | ||
4c476991 JB |
2975 | if (!rdev->ops->del_key) |
2976 | return -EOPNOTSUPP; | |
41ade00f | 2977 | |
fffd0934 JB |
2978 | wdev_lock(dev->ieee80211_ptr); |
2979 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2980 | |
2981 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2982 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2983 | err = -ENOENT; | |
2984 | ||
fffd0934 | 2985 | if (!err) |
e35e4d28 HG |
2986 | err = rdev_del_key(rdev, dev, key.idx, |
2987 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2988 | mac_addr); | |
41ade00f | 2989 | |
3d23e349 | 2990 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2991 | if (!err) { |
b9454e83 | 2992 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2993 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2994 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2995 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2996 | } | |
2997 | #endif | |
fffd0934 | 2998 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2999 | |
41ade00f JB |
3000 | return err; |
3001 | } | |
3002 | ||
77765eaf VT |
3003 | /* This function returns an error or the number of nested attributes */ |
3004 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3005 | { | |
3006 | struct nlattr *attr; | |
3007 | int n_entries = 0, tmp; | |
3008 | ||
3009 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3010 | if (nla_len(attr) != ETH_ALEN) | |
3011 | return -EINVAL; | |
3012 | ||
3013 | n_entries++; | |
3014 | } | |
3015 | ||
3016 | return n_entries; | |
3017 | } | |
3018 | ||
3019 | /* | |
3020 | * This function parses ACL information and allocates memory for ACL data. | |
3021 | * On successful return, the calling function is responsible to free the | |
3022 | * ACL buffer returned by this function. | |
3023 | */ | |
3024 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3025 | struct genl_info *info) | |
3026 | { | |
3027 | enum nl80211_acl_policy acl_policy; | |
3028 | struct nlattr *attr; | |
3029 | struct cfg80211_acl_data *acl; | |
3030 | int i = 0, n_entries, tmp; | |
3031 | ||
3032 | if (!wiphy->max_acl_mac_addrs) | |
3033 | return ERR_PTR(-EOPNOTSUPP); | |
3034 | ||
3035 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3036 | return ERR_PTR(-EINVAL); | |
3037 | ||
3038 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3039 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3040 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3041 | return ERR_PTR(-EINVAL); | |
3042 | ||
3043 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3044 | return ERR_PTR(-EINVAL); | |
3045 | ||
3046 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3047 | if (n_entries < 0) | |
3048 | return ERR_PTR(n_entries); | |
3049 | ||
3050 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3051 | return ERR_PTR(-ENOTSUPP); | |
3052 | ||
3053 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3054 | GFP_KERNEL); | |
3055 | if (!acl) | |
3056 | return ERR_PTR(-ENOMEM); | |
3057 | ||
3058 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3059 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3060 | i++; | |
3061 | } | |
3062 | ||
3063 | acl->n_acl_entries = n_entries; | |
3064 | acl->acl_policy = acl_policy; | |
3065 | ||
3066 | return acl; | |
3067 | } | |
3068 | ||
3069 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3070 | { | |
3071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3072 | struct net_device *dev = info->user_ptr[1]; | |
3073 | struct cfg80211_acl_data *acl; | |
3074 | int err; | |
3075 | ||
3076 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3077 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3078 | return -EOPNOTSUPP; | |
3079 | ||
3080 | if (!dev->ieee80211_ptr->beacon_interval) | |
3081 | return -EINVAL; | |
3082 | ||
3083 | acl = parse_acl_data(&rdev->wiphy, info); | |
3084 | if (IS_ERR(acl)) | |
3085 | return PTR_ERR(acl); | |
3086 | ||
3087 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3088 | ||
3089 | kfree(acl); | |
3090 | ||
3091 | return err; | |
3092 | } | |
3093 | ||
a1193be8 | 3094 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3095 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3096 | { |
8860020e | 3097 | bool haveinfo = false; |
ed1b6cc7 | 3098 | |
a1193be8 SW |
3099 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3100 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3101 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3102 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3103 | return -EINVAL; |
3104 | ||
8860020e | 3105 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3106 | |
a1193be8 SW |
3107 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3108 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3109 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3110 | if (!bcn->head_len) |
3111 | return -EINVAL; | |
3112 | haveinfo = true; | |
ed1b6cc7 JB |
3113 | } |
3114 | ||
a1193be8 SW |
3115 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3116 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3117 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3118 | haveinfo = true; |
ed1b6cc7 JB |
3119 | } |
3120 | ||
4c476991 JB |
3121 | if (!haveinfo) |
3122 | return -EINVAL; | |
3b85875a | 3123 | |
a1193be8 SW |
3124 | if (attrs[NL80211_ATTR_IE]) { |
3125 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3126 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3127 | } |
3128 | ||
a1193be8 | 3129 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3130 | bcn->proberesp_ies = |
a1193be8 | 3131 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3132 | bcn->proberesp_ies_len = |
a1193be8 | 3133 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3134 | } |
3135 | ||
a1193be8 | 3136 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3137 | bcn->assocresp_ies = |
a1193be8 | 3138 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3139 | bcn->assocresp_ies_len = |
a1193be8 | 3140 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3141 | } |
3142 | ||
a1193be8 SW |
3143 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3144 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3145 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3146 | } |
3147 | ||
8860020e JB |
3148 | return 0; |
3149 | } | |
3150 | ||
46c1dd0c FF |
3151 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3152 | struct cfg80211_ap_settings *params) | |
3153 | { | |
3154 | struct wireless_dev *wdev; | |
3155 | bool ret = false; | |
3156 | ||
89a54e48 | 3157 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3158 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3159 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3160 | continue; | |
3161 | ||
683b6d3b | 3162 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3163 | continue; |
3164 | ||
683b6d3b | 3165 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3166 | ret = true; |
3167 | break; | |
3168 | } | |
3169 | ||
46c1dd0c FF |
3170 | return ret; |
3171 | } | |
3172 | ||
e39e5b5e JM |
3173 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3174 | enum nl80211_auth_type auth_type, | |
3175 | enum nl80211_commands cmd) | |
3176 | { | |
3177 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3178 | return false; | |
3179 | ||
3180 | switch (cmd) { | |
3181 | case NL80211_CMD_AUTHENTICATE: | |
3182 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3183 | auth_type == NL80211_AUTHTYPE_SAE) | |
3184 | return false; | |
3185 | return true; | |
3186 | case NL80211_CMD_CONNECT: | |
3187 | case NL80211_CMD_START_AP: | |
3188 | /* SAE not supported yet */ | |
3189 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3190 | return false; | |
3191 | return true; | |
3192 | default: | |
3193 | return false; | |
3194 | } | |
3195 | } | |
3196 | ||
8860020e JB |
3197 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3198 | { | |
3199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3200 | struct net_device *dev = info->user_ptr[1]; | |
3201 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3202 | struct cfg80211_ap_settings params; | |
3203 | int err; | |
3204 | ||
3205 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3206 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3207 | return -EOPNOTSUPP; | |
3208 | ||
3209 | if (!rdev->ops->start_ap) | |
3210 | return -EOPNOTSUPP; | |
3211 | ||
3212 | if (wdev->beacon_interval) | |
3213 | return -EALREADY; | |
3214 | ||
3215 | memset(¶ms, 0, sizeof(params)); | |
3216 | ||
3217 | /* these are required for START_AP */ | |
3218 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3219 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3220 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3221 | return -EINVAL; | |
3222 | ||
a1193be8 | 3223 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3224 | if (err) |
3225 | return err; | |
3226 | ||
3227 | params.beacon_interval = | |
3228 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3229 | params.dtim_period = | |
3230 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3231 | ||
3232 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3233 | if (err) | |
3234 | return err; | |
3235 | ||
3236 | /* | |
3237 | * In theory, some of these attributes should be required here | |
3238 | * but since they were not used when the command was originally | |
3239 | * added, keep them optional for old user space programs to let | |
3240 | * them continue to work with drivers that do not need the | |
3241 | * additional information -- drivers must check! | |
3242 | */ | |
3243 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3244 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3245 | params.ssid_len = | |
3246 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3247 | if (params.ssid_len == 0 || | |
3248 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3249 | return -EINVAL; | |
3250 | } | |
3251 | ||
3252 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3253 | params.hidden_ssid = nla_get_u32( | |
3254 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3255 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3256 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3257 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3258 | return -EINVAL; | |
3259 | } | |
3260 | ||
3261 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3262 | ||
3263 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3264 | params.auth_type = nla_get_u32( | |
3265 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3266 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3267 | NL80211_CMD_START_AP)) | |
8860020e JB |
3268 | return -EINVAL; |
3269 | } else | |
3270 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3271 | ||
3272 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3273 | NL80211_MAX_NR_CIPHER_SUITES); | |
3274 | if (err) | |
3275 | return err; | |
3276 | ||
1b658f11 VT |
3277 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3278 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3279 | return -EOPNOTSUPP; | |
3280 | params.inactivity_timeout = nla_get_u16( | |
3281 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3282 | } | |
3283 | ||
53cabad7 JB |
3284 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3285 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3286 | return -EINVAL; | |
3287 | params.p2p_ctwindow = | |
3288 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3289 | if (params.p2p_ctwindow > 127) | |
3290 | return -EINVAL; | |
3291 | if (params.p2p_ctwindow != 0 && | |
3292 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3293 | return -EINVAL; | |
3294 | } | |
3295 | ||
3296 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3297 | u8 tmp; | |
3298 | ||
3299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3300 | return -EINVAL; | |
3301 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3302 | if (tmp > 1) | |
3303 | return -EINVAL; | |
3304 | params.p2p_opp_ps = tmp; | |
3305 | if (params.p2p_opp_ps != 0 && | |
3306 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3307 | return -EINVAL; | |
3308 | } | |
3309 | ||
aa430da4 | 3310 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3311 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3312 | if (err) | |
3313 | return err; | |
3314 | } else if (wdev->preset_chandef.chan) { | |
3315 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3316 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3317 | return -EINVAL; |
3318 | ||
174e0cd2 IP |
3319 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3320 | wdev->iftype)) | |
aa430da4 JB |
3321 | return -EINVAL; |
3322 | ||
77765eaf VT |
3323 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3324 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3325 | if (IS_ERR(params.acl)) | |
3326 | return PTR_ERR(params.acl); | |
3327 | } | |
3328 | ||
c56589ed | 3329 | wdev_lock(wdev); |
e35e4d28 | 3330 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3331 | if (!err) { |
683b6d3b | 3332 | wdev->preset_chandef = params.chandef; |
8860020e | 3333 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3334 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3335 | wdev->ssid_len = params.ssid_len; |
3336 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3337 | } |
c56589ed | 3338 | wdev_unlock(wdev); |
77765eaf VT |
3339 | |
3340 | kfree(params.acl); | |
3341 | ||
56d1893d | 3342 | return err; |
ed1b6cc7 JB |
3343 | } |
3344 | ||
8860020e JB |
3345 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3346 | { | |
3347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3348 | struct net_device *dev = info->user_ptr[1]; | |
3349 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3350 | struct cfg80211_beacon_data params; | |
3351 | int err; | |
3352 | ||
3353 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3354 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3355 | return -EOPNOTSUPP; | |
3356 | ||
3357 | if (!rdev->ops->change_beacon) | |
3358 | return -EOPNOTSUPP; | |
3359 | ||
3360 | if (!wdev->beacon_interval) | |
3361 | return -EINVAL; | |
3362 | ||
a1193be8 | 3363 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3364 | if (err) |
3365 | return err; | |
3366 | ||
c56589ed SW |
3367 | wdev_lock(wdev); |
3368 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3369 | wdev_unlock(wdev); | |
3370 | ||
3371 | return err; | |
8860020e JB |
3372 | } |
3373 | ||
3374 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3375 | { |
4c476991 JB |
3376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3377 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3378 | |
7c8d5e03 | 3379 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3380 | } |
3381 | ||
5727ef1b JB |
3382 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3383 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3384 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3385 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3386 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3387 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3388 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3389 | }; |
3390 | ||
eccb8e8f | 3391 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3392 | enum nl80211_iftype iftype, |
eccb8e8f | 3393 | struct station_parameters *params) |
5727ef1b JB |
3394 | { |
3395 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3396 | struct nlattr *nla; |
5727ef1b JB |
3397 | int flag; |
3398 | ||
eccb8e8f JB |
3399 | /* |
3400 | * Try parsing the new attribute first so userspace | |
3401 | * can specify both for older kernels. | |
3402 | */ | |
3403 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3404 | if (nla) { | |
3405 | struct nl80211_sta_flag_update *sta_flags; | |
3406 | ||
3407 | sta_flags = nla_data(nla); | |
3408 | params->sta_flags_mask = sta_flags->mask; | |
3409 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3410 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3411 | if ((params->sta_flags_mask | |
3412 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3413 | return -EINVAL; | |
3414 | return 0; | |
3415 | } | |
3416 | ||
3417 | /* if present, parse the old attribute */ | |
5727ef1b | 3418 | |
eccb8e8f | 3419 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3420 | if (!nla) |
3421 | return 0; | |
3422 | ||
3423 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3424 | nla, sta_flags_policy)) | |
3425 | return -EINVAL; | |
3426 | ||
bdd3ae3d JB |
3427 | /* |
3428 | * Only allow certain flags for interface types so that | |
3429 | * other attributes are silently ignored. Remember that | |
3430 | * this is backward compatibility code with old userspace | |
3431 | * and shouldn't be hit in other cases anyway. | |
3432 | */ | |
3433 | switch (iftype) { | |
3434 | case NL80211_IFTYPE_AP: | |
3435 | case NL80211_IFTYPE_AP_VLAN: | |
3436 | case NL80211_IFTYPE_P2P_GO: | |
3437 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3438 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3439 | BIT(NL80211_STA_FLAG_WME) | | |
3440 | BIT(NL80211_STA_FLAG_MFP); | |
3441 | break; | |
3442 | case NL80211_IFTYPE_P2P_CLIENT: | |
3443 | case NL80211_IFTYPE_STATION: | |
3444 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3445 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3446 | break; | |
3447 | case NL80211_IFTYPE_MESH_POINT: | |
3448 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3449 | BIT(NL80211_STA_FLAG_MFP) | | |
3450 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3451 | default: | |
3452 | return -EINVAL; | |
3453 | } | |
5727ef1b | 3454 | |
3383b5a6 JB |
3455 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3456 | if (flags[flag]) { | |
eccb8e8f | 3457 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3458 | |
3383b5a6 JB |
3459 | /* no longer support new API additions in old API */ |
3460 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3461 | return -EINVAL; | |
3462 | } | |
3463 | } | |
3464 | ||
5727ef1b JB |
3465 | return 0; |
3466 | } | |
3467 | ||
c8dcfd8a FF |
3468 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3469 | int attr) | |
3470 | { | |
3471 | struct nlattr *rate; | |
8eb41c8d VK |
3472 | u32 bitrate; |
3473 | u16 bitrate_compat; | |
c8dcfd8a FF |
3474 | |
3475 | rate = nla_nest_start(msg, attr); | |
3476 | if (!rate) | |
db9c64cf | 3477 | return false; |
c8dcfd8a FF |
3478 | |
3479 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3480 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3481 | /* report 16-bit bitrate only if we can */ |
3482 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3483 | if (bitrate > 0 && |
3484 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3485 | return false; | |
3486 | if (bitrate_compat > 0 && | |
3487 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3488 | return false; | |
3489 | ||
3490 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3491 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3492 | return false; | |
3493 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3494 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3495 | return false; | |
3496 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3497 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3498 | return false; | |
3499 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3500 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3501 | return false; | |
3502 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3503 | return false; | |
3504 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3505 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3506 | return false; | |
3507 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3508 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3509 | return false; | |
3510 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3511 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3512 | return false; | |
3513 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3514 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3515 | return false; | |
3516 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3517 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3518 | return false; | |
3519 | } | |
c8dcfd8a FF |
3520 | |
3521 | nla_nest_end(msg, rate); | |
3522 | return true; | |
c8dcfd8a FF |
3523 | } |
3524 | ||
119363c7 FF |
3525 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3526 | int id) | |
3527 | { | |
3528 | void *attr; | |
3529 | int i = 0; | |
3530 | ||
3531 | if (!mask) | |
3532 | return true; | |
3533 | ||
3534 | attr = nla_nest_start(msg, id); | |
3535 | if (!attr) | |
3536 | return false; | |
3537 | ||
3538 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3539 | if (!(mask & BIT(i))) | |
3540 | continue; | |
3541 | ||
3542 | if (nla_put_u8(msg, i, signal[i])) | |
3543 | return false; | |
3544 | } | |
3545 | ||
3546 | nla_nest_end(msg, attr); | |
3547 | ||
3548 | return true; | |
3549 | } | |
3550 | ||
15e47304 | 3551 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3552 | int flags, |
3553 | struct cfg80211_registered_device *rdev, | |
3554 | struct net_device *dev, | |
98b62183 | 3555 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3556 | { |
3557 | void *hdr; | |
f4263c98 | 3558 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3559 | |
15e47304 | 3560 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3561 | if (!hdr) |
3562 | return -1; | |
3563 | ||
9360ffd1 DM |
3564 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3565 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3566 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3567 | goto nla_put_failure; | |
f5ea9120 | 3568 | |
2ec600d6 LCC |
3569 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3570 | if (!sinfoattr) | |
fd5b74dc | 3571 | goto nla_put_failure; |
9360ffd1 DM |
3572 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3573 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3574 | sinfo->connected_time)) | |
3575 | goto nla_put_failure; | |
3576 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3577 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3578 | sinfo->inactive_time)) | |
3579 | goto nla_put_failure; | |
42745e03 VK |
3580 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3581 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3582 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3583 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3584 | goto nla_put_failure; |
42745e03 | 3585 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3586 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3587 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3588 | (u32)sinfo->tx_bytes)) |
3589 | goto nla_put_failure; | |
3590 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3591 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3592 | sinfo->rx_bytes)) | |
3593 | goto nla_put_failure; | |
3594 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3595 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3596 | sinfo->tx_bytes)) |
3597 | goto nla_put_failure; | |
3598 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3599 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3600 | goto nla_put_failure; | |
3601 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3602 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3603 | goto nla_put_failure; | |
3604 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3605 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3606 | sinfo->plink_state)) | |
3607 | goto nla_put_failure; | |
66266b3a JL |
3608 | switch (rdev->wiphy.signal_type) { |
3609 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3610 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3611 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3612 | sinfo->signal)) | |
3613 | goto nla_put_failure; | |
3614 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3615 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3616 | sinfo->signal_avg)) | |
3617 | goto nla_put_failure; | |
66266b3a JL |
3618 | break; |
3619 | default: | |
3620 | break; | |
3621 | } | |
119363c7 FF |
3622 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3623 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3624 | sinfo->chain_signal, | |
3625 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3626 | goto nla_put_failure; | |
3627 | } | |
3628 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3629 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3630 | sinfo->chain_signal_avg, | |
3631 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3632 | goto nla_put_failure; | |
3633 | } | |
420e7fab | 3634 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3635 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3636 | NL80211_STA_INFO_TX_BITRATE)) | |
3637 | goto nla_put_failure; | |
3638 | } | |
3639 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3640 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3641 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3642 | goto nla_put_failure; |
420e7fab | 3643 | } |
9360ffd1 DM |
3644 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3645 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3646 | sinfo->rx_packets)) | |
3647 | goto nla_put_failure; | |
3648 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3649 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3650 | sinfo->tx_packets)) | |
3651 | goto nla_put_failure; | |
3652 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3653 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3654 | sinfo->tx_retries)) | |
3655 | goto nla_put_failure; | |
3656 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3657 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3658 | sinfo->tx_failed)) | |
3659 | goto nla_put_failure; | |
867d849f AQ |
3660 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
3661 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, | |
3662 | sinfo->expected_throughput)) | |
3663 | goto nla_put_failure; | |
9360ffd1 DM |
3664 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
3665 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3666 | sinfo->beacon_loss_count)) | |
3667 | goto nla_put_failure; | |
3b1c5a53 MP |
3668 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3669 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3670 | sinfo->local_pm)) | |
3671 | goto nla_put_failure; | |
3672 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3673 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3674 | sinfo->peer_pm)) | |
3675 | goto nla_put_failure; | |
3676 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3677 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3678 | sinfo->nonpeer_pm)) | |
3679 | goto nla_put_failure; | |
f4263c98 PS |
3680 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3681 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3682 | if (!bss_param) | |
3683 | goto nla_put_failure; | |
3684 | ||
9360ffd1 DM |
3685 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3686 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3687 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3688 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3689 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3690 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3691 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3692 | sinfo->bss_param.dtim_period) || | |
3693 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3694 | sinfo->bss_param.beacon_interval)) | |
3695 | goto nla_put_failure; | |
f4263c98 PS |
3696 | |
3697 | nla_nest_end(msg, bss_param); | |
3698 | } | |
9360ffd1 DM |
3699 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3700 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3701 | sizeof(struct nl80211_sta_flag_update), | |
3702 | &sinfo->sta_flags)) | |
3703 | goto nla_put_failure; | |
7eab0f64 JL |
3704 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3705 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3706 | sinfo->t_offset)) | |
3707 | goto nla_put_failure; | |
2ec600d6 | 3708 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3709 | |
9360ffd1 DM |
3710 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3711 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3712 | sinfo->assoc_req_ies)) | |
3713 | goto nla_put_failure; | |
50d3dfb7 | 3714 | |
fd5b74dc JB |
3715 | return genlmsg_end(msg, hdr); |
3716 | ||
3717 | nla_put_failure: | |
bc3ed28c TG |
3718 | genlmsg_cancel(msg, hdr); |
3719 | return -EMSGSIZE; | |
fd5b74dc JB |
3720 | } |
3721 | ||
2ec600d6 | 3722 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3723 | struct netlink_callback *cb) |
2ec600d6 | 3724 | { |
2ec600d6 | 3725 | struct station_info sinfo; |
1b8ec87a | 3726 | struct cfg80211_registered_device *rdev; |
97990a06 | 3727 | struct wireless_dev *wdev; |
2ec600d6 | 3728 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3729 | int sta_idx = cb->args[2]; |
2ec600d6 | 3730 | int err; |
2ec600d6 | 3731 | |
1b8ec87a | 3732 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3733 | if (err) |
3734 | return err; | |
bba95fef | 3735 | |
97990a06 JB |
3736 | if (!wdev->netdev) { |
3737 | err = -EINVAL; | |
3738 | goto out_err; | |
3739 | } | |
3740 | ||
1b8ec87a | 3741 | if (!rdev->ops->dump_station) { |
eec60b03 | 3742 | err = -EOPNOTSUPP; |
bba95fef JB |
3743 | goto out_err; |
3744 | } | |
3745 | ||
bba95fef | 3746 | while (1) { |
f612cedf | 3747 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3748 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3749 | mac_addr, &sinfo); |
bba95fef JB |
3750 | if (err == -ENOENT) |
3751 | break; | |
3752 | if (err) | |
3b85875a | 3753 | goto out_err; |
bba95fef JB |
3754 | |
3755 | if (nl80211_send_station(skb, | |
15e47304 | 3756 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3757 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3758 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3759 | &sinfo) < 0) |
3760 | goto out; | |
3761 | ||
3762 | sta_idx++; | |
3763 | } | |
3764 | ||
3765 | ||
3766 | out: | |
97990a06 | 3767 | cb->args[2] = sta_idx; |
bba95fef | 3768 | err = skb->len; |
bba95fef | 3769 | out_err: |
1b8ec87a | 3770 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3771 | |
3772 | return err; | |
2ec600d6 | 3773 | } |
fd5b74dc | 3774 | |
5727ef1b JB |
3775 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3776 | { | |
4c476991 JB |
3777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3778 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3779 | struct station_info sinfo; |
fd5b74dc JB |
3780 | struct sk_buff *msg; |
3781 | u8 *mac_addr = NULL; | |
4c476991 | 3782 | int err; |
fd5b74dc | 3783 | |
2ec600d6 | 3784 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3785 | |
3786 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3787 | return -EINVAL; | |
3788 | ||
3789 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3790 | ||
4c476991 JB |
3791 | if (!rdev->ops->get_station) |
3792 | return -EOPNOTSUPP; | |
3b85875a | 3793 | |
e35e4d28 | 3794 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3795 | if (err) |
4c476991 | 3796 | return err; |
2ec600d6 | 3797 | |
fd2120ca | 3798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3799 | if (!msg) |
4c476991 | 3800 | return -ENOMEM; |
fd5b74dc | 3801 | |
15e47304 | 3802 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3803 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3804 | nlmsg_free(msg); |
3805 | return -ENOBUFS; | |
3806 | } | |
3b85875a | 3807 | |
4c476991 | 3808 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3809 | } |
3810 | ||
77ee7c89 JB |
3811 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3812 | struct station_parameters *params, | |
3813 | enum cfg80211_station_type statype) | |
3814 | { | |
3815 | if (params->listen_interval != -1) | |
3816 | return -EINVAL; | |
c72e1140 AN |
3817 | if (params->aid && |
3818 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3819 | return -EINVAL; |
3820 | ||
3821 | /* When you run into this, adjust the code below for the new flag */ | |
3822 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3823 | ||
3824 | switch (statype) { | |
eef941e6 TP |
3825 | case CFG80211_STA_MESH_PEER_KERNEL: |
3826 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3827 | /* |
3828 | * No ignoring the TDLS flag here -- the userspace mesh | |
3829 | * code doesn't have the bug of including TDLS in the | |
3830 | * mask everywhere. | |
3831 | */ | |
3832 | if (params->sta_flags_mask & | |
3833 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3834 | BIT(NL80211_STA_FLAG_MFP) | | |
3835 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3836 | return -EINVAL; | |
3837 | break; | |
3838 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3839 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3840 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3841 | return -EINVAL; | |
3842 | /* ignore since it can't change */ | |
3843 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3844 | break; | |
3845 | default: | |
3846 | /* disallow mesh-specific things */ | |
3847 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3848 | return -EINVAL; | |
3849 | if (params->local_pm) | |
3850 | return -EINVAL; | |
3851 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3852 | return -EINVAL; | |
3853 | } | |
3854 | ||
3855 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3856 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3857 | /* TDLS can't be set, ... */ | |
3858 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3859 | return -EINVAL; | |
3860 | /* | |
3861 | * ... but don't bother the driver with it. This works around | |
3862 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3863 | * TLDS_PEER flag in the mask even for AP mode. | |
3864 | */ | |
3865 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3866 | } | |
3867 | ||
3868 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3869 | /* reject other things that can't change */ | |
3870 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3871 | return -EINVAL; | |
3872 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3873 | return -EINVAL; | |
3874 | if (params->supported_rates) | |
3875 | return -EINVAL; | |
3876 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3877 | return -EINVAL; | |
3878 | } | |
3879 | ||
3880 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3881 | if (params->vlan) | |
3882 | return -EINVAL; | |
3883 | } | |
3884 | ||
3885 | switch (statype) { | |
3886 | case CFG80211_STA_AP_MLME_CLIENT: | |
3887 | /* Use this only for authorizing/unauthorizing a station */ | |
3888 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3889 | return -EOPNOTSUPP; | |
3890 | break; | |
3891 | case CFG80211_STA_AP_CLIENT: | |
3892 | /* accept only the listed bits */ | |
3893 | if (params->sta_flags_mask & | |
3894 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3895 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3896 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3897 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3898 | BIT(NL80211_STA_FLAG_WME) | | |
3899 | BIT(NL80211_STA_FLAG_MFP))) | |
3900 | return -EINVAL; | |
3901 | ||
3902 | /* but authenticated/associated only if driver handles it */ | |
3903 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3904 | params->sta_flags_mask & | |
3905 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3906 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3907 | return -EINVAL; | |
3908 | break; | |
3909 | case CFG80211_STA_IBSS: | |
3910 | case CFG80211_STA_AP_STA: | |
3911 | /* reject any changes other than AUTHORIZED */ | |
3912 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3913 | return -EINVAL; | |
3914 | break; | |
3915 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3916 | /* reject any changes other than AUTHORIZED or WME */ | |
3917 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3918 | BIT(NL80211_STA_FLAG_WME))) | |
3919 | return -EINVAL; | |
3920 | /* force (at least) rates when authorizing */ | |
3921 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3922 | !params->supported_rates) | |
3923 | return -EINVAL; | |
3924 | break; | |
3925 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3926 | /* reject any changes */ | |
3927 | return -EINVAL; | |
eef941e6 | 3928 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3929 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3930 | return -EINVAL; | |
3931 | break; | |
eef941e6 | 3932 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3933 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3934 | return -EINVAL; | |
3935 | break; | |
3936 | } | |
3937 | ||
3938 | return 0; | |
3939 | } | |
3940 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3941 | ||
5727ef1b | 3942 | /* |
c258d2de | 3943 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3944 | */ |
80b99899 JB |
3945 | static struct net_device *get_vlan(struct genl_info *info, |
3946 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3947 | { |
463d0183 | 3948 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3949 | struct net_device *v; |
3950 | int ret; | |
3951 | ||
3952 | if (!vlanattr) | |
3953 | return NULL; | |
3954 | ||
3955 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3956 | if (!v) | |
3957 | return ERR_PTR(-ENODEV); | |
3958 | ||
3959 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3960 | ret = -EINVAL; | |
3961 | goto error; | |
5727ef1b | 3962 | } |
80b99899 | 3963 | |
77ee7c89 JB |
3964 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3965 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3966 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3967 | ret = -EINVAL; | |
3968 | goto error; | |
3969 | } | |
3970 | ||
80b99899 JB |
3971 | if (!netif_running(v)) { |
3972 | ret = -ENETDOWN; | |
3973 | goto error; | |
3974 | } | |
3975 | ||
3976 | return v; | |
3977 | error: | |
3978 | dev_put(v); | |
3979 | return ERR_PTR(ret); | |
5727ef1b JB |
3980 | } |
3981 | ||
94e860f1 JB |
3982 | static const struct nla_policy |
3983 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
3984 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
3985 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3986 | }; | |
3987 | ||
ff276691 JB |
3988 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3989 | struct station_parameters *params) | |
df881293 | 3990 | { |
df881293 JM |
3991 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3992 | struct nlattr *nla; | |
3993 | int err; | |
3994 | ||
df881293 JM |
3995 | /* parse WME attributes if present */ |
3996 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3997 | return 0; | |
3998 | ||
3999 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4000 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4001 | nl80211_sta_wme_policy); | |
4002 | if (err) | |
4003 | return err; | |
4004 | ||
4005 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4006 | params->uapsd_queues = nla_get_u8( | |
4007 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4008 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4009 | return -EINVAL; | |
4010 | ||
4011 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4012 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4013 | ||
4014 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4015 | return -EINVAL; | |
4016 | ||
4017 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4018 | ||
4019 | return 0; | |
4020 | } | |
4021 | ||
c01fc9ad SD |
4022 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4023 | struct station_parameters *params) | |
4024 | { | |
4025 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4026 | params->supported_channels = | |
4027 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4028 | params->supported_channels_len = | |
4029 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4030 | /* | |
4031 | * Need to include at least one (first channel, number of | |
4032 | * channels) tuple for each subband, and must have proper | |
4033 | * tuples for the rest of the data as well. | |
4034 | */ | |
4035 | if (params->supported_channels_len < 2) | |
4036 | return -EINVAL; | |
4037 | if (params->supported_channels_len % 2) | |
4038 | return -EINVAL; | |
4039 | } | |
4040 | ||
4041 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4042 | params->supported_oper_classes = | |
4043 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4044 | params->supported_oper_classes_len = | |
4045 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4046 | /* | |
4047 | * The value of the Length field of the Supported Operating | |
4048 | * Classes element is between 2 and 253. | |
4049 | */ | |
4050 | if (params->supported_oper_classes_len < 2 || | |
4051 | params->supported_oper_classes_len > 253) | |
4052 | return -EINVAL; | |
4053 | } | |
4054 | return 0; | |
4055 | } | |
4056 | ||
ff276691 JB |
4057 | static int nl80211_set_station_tdls(struct genl_info *info, |
4058 | struct station_parameters *params) | |
4059 | { | |
c01fc9ad | 4060 | int err; |
ff276691 | 4061 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4062 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4063 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4064 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4065 | params->ht_capa = | |
4066 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4067 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4068 | params->vht_capa = | |
4069 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4070 | ||
c01fc9ad SD |
4071 | err = nl80211_parse_sta_channel_info(info, params); |
4072 | if (err) | |
4073 | return err; | |
4074 | ||
ff276691 JB |
4075 | return nl80211_parse_sta_wme(info, params); |
4076 | } | |
4077 | ||
5727ef1b JB |
4078 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4079 | { | |
4c476991 | 4080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4081 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4082 | struct station_parameters params; |
77ee7c89 JB |
4083 | u8 *mac_addr; |
4084 | int err; | |
5727ef1b JB |
4085 | |
4086 | memset(¶ms, 0, sizeof(params)); | |
4087 | ||
4088 | params.listen_interval = -1; | |
4089 | ||
77ee7c89 JB |
4090 | if (!rdev->ops->change_station) |
4091 | return -EOPNOTSUPP; | |
4092 | ||
5727ef1b JB |
4093 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4094 | return -EINVAL; | |
4095 | ||
4096 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4097 | return -EINVAL; | |
4098 | ||
4099 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4100 | ||
4101 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4102 | params.supported_rates = | |
4103 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4104 | params.supported_rates_len = | |
4105 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4106 | } | |
4107 | ||
9d62a986 JM |
4108 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4109 | params.capability = | |
4110 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4111 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4112 | } | |
4113 | ||
4114 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4115 | params.ext_capab = | |
4116 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4117 | params.ext_capab_len = | |
4118 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4119 | } | |
4120 | ||
df881293 | 4121 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4122 | return -EINVAL; |
36aedc90 | 4123 | |
bdd3ae3d | 4124 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4125 | return -EINVAL; |
4126 | ||
f8bacc21 | 4127 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4128 | params.plink_action = |
f8bacc21 JB |
4129 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4130 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4131 | return -EINVAL; | |
4132 | } | |
2ec600d6 | 4133 | |
f8bacc21 | 4134 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4135 | params.plink_state = |
f8bacc21 JB |
4136 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4137 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4138 | return -EINVAL; | |
4139 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4140 | } | |
9c3990aa | 4141 | |
3b1c5a53 MP |
4142 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4143 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4144 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4145 | ||
4146 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4147 | pm > NL80211_MESH_POWER_MAX) | |
4148 | return -EINVAL; | |
4149 | ||
4150 | params.local_pm = pm; | |
4151 | } | |
4152 | ||
77ee7c89 JB |
4153 | /* Include parameters for TDLS peer (will check later) */ |
4154 | err = nl80211_set_station_tdls(info, ¶ms); | |
4155 | if (err) | |
4156 | return err; | |
4157 | ||
4158 | params.vlan = get_vlan(info, rdev); | |
4159 | if (IS_ERR(params.vlan)) | |
4160 | return PTR_ERR(params.vlan); | |
4161 | ||
a97f4424 JB |
4162 | switch (dev->ieee80211_ptr->iftype) { |
4163 | case NL80211_IFTYPE_AP: | |
4164 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4165 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4166 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4167 | case NL80211_IFTYPE_STATION: |
267335d6 | 4168 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4169 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4170 | break; |
4171 | default: | |
77ee7c89 JB |
4172 | err = -EOPNOTSUPP; |
4173 | goto out_put_vlan; | |
034d655e JB |
4174 | } |
4175 | ||
77ee7c89 | 4176 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4177 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4178 | |
77ee7c89 | 4179 | out_put_vlan: |
5727ef1b JB |
4180 | if (params.vlan) |
4181 | dev_put(params.vlan); | |
3b85875a | 4182 | |
5727ef1b JB |
4183 | return err; |
4184 | } | |
4185 | ||
4186 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4187 | { | |
4c476991 | 4188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4189 | int err; |
4c476991 | 4190 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4191 | struct station_parameters params; |
4192 | u8 *mac_addr = NULL; | |
4193 | ||
4194 | memset(¶ms, 0, sizeof(params)); | |
4195 | ||
984c311b JB |
4196 | if (!rdev->ops->add_station) |
4197 | return -EOPNOTSUPP; | |
4198 | ||
5727ef1b JB |
4199 | if (!info->attrs[NL80211_ATTR_MAC]) |
4200 | return -EINVAL; | |
4201 | ||
5727ef1b JB |
4202 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4203 | return -EINVAL; | |
4204 | ||
4205 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4206 | return -EINVAL; | |
4207 | ||
5e4b6f56 JM |
4208 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4209 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4210 | return -EINVAL; |
4211 | ||
5727ef1b JB |
4212 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4213 | params.supported_rates = | |
4214 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4215 | params.supported_rates_len = | |
4216 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4217 | params.listen_interval = | |
4218 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4219 | |
3d124ea2 | 4220 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4221 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4222 | else |
4223 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4224 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4225 | return -EINVAL; | |
51b50fbe | 4226 | |
9d62a986 JM |
4227 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4228 | params.capability = | |
4229 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4230 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4231 | } | |
4232 | ||
4233 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4234 | params.ext_capab = | |
4235 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4236 | params.ext_capab_len = | |
4237 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4238 | } | |
4239 | ||
36aedc90 JM |
4240 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4241 | params.ht_capa = | |
4242 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4243 | |
f461be3e MP |
4244 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4245 | params.vht_capa = | |
4246 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4247 | ||
60f4a7b1 MK |
4248 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4249 | params.opmode_notif_used = true; | |
4250 | params.opmode_notif = | |
4251 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4252 | } | |
4253 | ||
f8bacc21 | 4254 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4255 | params.plink_action = |
f8bacc21 JB |
4256 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4257 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4258 | return -EINVAL; | |
4259 | } | |
96b78dff | 4260 | |
c01fc9ad SD |
4261 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4262 | if (err) | |
4263 | return err; | |
4264 | ||
ff276691 JB |
4265 | err = nl80211_parse_sta_wme(info, ¶ms); |
4266 | if (err) | |
4267 | return err; | |
bdd90d5e | 4268 | |
bdd3ae3d | 4269 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4270 | return -EINVAL; |
4271 | ||
77ee7c89 JB |
4272 | /* When you run into this, adjust the code below for the new flag */ |
4273 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4274 | ||
bdd90d5e JB |
4275 | switch (dev->ieee80211_ptr->iftype) { |
4276 | case NL80211_IFTYPE_AP: | |
4277 | case NL80211_IFTYPE_AP_VLAN: | |
4278 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4279 | /* ignore WME attributes if iface/sta is not capable */ |
4280 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4281 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4282 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4283 | |
bdd90d5e | 4284 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4285 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4286 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4287 | return -EINVAL; |
bdd90d5e JB |
4288 | /* but don't bother the driver with it */ |
4289 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4290 | |
d582cffb JB |
4291 | /* allow authenticated/associated only if driver handles it */ |
4292 | if (!(rdev->wiphy.features & | |
4293 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4294 | params.sta_flags_mask & | |
4295 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4296 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4297 | return -EINVAL; | |
4298 | ||
bdd90d5e JB |
4299 | /* must be last in here for error handling */ |
4300 | params.vlan = get_vlan(info, rdev); | |
4301 | if (IS_ERR(params.vlan)) | |
4302 | return PTR_ERR(params.vlan); | |
4303 | break; | |
4304 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4305 | /* ignore uAPSD data */ |
4306 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4307 | ||
d582cffb JB |
4308 | /* associated is disallowed */ |
4309 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4310 | return -EINVAL; | |
bdd90d5e | 4311 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4312 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4313 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4314 | return -EINVAL; |
4315 | break; | |
4316 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4317 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4318 | /* ignore uAPSD data */ |
4319 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4320 | ||
77ee7c89 JB |
4321 | /* these are disallowed */ |
4322 | if (params.sta_flags_mask & | |
4323 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4324 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4325 | return -EINVAL; |
bdd90d5e JB |
4326 | /* Only TDLS peers can be added */ |
4327 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4328 | return -EINVAL; | |
4329 | /* Can only add if TDLS ... */ | |
4330 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4331 | return -EOPNOTSUPP; | |
4332 | /* ... with external setup is supported */ | |
4333 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4334 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4335 | /* |
4336 | * Older wpa_supplicant versions always mark the TDLS peer | |
4337 | * as authorized, but it shouldn't yet be. | |
4338 | */ | |
4339 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4340 | break; |
4341 | default: | |
4342 | return -EOPNOTSUPP; | |
c75786c9 EP |
4343 | } |
4344 | ||
bdd90d5e | 4345 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4346 | |
e35e4d28 | 4347 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4348 | |
5727ef1b JB |
4349 | if (params.vlan) |
4350 | dev_put(params.vlan); | |
5727ef1b JB |
4351 | return err; |
4352 | } | |
4353 | ||
4354 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4355 | { | |
4c476991 JB |
4356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4357 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4358 | u8 *mac_addr = NULL; |
4359 | ||
4360 | if (info->attrs[NL80211_ATTR_MAC]) | |
4361 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4362 | ||
e80cf853 | 4363 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4364 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4366 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4367 | return -EINVAL; | |
5727ef1b | 4368 | |
4c476991 JB |
4369 | if (!rdev->ops->del_station) |
4370 | return -EOPNOTSUPP; | |
3b85875a | 4371 | |
e35e4d28 | 4372 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4373 | } |
4374 | ||
15e47304 | 4375 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4376 | int flags, struct net_device *dev, |
4377 | u8 *dst, u8 *next_hop, | |
4378 | struct mpath_info *pinfo) | |
4379 | { | |
4380 | void *hdr; | |
4381 | struct nlattr *pinfoattr; | |
4382 | ||
15e47304 | 4383 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4384 | if (!hdr) |
4385 | return -1; | |
4386 | ||
9360ffd1 DM |
4387 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4388 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4389 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4391 | goto nla_put_failure; | |
f5ea9120 | 4392 | |
2ec600d6 LCC |
4393 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4394 | if (!pinfoattr) | |
4395 | goto nla_put_failure; | |
9360ffd1 DM |
4396 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4397 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4398 | pinfo->frame_qlen)) | |
4399 | goto nla_put_failure; | |
4400 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4401 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4402 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4403 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4404 | pinfo->metric)) || | |
4405 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4406 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4407 | pinfo->exptime)) || | |
4408 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4409 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4410 | pinfo->flags)) || | |
4411 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4412 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4413 | pinfo->discovery_timeout)) || | |
4414 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4415 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4416 | pinfo->discovery_retries))) | |
4417 | goto nla_put_failure; | |
2ec600d6 LCC |
4418 | |
4419 | nla_nest_end(msg, pinfoattr); | |
4420 | ||
4421 | return genlmsg_end(msg, hdr); | |
4422 | ||
4423 | nla_put_failure: | |
bc3ed28c TG |
4424 | genlmsg_cancel(msg, hdr); |
4425 | return -EMSGSIZE; | |
2ec600d6 LCC |
4426 | } |
4427 | ||
4428 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4429 | struct netlink_callback *cb) |
2ec600d6 | 4430 | { |
2ec600d6 | 4431 | struct mpath_info pinfo; |
1b8ec87a | 4432 | struct cfg80211_registered_device *rdev; |
97990a06 | 4433 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4434 | u8 dst[ETH_ALEN]; |
4435 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4436 | int path_idx = cb->args[2]; |
2ec600d6 | 4437 | int err; |
2ec600d6 | 4438 | |
1b8ec87a | 4439 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4440 | if (err) |
4441 | return err; | |
bba95fef | 4442 | |
1b8ec87a | 4443 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4444 | err = -EOPNOTSUPP; |
bba95fef JB |
4445 | goto out_err; |
4446 | } | |
4447 | ||
97990a06 | 4448 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4449 | err = -EOPNOTSUPP; |
0448b5fc | 4450 | goto out_err; |
eec60b03 JM |
4451 | } |
4452 | ||
bba95fef | 4453 | while (1) { |
1b8ec87a | 4454 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4455 | next_hop, &pinfo); |
bba95fef | 4456 | if (err == -ENOENT) |
2ec600d6 | 4457 | break; |
bba95fef | 4458 | if (err) |
3b85875a | 4459 | goto out_err; |
2ec600d6 | 4460 | |
15e47304 | 4461 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4462 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4463 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4464 | &pinfo) < 0) |
4465 | goto out; | |
2ec600d6 | 4466 | |
bba95fef | 4467 | path_idx++; |
2ec600d6 | 4468 | } |
2ec600d6 | 4469 | |
2ec600d6 | 4470 | |
bba95fef | 4471 | out: |
97990a06 | 4472 | cb->args[2] = path_idx; |
bba95fef | 4473 | err = skb->len; |
bba95fef | 4474 | out_err: |
1b8ec87a | 4475 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4476 | return err; |
2ec600d6 LCC |
4477 | } |
4478 | ||
4479 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4480 | { | |
4c476991 | 4481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4482 | int err; |
4c476991 | 4483 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4484 | struct mpath_info pinfo; |
4485 | struct sk_buff *msg; | |
4486 | u8 *dst = NULL; | |
4487 | u8 next_hop[ETH_ALEN]; | |
4488 | ||
4489 | memset(&pinfo, 0, sizeof(pinfo)); | |
4490 | ||
4491 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4492 | return -EINVAL; | |
4493 | ||
4494 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4495 | ||
4c476991 JB |
4496 | if (!rdev->ops->get_mpath) |
4497 | return -EOPNOTSUPP; | |
2ec600d6 | 4498 | |
4c476991 JB |
4499 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4500 | return -EOPNOTSUPP; | |
eec60b03 | 4501 | |
e35e4d28 | 4502 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4503 | if (err) |
4c476991 | 4504 | return err; |
2ec600d6 | 4505 | |
fd2120ca | 4506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4507 | if (!msg) |
4c476991 | 4508 | return -ENOMEM; |
2ec600d6 | 4509 | |
15e47304 | 4510 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4511 | dev, dst, next_hop, &pinfo) < 0) { |
4512 | nlmsg_free(msg); | |
4513 | return -ENOBUFS; | |
4514 | } | |
3b85875a | 4515 | |
4c476991 | 4516 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4517 | } |
4518 | ||
4519 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4520 | { | |
4c476991 JB |
4521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4522 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4523 | u8 *dst = NULL; |
4524 | u8 *next_hop = NULL; | |
4525 | ||
4526 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4527 | return -EINVAL; | |
4528 | ||
4529 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4530 | return -EINVAL; | |
4531 | ||
4532 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4533 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4534 | ||
4c476991 JB |
4535 | if (!rdev->ops->change_mpath) |
4536 | return -EOPNOTSUPP; | |
35a8efe1 | 4537 | |
4c476991 JB |
4538 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4539 | return -EOPNOTSUPP; | |
2ec600d6 | 4540 | |
e35e4d28 | 4541 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4542 | } |
4c476991 | 4543 | |
2ec600d6 LCC |
4544 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4545 | { | |
4c476991 JB |
4546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4547 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4548 | u8 *dst = NULL; |
4549 | u8 *next_hop = NULL; | |
4550 | ||
4551 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4552 | return -EINVAL; | |
4553 | ||
4554 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4555 | return -EINVAL; | |
4556 | ||
4557 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4558 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4559 | ||
4c476991 JB |
4560 | if (!rdev->ops->add_mpath) |
4561 | return -EOPNOTSUPP; | |
35a8efe1 | 4562 | |
4c476991 JB |
4563 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4564 | return -EOPNOTSUPP; | |
2ec600d6 | 4565 | |
e35e4d28 | 4566 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4567 | } |
4568 | ||
4569 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4570 | { | |
4c476991 JB |
4571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4572 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4573 | u8 *dst = NULL; |
4574 | ||
4575 | if (info->attrs[NL80211_ATTR_MAC]) | |
4576 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4577 | ||
4c476991 JB |
4578 | if (!rdev->ops->del_mpath) |
4579 | return -EOPNOTSUPP; | |
3b85875a | 4580 | |
e35e4d28 | 4581 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4582 | } |
4583 | ||
9f1ba906 JM |
4584 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4585 | { | |
4c476991 JB |
4586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4587 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4588 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4589 | struct bss_parameters params; |
c56589ed | 4590 | int err; |
9f1ba906 JM |
4591 | |
4592 | memset(¶ms, 0, sizeof(params)); | |
4593 | /* default to not changing parameters */ | |
4594 | params.use_cts_prot = -1; | |
4595 | params.use_short_preamble = -1; | |
4596 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4597 | params.ap_isolate = -1; |
50b12f59 | 4598 | params.ht_opmode = -1; |
53cabad7 JB |
4599 | params.p2p_ctwindow = -1; |
4600 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4601 | |
4602 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4603 | params.use_cts_prot = | |
4604 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4605 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4606 | params.use_short_preamble = | |
4607 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4608 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4609 | params.use_short_slot_time = | |
4610 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4611 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4612 | params.basic_rates = | |
4613 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4614 | params.basic_rates_len = | |
4615 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4616 | } | |
fd8aaaf3 FF |
4617 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4618 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4619 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4620 | params.ht_opmode = | |
4621 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4622 | |
53cabad7 JB |
4623 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4625 | return -EINVAL; | |
4626 | params.p2p_ctwindow = | |
4627 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4628 | if (params.p2p_ctwindow < 0) | |
4629 | return -EINVAL; | |
4630 | if (params.p2p_ctwindow != 0 && | |
4631 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4632 | return -EINVAL; | |
4633 | } | |
4634 | ||
4635 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4636 | u8 tmp; | |
4637 | ||
4638 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4639 | return -EINVAL; | |
4640 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4641 | if (tmp > 1) | |
4642 | return -EINVAL; | |
4643 | params.p2p_opp_ps = tmp; | |
4644 | if (params.p2p_opp_ps && | |
4645 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4646 | return -EINVAL; | |
4647 | } | |
4648 | ||
4c476991 JB |
4649 | if (!rdev->ops->change_bss) |
4650 | return -EOPNOTSUPP; | |
9f1ba906 | 4651 | |
074ac8df | 4652 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4653 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4654 | return -EOPNOTSUPP; | |
3b85875a | 4655 | |
c56589ed SW |
4656 | wdev_lock(wdev); |
4657 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4658 | wdev_unlock(wdev); | |
4659 | ||
4660 | return err; | |
9f1ba906 JM |
4661 | } |
4662 | ||
b54452b0 | 4663 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4664 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4665 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4666 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4667 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4668 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4669 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4670 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4671 | }; |
4672 | ||
4673 | static int parse_reg_rule(struct nlattr *tb[], | |
4674 | struct ieee80211_reg_rule *reg_rule) | |
4675 | { | |
4676 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4677 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4678 | ||
4679 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4680 | return -EINVAL; | |
4681 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4682 | return -EINVAL; | |
4683 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4684 | return -EINVAL; | |
b0dfd2ea JD |
4685 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4686 | return -EINVAL; | |
b2e1b302 LR |
4687 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4688 | return -EINVAL; | |
4689 | ||
4690 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4691 | ||
4692 | freq_range->start_freq_khz = | |
4693 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4694 | freq_range->end_freq_khz = | |
4695 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4696 | freq_range->max_bandwidth_khz = |
4697 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4698 | |
4699 | power_rule->max_eirp = | |
4700 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4701 | ||
4702 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4703 | power_rule->max_antenna_gain = | |
4704 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4705 | ||
089027e5 JD |
4706 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4707 | reg_rule->dfs_cac_ms = | |
4708 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4709 | ||
b2e1b302 LR |
4710 | return 0; |
4711 | } | |
4712 | ||
4713 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4714 | { | |
b2e1b302 | 4715 | char *data = NULL; |
57b5ce07 | 4716 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4717 | |
80778f18 LR |
4718 | /* |
4719 | * You should only get this when cfg80211 hasn't yet initialized | |
4720 | * completely when built-in to the kernel right between the time | |
4721 | * window between nl80211_init() and regulatory_init(), if that is | |
4722 | * even possible. | |
4723 | */ | |
458f4f9e | 4724 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4725 | return -EINPROGRESS; |
80778f18 | 4726 | |
57b5ce07 LR |
4727 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4728 | user_reg_hint_type = | |
4729 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4730 | else | |
4731 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4732 | ||
4733 | switch (user_reg_hint_type) { | |
4734 | case NL80211_USER_REG_HINT_USER: | |
4735 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4736 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4737 | return -EINVAL; | |
4738 | ||
4739 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4740 | return regulatory_hint_user(data, user_reg_hint_type); | |
4741 | case NL80211_USER_REG_HINT_INDOOR: | |
4742 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4743 | default: |
4744 | return -EINVAL; | |
4745 | } | |
b2e1b302 LR |
4746 | } |
4747 | ||
24bdd9f4 | 4748 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4749 | struct genl_info *info) |
93da9cc1 | 4750 | { |
4c476991 | 4751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4752 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4753 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4754 | struct mesh_config cur_params; | |
4755 | int err = 0; | |
93da9cc1 | 4756 | void *hdr; |
4757 | struct nlattr *pinfoattr; | |
4758 | struct sk_buff *msg; | |
4759 | ||
29cbe68c JB |
4760 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4761 | return -EOPNOTSUPP; | |
4762 | ||
24bdd9f4 | 4763 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4764 | return -EOPNOTSUPP; |
f3f92586 | 4765 | |
29cbe68c JB |
4766 | wdev_lock(wdev); |
4767 | /* If not connected, get default parameters */ | |
4768 | if (!wdev->mesh_id_len) | |
4769 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4770 | else | |
e35e4d28 | 4771 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4772 | wdev_unlock(wdev); |
4773 | ||
93da9cc1 | 4774 | if (err) |
4c476991 | 4775 | return err; |
93da9cc1 | 4776 | |
4777 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4778 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4779 | if (!msg) |
4780 | return -ENOMEM; | |
15e47304 | 4781 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4782 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4783 | if (!hdr) |
efe1cf0c | 4784 | goto out; |
24bdd9f4 | 4785 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4786 | if (!pinfoattr) |
4787 | goto nla_put_failure; | |
9360ffd1 DM |
4788 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4789 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4790 | cur_params.dot11MeshRetryTimeout) || | |
4791 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4792 | cur_params.dot11MeshConfirmTimeout) || | |
4793 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4794 | cur_params.dot11MeshHoldingTimeout) || | |
4795 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4796 | cur_params.dot11MeshMaxPeerLinks) || | |
4797 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4798 | cur_params.dot11MeshMaxRetries) || | |
4799 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4800 | cur_params.dot11MeshTTL) || | |
4801 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4802 | cur_params.element_ttl) || | |
4803 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4804 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4805 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4806 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4807 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4808 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4809 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4810 | cur_params.path_refresh_time) || | |
4811 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4812 | cur_params.min_discovery_timeout) || | |
4813 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4814 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4815 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4816 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4817 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4818 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4819 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4820 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4821 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4822 | cur_params.dot11MeshHWMPRootMode) || | |
4823 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4824 | cur_params.dot11MeshHWMPRannInterval) || | |
4825 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4826 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4827 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4828 | cur_params.dot11MeshForwarding) || | |
4829 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4830 | cur_params.rssi_threshold) || |
4831 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4832 | cur_params.ht_opmode) || |
4833 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4834 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4835 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4836 | cur_params.dot11MeshHWMProotInterval) || |
4837 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4838 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4839 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4840 | cur_params.power_mode) || | |
4841 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4842 | cur_params.dot11MeshAwakeWindowDuration) || |
4843 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4844 | cur_params.plink_timeout)) | |
9360ffd1 | 4845 | goto nla_put_failure; |
93da9cc1 | 4846 | nla_nest_end(msg, pinfoattr); |
4847 | genlmsg_end(msg, hdr); | |
4c476991 | 4848 | return genlmsg_reply(msg, info); |
93da9cc1 | 4849 | |
3b85875a | 4850 | nla_put_failure: |
93da9cc1 | 4851 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4852 | out: |
d080e275 | 4853 | nlmsg_free(msg); |
4c476991 | 4854 | return -ENOBUFS; |
93da9cc1 | 4855 | } |
4856 | ||
b54452b0 | 4857 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4858 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4859 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4860 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4861 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4862 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4863 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4864 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4865 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4866 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4867 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4868 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4869 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4870 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4871 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4872 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4873 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4874 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4875 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4876 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4877 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4878 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4879 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4880 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4881 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4882 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4883 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4884 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4885 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4886 | }; |
4887 | ||
c80d545d JC |
4888 | static const struct nla_policy |
4889 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4890 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4891 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4892 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4893 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4894 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4895 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4896 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4897 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4898 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4899 | }; |
4900 | ||
24bdd9f4 | 4901 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4902 | struct mesh_config *cfg, |
4903 | u32 *mask_out) | |
93da9cc1 | 4904 | { |
93da9cc1 | 4905 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4906 | u32 mask = 0; |
93da9cc1 | 4907 | |
ea54fba2 MP |
4908 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4909 | do { \ | |
4910 | if (tb[attr]) { \ | |
4911 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4912 | return -EINVAL; \ | |
4913 | cfg->param = fn(tb[attr]); \ | |
4914 | mask |= (1 << (attr - 1)); \ | |
4915 | } \ | |
4916 | } while (0) | |
bd90fdcc JB |
4917 | |
4918 | ||
24bdd9f4 | 4919 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4920 | return -EINVAL; |
4921 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4922 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4923 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4924 | return -EINVAL; |
4925 | ||
93da9cc1 | 4926 | /* This makes sure that there aren't more than 32 mesh config |
4927 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4928 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4929 | ||
4930 | /* Fill in the params struct */ | |
ea54fba2 | 4931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4932 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4933 | nla_get_u16); | |
ea54fba2 | 4934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4935 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4936 | nla_get_u16); | |
ea54fba2 | 4937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4938 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4939 | nla_get_u16); | |
ea54fba2 | 4940 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4941 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4942 | nla_get_u16); | |
ea54fba2 | 4943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4944 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4945 | nla_get_u8); | |
ea54fba2 | 4946 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4947 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4948 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4949 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4950 | nla_get_u8); | |
ea54fba2 | 4951 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4952 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4953 | nla_get_u8); | |
ea54fba2 MP |
4954 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4955 | 1, 255, mask, | |
a4f606ea CYY |
4956 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4957 | nla_get_u32); | |
ea54fba2 | 4958 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4959 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4960 | nla_get_u8); | |
ea54fba2 | 4961 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4962 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4963 | nla_get_u32); | |
ea54fba2 | 4964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4965 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4966 | nla_get_u16); | |
ea54fba2 MP |
4967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4968 | 1, 65535, mask, | |
a4f606ea CYY |
4969 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4970 | nla_get_u32); | |
93da9cc1 | 4971 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4972 | 1, 65535, mask, |
4973 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4974 | nla_get_u16); |
dca7e943 | 4975 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4976 | 1, 65535, mask, |
4977 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4978 | nla_get_u16); |
93da9cc1 | 4979 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4980 | dot11MeshHWMPnetDiameterTraversalTime, |
4981 | 1, 65535, mask, | |
a4f606ea CYY |
4982 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4983 | nla_get_u16); | |
ea54fba2 MP |
4984 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4985 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4986 | nla_get_u8); | |
4987 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4988 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4989 | nla_get_u16); |
63c5723b | 4990 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4991 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4992 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4993 | nla_get_u8); |
ea54fba2 | 4994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4995 | mask, NL80211_MESHCONF_FORWARDING, |
4996 | nla_get_u8); | |
83374fe9 | 4997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 4998 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 4999 | nla_get_s32); |
ea54fba2 | 5000 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5001 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5002 | nla_get_u16); |
5003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5004 | 1, 65535, mask, |
ac1073a6 CYY |
5005 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5006 | nla_get_u32); | |
ea54fba2 | 5007 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5008 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5009 | nla_get_u16); |
5010 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5011 | dot11MeshHWMPconfirmationInterval, |
5012 | 1, 65535, mask, | |
728b19e5 | 5013 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5014 | nla_get_u16); |
3b1c5a53 MP |
5015 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5016 | NL80211_MESH_POWER_ACTIVE, | |
5017 | NL80211_MESH_POWER_MAX, | |
5018 | mask, NL80211_MESHCONF_POWER_MODE, | |
5019 | nla_get_u32); | |
5020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5021 | 0, 65535, mask, | |
5022 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5024 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5025 | nla_get_u32); | |
bd90fdcc JB |
5026 | if (mask_out) |
5027 | *mask_out = mask; | |
c80d545d | 5028 | |
bd90fdcc JB |
5029 | return 0; |
5030 | ||
5031 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5032 | } | |
5033 | ||
c80d545d JC |
5034 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5035 | struct mesh_setup *setup) | |
5036 | { | |
bb2798d4 | 5037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5038 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5039 | ||
5040 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5041 | return -EINVAL; | |
5042 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5043 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5044 | nl80211_mesh_setup_params_policy)) | |
5045 | return -EINVAL; | |
5046 | ||
d299a1f2 JC |
5047 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5048 | setup->sync_method = | |
5049 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5050 | IEEE80211_SYNC_METHOD_VENDOR : | |
5051 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5052 | ||
c80d545d JC |
5053 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5054 | setup->path_sel_proto = | |
5055 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5056 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5057 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5058 | ||
5059 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5060 | setup->path_metric = | |
5061 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5062 | IEEE80211_PATH_METRIC_VENDOR : | |
5063 | IEEE80211_PATH_METRIC_AIRTIME; | |
5064 | ||
581a8b0f JC |
5065 | |
5066 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5067 | struct nlattr *ieattr = |
581a8b0f | 5068 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5069 | if (!is_valid_ie_attr(ieattr)) |
5070 | return -EINVAL; | |
581a8b0f JC |
5071 | setup->ie = nla_data(ieattr); |
5072 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5073 | } |
bb2798d4 TP |
5074 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5075 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5076 | return -EINVAL; | |
5077 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5078 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5079 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5080 | if (setup->is_secure) |
5081 | setup->user_mpm = true; | |
c80d545d | 5082 | |
6e16d90b CT |
5083 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5084 | if (!setup->user_mpm) | |
5085 | return -EINVAL; | |
5086 | setup->auth_id = | |
5087 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5088 | } | |
5089 | ||
c80d545d JC |
5090 | return 0; |
5091 | } | |
5092 | ||
24bdd9f4 | 5093 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5094 | struct genl_info *info) |
bd90fdcc JB |
5095 | { |
5096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5097 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5098 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5099 | struct mesh_config cfg; |
5100 | u32 mask; | |
5101 | int err; | |
5102 | ||
29cbe68c JB |
5103 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5104 | return -EOPNOTSUPP; | |
5105 | ||
24bdd9f4 | 5106 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5107 | return -EOPNOTSUPP; |
5108 | ||
24bdd9f4 | 5109 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5110 | if (err) |
5111 | return err; | |
5112 | ||
29cbe68c JB |
5113 | wdev_lock(wdev); |
5114 | if (!wdev->mesh_id_len) | |
5115 | err = -ENOLINK; | |
5116 | ||
5117 | if (!err) | |
e35e4d28 | 5118 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5119 | |
5120 | wdev_unlock(wdev); | |
5121 | ||
5122 | return err; | |
93da9cc1 | 5123 | } |
5124 | ||
f130347c LR |
5125 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5126 | { | |
458f4f9e | 5127 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5128 | struct sk_buff *msg; |
5129 | void *hdr = NULL; | |
5130 | struct nlattr *nl_reg_rules; | |
5131 | unsigned int i; | |
f130347c LR |
5132 | |
5133 | if (!cfg80211_regdomain) | |
5fe231e8 | 5134 | return -EINVAL; |
f130347c | 5135 | |
fd2120ca | 5136 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5137 | if (!msg) |
5138 | return -ENOBUFS; | |
f130347c | 5139 | |
15e47304 | 5140 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5141 | NL80211_CMD_GET_REG); |
5142 | if (!hdr) | |
efe1cf0c | 5143 | goto put_failure; |
f130347c | 5144 | |
57b5ce07 LR |
5145 | if (reg_last_request_cell_base() && |
5146 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5147 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5148 | goto nla_put_failure; | |
5149 | ||
458f4f9e JB |
5150 | rcu_read_lock(); |
5151 | regdom = rcu_dereference(cfg80211_regdomain); | |
5152 | ||
5153 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5154 | (regdom->dfs_region && | |
5155 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5156 | goto nla_put_failure_rcu; | |
5157 | ||
f130347c LR |
5158 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5159 | if (!nl_reg_rules) | |
458f4f9e | 5160 | goto nla_put_failure_rcu; |
f130347c | 5161 | |
458f4f9e | 5162 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5163 | struct nlattr *nl_reg_rule; |
5164 | const struct ieee80211_reg_rule *reg_rule; | |
5165 | const struct ieee80211_freq_range *freq_range; | |
5166 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5167 | unsigned int max_bandwidth_khz; |
f130347c | 5168 | |
458f4f9e | 5169 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5170 | freq_range = ®_rule->freq_range; |
5171 | power_rule = ®_rule->power_rule; | |
5172 | ||
5173 | nl_reg_rule = nla_nest_start(msg, i); | |
5174 | if (!nl_reg_rule) | |
458f4f9e | 5175 | goto nla_put_failure_rcu; |
f130347c | 5176 | |
97524820 JD |
5177 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5178 | if (!max_bandwidth_khz) | |
5179 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5180 | reg_rule); | |
5181 | ||
9360ffd1 DM |
5182 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5183 | reg_rule->flags) || | |
5184 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5185 | freq_range->start_freq_khz) || | |
5186 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5187 | freq_range->end_freq_khz) || | |
5188 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5189 | max_bandwidth_khz) || |
9360ffd1 DM |
5190 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5191 | power_rule->max_antenna_gain) || | |
5192 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5193 | power_rule->max_eirp) || |
5194 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5195 | reg_rule->dfs_cac_ms)) | |
458f4f9e | 5196 | goto nla_put_failure_rcu; |
f130347c LR |
5197 | |
5198 | nla_nest_end(msg, nl_reg_rule); | |
5199 | } | |
458f4f9e | 5200 | rcu_read_unlock(); |
f130347c LR |
5201 | |
5202 | nla_nest_end(msg, nl_reg_rules); | |
5203 | ||
5204 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5205 | return genlmsg_reply(msg, info); |
f130347c | 5206 | |
458f4f9e JB |
5207 | nla_put_failure_rcu: |
5208 | rcu_read_unlock(); | |
f130347c LR |
5209 | nla_put_failure: |
5210 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5211 | put_failure: |
d080e275 | 5212 | nlmsg_free(msg); |
5fe231e8 | 5213 | return -EMSGSIZE; |
f130347c LR |
5214 | } |
5215 | ||
b2e1b302 LR |
5216 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5217 | { | |
5218 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5219 | struct nlattr *nl_reg_rule; | |
5220 | char *alpha2 = NULL; | |
5221 | int rem_reg_rules = 0, r = 0; | |
5222 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5223 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5224 | struct ieee80211_regdomain *rd = NULL; |
5225 | ||
5226 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5227 | return -EINVAL; | |
5228 | ||
5229 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5230 | return -EINVAL; | |
5231 | ||
5232 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5233 | ||
8b60b078 LR |
5234 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5235 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5236 | ||
b2e1b302 | 5237 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5238 | rem_reg_rules) { |
b2e1b302 LR |
5239 | num_rules++; |
5240 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5241 | return -EINVAL; |
b2e1b302 LR |
5242 | } |
5243 | ||
e438768f LR |
5244 | if (!reg_is_valid_request(alpha2)) |
5245 | return -EINVAL; | |
5246 | ||
b2e1b302 | 5247 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5248 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5249 | |
5250 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5251 | if (!rd) |
5252 | return -ENOMEM; | |
b2e1b302 LR |
5253 | |
5254 | rd->n_reg_rules = num_rules; | |
5255 | rd->alpha2[0] = alpha2[0]; | |
5256 | rd->alpha2[1] = alpha2[1]; | |
5257 | ||
8b60b078 LR |
5258 | /* |
5259 | * Disable DFS master mode if the DFS region was | |
5260 | * not supported or known on this kernel. | |
5261 | */ | |
5262 | if (reg_supported_dfs_region(dfs_region)) | |
5263 | rd->dfs_region = dfs_region; | |
5264 | ||
b2e1b302 | 5265 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5266 | rem_reg_rules) { |
ae811e21 JB |
5267 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5268 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5269 | reg_rule_policy); | |
5270 | if (r) | |
5271 | goto bad_reg; | |
b2e1b302 LR |
5272 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5273 | if (r) | |
5274 | goto bad_reg; | |
5275 | ||
5276 | rule_idx++; | |
5277 | ||
d0e18f83 LR |
5278 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5279 | r = -EINVAL; | |
b2e1b302 | 5280 | goto bad_reg; |
d0e18f83 | 5281 | } |
b2e1b302 LR |
5282 | } |
5283 | ||
b2e1b302 | 5284 | r = set_regdom(rd); |
6913b49a | 5285 | /* set_regdom took ownership */ |
1a919318 | 5286 | rd = NULL; |
b2e1b302 | 5287 | |
d2372b31 | 5288 | bad_reg: |
b2e1b302 | 5289 | kfree(rd); |
d0e18f83 | 5290 | return r; |
b2e1b302 LR |
5291 | } |
5292 | ||
83f5e2cf JB |
5293 | static int validate_scan_freqs(struct nlattr *freqs) |
5294 | { | |
5295 | struct nlattr *attr1, *attr2; | |
5296 | int n_channels = 0, tmp1, tmp2; | |
5297 | ||
5298 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5299 | n_channels++; | |
5300 | /* | |
5301 | * Some hardware has a limited channel list for | |
5302 | * scanning, and it is pretty much nonsensical | |
5303 | * to scan for a channel twice, so disallow that | |
5304 | * and don't require drivers to check that the | |
5305 | * channel list they get isn't longer than what | |
5306 | * they can scan, as long as they can scan all | |
5307 | * the channels they registered at once. | |
5308 | */ | |
5309 | nla_for_each_nested(attr2, freqs, tmp2) | |
5310 | if (attr1 != attr2 && | |
5311 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5312 | return 0; | |
5313 | } | |
5314 | ||
5315 | return n_channels; | |
5316 | } | |
5317 | ||
2a519311 JB |
5318 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5319 | { | |
4c476991 | 5320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5321 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5322 | struct cfg80211_scan_request *request; |
2a519311 JB |
5323 | struct nlattr *attr; |
5324 | struct wiphy *wiphy; | |
83f5e2cf | 5325 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5326 | size_t ie_len; |
2a519311 | 5327 | |
f4a11bb0 JB |
5328 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5329 | return -EINVAL; | |
5330 | ||
79c97e97 | 5331 | wiphy = &rdev->wiphy; |
2a519311 | 5332 | |
4c476991 JB |
5333 | if (!rdev->ops->scan) |
5334 | return -EOPNOTSUPP; | |
2a519311 | 5335 | |
f9d15d16 | 5336 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5337 | err = -EBUSY; |
5338 | goto unlock; | |
5339 | } | |
2a519311 JB |
5340 | |
5341 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5342 | n_channels = validate_scan_freqs( |
5343 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5344 | if (!n_channels) { |
5345 | err = -EINVAL; | |
5346 | goto unlock; | |
5347 | } | |
2a519311 | 5348 | } else { |
bdfbec2d | 5349 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5350 | } |
5351 | ||
5352 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5353 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5354 | n_ssids++; | |
5355 | ||
f9f47529 JB |
5356 | if (n_ssids > wiphy->max_scan_ssids) { |
5357 | err = -EINVAL; | |
5358 | goto unlock; | |
5359 | } | |
2a519311 | 5360 | |
70692ad2 JM |
5361 | if (info->attrs[NL80211_ATTR_IE]) |
5362 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5363 | else | |
5364 | ie_len = 0; | |
5365 | ||
f9f47529 JB |
5366 | if (ie_len > wiphy->max_scan_ie_len) { |
5367 | err = -EINVAL; | |
5368 | goto unlock; | |
5369 | } | |
18a83659 | 5370 | |
2a519311 | 5371 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5372 | + sizeof(*request->ssids) * n_ssids |
5373 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5374 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5375 | if (!request) { |
5376 | err = -ENOMEM; | |
5377 | goto unlock; | |
5378 | } | |
2a519311 | 5379 | |
2a519311 | 5380 | if (n_ssids) |
5ba63533 | 5381 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5382 | request->n_ssids = n_ssids; |
70692ad2 JM |
5383 | if (ie_len) { |
5384 | if (request->ssids) | |
5385 | request->ie = (void *)(request->ssids + n_ssids); | |
5386 | else | |
5387 | request->ie = (void *)(request->channels + n_channels); | |
5388 | } | |
2a519311 | 5389 | |
584991dc | 5390 | i = 0; |
2a519311 JB |
5391 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5392 | /* user specified, bail out if channel not found */ | |
2a519311 | 5393 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5394 | struct ieee80211_channel *chan; |
5395 | ||
5396 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5397 | ||
5398 | if (!chan) { | |
2a519311 JB |
5399 | err = -EINVAL; |
5400 | goto out_free; | |
5401 | } | |
584991dc JB |
5402 | |
5403 | /* ignore disabled channels */ | |
5404 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5405 | continue; | |
5406 | ||
5407 | request->channels[i] = chan; | |
2a519311 JB |
5408 | i++; |
5409 | } | |
5410 | } else { | |
34850ab2 JB |
5411 | enum ieee80211_band band; |
5412 | ||
2a519311 | 5413 | /* all channels */ |
2a519311 JB |
5414 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5415 | int j; | |
5416 | if (!wiphy->bands[band]) | |
5417 | continue; | |
5418 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5419 | struct ieee80211_channel *chan; |
5420 | ||
5421 | chan = &wiphy->bands[band]->channels[j]; | |
5422 | ||
5423 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5424 | continue; | |
5425 | ||
5426 | request->channels[i] = chan; | |
2a519311 JB |
5427 | i++; |
5428 | } | |
5429 | } | |
5430 | } | |
5431 | ||
584991dc JB |
5432 | if (!i) { |
5433 | err = -EINVAL; | |
5434 | goto out_free; | |
5435 | } | |
5436 | ||
5437 | request->n_channels = i; | |
5438 | ||
2a519311 JB |
5439 | i = 0; |
5440 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5441 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5442 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5443 | err = -EINVAL; |
5444 | goto out_free; | |
5445 | } | |
57a27e1d | 5446 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5447 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5448 | i++; |
5449 | } | |
5450 | } | |
5451 | ||
70692ad2 JM |
5452 | if (info->attrs[NL80211_ATTR_IE]) { |
5453 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5454 | memcpy((void *)request->ie, |
5455 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5456 | request->ie_len); |
5457 | } | |
5458 | ||
34850ab2 | 5459 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5460 | if (wiphy->bands[i]) |
5461 | request->rates[i] = | |
5462 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5463 | |
5464 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5465 | nla_for_each_nested(attr, | |
5466 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5467 | tmp) { | |
5468 | enum ieee80211_band band = nla_type(attr); | |
5469 | ||
84404623 | 5470 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5471 | err = -EINVAL; |
5472 | goto out_free; | |
5473 | } | |
1b09cd82 FF |
5474 | |
5475 | if (!wiphy->bands[band]) | |
5476 | continue; | |
5477 | ||
34850ab2 JB |
5478 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5479 | nla_data(attr), | |
5480 | nla_len(attr), | |
5481 | &request->rates[band]); | |
5482 | if (err) | |
5483 | goto out_free; | |
5484 | } | |
5485 | } | |
5486 | ||
46856bbf | 5487 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5488 | request->flags = nla_get_u32( |
5489 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5490 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5491 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5492 | err = -EOPNOTSUPP; |
5493 | goto out_free; | |
5494 | } | |
5495 | } | |
ed473771 | 5496 | |
e9f935e3 RM |
5497 | request->no_cck = |
5498 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5499 | ||
fd014284 | 5500 | request->wdev = wdev; |
79c97e97 | 5501 | request->wiphy = &rdev->wiphy; |
15d6030b | 5502 | request->scan_start = jiffies; |
2a519311 | 5503 | |
79c97e97 | 5504 | rdev->scan_req = request; |
e35e4d28 | 5505 | err = rdev_scan(rdev, request); |
2a519311 | 5506 | |
463d0183 | 5507 | if (!err) { |
fd014284 JB |
5508 | nl80211_send_scan_start(rdev, wdev); |
5509 | if (wdev->netdev) | |
5510 | dev_hold(wdev->netdev); | |
4c476991 | 5511 | } else { |
2a519311 | 5512 | out_free: |
79c97e97 | 5513 | rdev->scan_req = NULL; |
2a519311 JB |
5514 | kfree(request); |
5515 | } | |
3b85875a | 5516 | |
f9f47529 | 5517 | unlock: |
2a519311 JB |
5518 | return err; |
5519 | } | |
5520 | ||
807f8a8c LC |
5521 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5522 | struct genl_info *info) | |
5523 | { | |
5524 | struct cfg80211_sched_scan_request *request; | |
5525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5526 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5527 | struct nlattr *attr; |
5528 | struct wiphy *wiphy; | |
a1f1c21c | 5529 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5530 | u32 interval; |
807f8a8c LC |
5531 | enum ieee80211_band band; |
5532 | size_t ie_len; | |
a1f1c21c | 5533 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5534 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c LC |
5535 | |
5536 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5537 | !rdev->ops->sched_scan_start) | |
5538 | return -EOPNOTSUPP; | |
5539 | ||
5540 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5541 | return -EINVAL; | |
5542 | ||
bbe6ad6d LC |
5543 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5544 | return -EINVAL; | |
5545 | ||
5546 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5547 | if (interval == 0) | |
5548 | return -EINVAL; | |
5549 | ||
807f8a8c LC |
5550 | wiphy = &rdev->wiphy; |
5551 | ||
5552 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5553 | n_channels = validate_scan_freqs( | |
5554 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5555 | if (!n_channels) | |
5556 | return -EINVAL; | |
5557 | } else { | |
bdfbec2d | 5558 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5559 | } |
5560 | ||
5561 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5562 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5563 | tmp) | |
5564 | n_ssids++; | |
5565 | ||
93b6aa69 | 5566 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5567 | return -EINVAL; |
5568 | ||
ea73cbce JB |
5569 | /* |
5570 | * First, count the number of 'real' matchsets. Due to an issue with | |
5571 | * the old implementation, matchsets containing only the RSSI attribute | |
5572 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5573 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5574 | * all APs with a strong RSSI. This is needed to be compatible with | |
5575 | * older userspace that treated a matchset with only the RSSI as the | |
5576 | * global RSSI for all other matchsets - if there are other matchsets. | |
5577 | */ | |
5578 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
a1f1c21c LC |
5579 | nla_for_each_nested(attr, |
5580 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
ea73cbce JB |
5581 | tmp) { |
5582 | struct nlattr *rssi; | |
5583 | ||
5584 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5585 | nla_data(attr), nla_len(attr), | |
5586 | nl80211_match_policy); | |
5587 | if (err) | |
5588 | return err; | |
5589 | /* add other standalone attributes here */ | |
5590 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5591 | n_match_sets++; | |
5592 | continue; | |
5593 | } | |
5594 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5595 | if (rssi) | |
5596 | default_match_rssi = nla_get_s32(rssi); | |
5597 | } | |
5598 | } | |
5599 | ||
5600 | /* However, if there's no other matchset, add the RSSI one */ | |
5601 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5602 | n_match_sets = 1; | |
a1f1c21c LC |
5603 | |
5604 | if (n_match_sets > wiphy->max_match_sets) | |
5605 | return -EINVAL; | |
5606 | ||
807f8a8c LC |
5607 | if (info->attrs[NL80211_ATTR_IE]) |
5608 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5609 | else | |
5610 | ie_len = 0; | |
5611 | ||
5a865bad | 5612 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5613 | return -EINVAL; |
5614 | ||
c10841ca LC |
5615 | if (rdev->sched_scan_req) { |
5616 | err = -EINPROGRESS; | |
5617 | goto out; | |
5618 | } | |
5619 | ||
807f8a8c | 5620 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5621 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5622 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5623 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5624 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5625 | if (!request) { |
5626 | err = -ENOMEM; | |
5627 | goto out; | |
5628 | } | |
807f8a8c LC |
5629 | |
5630 | if (n_ssids) | |
5631 | request->ssids = (void *)&request->channels[n_channels]; | |
5632 | request->n_ssids = n_ssids; | |
5633 | if (ie_len) { | |
5634 | if (request->ssids) | |
5635 | request->ie = (void *)(request->ssids + n_ssids); | |
5636 | else | |
5637 | request->ie = (void *)(request->channels + n_channels); | |
5638 | } | |
5639 | ||
a1f1c21c LC |
5640 | if (n_match_sets) { |
5641 | if (request->ie) | |
5642 | request->match_sets = (void *)(request->ie + ie_len); | |
5643 | else if (request->ssids) | |
5644 | request->match_sets = | |
5645 | (void *)(request->ssids + n_ssids); | |
5646 | else | |
5647 | request->match_sets = | |
5648 | (void *)(request->channels + n_channels); | |
5649 | } | |
5650 | request->n_match_sets = n_match_sets; | |
5651 | ||
807f8a8c LC |
5652 | i = 0; |
5653 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5654 | /* user specified, bail out if channel not found */ | |
5655 | nla_for_each_nested(attr, | |
5656 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5657 | tmp) { | |
5658 | struct ieee80211_channel *chan; | |
5659 | ||
5660 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5661 | ||
5662 | if (!chan) { | |
5663 | err = -EINVAL; | |
5664 | goto out_free; | |
5665 | } | |
5666 | ||
5667 | /* ignore disabled channels */ | |
5668 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5669 | continue; | |
5670 | ||
5671 | request->channels[i] = chan; | |
5672 | i++; | |
5673 | } | |
5674 | } else { | |
5675 | /* all channels */ | |
5676 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5677 | int j; | |
5678 | if (!wiphy->bands[band]) | |
5679 | continue; | |
5680 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5681 | struct ieee80211_channel *chan; | |
5682 | ||
5683 | chan = &wiphy->bands[band]->channels[j]; | |
5684 | ||
5685 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5686 | continue; | |
5687 | ||
5688 | request->channels[i] = chan; | |
5689 | i++; | |
5690 | } | |
5691 | } | |
5692 | } | |
5693 | ||
5694 | if (!i) { | |
5695 | err = -EINVAL; | |
5696 | goto out_free; | |
5697 | } | |
5698 | ||
5699 | request->n_channels = i; | |
5700 | ||
5701 | i = 0; | |
5702 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5703 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5704 | tmp) { | |
57a27e1d | 5705 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5706 | err = -EINVAL; |
5707 | goto out_free; | |
5708 | } | |
57a27e1d | 5709 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5710 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5711 | nla_len(attr)); | |
807f8a8c LC |
5712 | i++; |
5713 | } | |
5714 | } | |
5715 | ||
a1f1c21c LC |
5716 | i = 0; |
5717 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5718 | nla_for_each_nested(attr, | |
5719 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5720 | tmp) { | |
88e920b4 | 5721 | struct nlattr *ssid, *rssi; |
a1f1c21c | 5722 | |
ae811e21 JB |
5723 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
5724 | nla_data(attr), nla_len(attr), | |
5725 | nl80211_match_policy); | |
5726 | if (err) | |
5727 | goto out_free; | |
4a4ab0d7 | 5728 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 5729 | if (ssid) { |
ea73cbce JB |
5730 | if (WARN_ON(i >= n_match_sets)) { |
5731 | /* this indicates a programming error, | |
5732 | * the loop above should have verified | |
5733 | * things properly | |
5734 | */ | |
5735 | err = -EINVAL; | |
5736 | goto out_free; | |
5737 | } | |
5738 | ||
a1f1c21c LC |
5739 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
5740 | err = -EINVAL; | |
5741 | goto out_free; | |
5742 | } | |
5743 | memcpy(request->match_sets[i].ssid.ssid, | |
5744 | nla_data(ssid), nla_len(ssid)); | |
5745 | request->match_sets[i].ssid.ssid_len = | |
5746 | nla_len(ssid); | |
ea73cbce JB |
5747 | /* special attribute - old implemenation w/a */ |
5748 | request->match_sets[i].rssi_thold = | |
5749 | default_match_rssi; | |
5750 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5751 | if (rssi) | |
5752 | request->match_sets[i].rssi_thold = | |
5753 | nla_get_s32(rssi); | |
a1f1c21c LC |
5754 | } |
5755 | i++; | |
5756 | } | |
ea73cbce JB |
5757 | |
5758 | /* there was no other matchset, so the RSSI one is alone */ | |
5759 | if (i == 0) | |
5760 | request->match_sets[0].rssi_thold = default_match_rssi; | |
5761 | ||
5762 | request->min_rssi_thold = INT_MAX; | |
5763 | for (i = 0; i < n_match_sets; i++) | |
5764 | request->min_rssi_thold = | |
5765 | min(request->match_sets[i].rssi_thold, | |
5766 | request->min_rssi_thold); | |
5767 | } else { | |
5768 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5769 | } |
5770 | ||
9900e484 JB |
5771 | if (ie_len) { |
5772 | request->ie_len = ie_len; | |
807f8a8c LC |
5773 | memcpy((void *)request->ie, |
5774 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5775 | request->ie_len); | |
5776 | } | |
5777 | ||
46856bbf | 5778 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5779 | request->flags = nla_get_u32( |
5780 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5781 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5782 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5783 | err = -EOPNOTSUPP; |
5784 | goto out_free; | |
5785 | } | |
5786 | } | |
ed473771 | 5787 | |
807f8a8c LC |
5788 | request->dev = dev; |
5789 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5790 | request->interval = interval; |
15d6030b | 5791 | request->scan_start = jiffies; |
807f8a8c | 5792 | |
e35e4d28 | 5793 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5794 | if (!err) { |
5795 | rdev->sched_scan_req = request; | |
5796 | nl80211_send_sched_scan(rdev, dev, | |
5797 | NL80211_CMD_START_SCHED_SCAN); | |
5798 | goto out; | |
5799 | } | |
5800 | ||
5801 | out_free: | |
5802 | kfree(request); | |
5803 | out: | |
5804 | return err; | |
5805 | } | |
5806 | ||
5807 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5808 | struct genl_info *info) | |
5809 | { | |
5810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5811 | ||
5812 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5813 | !rdev->ops->sched_scan_stop) | |
5814 | return -EOPNOTSUPP; | |
5815 | ||
5fe231e8 | 5816 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5817 | } |
5818 | ||
04f39047 SW |
5819 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5820 | struct genl_info *info) | |
5821 | { | |
5822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5823 | struct net_device *dev = info->user_ptr[1]; | |
5824 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5825 | struct cfg80211_chan_def chandef; | |
55f7435c | 5826 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 5827 | unsigned int cac_time_ms; |
04f39047 SW |
5828 | int err; |
5829 | ||
55f7435c LR |
5830 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5831 | if (dfs_region == NL80211_DFS_UNSET) | |
5832 | return -EINVAL; | |
5833 | ||
04f39047 SW |
5834 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5835 | if (err) | |
5836 | return err; | |
5837 | ||
ff311bc1 SW |
5838 | if (netif_carrier_ok(dev)) |
5839 | return -EBUSY; | |
5840 | ||
04f39047 SW |
5841 | if (wdev->cac_started) |
5842 | return -EBUSY; | |
5843 | ||
2beb6dab | 5844 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 5845 | wdev->iftype); |
04f39047 SW |
5846 | if (err < 0) |
5847 | return err; | |
5848 | ||
5849 | if (err == 0) | |
5850 | return -EINVAL; | |
5851 | ||
fe7c3a1f | 5852 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
5853 | return -EINVAL; |
5854 | ||
5855 | if (!rdev->ops->start_radar_detection) | |
5856 | return -EOPNOTSUPP; | |
5857 | ||
31559f35 JD |
5858 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
5859 | if (WARN_ON(!cac_time_ms)) | |
5860 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
5861 | ||
5862 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
5863 | cac_time_ms); | |
04f39047 | 5864 | if (!err) { |
9e0e2961 | 5865 | wdev->chandef = chandef; |
04f39047 SW |
5866 | wdev->cac_started = true; |
5867 | wdev->cac_start_time = jiffies; | |
31559f35 | 5868 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 5869 | } |
04f39047 SW |
5870 | return err; |
5871 | } | |
5872 | ||
16ef1fe2 SW |
5873 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5874 | { | |
5875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5876 | struct net_device *dev = info->user_ptr[1]; | |
5877 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5878 | struct cfg80211_csa_settings params; | |
5879 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5880 | * function is called under RTNL lock, so this should not be a problem. | |
5881 | */ | |
5882 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5883 | u8 radar_detect_width = 0; | |
5884 | int err; | |
ee4bc9e7 | 5885 | bool need_new_beacon = false; |
9a774c78 | 5886 | int len, i; |
16ef1fe2 SW |
5887 | |
5888 | if (!rdev->ops->channel_switch || | |
5889 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5890 | return -EOPNOTSUPP; | |
5891 | ||
ee4bc9e7 SW |
5892 | switch (dev->ieee80211_ptr->iftype) { |
5893 | case NL80211_IFTYPE_AP: | |
5894 | case NL80211_IFTYPE_P2P_GO: | |
5895 | need_new_beacon = true; | |
5896 | ||
5897 | /* useless if AP is not running */ | |
5898 | if (!wdev->beacon_interval) | |
1ff79dfa | 5899 | return -ENOTCONN; |
ee4bc9e7 SW |
5900 | break; |
5901 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
5902 | if (!wdev->ssid_len) |
5903 | return -ENOTCONN; | |
5904 | break; | |
c6da674a | 5905 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
5906 | if (!wdev->mesh_id_len) |
5907 | return -ENOTCONN; | |
ee4bc9e7 SW |
5908 | break; |
5909 | default: | |
16ef1fe2 | 5910 | return -EOPNOTSUPP; |
ee4bc9e7 | 5911 | } |
16ef1fe2 SW |
5912 | |
5913 | memset(¶ms, 0, sizeof(params)); | |
5914 | ||
5915 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5916 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5917 | return -EINVAL; | |
5918 | ||
5919 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 5920 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
5921 | return -EINVAL; |
5922 | ||
5923 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5924 | ||
ee4bc9e7 SW |
5925 | if (!need_new_beacon) |
5926 | goto skip_beacons; | |
5927 | ||
16ef1fe2 SW |
5928 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
5929 | if (err) | |
5930 | return err; | |
5931 | ||
5932 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5933 | info->attrs[NL80211_ATTR_CSA_IES], | |
5934 | nl80211_policy); | |
5935 | if (err) | |
5936 | return err; | |
5937 | ||
5938 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5939 | if (err) | |
5940 | return err; | |
5941 | ||
5942 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5943 | return -EINVAL; | |
5944 | ||
9a774c78 AO |
5945 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
5946 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
5947 | return -EINVAL; |
5948 | ||
9a774c78 AO |
5949 | params.n_counter_offsets_beacon = len / sizeof(u16); |
5950 | if (rdev->wiphy.max_num_csa_counters && | |
5951 | (params.n_counter_offsets_beacon > | |
5952 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
5953 | return -EINVAL; |
5954 | ||
9a774c78 AO |
5955 | params.counter_offsets_beacon = |
5956 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5957 | ||
5958 | /* sanity checks - counters should fit and be the same */ | |
5959 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
5960 | u16 offset = params.counter_offsets_beacon[i]; | |
5961 | ||
5962 | if (offset >= params.beacon_csa.tail_len) | |
5963 | return -EINVAL; | |
5964 | ||
5965 | if (params.beacon_csa.tail[offset] != params.count) | |
5966 | return -EINVAL; | |
5967 | } | |
5968 | ||
16ef1fe2 | 5969 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
5970 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
5971 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
5972 | return -EINVAL; |
5973 | ||
9a774c78 AO |
5974 | params.n_counter_offsets_presp = len / sizeof(u16); |
5975 | if (rdev->wiphy.max_num_csa_counters && | |
5976 | (params.n_counter_offsets_beacon > | |
5977 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 5978 | return -EINVAL; |
9a774c78 AO |
5979 | |
5980 | params.counter_offsets_presp = | |
5981 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5982 | ||
5983 | /* sanity checks - counters should fit and be the same */ | |
5984 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
5985 | u16 offset = params.counter_offsets_presp[i]; | |
5986 | ||
5987 | if (offset >= params.beacon_csa.probe_resp_len) | |
5988 | return -EINVAL; | |
5989 | ||
5990 | if (params.beacon_csa.probe_resp[offset] != | |
5991 | params.count) | |
5992 | return -EINVAL; | |
5993 | } | |
16ef1fe2 SW |
5994 | } |
5995 | ||
ee4bc9e7 | 5996 | skip_beacons: |
16ef1fe2 SW |
5997 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
5998 | if (err) | |
5999 | return err; | |
6000 | ||
174e0cd2 IP |
6001 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6002 | wdev->iftype)) | |
16ef1fe2 SW |
6003 | return -EINVAL; |
6004 | ||
2beb6dab LC |
6005 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6006 | ¶ms.chandef, | |
6007 | wdev->iftype); | |
6008 | if (err < 0) | |
6009 | return err; | |
6010 | ||
6011 | if (err > 0) { | |
6012 | radar_detect_width = BIT(params.chandef.width); | |
6013 | params.radar_required = true; | |
16ef1fe2 SW |
6014 | } |
6015 | ||
16ef1fe2 SW |
6016 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6017 | params.block_tx = true; | |
6018 | ||
c56589ed SW |
6019 | wdev_lock(wdev); |
6020 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6021 | wdev_unlock(wdev); | |
6022 | ||
6023 | return err; | |
16ef1fe2 SW |
6024 | } |
6025 | ||
9720bb3a JB |
6026 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6027 | u32 seq, int flags, | |
2a519311 | 6028 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6029 | struct wireless_dev *wdev, |
6030 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6031 | { |
48ab905d | 6032 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6033 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6034 | void *hdr; |
6035 | struct nlattr *bss; | |
8cef2c9d | 6036 | bool tsf = false; |
48ab905d JB |
6037 | |
6038 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6039 | |
15e47304 | 6040 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6041 | NL80211_CMD_NEW_SCAN_RESULTS); |
6042 | if (!hdr) | |
6043 | return -1; | |
6044 | ||
9720bb3a JB |
6045 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6046 | ||
97990a06 JB |
6047 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6048 | goto nla_put_failure; | |
6049 | if (wdev->netdev && | |
9360ffd1 DM |
6050 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6051 | goto nla_put_failure; | |
97990a06 JB |
6052 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6053 | goto nla_put_failure; | |
2a519311 JB |
6054 | |
6055 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6056 | if (!bss) | |
6057 | goto nla_put_failure; | |
9360ffd1 | 6058 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6059 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6060 | goto nla_put_failure; |
9caf0364 JB |
6061 | |
6062 | rcu_read_lock(); | |
6063 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
6064 | if (ies) { |
6065 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6066 | goto fail_unlock_rcu; | |
6067 | tsf = true; | |
6068 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
6069 | ies->len, ies->data)) | |
6070 | goto fail_unlock_rcu; | |
9caf0364 JB |
6071 | } |
6072 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
6073 | if (ies) { |
6074 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6075 | goto fail_unlock_rcu; | |
6076 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6077 | ies->len, ies->data)) | |
6078 | goto fail_unlock_rcu; | |
9caf0364 JB |
6079 | } |
6080 | rcu_read_unlock(); | |
6081 | ||
9360ffd1 DM |
6082 | if (res->beacon_interval && |
6083 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6084 | goto nla_put_failure; | |
6085 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6086 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6087 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6088 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6089 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6090 | goto nla_put_failure; | |
2a519311 | 6091 | |
77965c97 | 6092 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6093 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6094 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6095 | goto nla_put_failure; | |
2a519311 JB |
6096 | break; |
6097 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6098 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6099 | goto nla_put_failure; | |
2a519311 JB |
6100 | break; |
6101 | default: | |
6102 | break; | |
6103 | } | |
6104 | ||
48ab905d | 6105 | switch (wdev->iftype) { |
074ac8df | 6106 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6107 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6108 | if (intbss == wdev->current_bss && |
6109 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6110 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6111 | goto nla_put_failure; | |
48ab905d JB |
6112 | break; |
6113 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6114 | if (intbss == wdev->current_bss && |
6115 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6116 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6117 | goto nla_put_failure; | |
48ab905d JB |
6118 | break; |
6119 | default: | |
6120 | break; | |
6121 | } | |
6122 | ||
2a519311 JB |
6123 | nla_nest_end(msg, bss); |
6124 | ||
6125 | return genlmsg_end(msg, hdr); | |
6126 | ||
8cef2c9d JB |
6127 | fail_unlock_rcu: |
6128 | rcu_read_unlock(); | |
2a519311 JB |
6129 | nla_put_failure: |
6130 | genlmsg_cancel(msg, hdr); | |
6131 | return -EMSGSIZE; | |
6132 | } | |
6133 | ||
97990a06 | 6134 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6135 | { |
48ab905d | 6136 | struct cfg80211_registered_device *rdev; |
2a519311 | 6137 | struct cfg80211_internal_bss *scan; |
48ab905d | 6138 | struct wireless_dev *wdev; |
97990a06 | 6139 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6140 | int err; |
6141 | ||
97990a06 | 6142 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6143 | if (err) |
6144 | return err; | |
2a519311 | 6145 | |
48ab905d JB |
6146 | wdev_lock(wdev); |
6147 | spin_lock_bh(&rdev->bss_lock); | |
6148 | cfg80211_bss_expire(rdev); | |
6149 | ||
9720bb3a JB |
6150 | cb->seq = rdev->bss_generation; |
6151 | ||
48ab905d | 6152 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6153 | if (++idx <= start) |
6154 | continue; | |
9720bb3a | 6155 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6156 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6157 | rdev, wdev, scan) < 0) { |
2a519311 | 6158 | idx--; |
67748893 | 6159 | break; |
2a519311 JB |
6160 | } |
6161 | } | |
6162 | ||
48ab905d JB |
6163 | spin_unlock_bh(&rdev->bss_lock); |
6164 | wdev_unlock(wdev); | |
2a519311 | 6165 | |
97990a06 JB |
6166 | cb->args[2] = idx; |
6167 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6168 | |
67748893 | 6169 | return skb->len; |
2a519311 JB |
6170 | } |
6171 | ||
15e47304 | 6172 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6173 | int flags, struct net_device *dev, |
6174 | struct survey_info *survey) | |
6175 | { | |
6176 | void *hdr; | |
6177 | struct nlattr *infoattr; | |
6178 | ||
15e47304 | 6179 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6180 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6181 | if (!hdr) | |
6182 | return -ENOMEM; | |
6183 | ||
9360ffd1 DM |
6184 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6185 | goto nla_put_failure; | |
61fa713c HS |
6186 | |
6187 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6188 | if (!infoattr) | |
6189 | goto nla_put_failure; | |
6190 | ||
9360ffd1 DM |
6191 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6192 | survey->channel->center_freq)) | |
6193 | goto nla_put_failure; | |
6194 | ||
6195 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6196 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6197 | goto nla_put_failure; | |
6198 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6199 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6200 | goto nla_put_failure; | |
6201 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6202 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6203 | survey->channel_time)) | |
6204 | goto nla_put_failure; | |
6205 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6206 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6207 | survey->channel_time_busy)) | |
6208 | goto nla_put_failure; | |
6209 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6210 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6211 | survey->channel_time_ext_busy)) | |
6212 | goto nla_put_failure; | |
6213 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6214 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6215 | survey->channel_time_rx)) | |
6216 | goto nla_put_failure; | |
6217 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6218 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6219 | survey->channel_time_tx)) | |
6220 | goto nla_put_failure; | |
61fa713c HS |
6221 | |
6222 | nla_nest_end(msg, infoattr); | |
6223 | ||
6224 | return genlmsg_end(msg, hdr); | |
6225 | ||
6226 | nla_put_failure: | |
6227 | genlmsg_cancel(msg, hdr); | |
6228 | return -EMSGSIZE; | |
6229 | } | |
6230 | ||
6231 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6232 | struct netlink_callback *cb) | |
6233 | { | |
6234 | struct survey_info survey; | |
1b8ec87a | 6235 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6236 | struct wireless_dev *wdev; |
6237 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6238 | int res; |
6239 | ||
1b8ec87a | 6240 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6241 | if (res) |
6242 | return res; | |
61fa713c | 6243 | |
97990a06 JB |
6244 | if (!wdev->netdev) { |
6245 | res = -EINVAL; | |
6246 | goto out_err; | |
6247 | } | |
6248 | ||
1b8ec87a | 6249 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6250 | res = -EOPNOTSUPP; |
6251 | goto out_err; | |
6252 | } | |
6253 | ||
6254 | while (1) { | |
180cdc79 LR |
6255 | struct ieee80211_channel *chan; |
6256 | ||
1b8ec87a | 6257 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6258 | if (res == -ENOENT) |
6259 | break; | |
6260 | if (res) | |
6261 | goto out_err; | |
6262 | ||
180cdc79 LR |
6263 | /* Survey without a channel doesn't make sense */ |
6264 | if (!survey.channel) { | |
6265 | res = -EINVAL; | |
6266 | goto out; | |
6267 | } | |
6268 | ||
1b8ec87a | 6269 | chan = ieee80211_get_channel(&rdev->wiphy, |
180cdc79 LR |
6270 | survey.channel->center_freq); |
6271 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6272 | survey_idx++; | |
6273 | continue; | |
6274 | } | |
6275 | ||
61fa713c | 6276 | if (nl80211_send_survey(skb, |
15e47304 | 6277 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6278 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6279 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6280 | goto out; |
6281 | survey_idx++; | |
6282 | } | |
6283 | ||
6284 | out: | |
97990a06 | 6285 | cb->args[2] = survey_idx; |
61fa713c HS |
6286 | res = skb->len; |
6287 | out_err: | |
1b8ec87a | 6288 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6289 | return res; |
6290 | } | |
6291 | ||
b23aa676 SO |
6292 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6293 | { | |
6294 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6295 | NL80211_WPA_VERSION_2)); | |
6296 | } | |
6297 | ||
636a5d36 JM |
6298 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6299 | { | |
4c476991 JB |
6300 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6301 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6302 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6303 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6304 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6305 | enum nl80211_auth_type auth_type; |
fffd0934 | 6306 | struct key_parse key; |
d5cdfacb | 6307 | bool local_state_change; |
636a5d36 | 6308 | |
f4a11bb0 JB |
6309 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6310 | return -EINVAL; | |
6311 | ||
6312 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6313 | return -EINVAL; | |
6314 | ||
1778092e JM |
6315 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6316 | return -EINVAL; | |
6317 | ||
19957bb3 JB |
6318 | if (!info->attrs[NL80211_ATTR_SSID]) |
6319 | return -EINVAL; | |
6320 | ||
6321 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6322 | return -EINVAL; | |
6323 | ||
fffd0934 JB |
6324 | err = nl80211_parse_key(info, &key); |
6325 | if (err) | |
6326 | return err; | |
6327 | ||
6328 | if (key.idx >= 0) { | |
e31b8213 JB |
6329 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6330 | return -EINVAL; | |
fffd0934 JB |
6331 | if (!key.p.key || !key.p.key_len) |
6332 | return -EINVAL; | |
6333 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6334 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6335 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6336 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6337 | return -EINVAL; | |
6338 | if (key.idx > 4) | |
6339 | return -EINVAL; | |
6340 | } else { | |
6341 | key.p.key_len = 0; | |
6342 | key.p.key = NULL; | |
6343 | } | |
6344 | ||
afea0b7a JB |
6345 | if (key.idx >= 0) { |
6346 | int i; | |
6347 | bool ok = false; | |
6348 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6349 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6350 | ok = true; | |
6351 | break; | |
6352 | } | |
6353 | } | |
4c476991 JB |
6354 | if (!ok) |
6355 | return -EINVAL; | |
afea0b7a JB |
6356 | } |
6357 | ||
4c476991 JB |
6358 | if (!rdev->ops->auth) |
6359 | return -EOPNOTSUPP; | |
636a5d36 | 6360 | |
074ac8df | 6361 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6362 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6363 | return -EOPNOTSUPP; | |
eec60b03 | 6364 | |
19957bb3 | 6365 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6366 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6367 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6368 | if (!chan) | |
4c476991 | 6369 | return -EINVAL; |
636a5d36 | 6370 | |
19957bb3 JB |
6371 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6372 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6373 | |
6374 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6375 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6376 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6377 | } |
6378 | ||
19957bb3 | 6379 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6380 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6381 | return -EINVAL; |
636a5d36 | 6382 | |
e39e5b5e JM |
6383 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6384 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6385 | return -EINVAL; | |
6386 | ||
6387 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6388 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6389 | return -EINVAL; | |
6390 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6391 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6392 | /* need to include at least Auth Transaction and Status Code */ | |
6393 | if (sae_data_len < 4) | |
6394 | return -EINVAL; | |
6395 | } | |
6396 | ||
d5cdfacb JM |
6397 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6398 | ||
95de817b JB |
6399 | /* |
6400 | * Since we no longer track auth state, ignore | |
6401 | * requests to only change local state. | |
6402 | */ | |
6403 | if (local_state_change) | |
6404 | return 0; | |
6405 | ||
91bf9b26 JB |
6406 | wdev_lock(dev->ieee80211_ptr); |
6407 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6408 | ssid, ssid_len, ie, ie_len, | |
6409 | key.p.key, key.p.key_len, key.idx, | |
6410 | sae_data, sae_data_len); | |
6411 | wdev_unlock(dev->ieee80211_ptr); | |
6412 | return err; | |
636a5d36 JM |
6413 | } |
6414 | ||
c0692b8f JB |
6415 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6416 | struct genl_info *info, | |
3dc27d25 JB |
6417 | struct cfg80211_crypto_settings *settings, |
6418 | int cipher_limit) | |
b23aa676 | 6419 | { |
c0b2bbd8 JB |
6420 | memset(settings, 0, sizeof(*settings)); |
6421 | ||
b23aa676 SO |
6422 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6423 | ||
c0692b8f JB |
6424 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6425 | u16 proto; | |
6426 | proto = nla_get_u16( | |
6427 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6428 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6429 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6430 | proto != ETH_P_PAE) | |
6431 | return -EINVAL; | |
6432 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6433 | settings->control_port_no_encrypt = true; | |
6434 | } else | |
6435 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6436 | ||
b23aa676 SO |
6437 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6438 | void *data; | |
6439 | int len, i; | |
6440 | ||
6441 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6442 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6443 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6444 | ||
6445 | if (len % sizeof(u32)) | |
6446 | return -EINVAL; | |
6447 | ||
3dc27d25 | 6448 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6449 | return -EINVAL; |
6450 | ||
6451 | memcpy(settings->ciphers_pairwise, data, len); | |
6452 | ||
6453 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6454 | if (!cfg80211_supported_cipher_suite( |
6455 | &rdev->wiphy, | |
b23aa676 SO |
6456 | settings->ciphers_pairwise[i])) |
6457 | return -EINVAL; | |
6458 | } | |
6459 | ||
6460 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6461 | settings->cipher_group = | |
6462 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6463 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6464 | settings->cipher_group)) | |
b23aa676 SO |
6465 | return -EINVAL; |
6466 | } | |
6467 | ||
6468 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6469 | settings->wpa_versions = | |
6470 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6471 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6472 | return -EINVAL; | |
6473 | } | |
6474 | ||
6475 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6476 | void *data; | |
6d30240e | 6477 | int len; |
b23aa676 SO |
6478 | |
6479 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6480 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6481 | settings->n_akm_suites = len / sizeof(u32); | |
6482 | ||
6483 | if (len % sizeof(u32)) | |
6484 | return -EINVAL; | |
6485 | ||
1b9ca027 JM |
6486 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6487 | return -EINVAL; | |
6488 | ||
b23aa676 | 6489 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6490 | } |
6491 | ||
6492 | return 0; | |
6493 | } | |
6494 | ||
636a5d36 JM |
6495 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6496 | { | |
4c476991 JB |
6497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6498 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6499 | struct ieee80211_channel *chan; |
f62fab73 JB |
6500 | struct cfg80211_assoc_request req = {}; |
6501 | const u8 *bssid, *ssid; | |
6502 | int err, ssid_len = 0; | |
636a5d36 | 6503 | |
f4a11bb0 JB |
6504 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6505 | return -EINVAL; | |
6506 | ||
6507 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6508 | !info->attrs[NL80211_ATTR_SSID] || |
6509 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6510 | return -EINVAL; |
6511 | ||
4c476991 JB |
6512 | if (!rdev->ops->assoc) |
6513 | return -EOPNOTSUPP; | |
636a5d36 | 6514 | |
074ac8df | 6515 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6516 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6517 | return -EOPNOTSUPP; | |
eec60b03 | 6518 | |
19957bb3 | 6519 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6520 | |
664834de JM |
6521 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6522 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6523 | if (!chan) | |
4c476991 | 6524 | return -EINVAL; |
636a5d36 | 6525 | |
19957bb3 JB |
6526 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6527 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6528 | |
6529 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6530 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6531 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6532 | } |
6533 | ||
dc6382ce | 6534 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6535 | enum nl80211_mfp mfp = |
dc6382ce | 6536 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6537 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6538 | req.use_mfp = true; |
4c476991 JB |
6539 | else if (mfp != NL80211_MFP_NO) |
6540 | return -EINVAL; | |
dc6382ce JM |
6541 | } |
6542 | ||
3e5d7649 | 6543 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6544 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6545 | |
7e7c8926 | 6546 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6547 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6548 | |
6549 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6550 | memcpy(&req.ht_capa_mask, |
6551 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6552 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6553 | |
6554 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6555 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6556 | return -EINVAL; |
f62fab73 JB |
6557 | memcpy(&req.ht_capa, |
6558 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6559 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6560 | } |
6561 | ||
ee2aca34 | 6562 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6563 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6564 | |
6565 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6566 | memcpy(&req.vht_capa_mask, |
6567 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6568 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6569 | |
6570 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6571 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6572 | return -EINVAL; |
f62fab73 JB |
6573 | memcpy(&req.vht_capa, |
6574 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6575 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6576 | } |
6577 | ||
f62fab73 | 6578 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6579 | if (!err) { |
6580 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6581 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6582 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6583 | wdev_unlock(dev->ieee80211_ptr); |
6584 | } | |
636a5d36 | 6585 | |
636a5d36 JM |
6586 | return err; |
6587 | } | |
6588 | ||
6589 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6590 | { | |
4c476991 JB |
6591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6592 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6593 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6594 | int ie_len = 0, err; |
19957bb3 | 6595 | u16 reason_code; |
d5cdfacb | 6596 | bool local_state_change; |
636a5d36 | 6597 | |
f4a11bb0 JB |
6598 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6599 | return -EINVAL; | |
6600 | ||
6601 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6602 | return -EINVAL; | |
6603 | ||
6604 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6605 | return -EINVAL; | |
6606 | ||
4c476991 JB |
6607 | if (!rdev->ops->deauth) |
6608 | return -EOPNOTSUPP; | |
636a5d36 | 6609 | |
074ac8df | 6610 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6611 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6612 | return -EOPNOTSUPP; | |
eec60b03 | 6613 | |
19957bb3 | 6614 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6615 | |
19957bb3 JB |
6616 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6617 | if (reason_code == 0) { | |
f4a11bb0 | 6618 | /* Reason Code 0 is reserved */ |
4c476991 | 6619 | return -EINVAL; |
255e737e | 6620 | } |
636a5d36 JM |
6621 | |
6622 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6623 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6624 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6625 | } |
6626 | ||
d5cdfacb JM |
6627 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6628 | ||
91bf9b26 JB |
6629 | wdev_lock(dev->ieee80211_ptr); |
6630 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6631 | local_state_change); | |
6632 | wdev_unlock(dev->ieee80211_ptr); | |
6633 | return err; | |
636a5d36 JM |
6634 | } |
6635 | ||
6636 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6637 | { | |
4c476991 JB |
6638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6639 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6640 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6641 | int ie_len = 0, err; |
19957bb3 | 6642 | u16 reason_code; |
d5cdfacb | 6643 | bool local_state_change; |
636a5d36 | 6644 | |
f4a11bb0 JB |
6645 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6646 | return -EINVAL; | |
6647 | ||
6648 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6649 | return -EINVAL; | |
6650 | ||
6651 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6652 | return -EINVAL; | |
6653 | ||
4c476991 JB |
6654 | if (!rdev->ops->disassoc) |
6655 | return -EOPNOTSUPP; | |
636a5d36 | 6656 | |
074ac8df | 6657 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6658 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6659 | return -EOPNOTSUPP; | |
eec60b03 | 6660 | |
19957bb3 | 6661 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6662 | |
19957bb3 JB |
6663 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6664 | if (reason_code == 0) { | |
f4a11bb0 | 6665 | /* Reason Code 0 is reserved */ |
4c476991 | 6666 | return -EINVAL; |
255e737e | 6667 | } |
636a5d36 JM |
6668 | |
6669 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6670 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6671 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6672 | } |
6673 | ||
d5cdfacb JM |
6674 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6675 | ||
91bf9b26 JB |
6676 | wdev_lock(dev->ieee80211_ptr); |
6677 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6678 | local_state_change); | |
6679 | wdev_unlock(dev->ieee80211_ptr); | |
6680 | return err; | |
636a5d36 JM |
6681 | } |
6682 | ||
dd5b4cc7 FF |
6683 | static bool |
6684 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6685 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6686 | int rateval) | |
6687 | { | |
6688 | struct wiphy *wiphy = &rdev->wiphy; | |
6689 | bool found = false; | |
6690 | int band, i; | |
6691 | ||
6692 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6693 | struct ieee80211_supported_band *sband; | |
6694 | ||
6695 | sband = wiphy->bands[band]; | |
6696 | if (!sband) | |
6697 | continue; | |
6698 | ||
6699 | for (i = 0; i < sband->n_bitrates; i++) { | |
6700 | if (sband->bitrates[i].bitrate == rateval) { | |
6701 | mcast_rate[band] = i + 1; | |
6702 | found = true; | |
6703 | break; | |
6704 | } | |
6705 | } | |
6706 | } | |
6707 | ||
6708 | return found; | |
6709 | } | |
6710 | ||
04a773ad JB |
6711 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6712 | { | |
4c476991 JB |
6713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6714 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6715 | struct cfg80211_ibss_params ibss; |
6716 | struct wiphy *wiphy; | |
fffd0934 | 6717 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6718 | int err; |
6719 | ||
8e30bc55 JB |
6720 | memset(&ibss, 0, sizeof(ibss)); |
6721 | ||
04a773ad JB |
6722 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6723 | return -EINVAL; | |
6724 | ||
683b6d3b | 6725 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6726 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6727 | return -EINVAL; | |
6728 | ||
8e30bc55 JB |
6729 | ibss.beacon_interval = 100; |
6730 | ||
6731 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6732 | ibss.beacon_interval = | |
6733 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6734 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6735 | return -EINVAL; | |
6736 | } | |
6737 | ||
4c476991 JB |
6738 | if (!rdev->ops->join_ibss) |
6739 | return -EOPNOTSUPP; | |
04a773ad | 6740 | |
4c476991 JB |
6741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6742 | return -EOPNOTSUPP; | |
04a773ad | 6743 | |
79c97e97 | 6744 | wiphy = &rdev->wiphy; |
04a773ad | 6745 | |
39193498 | 6746 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6747 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6748 | |
6749 | if (!is_valid_ether_addr(ibss.bssid)) | |
6750 | return -EINVAL; | |
6751 | } | |
04a773ad JB |
6752 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6753 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6754 | ||
6755 | if (info->attrs[NL80211_ATTR_IE]) { | |
6756 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6757 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6758 | } | |
6759 | ||
683b6d3b JB |
6760 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6761 | if (err) | |
6762 | return err; | |
04a773ad | 6763 | |
174e0cd2 IP |
6764 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
6765 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
6766 | return -EINVAL; |
6767 | ||
2f301ab2 | 6768 | switch (ibss.chandef.width) { |
bf372645 SW |
6769 | case NL80211_CHAN_WIDTH_5: |
6770 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6771 | case NL80211_CHAN_WIDTH_20_NOHT: |
6772 | break; | |
6773 | case NL80211_CHAN_WIDTH_20: | |
6774 | case NL80211_CHAN_WIDTH_40: | |
6775 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6776 | break; | |
6777 | default: | |
c04d6150 | 6778 | return -EINVAL; |
2f301ab2 | 6779 | } |
db9c64cf | 6780 | |
04a773ad | 6781 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6782 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6783 | ||
fbd2c8dc TP |
6784 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6785 | u8 *rates = | |
6786 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6787 | int n_rates = | |
6788 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6789 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6790 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6791 | |
34850ab2 JB |
6792 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6793 | &ibss.basic_rates); | |
6794 | if (err) | |
6795 | return err; | |
fbd2c8dc | 6796 | } |
dd5b4cc7 | 6797 | |
803768f5 SW |
6798 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6799 | memcpy(&ibss.ht_capa_mask, | |
6800 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6801 | sizeof(ibss.ht_capa_mask)); | |
6802 | ||
6803 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6804 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6805 | return -EINVAL; | |
6806 | memcpy(&ibss.ht_capa, | |
6807 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6808 | sizeof(ibss.ht_capa)); | |
6809 | } | |
6810 | ||
dd5b4cc7 FF |
6811 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6812 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6813 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6814 | return -EINVAL; | |
fbd2c8dc | 6815 | |
4c476991 | 6816 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6817 | bool no_ht = false; |
6818 | ||
4c476991 | 6819 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6820 | info->attrs[NL80211_ATTR_KEYS], |
6821 | &no_ht); | |
4c476991 JB |
6822 | if (IS_ERR(connkeys)) |
6823 | return PTR_ERR(connkeys); | |
de7044ee | 6824 | |
3d9d1d66 JB |
6825 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6826 | no_ht) { | |
de7044ee SM |
6827 | kfree(connkeys); |
6828 | return -EINVAL; | |
6829 | } | |
4c476991 | 6830 | } |
04a773ad | 6831 | |
267335d6 AQ |
6832 | ibss.control_port = |
6833 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6834 | ||
5336fa88 SW |
6835 | ibss.userspace_handles_dfs = |
6836 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
6837 | ||
4c476991 | 6838 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6839 | if (err) |
6840 | kfree(connkeys); | |
04a773ad JB |
6841 | return err; |
6842 | } | |
6843 | ||
6844 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6845 | { | |
4c476991 JB |
6846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6847 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6848 | |
4c476991 JB |
6849 | if (!rdev->ops->leave_ibss) |
6850 | return -EOPNOTSUPP; | |
04a773ad | 6851 | |
4c476991 JB |
6852 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6853 | return -EOPNOTSUPP; | |
04a773ad | 6854 | |
4c476991 | 6855 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6856 | } |
6857 | ||
f4e583c8 AQ |
6858 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6859 | { | |
6860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6861 | struct net_device *dev = info->user_ptr[1]; | |
6862 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6863 | u32 nla_rate; | |
6864 | int err; | |
6865 | ||
6866 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6867 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6868 | return -EOPNOTSUPP; | |
6869 | ||
6870 | if (!rdev->ops->set_mcast_rate) | |
6871 | return -EOPNOTSUPP; | |
6872 | ||
6873 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6874 | ||
6875 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6876 | return -EINVAL; | |
6877 | ||
6878 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6879 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6880 | return -EINVAL; | |
6881 | ||
6882 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6883 | ||
6884 | return err; | |
6885 | } | |
6886 | ||
ad7e718c JB |
6887 | static struct sk_buff * |
6888 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6889 | int approxlen, u32 portid, u32 seq, | |
6890 | enum nl80211_commands cmd, | |
567ffc35 JB |
6891 | enum nl80211_attrs attr, |
6892 | const struct nl80211_vendor_cmd_info *info, | |
6893 | gfp_t gfp) | |
ad7e718c JB |
6894 | { |
6895 | struct sk_buff *skb; | |
6896 | void *hdr; | |
6897 | struct nlattr *data; | |
6898 | ||
6899 | skb = nlmsg_new(approxlen + 100, gfp); | |
6900 | if (!skb) | |
6901 | return NULL; | |
6902 | ||
6903 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
6904 | if (!hdr) { | |
6905 | kfree_skb(skb); | |
6906 | return NULL; | |
6907 | } | |
6908 | ||
6909 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
6910 | goto nla_put_failure; | |
567ffc35 JB |
6911 | |
6912 | if (info) { | |
6913 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
6914 | info->vendor_id)) | |
6915 | goto nla_put_failure; | |
6916 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
6917 | info->subcmd)) | |
6918 | goto nla_put_failure; | |
6919 | } | |
6920 | ||
ad7e718c JB |
6921 | data = nla_nest_start(skb, attr); |
6922 | ||
6923 | ((void **)skb->cb)[0] = rdev; | |
6924 | ((void **)skb->cb)[1] = hdr; | |
6925 | ((void **)skb->cb)[2] = data; | |
6926 | ||
6927 | return skb; | |
6928 | ||
6929 | nla_put_failure: | |
6930 | kfree_skb(skb); | |
6931 | return NULL; | |
6932 | } | |
f4e583c8 | 6933 | |
e03ad6ea JB |
6934 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6935 | enum nl80211_commands cmd, | |
6936 | enum nl80211_attrs attr, | |
6937 | int vendor_event_idx, | |
6938 | int approxlen, gfp_t gfp) | |
6939 | { | |
f26cbf40 | 6940 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
6941 | const struct nl80211_vendor_cmd_info *info; |
6942 | ||
6943 | switch (cmd) { | |
6944 | case NL80211_CMD_TESTMODE: | |
6945 | if (WARN_ON(vendor_event_idx != -1)) | |
6946 | return NULL; | |
6947 | info = NULL; | |
6948 | break; | |
6949 | case NL80211_CMD_VENDOR: | |
6950 | if (WARN_ON(vendor_event_idx < 0 || | |
6951 | vendor_event_idx >= wiphy->n_vendor_events)) | |
6952 | return NULL; | |
6953 | info = &wiphy->vendor_events[vendor_event_idx]; | |
6954 | break; | |
6955 | default: | |
6956 | WARN_ON(1); | |
6957 | return NULL; | |
6958 | } | |
6959 | ||
6960 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
6961 | cmd, attr, info, gfp); | |
6962 | } | |
6963 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
6964 | ||
6965 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
6966 | { | |
6967 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6968 | void *hdr = ((void **)skb->cb)[1]; | |
6969 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6970 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
6971 | ||
6972 | nla_nest_end(skb, data); | |
6973 | genlmsg_end(skb, hdr); | |
6974 | ||
6975 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
6976 | mcgrp = NL80211_MCGRP_VENDOR; | |
6977 | ||
6978 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
6979 | mcgrp, gfp); | |
6980 | } | |
6981 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
6982 | ||
aff89a9b | 6983 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
6984 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
6985 | { | |
4c476991 | 6986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
6987 | struct wireless_dev *wdev = |
6988 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
6989 | int err; |
6990 | ||
fc73f11f DS |
6991 | if (!rdev->ops->testmode_cmd) |
6992 | return -EOPNOTSUPP; | |
6993 | ||
6994 | if (IS_ERR(wdev)) { | |
6995 | err = PTR_ERR(wdev); | |
6996 | if (err != -EINVAL) | |
6997 | return err; | |
6998 | wdev = NULL; | |
6999 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7000 | return -EINVAL; | |
7001 | } | |
7002 | ||
aff89a9b JB |
7003 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7004 | return -EINVAL; | |
7005 | ||
ad7e718c | 7006 | rdev->cur_cmd_info = info; |
fc73f11f | 7007 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7008 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7009 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7010 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7011 | |
aff89a9b JB |
7012 | return err; |
7013 | } | |
7014 | ||
71063f0e WYG |
7015 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7016 | struct netlink_callback *cb) | |
7017 | { | |
00918d33 | 7018 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7019 | int err; |
7020 | long phy_idx; | |
7021 | void *data = NULL; | |
7022 | int data_len = 0; | |
7023 | ||
5fe231e8 JB |
7024 | rtnl_lock(); |
7025 | ||
71063f0e WYG |
7026 | if (cb->args[0]) { |
7027 | /* | |
7028 | * 0 is a valid index, but not valid for args[0], | |
7029 | * so we need to offset by 1. | |
7030 | */ | |
7031 | phy_idx = cb->args[0] - 1; | |
7032 | } else { | |
7033 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7034 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7035 | nl80211_policy); | |
7036 | if (err) | |
5fe231e8 | 7037 | goto out_err; |
00918d33 | 7038 | |
2bd7e35d JB |
7039 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7040 | nl80211_fam.attrbuf); | |
7041 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7042 | err = PTR_ERR(rdev); |
7043 | goto out_err; | |
00918d33 | 7044 | } |
2bd7e35d JB |
7045 | phy_idx = rdev->wiphy_idx; |
7046 | rdev = NULL; | |
2bd7e35d | 7047 | |
71063f0e WYG |
7048 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7049 | cb->args[1] = | |
7050 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7051 | } | |
7052 | ||
7053 | if (cb->args[1]) { | |
7054 | data = nla_data((void *)cb->args[1]); | |
7055 | data_len = nla_len((void *)cb->args[1]); | |
7056 | } | |
7057 | ||
00918d33 JB |
7058 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7059 | if (!rdev) { | |
5fe231e8 JB |
7060 | err = -ENOENT; |
7061 | goto out_err; | |
71063f0e | 7062 | } |
71063f0e | 7063 | |
00918d33 | 7064 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7065 | err = -EOPNOTSUPP; |
7066 | goto out_err; | |
7067 | } | |
7068 | ||
7069 | while (1) { | |
15e47304 | 7070 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7071 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7072 | NL80211_CMD_TESTMODE); | |
7073 | struct nlattr *tmdata; | |
7074 | ||
cb35fba3 DC |
7075 | if (!hdr) |
7076 | break; | |
7077 | ||
9360ffd1 | 7078 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7079 | genlmsg_cancel(skb, hdr); |
7080 | break; | |
7081 | } | |
7082 | ||
7083 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7084 | if (!tmdata) { | |
7085 | genlmsg_cancel(skb, hdr); | |
7086 | break; | |
7087 | } | |
e35e4d28 | 7088 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7089 | nla_nest_end(skb, tmdata); |
7090 | ||
7091 | if (err == -ENOBUFS || err == -ENOENT) { | |
7092 | genlmsg_cancel(skb, hdr); | |
7093 | break; | |
7094 | } else if (err) { | |
7095 | genlmsg_cancel(skb, hdr); | |
7096 | goto out_err; | |
7097 | } | |
7098 | ||
7099 | genlmsg_end(skb, hdr); | |
7100 | } | |
7101 | ||
7102 | err = skb->len; | |
7103 | /* see above */ | |
7104 | cb->args[0] = phy_idx + 1; | |
7105 | out_err: | |
5fe231e8 | 7106 | rtnl_unlock(); |
71063f0e WYG |
7107 | return err; |
7108 | } | |
aff89a9b JB |
7109 | #endif |
7110 | ||
b23aa676 SO |
7111 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7112 | { | |
4c476991 JB |
7113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7114 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7115 | struct cfg80211_connect_params connect; |
7116 | struct wiphy *wiphy; | |
fffd0934 | 7117 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7118 | int err; |
7119 | ||
7120 | memset(&connect, 0, sizeof(connect)); | |
7121 | ||
7122 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7123 | return -EINVAL; | |
7124 | ||
7125 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7126 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7127 | return -EINVAL; | |
7128 | ||
7129 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7130 | connect.auth_type = | |
7131 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7132 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7133 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7134 | return -EINVAL; |
7135 | } else | |
7136 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7137 | ||
7138 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7139 | ||
c0692b8f | 7140 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7141 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7142 | if (err) |
7143 | return err; | |
b23aa676 | 7144 | |
074ac8df | 7145 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7146 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7147 | return -EOPNOTSUPP; | |
b23aa676 | 7148 | |
79c97e97 | 7149 | wiphy = &rdev->wiphy; |
b23aa676 | 7150 | |
4486ea98 BS |
7151 | connect.bg_scan_period = -1; |
7152 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7153 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7154 | connect.bg_scan_period = | |
7155 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7156 | } | |
7157 | ||
b23aa676 SO |
7158 | if (info->attrs[NL80211_ATTR_MAC]) |
7159 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7160 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7161 | connect.bssid_hint = | |
7162 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7163 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7164 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7165 | ||
7166 | if (info->attrs[NL80211_ATTR_IE]) { | |
7167 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7168 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7169 | } | |
7170 | ||
cee00a95 JM |
7171 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7172 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7173 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7174 | connect.mfp != NL80211_MFP_NO) | |
7175 | return -EINVAL; | |
7176 | } else { | |
7177 | connect.mfp = NL80211_MFP_NO; | |
7178 | } | |
7179 | ||
b23aa676 | 7180 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7181 | connect.channel = nl80211_get_valid_chan( |
7182 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7183 | if (!connect.channel) | |
1df4a510 JM |
7184 | return -EINVAL; |
7185 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7186 | connect.channel_hint = nl80211_get_valid_chan( |
7187 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7188 | if (!connect.channel_hint) | |
4c476991 | 7189 | return -EINVAL; |
b23aa676 SO |
7190 | } |
7191 | ||
fffd0934 JB |
7192 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7193 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7194 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7195 | if (IS_ERR(connkeys)) |
7196 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7197 | } |
7198 | ||
7e7c8926 BG |
7199 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7200 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7201 | ||
7202 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7203 | memcpy(&connect.ht_capa_mask, | |
7204 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7205 | sizeof(connect.ht_capa_mask)); | |
7206 | ||
7207 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
7208 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
7209 | kfree(connkeys); | |
7e7c8926 | 7210 | return -EINVAL; |
b4e4f47e | 7211 | } |
7e7c8926 BG |
7212 | memcpy(&connect.ht_capa, |
7213 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7214 | sizeof(connect.ht_capa)); | |
7215 | } | |
7216 | ||
ee2aca34 JB |
7217 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7218 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7219 | ||
7220 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7221 | memcpy(&connect.vht_capa_mask, | |
7222 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7223 | sizeof(connect.vht_capa_mask)); | |
7224 | ||
7225 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7226 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
7227 | kfree(connkeys); | |
7228 | return -EINVAL; | |
7229 | } | |
7230 | memcpy(&connect.vht_capa, | |
7231 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7232 | sizeof(connect.vht_capa)); | |
7233 | } | |
7234 | ||
83739b03 JB |
7235 | wdev_lock(dev->ieee80211_ptr); |
7236 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7237 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
7238 | if (err) |
7239 | kfree(connkeys); | |
b23aa676 SO |
7240 | return err; |
7241 | } | |
7242 | ||
7243 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7244 | { | |
4c476991 JB |
7245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7246 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7247 | u16 reason; |
83739b03 | 7248 | int ret; |
b23aa676 SO |
7249 | |
7250 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7251 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7252 | else | |
7253 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7254 | ||
7255 | if (reason == 0) | |
7256 | return -EINVAL; | |
7257 | ||
074ac8df | 7258 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7259 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7260 | return -EOPNOTSUPP; | |
b23aa676 | 7261 | |
83739b03 JB |
7262 | wdev_lock(dev->ieee80211_ptr); |
7263 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7264 | wdev_unlock(dev->ieee80211_ptr); | |
7265 | return ret; | |
b23aa676 SO |
7266 | } |
7267 | ||
463d0183 JB |
7268 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7269 | { | |
4c476991 | 7270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7271 | struct net *net; |
7272 | int err; | |
7273 | u32 pid; | |
7274 | ||
7275 | if (!info->attrs[NL80211_ATTR_PID]) | |
7276 | return -EINVAL; | |
7277 | ||
7278 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7279 | ||
463d0183 | 7280 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7281 | if (IS_ERR(net)) |
7282 | return PTR_ERR(net); | |
463d0183 JB |
7283 | |
7284 | err = 0; | |
7285 | ||
7286 | /* check if anything to do */ | |
4c476991 JB |
7287 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7288 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7289 | |
463d0183 | 7290 | put_net(net); |
463d0183 JB |
7291 | return err; |
7292 | } | |
7293 | ||
67fbb16b SO |
7294 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7295 | { | |
4c476991 | 7296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7297 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7298 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7299 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7300 | struct cfg80211_pmksa pmksa; |
7301 | ||
7302 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7303 | ||
7304 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7305 | return -EINVAL; | |
7306 | ||
7307 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7308 | return -EINVAL; | |
7309 | ||
67fbb16b SO |
7310 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7311 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7312 | ||
074ac8df | 7313 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7314 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7315 | return -EOPNOTSUPP; | |
67fbb16b SO |
7316 | |
7317 | switch (info->genlhdr->cmd) { | |
7318 | case NL80211_CMD_SET_PMKSA: | |
7319 | rdev_ops = rdev->ops->set_pmksa; | |
7320 | break; | |
7321 | case NL80211_CMD_DEL_PMKSA: | |
7322 | rdev_ops = rdev->ops->del_pmksa; | |
7323 | break; | |
7324 | default: | |
7325 | WARN_ON(1); | |
7326 | break; | |
7327 | } | |
7328 | ||
4c476991 JB |
7329 | if (!rdev_ops) |
7330 | return -EOPNOTSUPP; | |
67fbb16b | 7331 | |
4c476991 | 7332 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7333 | } |
7334 | ||
7335 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7336 | { | |
4c476991 JB |
7337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7338 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7339 | |
074ac8df | 7340 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7341 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7342 | return -EOPNOTSUPP; | |
67fbb16b | 7343 | |
4c476991 JB |
7344 | if (!rdev->ops->flush_pmksa) |
7345 | return -EOPNOTSUPP; | |
67fbb16b | 7346 | |
e35e4d28 | 7347 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7348 | } |
7349 | ||
109086ce AN |
7350 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7351 | { | |
7352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7353 | struct net_device *dev = info->user_ptr[1]; | |
7354 | u8 action_code, dialog_token; | |
df942e7b | 7355 | u32 peer_capability = 0; |
109086ce AN |
7356 | u16 status_code; |
7357 | u8 *peer; | |
31fa97c5 | 7358 | bool initiator; |
109086ce AN |
7359 | |
7360 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7361 | !rdev->ops->tdls_mgmt) | |
7362 | return -EOPNOTSUPP; | |
7363 | ||
7364 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7365 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7366 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7367 | !info->attrs[NL80211_ATTR_IE] || | |
7368 | !info->attrs[NL80211_ATTR_MAC]) | |
7369 | return -EINVAL; | |
7370 | ||
7371 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7372 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7373 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7374 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7375 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7376 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7377 | peer_capability = | |
7378 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7379 | |
e35e4d28 | 7380 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7381 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7382 | initiator, |
e35e4d28 HG |
7383 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7384 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7385 | } |
7386 | ||
7387 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7388 | { | |
7389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7390 | struct net_device *dev = info->user_ptr[1]; | |
7391 | enum nl80211_tdls_operation operation; | |
7392 | u8 *peer; | |
7393 | ||
7394 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7395 | !rdev->ops->tdls_oper) | |
7396 | return -EOPNOTSUPP; | |
7397 | ||
7398 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7399 | !info->attrs[NL80211_ATTR_MAC]) | |
7400 | return -EINVAL; | |
7401 | ||
7402 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7403 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7404 | ||
e35e4d28 | 7405 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7406 | } |
7407 | ||
9588bbd5 JM |
7408 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7409 | struct genl_info *info) | |
7410 | { | |
4c476991 | 7411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7412 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7413 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7414 | struct sk_buff *msg; |
7415 | void *hdr; | |
7416 | u64 cookie; | |
683b6d3b | 7417 | u32 duration; |
9588bbd5 JM |
7418 | int err; |
7419 | ||
7420 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7421 | !info->attrs[NL80211_ATTR_DURATION]) | |
7422 | return -EINVAL; | |
7423 | ||
7424 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7425 | ||
ebf348fc JB |
7426 | if (!rdev->ops->remain_on_channel || |
7427 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7428 | return -EOPNOTSUPP; | |
7429 | ||
9588bbd5 | 7430 | /* |
ebf348fc JB |
7431 | * We should be on that channel for at least a minimum amount of |
7432 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7433 | */ |
ebf348fc | 7434 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7435 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7436 | return -EINVAL; |
7437 | ||
683b6d3b JB |
7438 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7439 | if (err) | |
7440 | return err; | |
9588bbd5 JM |
7441 | |
7442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7443 | if (!msg) |
7444 | return -ENOMEM; | |
9588bbd5 | 7445 | |
15e47304 | 7446 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7447 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7448 | if (!hdr) { |
7449 | err = -ENOBUFS; | |
9588bbd5 JM |
7450 | goto free_msg; |
7451 | } | |
7452 | ||
683b6d3b JB |
7453 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7454 | duration, &cookie); | |
9588bbd5 JM |
7455 | |
7456 | if (err) | |
7457 | goto free_msg; | |
7458 | ||
9360ffd1 DM |
7459 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7460 | goto nla_put_failure; | |
9588bbd5 JM |
7461 | |
7462 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7463 | |
7464 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7465 | |
7466 | nla_put_failure: | |
7467 | err = -ENOBUFS; | |
7468 | free_msg: | |
7469 | nlmsg_free(msg); | |
9588bbd5 JM |
7470 | return err; |
7471 | } | |
7472 | ||
7473 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7474 | struct genl_info *info) | |
7475 | { | |
4c476991 | 7476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7477 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7478 | u64 cookie; |
9588bbd5 JM |
7479 | |
7480 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7481 | return -EINVAL; | |
7482 | ||
4c476991 JB |
7483 | if (!rdev->ops->cancel_remain_on_channel) |
7484 | return -EOPNOTSUPP; | |
9588bbd5 | 7485 | |
9588bbd5 JM |
7486 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7487 | ||
e35e4d28 | 7488 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7489 | } |
7490 | ||
13ae75b1 JM |
7491 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7492 | u8 *rates, u8 rates_len) | |
7493 | { | |
7494 | u8 i; | |
7495 | u32 mask = 0; | |
7496 | ||
7497 | for (i = 0; i < rates_len; i++) { | |
7498 | int rate = (rates[i] & 0x7f) * 5; | |
7499 | int ridx; | |
7500 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7501 | struct ieee80211_rate *srate = | |
7502 | &sband->bitrates[ridx]; | |
7503 | if (rate == srate->bitrate) { | |
7504 | mask |= 1 << ridx; | |
7505 | break; | |
7506 | } | |
7507 | } | |
7508 | if (ridx == sband->n_bitrates) | |
7509 | return 0; /* rate not found */ | |
7510 | } | |
7511 | ||
7512 | return mask; | |
7513 | } | |
7514 | ||
24db78c0 SW |
7515 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7516 | u8 *rates, u8 rates_len, | |
7517 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7518 | { | |
7519 | u8 i; | |
7520 | ||
7521 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7522 | ||
7523 | for (i = 0; i < rates_len; i++) { | |
7524 | int ridx, rbit; | |
7525 | ||
7526 | ridx = rates[i] / 8; | |
7527 | rbit = BIT(rates[i] % 8); | |
7528 | ||
7529 | /* check validity */ | |
910570b5 | 7530 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7531 | return false; |
7532 | ||
7533 | /* check availability */ | |
7534 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7535 | mcs[ridx] |= rbit; | |
7536 | else | |
7537 | return false; | |
7538 | } | |
7539 | ||
7540 | return true; | |
7541 | } | |
7542 | ||
204e35a9 JD |
7543 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7544 | { | |
7545 | u16 mcs_mask = 0; | |
7546 | ||
7547 | switch (vht_mcs_map) { | |
7548 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7549 | break; | |
7550 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7551 | mcs_mask = 0x00FF; | |
7552 | break; | |
7553 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7554 | mcs_mask = 0x01FF; | |
7555 | break; | |
7556 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7557 | mcs_mask = 0x03FF; | |
7558 | break; | |
7559 | default: | |
7560 | break; | |
7561 | } | |
7562 | ||
7563 | return mcs_mask; | |
7564 | } | |
7565 | ||
7566 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7567 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7568 | { | |
7569 | u8 nss; | |
7570 | ||
7571 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7572 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7573 | vht_mcs_map >>= 2; | |
7574 | } | |
7575 | } | |
7576 | ||
7577 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7578 | struct nl80211_txrate_vht *txrate, | |
7579 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7580 | { | |
7581 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7582 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7583 | u8 i; | |
7584 | ||
7585 | if (!sband->vht_cap.vht_supported) | |
7586 | return false; | |
7587 | ||
7588 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7589 | ||
7590 | /* Build vht_mcs_mask from VHT capabilities */ | |
7591 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7592 | ||
7593 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7594 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7595 | mcs[i] = txrate->mcs[i]; | |
7596 | else | |
7597 | return false; | |
7598 | } | |
7599 | ||
7600 | return true; | |
7601 | } | |
7602 | ||
b54452b0 | 7603 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7604 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7605 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7606 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7607 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7608 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 7609 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
7610 | }; |
7611 | ||
7612 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7613 | struct genl_info *info) | |
7614 | { | |
7615 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7617 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7618 | int rem, i; |
7619 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7620 | struct nlattr *tx_rates; |
7621 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7622 | u16 vht_tx_mcs_map; |
13ae75b1 | 7623 | |
4c476991 JB |
7624 | if (!rdev->ops->set_bitrate_mask) |
7625 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7626 | |
7627 | memset(&mask, 0, sizeof(mask)); | |
7628 | /* Default to all rates enabled */ | |
7629 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7630 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7631 | |
7632 | if (!sband) | |
7633 | continue; | |
7634 | ||
7635 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7636 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7637 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7638 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7639 | |
7640 | if (!sband->vht_cap.vht_supported) | |
7641 | continue; | |
7642 | ||
7643 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7644 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7645 | } |
7646 | ||
b9243ab0 JD |
7647 | /* if no rates are given set it back to the defaults */ |
7648 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7649 | goto out; | |
7650 | ||
13ae75b1 JM |
7651 | /* |
7652 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7653 | * directly to the enum ieee80211_band values used in cfg80211. | |
7654 | */ | |
24db78c0 | 7655 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 7656 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 7657 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
7658 | int err; |
7659 | ||
4c476991 JB |
7660 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7661 | return -EINVAL; | |
13ae75b1 | 7662 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7663 | if (sband == NULL) |
7664 | return -EINVAL; | |
ae811e21 JB |
7665 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7666 | nla_len(tx_rates), nl80211_txattr_policy); | |
7667 | if (err) | |
7668 | return err; | |
13ae75b1 JM |
7669 | if (tb[NL80211_TXRATE_LEGACY]) { |
7670 | mask.control[band].legacy = rateset_to_mask( | |
7671 | sband, | |
7672 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7673 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7674 | if ((mask.control[band].legacy == 0) && |
7675 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7676 | return -EINVAL; | |
24db78c0 | 7677 | } |
d1e33e65 | 7678 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7679 | if (!ht_rateset_to_mask( |
7680 | sband, | |
d1e33e65 JD |
7681 | nla_data(tb[NL80211_TXRATE_HT]), |
7682 | nla_len(tb[NL80211_TXRATE_HT]), | |
7683 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7684 | return -EINVAL; |
7685 | } | |
204e35a9 JD |
7686 | if (tb[NL80211_TXRATE_VHT]) { |
7687 | if (!vht_set_mcs_mask( | |
7688 | sband, | |
7689 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7690 | mask.control[band].vht_mcs)) | |
7691 | return -EINVAL; | |
7692 | } | |
0b9323f6 JD |
7693 | if (tb[NL80211_TXRATE_GI]) { |
7694 | mask.control[band].gi = | |
7695 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
7696 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
7697 | return -EINVAL; | |
7698 | } | |
24db78c0 SW |
7699 | |
7700 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7701 | /* don't allow empty legacy rates if HT or VHT |
7702 | * are not even supported. | |
7703 | */ | |
7704 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7705 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7706 | return -EINVAL; |
7707 | ||
7708 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7709 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7710 | goto out; |
7711 | ||
7712 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7713 | if (mask.control[band].vht_mcs[i]) | |
7714 | goto out; | |
24db78c0 SW |
7715 | |
7716 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7717 | return -EINVAL; |
13ae75b1 JM |
7718 | } |
7719 | } | |
7720 | ||
b9243ab0 | 7721 | out: |
e35e4d28 | 7722 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7723 | } |
7724 | ||
2e161f78 | 7725 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7726 | { |
4c476991 | 7727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7728 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7729 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7730 | |
7731 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7732 | return -EINVAL; | |
7733 | ||
2e161f78 JB |
7734 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7735 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7736 | |
71bbc994 JB |
7737 | switch (wdev->iftype) { |
7738 | case NL80211_IFTYPE_STATION: | |
7739 | case NL80211_IFTYPE_ADHOC: | |
7740 | case NL80211_IFTYPE_P2P_CLIENT: | |
7741 | case NL80211_IFTYPE_AP: | |
7742 | case NL80211_IFTYPE_AP_VLAN: | |
7743 | case NL80211_IFTYPE_MESH_POINT: | |
7744 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7745 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7746 | break; |
7747 | default: | |
4c476991 | 7748 | return -EOPNOTSUPP; |
71bbc994 | 7749 | } |
026331c4 JM |
7750 | |
7751 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7752 | if (!rdev->ops->mgmt_tx) |
7753 | return -EOPNOTSUPP; | |
026331c4 | 7754 | |
15e47304 | 7755 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7756 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7757 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7758 | } |
7759 | ||
2e161f78 | 7760 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7761 | { |
4c476991 | 7762 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7763 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7764 | struct cfg80211_chan_def chandef; |
026331c4 | 7765 | int err; |
d64d373f | 7766 | void *hdr = NULL; |
026331c4 | 7767 | u64 cookie; |
e247bd90 | 7768 | struct sk_buff *msg = NULL; |
b176e629 AO |
7769 | struct cfg80211_mgmt_tx_params params = { |
7770 | .dont_wait_for_ack = | |
7771 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7772 | }; | |
026331c4 | 7773 | |
683b6d3b | 7774 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7775 | return -EINVAL; |
7776 | ||
4c476991 JB |
7777 | if (!rdev->ops->mgmt_tx) |
7778 | return -EOPNOTSUPP; | |
026331c4 | 7779 | |
71bbc994 | 7780 | switch (wdev->iftype) { |
ea141b75 AQ |
7781 | case NL80211_IFTYPE_P2P_DEVICE: |
7782 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7783 | return -EINVAL; | |
71bbc994 JB |
7784 | case NL80211_IFTYPE_STATION: |
7785 | case NL80211_IFTYPE_ADHOC: | |
7786 | case NL80211_IFTYPE_P2P_CLIENT: | |
7787 | case NL80211_IFTYPE_AP: | |
7788 | case NL80211_IFTYPE_AP_VLAN: | |
7789 | case NL80211_IFTYPE_MESH_POINT: | |
7790 | case NL80211_IFTYPE_P2P_GO: | |
7791 | break; | |
7792 | default: | |
4c476991 | 7793 | return -EOPNOTSUPP; |
71bbc994 | 7794 | } |
026331c4 | 7795 | |
f7ca38df | 7796 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7797 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7798 | return -EINVAL; |
b176e629 | 7799 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7800 | |
7801 | /* | |
7802 | * We should wait on the channel for at least a minimum amount | |
7803 | * of time (10ms) but no longer than the driver supports. | |
7804 | */ | |
b176e629 AO |
7805 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7806 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7807 | return -EINVAL; |
7808 | ||
f7ca38df JB |
7809 | } |
7810 | ||
b176e629 | 7811 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 7812 | |
b176e629 | 7813 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
7814 | return -EINVAL; |
7815 | ||
b176e629 | 7816 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 7817 | |
ea141b75 AQ |
7818 | /* get the channel if any has been specified, otherwise pass NULL to |
7819 | * the driver. The latter will use the current one | |
7820 | */ | |
7821 | chandef.chan = NULL; | |
7822 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7823 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7824 | if (err) | |
7825 | return err; | |
7826 | } | |
7827 | ||
b176e629 | 7828 | if (!chandef.chan && params.offchan) |
ea141b75 | 7829 | return -EINVAL; |
026331c4 | 7830 | |
34d22ce2 AO |
7831 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
7832 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
7833 | ||
7834 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
7835 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
7836 | int i; | |
7837 | ||
7838 | if (len % sizeof(u16)) | |
7839 | return -EINVAL; | |
7840 | ||
7841 | params.n_csa_offsets = len / sizeof(u16); | |
7842 | params.csa_offsets = | |
7843 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
7844 | ||
7845 | /* check that all the offsets fit the frame */ | |
7846 | for (i = 0; i < params.n_csa_offsets; i++) { | |
7847 | if (params.csa_offsets[i] >= params.len) | |
7848 | return -EINVAL; | |
7849 | } | |
7850 | } | |
7851 | ||
b176e629 | 7852 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
7853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7854 | if (!msg) | |
7855 | return -ENOMEM; | |
026331c4 | 7856 | |
15e47304 | 7857 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7858 | NL80211_CMD_FRAME); |
cb35fba3 DC |
7859 | if (!hdr) { |
7860 | err = -ENOBUFS; | |
e247bd90 JB |
7861 | goto free_msg; |
7862 | } | |
026331c4 | 7863 | } |
e247bd90 | 7864 | |
b176e629 AO |
7865 | params.chan = chandef.chan; |
7866 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
7867 | if (err) |
7868 | goto free_msg; | |
7869 | ||
e247bd90 | 7870 | if (msg) { |
9360ffd1 DM |
7871 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7872 | goto nla_put_failure; | |
026331c4 | 7873 | |
e247bd90 JB |
7874 | genlmsg_end(msg, hdr); |
7875 | return genlmsg_reply(msg, info); | |
7876 | } | |
7877 | ||
7878 | return 0; | |
026331c4 JM |
7879 | |
7880 | nla_put_failure: | |
7881 | err = -ENOBUFS; | |
7882 | free_msg: | |
7883 | nlmsg_free(msg); | |
026331c4 JM |
7884 | return err; |
7885 | } | |
7886 | ||
f7ca38df JB |
7887 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7888 | { | |
7889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7890 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7891 | u64 cookie; |
7892 | ||
7893 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7894 | return -EINVAL; | |
7895 | ||
7896 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7897 | return -EOPNOTSUPP; | |
7898 | ||
71bbc994 JB |
7899 | switch (wdev->iftype) { |
7900 | case NL80211_IFTYPE_STATION: | |
7901 | case NL80211_IFTYPE_ADHOC: | |
7902 | case NL80211_IFTYPE_P2P_CLIENT: | |
7903 | case NL80211_IFTYPE_AP: | |
7904 | case NL80211_IFTYPE_AP_VLAN: | |
7905 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7906 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7907 | break; |
7908 | default: | |
f7ca38df | 7909 | return -EOPNOTSUPP; |
71bbc994 | 7910 | } |
f7ca38df JB |
7911 | |
7912 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7913 | ||
e35e4d28 | 7914 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7915 | } |
7916 | ||
ffb9eb3d KV |
7917 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7918 | { | |
4c476991 | 7919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7920 | struct wireless_dev *wdev; |
4c476991 | 7921 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7922 | u8 ps_state; |
7923 | bool state; | |
7924 | int err; | |
7925 | ||
4c476991 JB |
7926 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7927 | return -EINVAL; | |
ffb9eb3d KV |
7928 | |
7929 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7930 | ||
4c476991 JB |
7931 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7932 | return -EINVAL; | |
ffb9eb3d KV |
7933 | |
7934 | wdev = dev->ieee80211_ptr; | |
7935 | ||
4c476991 JB |
7936 | if (!rdev->ops->set_power_mgmt) |
7937 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7938 | |
7939 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7940 | ||
7941 | if (state == wdev->ps) | |
4c476991 | 7942 | return 0; |
ffb9eb3d | 7943 | |
e35e4d28 | 7944 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7945 | if (!err) |
7946 | wdev->ps = state; | |
ffb9eb3d KV |
7947 | return err; |
7948 | } | |
7949 | ||
7950 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7951 | { | |
4c476991 | 7952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7953 | enum nl80211_ps_state ps_state; |
7954 | struct wireless_dev *wdev; | |
4c476991 | 7955 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7956 | struct sk_buff *msg; |
7957 | void *hdr; | |
7958 | int err; | |
7959 | ||
ffb9eb3d KV |
7960 | wdev = dev->ieee80211_ptr; |
7961 | ||
4c476991 JB |
7962 | if (!rdev->ops->set_power_mgmt) |
7963 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7964 | |
7965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7966 | if (!msg) |
7967 | return -ENOMEM; | |
ffb9eb3d | 7968 | |
15e47304 | 7969 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7970 | NL80211_CMD_GET_POWER_SAVE); |
7971 | if (!hdr) { | |
4c476991 | 7972 | err = -ENOBUFS; |
ffb9eb3d KV |
7973 | goto free_msg; |
7974 | } | |
7975 | ||
7976 | if (wdev->ps) | |
7977 | ps_state = NL80211_PS_ENABLED; | |
7978 | else | |
7979 | ps_state = NL80211_PS_DISABLED; | |
7980 | ||
9360ffd1 DM |
7981 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7982 | goto nla_put_failure; | |
ffb9eb3d KV |
7983 | |
7984 | genlmsg_end(msg, hdr); | |
4c476991 | 7985 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7986 | |
4c476991 | 7987 | nla_put_failure: |
ffb9eb3d | 7988 | err = -ENOBUFS; |
4c476991 | 7989 | free_msg: |
ffb9eb3d | 7990 | nlmsg_free(msg); |
ffb9eb3d KV |
7991 | return err; |
7992 | } | |
7993 | ||
94e860f1 JB |
7994 | static const struct nla_policy |
7995 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
7996 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
7997 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7998 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7999 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8000 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8001 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8002 | }; |
8003 | ||
84f10708 | 8004 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8005 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8006 | { |
8007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8008 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8009 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8010 | |
d9d8b019 | 8011 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8012 | return -EINVAL; |
8013 | ||
84f10708 TP |
8014 | if (!rdev->ops->set_cqm_txe_config) |
8015 | return -EOPNOTSUPP; | |
8016 | ||
8017 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8018 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8019 | return -EOPNOTSUPP; | |
8020 | ||
e35e4d28 | 8021 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8022 | } |
8023 | ||
d6dc1a38 JO |
8024 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8025 | s32 threshold, u32 hysteresis) | |
8026 | { | |
4c476991 | 8027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8028 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8029 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8030 | |
8031 | if (threshold > 0) | |
8032 | return -EINVAL; | |
8033 | ||
1da5fcc8 JB |
8034 | /* disabling - hysteresis should also be zero then */ |
8035 | if (threshold == 0) | |
8036 | hysteresis = 0; | |
d6dc1a38 | 8037 | |
4c476991 JB |
8038 | if (!rdev->ops->set_cqm_rssi_config) |
8039 | return -EOPNOTSUPP; | |
d6dc1a38 | 8040 | |
074ac8df | 8041 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8042 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8043 | return -EOPNOTSUPP; | |
d6dc1a38 | 8044 | |
e35e4d28 | 8045 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8046 | } |
8047 | ||
8048 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8049 | { | |
8050 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8051 | struct nlattr *cqm; | |
8052 | int err; | |
8053 | ||
8054 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8055 | if (!cqm) |
8056 | return -EINVAL; | |
d6dc1a38 JO |
8057 | |
8058 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8059 | nl80211_attr_cqm_policy); | |
8060 | if (err) | |
1da5fcc8 | 8061 | return err; |
d6dc1a38 JO |
8062 | |
8063 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8064 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8065 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8066 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8067 | |
1da5fcc8 JB |
8068 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8069 | } | |
8070 | ||
8071 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8072 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8073 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8074 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8075 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8076 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8077 | ||
8078 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8079 | } | |
8080 | ||
8081 | return -EINVAL; | |
d6dc1a38 JO |
8082 | } |
8083 | ||
29cbe68c JB |
8084 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8085 | { | |
8086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8087 | struct net_device *dev = info->user_ptr[1]; | |
8088 | struct mesh_config cfg; | |
c80d545d | 8089 | struct mesh_setup setup; |
29cbe68c JB |
8090 | int err; |
8091 | ||
8092 | /* start with default */ | |
8093 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8094 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8095 | |
24bdd9f4 | 8096 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8097 | /* and parse parameters if given */ |
24bdd9f4 | 8098 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8099 | if (err) |
8100 | return err; | |
8101 | } | |
8102 | ||
8103 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8104 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8105 | return -EINVAL; | |
8106 | ||
c80d545d JC |
8107 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8108 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8109 | ||
4bb62344 CYY |
8110 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8111 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8112 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8113 | return -EINVAL; | |
8114 | ||
9bdbf04d MP |
8115 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8116 | setup.beacon_interval = | |
8117 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8118 | if (setup.beacon_interval < 10 || | |
8119 | setup.beacon_interval > 10000) | |
8120 | return -EINVAL; | |
8121 | } | |
8122 | ||
8123 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8124 | setup.dtim_period = | |
8125 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8126 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8127 | return -EINVAL; | |
8128 | } | |
8129 | ||
c80d545d JC |
8130 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8131 | /* parse additional setup parameters if given */ | |
8132 | err = nl80211_parse_mesh_setup(info, &setup); | |
8133 | if (err) | |
8134 | return err; | |
8135 | } | |
8136 | ||
d37bb18a TP |
8137 | if (setup.user_mpm) |
8138 | cfg.auto_open_plinks = false; | |
8139 | ||
cc1d2806 | 8140 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8141 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8142 | if (err) | |
8143 | return err; | |
cc1d2806 JB |
8144 | } else { |
8145 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8146 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8147 | } |
8148 | ||
ffb3cf30 AN |
8149 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8150 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8151 | int n_rates = | |
8152 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8153 | struct ieee80211_supported_band *sband; | |
8154 | ||
8155 | if (!setup.chandef.chan) | |
8156 | return -EINVAL; | |
8157 | ||
8158 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8159 | ||
8160 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8161 | &setup.basic_rates); | |
8162 | if (err) | |
8163 | return err; | |
8164 | } | |
8165 | ||
c80d545d | 8166 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8167 | } |
8168 | ||
8169 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8170 | { | |
8171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8172 | struct net_device *dev = info->user_ptr[1]; | |
8173 | ||
8174 | return cfg80211_leave_mesh(rdev, dev); | |
8175 | } | |
8176 | ||
dfb89c56 | 8177 | #ifdef CONFIG_PM |
bb92d199 AK |
8178 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8179 | struct cfg80211_registered_device *rdev) | |
8180 | { | |
6abb9cb9 | 8181 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8182 | struct nlattr *nl_pats, *nl_pat; |
8183 | int i, pat_len; | |
8184 | ||
6abb9cb9 | 8185 | if (!wowlan->n_patterns) |
bb92d199 AK |
8186 | return 0; |
8187 | ||
8188 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8189 | if (!nl_pats) | |
8190 | return -ENOBUFS; | |
8191 | ||
6abb9cb9 | 8192 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8193 | nl_pat = nla_nest_start(msg, i + 1); |
8194 | if (!nl_pat) | |
8195 | return -ENOBUFS; | |
6abb9cb9 | 8196 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8197 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8198 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8199 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8200 | wowlan->patterns[i].pattern) || | |
8201 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8202 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8203 | return -ENOBUFS; |
8204 | nla_nest_end(msg, nl_pat); | |
8205 | } | |
8206 | nla_nest_end(msg, nl_pats); | |
8207 | ||
8208 | return 0; | |
8209 | } | |
8210 | ||
2a0e047e JB |
8211 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8212 | struct cfg80211_wowlan_tcp *tcp) | |
8213 | { | |
8214 | struct nlattr *nl_tcp; | |
8215 | ||
8216 | if (!tcp) | |
8217 | return 0; | |
8218 | ||
8219 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8220 | if (!nl_tcp) | |
8221 | return -ENOBUFS; | |
8222 | ||
8223 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8224 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8225 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8226 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8227 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8228 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8229 | tcp->payload_len, tcp->payload) || | |
8230 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8231 | tcp->data_interval) || | |
8232 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8233 | tcp->wake_len, tcp->wake_data) || | |
8234 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8235 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8236 | return -ENOBUFS; | |
8237 | ||
8238 | if (tcp->payload_seq.len && | |
8239 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8240 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8241 | return -ENOBUFS; | |
8242 | ||
8243 | if (tcp->payload_tok.len && | |
8244 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8245 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8246 | &tcp->payload_tok)) | |
8247 | return -ENOBUFS; | |
8248 | ||
e248ad30 JB |
8249 | nla_nest_end(msg, nl_tcp); |
8250 | ||
2a0e047e JB |
8251 | return 0; |
8252 | } | |
8253 | ||
ff1b6e69 JB |
8254 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8255 | { | |
8256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8257 | struct sk_buff *msg; | |
8258 | void *hdr; | |
2a0e047e | 8259 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8260 | |
964dc9e2 | 8261 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8262 | return -EOPNOTSUPP; |
8263 | ||
6abb9cb9 | 8264 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8265 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8266 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8267 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8268 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8269 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8270 | } |
8271 | ||
8272 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8273 | if (!msg) |
8274 | return -ENOMEM; | |
8275 | ||
15e47304 | 8276 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8277 | NL80211_CMD_GET_WOWLAN); |
8278 | if (!hdr) | |
8279 | goto nla_put_failure; | |
8280 | ||
6abb9cb9 | 8281 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8282 | struct nlattr *nl_wowlan; |
8283 | ||
8284 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8285 | if (!nl_wowlan) | |
8286 | goto nla_put_failure; | |
8287 | ||
6abb9cb9 | 8288 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8289 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8290 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8291 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8292 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8293 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8294 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8295 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8296 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8297 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8298 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8299 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8300 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8301 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8302 | goto nla_put_failure; | |
2a0e047e | 8303 | |
bb92d199 AK |
8304 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8305 | goto nla_put_failure; | |
2a0e047e | 8306 | |
6abb9cb9 JB |
8307 | if (nl80211_send_wowlan_tcp(msg, |
8308 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8309 | goto nla_put_failure; |
8310 | ||
ff1b6e69 JB |
8311 | nla_nest_end(msg, nl_wowlan); |
8312 | } | |
8313 | ||
8314 | genlmsg_end(msg, hdr); | |
8315 | return genlmsg_reply(msg, info); | |
8316 | ||
8317 | nla_put_failure: | |
8318 | nlmsg_free(msg); | |
8319 | return -ENOBUFS; | |
8320 | } | |
8321 | ||
2a0e047e JB |
8322 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8323 | struct nlattr *attr, | |
8324 | struct cfg80211_wowlan *trig) | |
8325 | { | |
8326 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8327 | struct cfg80211_wowlan_tcp *cfg; | |
8328 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8329 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8330 | u32 size; | |
8331 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8332 | int err, port; | |
8333 | ||
964dc9e2 | 8334 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8335 | return -EINVAL; |
8336 | ||
8337 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8338 | nla_data(attr), nla_len(attr), | |
8339 | nl80211_wowlan_tcp_policy); | |
8340 | if (err) | |
8341 | return err; | |
8342 | ||
8343 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8344 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8345 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8346 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8347 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8348 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8349 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8350 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8351 | return -EINVAL; | |
8352 | ||
8353 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8354 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8355 | return -EINVAL; |
8356 | ||
8357 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8358 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8359 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8360 | return -EINVAL; |
8361 | ||
8362 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8363 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8364 | return -EINVAL; |
8365 | ||
8366 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8367 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8368 | return -EINVAL; | |
8369 | ||
8370 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8371 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8372 | ||
8373 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8374 | tokens_size = tokln - sizeof(*tok); | |
8375 | ||
8376 | if (!tok->len || tokens_size % tok->len) | |
8377 | return -EINVAL; | |
964dc9e2 | 8378 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8379 | return -EINVAL; |
964dc9e2 | 8380 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8381 | return -EINVAL; |
964dc9e2 | 8382 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8383 | return -EINVAL; |
964dc9e2 | 8384 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8385 | return -EINVAL; |
8386 | if (tok->offset + tok->len > data_size) | |
8387 | return -EINVAL; | |
8388 | } | |
8389 | ||
8390 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8391 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8392 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8393 | return -EINVAL; |
8394 | if (seq->len == 0 || seq->len > 4) | |
8395 | return -EINVAL; | |
8396 | if (seq->len + seq->offset > data_size) | |
8397 | return -EINVAL; | |
8398 | } | |
8399 | ||
8400 | size = sizeof(*cfg); | |
8401 | size += data_size; | |
8402 | size += wake_size + wake_mask_size; | |
8403 | size += tokens_size; | |
8404 | ||
8405 | cfg = kzalloc(size, GFP_KERNEL); | |
8406 | if (!cfg) | |
8407 | return -ENOMEM; | |
8408 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8409 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8410 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8411 | ETH_ALEN); | |
8412 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8413 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8414 | else | |
8415 | port = 0; | |
8416 | #ifdef CONFIG_INET | |
8417 | /* allocate a socket and port for it and use it */ | |
8418 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8419 | IPPROTO_TCP, &cfg->sock, 1); | |
8420 | if (err) { | |
8421 | kfree(cfg); | |
8422 | return err; | |
8423 | } | |
8424 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8425 | sock_release(cfg->sock); | |
8426 | kfree(cfg); | |
8427 | return -EADDRINUSE; | |
8428 | } | |
8429 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8430 | #else | |
8431 | if (!port) { | |
8432 | kfree(cfg); | |
8433 | return -EINVAL; | |
8434 | } | |
8435 | cfg->src_port = port; | |
8436 | #endif | |
8437 | ||
8438 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8439 | cfg->payload_len = data_size; | |
8440 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8441 | memcpy((void *)cfg->payload, | |
8442 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8443 | data_size); | |
8444 | if (seq) | |
8445 | cfg->payload_seq = *seq; | |
8446 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8447 | cfg->wake_len = wake_size; | |
8448 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8449 | memcpy((void *)cfg->wake_data, | |
8450 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8451 | wake_size); | |
8452 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8453 | data_size + wake_size; | |
8454 | memcpy((void *)cfg->wake_mask, | |
8455 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8456 | wake_mask_size); | |
8457 | if (tok) { | |
8458 | cfg->tokens_size = tokens_size; | |
8459 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8460 | } | |
8461 | ||
8462 | trig->tcp = cfg; | |
8463 | ||
8464 | return 0; | |
8465 | } | |
8466 | ||
ff1b6e69 JB |
8467 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8468 | { | |
8469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8470 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8471 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8472 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8473 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8474 | int err, i; |
6abb9cb9 | 8475 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8476 | |
964dc9e2 | 8477 | if (!wowlan) |
ff1b6e69 JB |
8478 | return -EOPNOTSUPP; |
8479 | ||
ae33bd81 JB |
8480 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8481 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8482 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8483 | goto set_wakeup; |
8484 | } | |
ff1b6e69 JB |
8485 | |
8486 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8487 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8488 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8489 | nl80211_wowlan_policy); | |
8490 | if (err) | |
8491 | return err; | |
8492 | ||
8493 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8494 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8495 | return -EINVAL; | |
8496 | new_triggers.any = true; | |
8497 | } | |
8498 | ||
8499 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8500 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8501 | return -EINVAL; | |
8502 | new_triggers.disconnect = true; | |
8503 | } | |
8504 | ||
8505 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8506 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8507 | return -EINVAL; | |
8508 | new_triggers.magic_pkt = true; | |
8509 | } | |
8510 | ||
77dbbb13 JB |
8511 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8512 | return -EINVAL; | |
8513 | ||
8514 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8515 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8516 | return -EINVAL; | |
8517 | new_triggers.gtk_rekey_failure = true; | |
8518 | } | |
8519 | ||
8520 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8521 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8522 | return -EINVAL; | |
8523 | new_triggers.eap_identity_req = true; | |
8524 | } | |
8525 | ||
8526 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8527 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8528 | return -EINVAL; | |
8529 | new_triggers.four_way_handshake = true; | |
8530 | } | |
8531 | ||
8532 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8533 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8534 | return -EINVAL; | |
8535 | new_triggers.rfkill_release = true; | |
8536 | } | |
8537 | ||
ff1b6e69 JB |
8538 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8539 | struct nlattr *pat; | |
8540 | int n_patterns = 0; | |
bb92d199 | 8541 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8542 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8543 | |
8544 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8545 | rem) | |
8546 | n_patterns++; | |
8547 | if (n_patterns > wowlan->n_patterns) | |
8548 | return -EINVAL; | |
8549 | ||
8550 | new_triggers.patterns = kcalloc(n_patterns, | |
8551 | sizeof(new_triggers.patterns[0]), | |
8552 | GFP_KERNEL); | |
8553 | if (!new_triggers.patterns) | |
8554 | return -ENOMEM; | |
8555 | ||
8556 | new_triggers.n_patterns = n_patterns; | |
8557 | i = 0; | |
8558 | ||
8559 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8560 | rem) { | |
922bd80f JB |
8561 | u8 *mask_pat; |
8562 | ||
50ac6607 AK |
8563 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8564 | nla_len(pat), NULL); | |
ff1b6e69 | 8565 | err = -EINVAL; |
50ac6607 AK |
8566 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8567 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8568 | goto error; |
50ac6607 | 8569 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8570 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8571 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8572 | goto error; |
8573 | if (pat_len > wowlan->pattern_max_len || | |
8574 | pat_len < wowlan->pattern_min_len) | |
8575 | goto error; | |
8576 | ||
50ac6607 | 8577 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8578 | pkt_offset = 0; |
8579 | else | |
8580 | pkt_offset = nla_get_u32( | |
50ac6607 | 8581 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8582 | if (pkt_offset > wowlan->max_pkt_offset) |
8583 | goto error; | |
8584 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8585 | ||
922bd80f JB |
8586 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
8587 | if (!mask_pat) { | |
ff1b6e69 JB |
8588 | err = -ENOMEM; |
8589 | goto error; | |
8590 | } | |
922bd80f JB |
8591 | new_triggers.patterns[i].mask = mask_pat; |
8592 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 8593 | mask_len); |
922bd80f JB |
8594 | mask_pat += mask_len; |
8595 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 8596 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 8597 | memcpy(mask_pat, |
50ac6607 | 8598 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8599 | pat_len); |
8600 | i++; | |
8601 | } | |
8602 | } | |
8603 | ||
2a0e047e JB |
8604 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8605 | err = nl80211_parse_wowlan_tcp( | |
8606 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8607 | &new_triggers); | |
8608 | if (err) | |
8609 | goto error; | |
8610 | } | |
8611 | ||
ae33bd81 JB |
8612 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8613 | if (!ntrig) { | |
8614 | err = -ENOMEM; | |
8615 | goto error; | |
ff1b6e69 | 8616 | } |
ae33bd81 | 8617 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8618 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8619 | |
ae33bd81 | 8620 | set_wakeup: |
6abb9cb9 JB |
8621 | if (rdev->ops->set_wakeup && |
8622 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8623 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8624 | |
ff1b6e69 JB |
8625 | return 0; |
8626 | error: | |
8627 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8628 | kfree(new_triggers.patterns[i].mask); | |
8629 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8630 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8631 | sock_release(new_triggers.tcp->sock); | |
8632 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8633 | return err; |
8634 | } | |
dfb89c56 | 8635 | #endif |
ff1b6e69 | 8636 | |
be29b99a AK |
8637 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8638 | struct cfg80211_registered_device *rdev) | |
8639 | { | |
8640 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8641 | int i, j, pat_len; | |
8642 | struct cfg80211_coalesce_rules *rule; | |
8643 | ||
8644 | if (!rdev->coalesce->n_rules) | |
8645 | return 0; | |
8646 | ||
8647 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8648 | if (!nl_rules) | |
8649 | return -ENOBUFS; | |
8650 | ||
8651 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8652 | nl_rule = nla_nest_start(msg, i + 1); | |
8653 | if (!nl_rule) | |
8654 | return -ENOBUFS; | |
8655 | ||
8656 | rule = &rdev->coalesce->rules[i]; | |
8657 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8658 | rule->delay)) | |
8659 | return -ENOBUFS; | |
8660 | ||
8661 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8662 | rule->condition)) | |
8663 | return -ENOBUFS; | |
8664 | ||
8665 | nl_pats = nla_nest_start(msg, | |
8666 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8667 | if (!nl_pats) | |
8668 | return -ENOBUFS; | |
8669 | ||
8670 | for (j = 0; j < rule->n_patterns; j++) { | |
8671 | nl_pat = nla_nest_start(msg, j + 1); | |
8672 | if (!nl_pat) | |
8673 | return -ENOBUFS; | |
8674 | pat_len = rule->patterns[j].pattern_len; | |
8675 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8676 | DIV_ROUND_UP(pat_len, 8), | |
8677 | rule->patterns[j].mask) || | |
8678 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8679 | rule->patterns[j].pattern) || | |
8680 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8681 | rule->patterns[j].pkt_offset)) | |
8682 | return -ENOBUFS; | |
8683 | nla_nest_end(msg, nl_pat); | |
8684 | } | |
8685 | nla_nest_end(msg, nl_pats); | |
8686 | nla_nest_end(msg, nl_rule); | |
8687 | } | |
8688 | nla_nest_end(msg, nl_rules); | |
8689 | ||
8690 | return 0; | |
8691 | } | |
8692 | ||
8693 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8694 | { | |
8695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8696 | struct sk_buff *msg; | |
8697 | void *hdr; | |
8698 | ||
8699 | if (!rdev->wiphy.coalesce) | |
8700 | return -EOPNOTSUPP; | |
8701 | ||
8702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8703 | if (!msg) | |
8704 | return -ENOMEM; | |
8705 | ||
8706 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8707 | NL80211_CMD_GET_COALESCE); | |
8708 | if (!hdr) | |
8709 | goto nla_put_failure; | |
8710 | ||
8711 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8712 | goto nla_put_failure; | |
8713 | ||
8714 | genlmsg_end(msg, hdr); | |
8715 | return genlmsg_reply(msg, info); | |
8716 | ||
8717 | nla_put_failure: | |
8718 | nlmsg_free(msg); | |
8719 | return -ENOBUFS; | |
8720 | } | |
8721 | ||
8722 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8723 | { | |
8724 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8725 | int i, j; | |
8726 | struct cfg80211_coalesce_rules *rule; | |
8727 | ||
8728 | if (!coalesce) | |
8729 | return; | |
8730 | ||
8731 | for (i = 0; i < coalesce->n_rules; i++) { | |
8732 | rule = &coalesce->rules[i]; | |
8733 | for (j = 0; j < rule->n_patterns; j++) | |
8734 | kfree(rule->patterns[j].mask); | |
8735 | kfree(rule->patterns); | |
8736 | } | |
8737 | kfree(coalesce->rules); | |
8738 | kfree(coalesce); | |
8739 | rdev->coalesce = NULL; | |
8740 | } | |
8741 | ||
8742 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8743 | struct nlattr *rule, | |
8744 | struct cfg80211_coalesce_rules *new_rule) | |
8745 | { | |
8746 | int err, i; | |
8747 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8748 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8749 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8750 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8751 | ||
8752 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8753 | nla_len(rule), nl80211_coalesce_policy); | |
8754 | if (err) | |
8755 | return err; | |
8756 | ||
8757 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8758 | new_rule->delay = | |
8759 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8760 | if (new_rule->delay > coalesce->max_delay) | |
8761 | return -EINVAL; | |
8762 | ||
8763 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8764 | new_rule->condition = | |
8765 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8766 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8767 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8768 | return -EINVAL; | |
8769 | ||
8770 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8771 | return -EINVAL; | |
8772 | ||
8773 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8774 | rem) | |
8775 | n_patterns++; | |
8776 | if (n_patterns > coalesce->n_patterns) | |
8777 | return -EINVAL; | |
8778 | ||
8779 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8780 | GFP_KERNEL); | |
8781 | if (!new_rule->patterns) | |
8782 | return -ENOMEM; | |
8783 | ||
8784 | new_rule->n_patterns = n_patterns; | |
8785 | i = 0; | |
8786 | ||
8787 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8788 | rem) { | |
922bd80f JB |
8789 | u8 *mask_pat; |
8790 | ||
be29b99a AK |
8791 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8792 | nla_len(pat), NULL); | |
8793 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8794 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8795 | return -EINVAL; | |
8796 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8797 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8798 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8799 | return -EINVAL; | |
8800 | if (pat_len > coalesce->pattern_max_len || | |
8801 | pat_len < coalesce->pattern_min_len) | |
8802 | return -EINVAL; | |
8803 | ||
8804 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8805 | pkt_offset = 0; | |
8806 | else | |
8807 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8808 | if (pkt_offset > coalesce->max_pkt_offset) | |
8809 | return -EINVAL; | |
8810 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8811 | ||
922bd80f JB |
8812 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
8813 | if (!mask_pat) | |
be29b99a | 8814 | return -ENOMEM; |
922bd80f JB |
8815 | |
8816 | new_rule->patterns[i].mask = mask_pat; | |
8817 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
8818 | mask_len); | |
8819 | ||
8820 | mask_pat += mask_len; | |
8821 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 8822 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
8823 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
8824 | pat_len); | |
be29b99a AK |
8825 | i++; |
8826 | } | |
8827 | ||
8828 | return 0; | |
8829 | } | |
8830 | ||
8831 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8832 | { | |
8833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8834 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8835 | struct cfg80211_coalesce new_coalesce = {}; | |
8836 | struct cfg80211_coalesce *n_coalesce; | |
8837 | int err, rem_rule, n_rules = 0, i, j; | |
8838 | struct nlattr *rule; | |
8839 | struct cfg80211_coalesce_rules *tmp_rule; | |
8840 | ||
8841 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8842 | return -EOPNOTSUPP; | |
8843 | ||
8844 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8845 | cfg80211_rdev_free_coalesce(rdev); | |
8846 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8847 | return 0; | |
8848 | } | |
8849 | ||
8850 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8851 | rem_rule) | |
8852 | n_rules++; | |
8853 | if (n_rules > coalesce->n_rules) | |
8854 | return -EINVAL; | |
8855 | ||
8856 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8857 | GFP_KERNEL); | |
8858 | if (!new_coalesce.rules) | |
8859 | return -ENOMEM; | |
8860 | ||
8861 | new_coalesce.n_rules = n_rules; | |
8862 | i = 0; | |
8863 | ||
8864 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8865 | rem_rule) { | |
8866 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8867 | &new_coalesce.rules[i]); | |
8868 | if (err) | |
8869 | goto error; | |
8870 | ||
8871 | i++; | |
8872 | } | |
8873 | ||
8874 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8875 | if (err) | |
8876 | goto error; | |
8877 | ||
8878 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8879 | if (!n_coalesce) { | |
8880 | err = -ENOMEM; | |
8881 | goto error; | |
8882 | } | |
8883 | cfg80211_rdev_free_coalesce(rdev); | |
8884 | rdev->coalesce = n_coalesce; | |
8885 | ||
8886 | return 0; | |
8887 | error: | |
8888 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8889 | tmp_rule = &new_coalesce.rules[i]; | |
8890 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8891 | kfree(tmp_rule->patterns[j].mask); | |
8892 | kfree(tmp_rule->patterns); | |
8893 | } | |
8894 | kfree(new_coalesce.rules); | |
8895 | ||
8896 | return err; | |
8897 | } | |
8898 | ||
e5497d76 JB |
8899 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8900 | { | |
8901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8902 | struct net_device *dev = info->user_ptr[1]; | |
8903 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8904 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8905 | struct cfg80211_gtk_rekey_data rekey_data; | |
8906 | int err; | |
8907 | ||
8908 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8909 | return -EINVAL; | |
8910 | ||
8911 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8912 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8913 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8914 | nl80211_rekey_policy); | |
8915 | if (err) | |
8916 | return err; | |
8917 | ||
8918 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8919 | return -ERANGE; | |
8920 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8921 | return -ERANGE; | |
8922 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8923 | return -ERANGE; | |
8924 | ||
8925 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8926 | NL80211_KEK_LEN); | |
8927 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8928 | NL80211_KCK_LEN); | |
8929 | memcpy(rekey_data.replay_ctr, | |
8930 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8931 | NL80211_REPLAY_CTR_LEN); | |
8932 | ||
8933 | wdev_lock(wdev); | |
8934 | if (!wdev->current_bss) { | |
8935 | err = -ENOTCONN; | |
8936 | goto out; | |
8937 | } | |
8938 | ||
8939 | if (!rdev->ops->set_rekey_data) { | |
8940 | err = -EOPNOTSUPP; | |
8941 | goto out; | |
8942 | } | |
8943 | ||
e35e4d28 | 8944 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8945 | out: |
8946 | wdev_unlock(wdev); | |
8947 | return err; | |
8948 | } | |
8949 | ||
28946da7 JB |
8950 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8951 | struct genl_info *info) | |
8952 | { | |
8953 | struct net_device *dev = info->user_ptr[1]; | |
8954 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8955 | ||
8956 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8957 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8958 | return -EINVAL; | |
8959 | ||
15e47304 | 8960 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8961 | return -EBUSY; |
8962 | ||
15e47304 | 8963 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8964 | return 0; |
8965 | } | |
8966 | ||
7f6cf311 JB |
8967 | static int nl80211_probe_client(struct sk_buff *skb, |
8968 | struct genl_info *info) | |
8969 | { | |
8970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8971 | struct net_device *dev = info->user_ptr[1]; | |
8972 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8973 | struct sk_buff *msg; | |
8974 | void *hdr; | |
8975 | const u8 *addr; | |
8976 | u64 cookie; | |
8977 | int err; | |
8978 | ||
8979 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8980 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8981 | return -EOPNOTSUPP; | |
8982 | ||
8983 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8984 | return -EINVAL; | |
8985 | ||
8986 | if (!rdev->ops->probe_client) | |
8987 | return -EOPNOTSUPP; | |
8988 | ||
8989 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8990 | if (!msg) | |
8991 | return -ENOMEM; | |
8992 | ||
15e47304 | 8993 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 8994 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
8995 | if (!hdr) { |
8996 | err = -ENOBUFS; | |
7f6cf311 JB |
8997 | goto free_msg; |
8998 | } | |
8999 | ||
9000 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9001 | ||
e35e4d28 | 9002 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9003 | if (err) |
9004 | goto free_msg; | |
9005 | ||
9360ffd1 DM |
9006 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9007 | goto nla_put_failure; | |
7f6cf311 JB |
9008 | |
9009 | genlmsg_end(msg, hdr); | |
9010 | ||
9011 | return genlmsg_reply(msg, info); | |
9012 | ||
9013 | nla_put_failure: | |
9014 | err = -ENOBUFS; | |
9015 | free_msg: | |
9016 | nlmsg_free(msg); | |
9017 | return err; | |
9018 | } | |
9019 | ||
5e760230 JB |
9020 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9021 | { | |
9022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9023 | struct cfg80211_beacon_registration *reg, *nreg; |
9024 | int rv; | |
5e760230 JB |
9025 | |
9026 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9027 | return -EOPNOTSUPP; | |
9028 | ||
37c73b5f BG |
9029 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9030 | if (!nreg) | |
9031 | return -ENOMEM; | |
9032 | ||
9033 | /* First, check if already registered. */ | |
9034 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9035 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9036 | if (reg->nlportid == info->snd_portid) { | |
9037 | rv = -EALREADY; | |
9038 | goto out_err; | |
9039 | } | |
9040 | } | |
9041 | /* Add it to the list */ | |
9042 | nreg->nlportid = info->snd_portid; | |
9043 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9044 | |
37c73b5f | 9045 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9046 | |
9047 | return 0; | |
37c73b5f BG |
9048 | out_err: |
9049 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9050 | kfree(nreg); | |
9051 | return rv; | |
5e760230 JB |
9052 | } |
9053 | ||
98104fde JB |
9054 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9055 | { | |
9056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9057 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9058 | int err; | |
9059 | ||
9060 | if (!rdev->ops->start_p2p_device) | |
9061 | return -EOPNOTSUPP; | |
9062 | ||
9063 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9064 | return -EOPNOTSUPP; | |
9065 | ||
9066 | if (wdev->p2p_started) | |
9067 | return 0; | |
9068 | ||
b6a55015 LC |
9069 | if (rfkill_blocked(rdev->rfkill)) |
9070 | return -ERFKILL; | |
98104fde | 9071 | |
eeb126e9 | 9072 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9073 | if (err) |
9074 | return err; | |
9075 | ||
9076 | wdev->p2p_started = true; | |
98104fde | 9077 | rdev->opencount++; |
98104fde JB |
9078 | |
9079 | return 0; | |
9080 | } | |
9081 | ||
9082 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9083 | { | |
9084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9085 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9086 | ||
9087 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9088 | return -EOPNOTSUPP; | |
9089 | ||
9090 | if (!rdev->ops->stop_p2p_device) | |
9091 | return -EOPNOTSUPP; | |
9092 | ||
f9f47529 | 9093 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9094 | |
9095 | return 0; | |
9096 | } | |
9097 | ||
3713b4e3 JB |
9098 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9099 | struct genl_info *info) | |
9100 | { | |
9101 | void *hdr; | |
9102 | struct sk_buff *msg; | |
9103 | ||
9104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9105 | if (!msg) | |
9106 | return -ENOMEM; | |
9107 | ||
9108 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9109 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9110 | if (!hdr) | |
9111 | goto nla_put_failure; | |
9112 | ||
9113 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9114 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9115 | goto nla_put_failure; | |
9116 | ||
9117 | genlmsg_end(msg, hdr); | |
9118 | return genlmsg_reply(msg, info); | |
9119 | ||
9120 | nla_put_failure: | |
9121 | kfree_skb(msg); | |
9122 | return -ENOBUFS; | |
9123 | } | |
9124 | ||
355199e0 JM |
9125 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9126 | { | |
9127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9128 | struct cfg80211_update_ft_ies_params ft_params; | |
9129 | struct net_device *dev = info->user_ptr[1]; | |
9130 | ||
9131 | if (!rdev->ops->update_ft_ies) | |
9132 | return -EOPNOTSUPP; | |
9133 | ||
9134 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9135 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9136 | return -EINVAL; | |
9137 | ||
9138 | memset(&ft_params, 0, sizeof(ft_params)); | |
9139 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9140 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9141 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9142 | ||
9143 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9144 | } | |
9145 | ||
5de17984 AS |
9146 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9147 | struct genl_info *info) | |
9148 | { | |
9149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9150 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9151 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9152 | u16 duration; | |
9153 | int ret; | |
9154 | ||
9155 | if (!rdev->ops->crit_proto_start) | |
9156 | return -EOPNOTSUPP; | |
9157 | ||
9158 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9159 | return -EINVAL; | |
9160 | ||
9161 | if (rdev->crit_proto_nlportid) | |
9162 | return -EBUSY; | |
9163 | ||
9164 | /* determine protocol if provided */ | |
9165 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9166 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9167 | ||
9168 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9169 | return -EINVAL; | |
9170 | ||
9171 | /* timeout must be provided */ | |
9172 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9173 | return -EINVAL; | |
9174 | ||
9175 | duration = | |
9176 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9177 | ||
9178 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9179 | return -ERANGE; | |
9180 | ||
9181 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9182 | if (!ret) | |
9183 | rdev->crit_proto_nlportid = info->snd_portid; | |
9184 | ||
9185 | return ret; | |
9186 | } | |
9187 | ||
9188 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9189 | struct genl_info *info) | |
9190 | { | |
9191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9192 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9193 | ||
9194 | if (!rdev->ops->crit_proto_stop) | |
9195 | return -EOPNOTSUPP; | |
9196 | ||
9197 | if (rdev->crit_proto_nlportid) { | |
9198 | rdev->crit_proto_nlportid = 0; | |
9199 | rdev_crit_proto_stop(rdev, wdev); | |
9200 | } | |
9201 | return 0; | |
9202 | } | |
9203 | ||
ad7e718c JB |
9204 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9205 | { | |
9206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9207 | struct wireless_dev *wdev = | |
9208 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9209 | int i, err; | |
9210 | u32 vid, subcmd; | |
9211 | ||
9212 | if (!rdev->wiphy.vendor_commands) | |
9213 | return -EOPNOTSUPP; | |
9214 | ||
9215 | if (IS_ERR(wdev)) { | |
9216 | err = PTR_ERR(wdev); | |
9217 | if (err != -EINVAL) | |
9218 | return err; | |
9219 | wdev = NULL; | |
9220 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9221 | return -EINVAL; | |
9222 | } | |
9223 | ||
9224 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9225 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9226 | return -EINVAL; | |
9227 | ||
9228 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9229 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9230 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9231 | const struct wiphy_vendor_command *vcmd; | |
9232 | void *data = NULL; | |
9233 | int len = 0; | |
9234 | ||
9235 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9236 | ||
9237 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9238 | continue; | |
9239 | ||
9240 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9241 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9242 | if (!wdev) | |
9243 | return -EINVAL; | |
9244 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9245 | !wdev->netdev) | |
9246 | return -EINVAL; | |
9247 | ||
9248 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9249 | if (wdev->netdev && | |
9250 | !netif_running(wdev->netdev)) | |
9251 | return -ENETDOWN; | |
9252 | if (!wdev->netdev && !wdev->p2p_started) | |
9253 | return -ENETDOWN; | |
9254 | } | |
9255 | } else { | |
9256 | wdev = NULL; | |
9257 | } | |
9258 | ||
9259 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9260 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9261 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9262 | } | |
9263 | ||
9264 | rdev->cur_cmd_info = info; | |
9265 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9266 | data, len); | |
9267 | rdev->cur_cmd_info = NULL; | |
9268 | return err; | |
9269 | } | |
9270 | ||
9271 | return -EOPNOTSUPP; | |
9272 | } | |
9273 | ||
9274 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9275 | enum nl80211_commands cmd, | |
9276 | enum nl80211_attrs attr, | |
9277 | int approxlen) | |
9278 | { | |
f26cbf40 | 9279 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9280 | |
9281 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9282 | return NULL; | |
9283 | ||
9284 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9285 | rdev->cur_cmd_info->snd_portid, | |
9286 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9287 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9288 | } |
9289 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9290 | ||
9291 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9292 | { | |
9293 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9294 | void *hdr = ((void **)skb->cb)[1]; | |
9295 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9296 | ||
9297 | if (WARN_ON(!rdev->cur_cmd_info)) { | |
9298 | kfree_skb(skb); | |
9299 | return -EINVAL; | |
9300 | } | |
9301 | ||
9302 | nla_nest_end(skb, data); | |
9303 | genlmsg_end(skb, hdr); | |
9304 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9305 | } | |
9306 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9307 | ||
9308 | ||
fa9ffc74 KP |
9309 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9310 | struct genl_info *info) | |
9311 | { | |
9312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9313 | struct cfg80211_qos_map *qos_map = NULL; | |
9314 | struct net_device *dev = info->user_ptr[1]; | |
9315 | u8 *pos, len, num_des, des_len, des; | |
9316 | int ret; | |
9317 | ||
9318 | if (!rdev->ops->set_qos_map) | |
9319 | return -EOPNOTSUPP; | |
9320 | ||
9321 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9322 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9323 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9324 | ||
9325 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9326 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9327 | return -EINVAL; | |
9328 | ||
9329 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9330 | if (!qos_map) | |
9331 | return -ENOMEM; | |
9332 | ||
9333 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9334 | if (num_des) { | |
9335 | des_len = num_des * | |
9336 | sizeof(struct cfg80211_dscp_exception); | |
9337 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9338 | qos_map->num_des = num_des; | |
9339 | for (des = 0; des < num_des; des++) { | |
9340 | if (qos_map->dscp_exception[des].up > 7) { | |
9341 | kfree(qos_map); | |
9342 | return -EINVAL; | |
9343 | } | |
9344 | } | |
9345 | pos += des_len; | |
9346 | } | |
9347 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9348 | } | |
9349 | ||
9350 | wdev_lock(dev->ieee80211_ptr); | |
9351 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9352 | if (!ret) | |
9353 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9354 | wdev_unlock(dev->ieee80211_ptr); | |
9355 | ||
9356 | kfree(qos_map); | |
9357 | return ret; | |
9358 | } | |
9359 | ||
4c476991 JB |
9360 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9361 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9362 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9363 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9364 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9365 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9366 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9367 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9368 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9369 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 | 9370 | |
f84f771d | 9371 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9372 | struct genl_info *info) |
9373 | { | |
9374 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9375 | struct wireless_dev *wdev; |
4c476991 | 9376 | struct net_device *dev; |
4c476991 JB |
9377 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9378 | ||
9379 | if (rtnl) | |
9380 | rtnl_lock(); | |
9381 | ||
9382 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9383 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9384 | if (IS_ERR(rdev)) { |
9385 | if (rtnl) | |
9386 | rtnl_unlock(); | |
9387 | return PTR_ERR(rdev); | |
9388 | } | |
9389 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9390 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9391 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9392 | ASSERT_RTNL(); |
9393 | ||
89a54e48 JB |
9394 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9395 | info->attrs); | |
9396 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9397 | if (rtnl) |
9398 | rtnl_unlock(); | |
89a54e48 | 9399 | return PTR_ERR(wdev); |
4c476991 | 9400 | } |
89a54e48 | 9401 | |
89a54e48 | 9402 | dev = wdev->netdev; |
f26cbf40 | 9403 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 9404 | |
1bf614ef JB |
9405 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9406 | if (!dev) { | |
1bf614ef JB |
9407 | if (rtnl) |
9408 | rtnl_unlock(); | |
9409 | return -EINVAL; | |
9410 | } | |
9411 | ||
9412 | info->user_ptr[1] = dev; | |
9413 | } else { | |
9414 | info->user_ptr[1] = wdev; | |
41265714 | 9415 | } |
1bf614ef JB |
9416 | |
9417 | if (dev) { | |
9418 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9419 | !netif_running(dev)) { | |
1bf614ef JB |
9420 | if (rtnl) |
9421 | rtnl_unlock(); | |
9422 | return -ENETDOWN; | |
9423 | } | |
9424 | ||
9425 | dev_hold(dev); | |
98104fde JB |
9426 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9427 | if (!wdev->p2p_started) { | |
98104fde JB |
9428 | if (rtnl) |
9429 | rtnl_unlock(); | |
9430 | return -ENETDOWN; | |
9431 | } | |
41265714 | 9432 | } |
89a54e48 | 9433 | |
4c476991 | 9434 | info->user_ptr[0] = rdev; |
4c476991 JB |
9435 | } |
9436 | ||
9437 | return 0; | |
9438 | } | |
9439 | ||
f84f771d | 9440 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9441 | struct genl_info *info) |
9442 | { | |
1bf614ef JB |
9443 | if (info->user_ptr[1]) { |
9444 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9445 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9446 | ||
9447 | if (wdev->netdev) | |
9448 | dev_put(wdev->netdev); | |
9449 | } else { | |
9450 | dev_put(info->user_ptr[1]); | |
9451 | } | |
9452 | } | |
4c476991 JB |
9453 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9454 | rtnl_unlock(); | |
9455 | } | |
9456 | ||
4534de83 | 9457 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9458 | { |
9459 | .cmd = NL80211_CMD_GET_WIPHY, | |
9460 | .doit = nl80211_get_wiphy, | |
9461 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9462 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9463 | .policy = nl80211_policy, |
9464 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9465 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9466 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9467 | }, |
9468 | { | |
9469 | .cmd = NL80211_CMD_SET_WIPHY, | |
9470 | .doit = nl80211_set_wiphy, | |
9471 | .policy = nl80211_policy, | |
9472 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9473 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9474 | }, |
9475 | { | |
9476 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9477 | .doit = nl80211_get_interface, | |
9478 | .dumpit = nl80211_dump_interface, | |
9479 | .policy = nl80211_policy, | |
9480 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9481 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9482 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9483 | }, |
9484 | { | |
9485 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9486 | .doit = nl80211_set_interface, | |
9487 | .policy = nl80211_policy, | |
9488 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9489 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9490 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9491 | }, |
9492 | { | |
9493 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9494 | .doit = nl80211_new_interface, | |
9495 | .policy = nl80211_policy, | |
9496 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9497 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9498 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9499 | }, |
9500 | { | |
9501 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9502 | .doit = nl80211_del_interface, | |
9503 | .policy = nl80211_policy, | |
41ade00f | 9504 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9505 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9506 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9507 | }, |
9508 | { | |
9509 | .cmd = NL80211_CMD_GET_KEY, | |
9510 | .doit = nl80211_get_key, | |
9511 | .policy = nl80211_policy, | |
9512 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9514 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9515 | }, |
9516 | { | |
9517 | .cmd = NL80211_CMD_SET_KEY, | |
9518 | .doit = nl80211_set_key, | |
9519 | .policy = nl80211_policy, | |
9520 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9522 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9523 | }, |
9524 | { | |
9525 | .cmd = NL80211_CMD_NEW_KEY, | |
9526 | .doit = nl80211_new_key, | |
9527 | .policy = nl80211_policy, | |
9528 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9530 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9531 | }, |
9532 | { | |
9533 | .cmd = NL80211_CMD_DEL_KEY, | |
9534 | .doit = nl80211_del_key, | |
9535 | .policy = nl80211_policy, | |
55682965 | 9536 | .flags = GENL_ADMIN_PERM, |
41265714 | 9537 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9538 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9539 | }, |
ed1b6cc7 JB |
9540 | { |
9541 | .cmd = NL80211_CMD_SET_BEACON, | |
9542 | .policy = nl80211_policy, | |
9543 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9544 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9545 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9546 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9547 | }, |
9548 | { | |
8860020e | 9549 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9550 | .policy = nl80211_policy, |
9551 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9552 | .doit = nl80211_start_ap, |
2b5f8b0b | 9553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9554 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9555 | }, |
9556 | { | |
8860020e | 9557 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9558 | .policy = nl80211_policy, |
9559 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9560 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9562 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9563 | }, |
5727ef1b JB |
9564 | { |
9565 | .cmd = NL80211_CMD_GET_STATION, | |
9566 | .doit = nl80211_get_station, | |
2ec600d6 | 9567 | .dumpit = nl80211_dump_station, |
5727ef1b | 9568 | .policy = nl80211_policy, |
4c476991 JB |
9569 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9570 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9571 | }, |
9572 | { | |
9573 | .cmd = NL80211_CMD_SET_STATION, | |
9574 | .doit = nl80211_set_station, | |
9575 | .policy = nl80211_policy, | |
9576 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9578 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9579 | }, |
9580 | { | |
9581 | .cmd = NL80211_CMD_NEW_STATION, | |
9582 | .doit = nl80211_new_station, | |
9583 | .policy = nl80211_policy, | |
9584 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9586 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9587 | }, |
9588 | { | |
9589 | .cmd = NL80211_CMD_DEL_STATION, | |
9590 | .doit = nl80211_del_station, | |
9591 | .policy = nl80211_policy, | |
2ec600d6 | 9592 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9593 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9594 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9595 | }, |
9596 | { | |
9597 | .cmd = NL80211_CMD_GET_MPATH, | |
9598 | .doit = nl80211_get_mpath, | |
9599 | .dumpit = nl80211_dump_mpath, | |
9600 | .policy = nl80211_policy, | |
9601 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9603 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9604 | }, |
9605 | { | |
9606 | .cmd = NL80211_CMD_SET_MPATH, | |
9607 | .doit = nl80211_set_mpath, | |
9608 | .policy = nl80211_policy, | |
9609 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9611 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9612 | }, |
9613 | { | |
9614 | .cmd = NL80211_CMD_NEW_MPATH, | |
9615 | .doit = nl80211_new_mpath, | |
9616 | .policy = nl80211_policy, | |
9617 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9619 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9620 | }, |
9621 | { | |
9622 | .cmd = NL80211_CMD_DEL_MPATH, | |
9623 | .doit = nl80211_del_mpath, | |
9624 | .policy = nl80211_policy, | |
9f1ba906 | 9625 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9627 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9628 | }, |
9629 | { | |
9630 | .cmd = NL80211_CMD_SET_BSS, | |
9631 | .doit = nl80211_set_bss, | |
9632 | .policy = nl80211_policy, | |
b2e1b302 | 9633 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9635 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9636 | }, |
f130347c LR |
9637 | { |
9638 | .cmd = NL80211_CMD_GET_REG, | |
9639 | .doit = nl80211_get_reg, | |
9640 | .policy = nl80211_policy, | |
5fe231e8 | 9641 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9642 | /* can be retrieved by unprivileged users */ |
9643 | }, | |
b2e1b302 LR |
9644 | { |
9645 | .cmd = NL80211_CMD_SET_REG, | |
9646 | .doit = nl80211_set_reg, | |
9647 | .policy = nl80211_policy, | |
9648 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9649 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9650 | }, |
9651 | { | |
9652 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9653 | .doit = nl80211_req_set_reg, | |
9654 | .policy = nl80211_policy, | |
93da9cc1 | 9655 | .flags = GENL_ADMIN_PERM, |
9656 | }, | |
9657 | { | |
24bdd9f4 JC |
9658 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9659 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9660 | .policy = nl80211_policy, |
9661 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9662 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9663 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9664 | }, |
9665 | { | |
24bdd9f4 JC |
9666 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9667 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9668 | .policy = nl80211_policy, |
9aed3cc1 | 9669 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9671 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9672 | }, |
2a519311 JB |
9673 | { |
9674 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9675 | .doit = nl80211_trigger_scan, | |
9676 | .policy = nl80211_policy, | |
9677 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9678 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9679 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9680 | }, |
9681 | { | |
9682 | .cmd = NL80211_CMD_GET_SCAN, | |
9683 | .policy = nl80211_policy, | |
9684 | .dumpit = nl80211_dump_scan, | |
9685 | }, | |
807f8a8c LC |
9686 | { |
9687 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9688 | .doit = nl80211_start_sched_scan, | |
9689 | .policy = nl80211_policy, | |
9690 | .flags = GENL_ADMIN_PERM, | |
9691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9692 | NL80211_FLAG_NEED_RTNL, | |
9693 | }, | |
9694 | { | |
9695 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9696 | .doit = nl80211_stop_sched_scan, | |
9697 | .policy = nl80211_policy, | |
9698 | .flags = GENL_ADMIN_PERM, | |
9699 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9700 | NL80211_FLAG_NEED_RTNL, | |
9701 | }, | |
636a5d36 JM |
9702 | { |
9703 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9704 | .doit = nl80211_authenticate, | |
9705 | .policy = nl80211_policy, | |
9706 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9707 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9708 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9709 | }, |
9710 | { | |
9711 | .cmd = NL80211_CMD_ASSOCIATE, | |
9712 | .doit = nl80211_associate, | |
9713 | .policy = nl80211_policy, | |
9714 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9715 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9716 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9717 | }, |
9718 | { | |
9719 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9720 | .doit = nl80211_deauthenticate, | |
9721 | .policy = nl80211_policy, | |
9722 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9723 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9724 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9725 | }, |
9726 | { | |
9727 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9728 | .doit = nl80211_disassociate, | |
9729 | .policy = nl80211_policy, | |
9730 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9731 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9732 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9733 | }, |
04a773ad JB |
9734 | { |
9735 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9736 | .doit = nl80211_join_ibss, | |
9737 | .policy = nl80211_policy, | |
9738 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9740 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9741 | }, |
9742 | { | |
9743 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9744 | .doit = nl80211_leave_ibss, | |
9745 | .policy = nl80211_policy, | |
9746 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9747 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9748 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9749 | }, |
aff89a9b JB |
9750 | #ifdef CONFIG_NL80211_TESTMODE |
9751 | { | |
9752 | .cmd = NL80211_CMD_TESTMODE, | |
9753 | .doit = nl80211_testmode_do, | |
71063f0e | 9754 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9755 | .policy = nl80211_policy, |
9756 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9757 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9758 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9759 | }, |
9760 | #endif | |
b23aa676 SO |
9761 | { |
9762 | .cmd = NL80211_CMD_CONNECT, | |
9763 | .doit = nl80211_connect, | |
9764 | .policy = nl80211_policy, | |
9765 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9767 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9768 | }, |
9769 | { | |
9770 | .cmd = NL80211_CMD_DISCONNECT, | |
9771 | .doit = nl80211_disconnect, | |
9772 | .policy = nl80211_policy, | |
9773 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9775 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9776 | }, |
463d0183 JB |
9777 | { |
9778 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9779 | .doit = nl80211_wiphy_netns, | |
9780 | .policy = nl80211_policy, | |
9781 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9782 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9783 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9784 | }, |
61fa713c HS |
9785 | { |
9786 | .cmd = NL80211_CMD_GET_SURVEY, | |
9787 | .policy = nl80211_policy, | |
9788 | .dumpit = nl80211_dump_survey, | |
9789 | }, | |
67fbb16b SO |
9790 | { |
9791 | .cmd = NL80211_CMD_SET_PMKSA, | |
9792 | .doit = nl80211_setdel_pmksa, | |
9793 | .policy = nl80211_policy, | |
9794 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9795 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9796 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9797 | }, |
9798 | { | |
9799 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9800 | .doit = nl80211_setdel_pmksa, | |
9801 | .policy = nl80211_policy, | |
9802 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9804 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9805 | }, |
9806 | { | |
9807 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9808 | .doit = nl80211_flush_pmksa, | |
9809 | .policy = nl80211_policy, | |
9810 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9812 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9813 | }, |
9588bbd5 JM |
9814 | { |
9815 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9816 | .doit = nl80211_remain_on_channel, | |
9817 | .policy = nl80211_policy, | |
9818 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9819 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9820 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9821 | }, |
9822 | { | |
9823 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9824 | .doit = nl80211_cancel_remain_on_channel, | |
9825 | .policy = nl80211_policy, | |
9826 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9827 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9828 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9829 | }, |
13ae75b1 JM |
9830 | { |
9831 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9832 | .doit = nl80211_set_tx_bitrate_mask, | |
9833 | .policy = nl80211_policy, | |
9834 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9835 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9836 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9837 | }, |
026331c4 | 9838 | { |
2e161f78 JB |
9839 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9840 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9841 | .policy = nl80211_policy, |
9842 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9843 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9844 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9845 | }, |
9846 | { | |
2e161f78 JB |
9847 | .cmd = NL80211_CMD_FRAME, |
9848 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9849 | .policy = nl80211_policy, |
f7ca38df | 9850 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9851 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9852 | NL80211_FLAG_NEED_RTNL, |
9853 | }, | |
9854 | { | |
9855 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9856 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9857 | .policy = nl80211_policy, | |
026331c4 | 9858 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9859 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9860 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9861 | }, |
ffb9eb3d KV |
9862 | { |
9863 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9864 | .doit = nl80211_set_power_save, | |
9865 | .policy = nl80211_policy, | |
9866 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9867 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9868 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9869 | }, |
9870 | { | |
9871 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9872 | .doit = nl80211_get_power_save, | |
9873 | .policy = nl80211_policy, | |
9874 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9875 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9876 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9877 | }, |
d6dc1a38 JO |
9878 | { |
9879 | .cmd = NL80211_CMD_SET_CQM, | |
9880 | .doit = nl80211_set_cqm, | |
9881 | .policy = nl80211_policy, | |
9882 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9883 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9884 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9885 | }, |
f444de05 JB |
9886 | { |
9887 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9888 | .doit = nl80211_set_channel, | |
9889 | .policy = nl80211_policy, | |
9890 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9891 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9892 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9893 | }, |
e8347eba BJ |
9894 | { |
9895 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9896 | .doit = nl80211_set_wds_peer, | |
9897 | .policy = nl80211_policy, | |
9898 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9899 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9900 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9901 | }, |
29cbe68c JB |
9902 | { |
9903 | .cmd = NL80211_CMD_JOIN_MESH, | |
9904 | .doit = nl80211_join_mesh, | |
9905 | .policy = nl80211_policy, | |
9906 | .flags = GENL_ADMIN_PERM, | |
9907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9908 | NL80211_FLAG_NEED_RTNL, | |
9909 | }, | |
9910 | { | |
9911 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9912 | .doit = nl80211_leave_mesh, | |
9913 | .policy = nl80211_policy, | |
9914 | .flags = GENL_ADMIN_PERM, | |
9915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9916 | NL80211_FLAG_NEED_RTNL, | |
9917 | }, | |
dfb89c56 | 9918 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9919 | { |
9920 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9921 | .doit = nl80211_get_wowlan, | |
9922 | .policy = nl80211_policy, | |
9923 | /* can be retrieved by unprivileged users */ | |
9924 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9925 | NL80211_FLAG_NEED_RTNL, | |
9926 | }, | |
9927 | { | |
9928 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9929 | .doit = nl80211_set_wowlan, | |
9930 | .policy = nl80211_policy, | |
9931 | .flags = GENL_ADMIN_PERM, | |
9932 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9933 | NL80211_FLAG_NEED_RTNL, | |
9934 | }, | |
dfb89c56 | 9935 | #endif |
e5497d76 JB |
9936 | { |
9937 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9938 | .doit = nl80211_set_rekey_data, | |
9939 | .policy = nl80211_policy, | |
9940 | .flags = GENL_ADMIN_PERM, | |
9941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9942 | NL80211_FLAG_NEED_RTNL, | |
9943 | }, | |
109086ce AN |
9944 | { |
9945 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9946 | .doit = nl80211_tdls_mgmt, | |
9947 | .policy = nl80211_policy, | |
9948 | .flags = GENL_ADMIN_PERM, | |
9949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9950 | NL80211_FLAG_NEED_RTNL, | |
9951 | }, | |
9952 | { | |
9953 | .cmd = NL80211_CMD_TDLS_OPER, | |
9954 | .doit = nl80211_tdls_oper, | |
9955 | .policy = nl80211_policy, | |
9956 | .flags = GENL_ADMIN_PERM, | |
9957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9958 | NL80211_FLAG_NEED_RTNL, | |
9959 | }, | |
28946da7 JB |
9960 | { |
9961 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9962 | .doit = nl80211_register_unexpected_frame, | |
9963 | .policy = nl80211_policy, | |
9964 | .flags = GENL_ADMIN_PERM, | |
9965 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9966 | NL80211_FLAG_NEED_RTNL, | |
9967 | }, | |
7f6cf311 JB |
9968 | { |
9969 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9970 | .doit = nl80211_probe_client, | |
9971 | .policy = nl80211_policy, | |
9972 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9973 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9974 | NL80211_FLAG_NEED_RTNL, |
9975 | }, | |
5e760230 JB |
9976 | { |
9977 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9978 | .doit = nl80211_register_beacons, | |
9979 | .policy = nl80211_policy, | |
9980 | .flags = GENL_ADMIN_PERM, | |
9981 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9982 | NL80211_FLAG_NEED_RTNL, | |
9983 | }, | |
1d9d9213 SW |
9984 | { |
9985 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9986 | .doit = nl80211_set_noack_map, | |
9987 | .policy = nl80211_policy, | |
9988 | .flags = GENL_ADMIN_PERM, | |
9989 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9990 | NL80211_FLAG_NEED_RTNL, | |
9991 | }, | |
98104fde JB |
9992 | { |
9993 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9994 | .doit = nl80211_start_p2p_device, | |
9995 | .policy = nl80211_policy, | |
9996 | .flags = GENL_ADMIN_PERM, | |
9997 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9998 | NL80211_FLAG_NEED_RTNL, | |
9999 | }, | |
10000 | { | |
10001 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10002 | .doit = nl80211_stop_p2p_device, | |
10003 | .policy = nl80211_policy, | |
10004 | .flags = GENL_ADMIN_PERM, | |
10005 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10006 | NL80211_FLAG_NEED_RTNL, | |
10007 | }, | |
f4e583c8 AQ |
10008 | { |
10009 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10010 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10011 | .policy = nl80211_policy, |
10012 | .flags = GENL_ADMIN_PERM, | |
10013 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10014 | NL80211_FLAG_NEED_RTNL, | |
10015 | }, | |
10016 | { | |
10017 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10018 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10019 | .policy = nl80211_policy, |
10020 | .flags = GENL_ADMIN_PERM, | |
10021 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10022 | NL80211_FLAG_NEED_RTNL, | |
10023 | }, | |
04f39047 SW |
10024 | { |
10025 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10026 | .doit = nl80211_start_radar_detection, | |
10027 | .policy = nl80211_policy, | |
10028 | .flags = GENL_ADMIN_PERM, | |
10029 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10030 | NL80211_FLAG_NEED_RTNL, | |
10031 | }, | |
3713b4e3 JB |
10032 | { |
10033 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10034 | .doit = nl80211_get_protocol_features, | |
10035 | .policy = nl80211_policy, | |
10036 | }, | |
355199e0 JM |
10037 | { |
10038 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10039 | .doit = nl80211_update_ft_ies, | |
10040 | .policy = nl80211_policy, | |
10041 | .flags = GENL_ADMIN_PERM, | |
10042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10043 | NL80211_FLAG_NEED_RTNL, | |
10044 | }, | |
5de17984 AS |
10045 | { |
10046 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10047 | .doit = nl80211_crit_protocol_start, | |
10048 | .policy = nl80211_policy, | |
10049 | .flags = GENL_ADMIN_PERM, | |
10050 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10051 | NL80211_FLAG_NEED_RTNL, | |
10052 | }, | |
10053 | { | |
10054 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10055 | .doit = nl80211_crit_protocol_stop, | |
10056 | .policy = nl80211_policy, | |
10057 | .flags = GENL_ADMIN_PERM, | |
10058 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10059 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10060 | }, |
10061 | { | |
10062 | .cmd = NL80211_CMD_GET_COALESCE, | |
10063 | .doit = nl80211_get_coalesce, | |
10064 | .policy = nl80211_policy, | |
10065 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10066 | NL80211_FLAG_NEED_RTNL, | |
10067 | }, | |
10068 | { | |
10069 | .cmd = NL80211_CMD_SET_COALESCE, | |
10070 | .doit = nl80211_set_coalesce, | |
10071 | .policy = nl80211_policy, | |
10072 | .flags = GENL_ADMIN_PERM, | |
10073 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10074 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10075 | }, |
10076 | { | |
10077 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10078 | .doit = nl80211_channel_switch, | |
10079 | .policy = nl80211_policy, | |
10080 | .flags = GENL_ADMIN_PERM, | |
10081 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10082 | NL80211_FLAG_NEED_RTNL, | |
10083 | }, | |
ad7e718c JB |
10084 | { |
10085 | .cmd = NL80211_CMD_VENDOR, | |
10086 | .doit = nl80211_vendor_cmd, | |
10087 | .policy = nl80211_policy, | |
10088 | .flags = GENL_ADMIN_PERM, | |
10089 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10090 | NL80211_FLAG_NEED_RTNL, | |
10091 | }, | |
fa9ffc74 KP |
10092 | { |
10093 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10094 | .doit = nl80211_set_qos_map, | |
10095 | .policy = nl80211_policy, | |
10096 | .flags = GENL_ADMIN_PERM, | |
10097 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10098 | NL80211_FLAG_NEED_RTNL, | |
10099 | }, | |
55682965 | 10100 | }; |
9588bbd5 | 10101 | |
55682965 JB |
10102 | /* notification functions */ |
10103 | ||
3bb20556 JB |
10104 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10105 | enum nl80211_commands cmd) | |
55682965 JB |
10106 | { |
10107 | struct sk_buff *msg; | |
86e8cf98 | 10108 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10109 | |
3bb20556 JB |
10110 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10111 | cmd != NL80211_CMD_DEL_WIPHY); | |
10112 | ||
fd2120ca | 10113 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10114 | if (!msg) |
10115 | return; | |
10116 | ||
3bb20556 | 10117 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10118 | nlmsg_free(msg); |
10119 | return; | |
10120 | } | |
10121 | ||
68eb5503 | 10122 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10123 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10124 | } |
10125 | ||
362a415d JB |
10126 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10127 | struct cfg80211_registered_device *rdev) | |
10128 | { | |
10129 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10130 | struct nlattr *nest; | |
10131 | int i; | |
10132 | ||
10133 | if (WARN_ON(!req)) | |
10134 | return 0; | |
10135 | ||
10136 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10137 | if (!nest) | |
10138 | goto nla_put_failure; | |
9360ffd1 DM |
10139 | for (i = 0; i < req->n_ssids; i++) { |
10140 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10141 | goto nla_put_failure; | |
10142 | } | |
362a415d JB |
10143 | nla_nest_end(msg, nest); |
10144 | ||
10145 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10146 | if (!nest) | |
10147 | goto nla_put_failure; | |
9360ffd1 DM |
10148 | for (i = 0; i < req->n_channels; i++) { |
10149 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10150 | goto nla_put_failure; | |
10151 | } | |
362a415d JB |
10152 | nla_nest_end(msg, nest); |
10153 | ||
9360ffd1 DM |
10154 | if (req->ie && |
10155 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10156 | goto nla_put_failure; | |
362a415d | 10157 | |
ae917c9f JB |
10158 | if (req->flags && |
10159 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10160 | goto nla_put_failure; | |
ed473771 | 10161 | |
362a415d JB |
10162 | return 0; |
10163 | nla_put_failure: | |
10164 | return -ENOBUFS; | |
10165 | } | |
10166 | ||
a538e2d5 JB |
10167 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10168 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10169 | struct wireless_dev *wdev, |
15e47304 | 10170 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10171 | u32 cmd) |
2a519311 JB |
10172 | { |
10173 | void *hdr; | |
10174 | ||
15e47304 | 10175 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10176 | if (!hdr) |
10177 | return -1; | |
10178 | ||
9360ffd1 | 10179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10180 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10181 | wdev->netdev->ifindex)) || | |
10182 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10183 | goto nla_put_failure; |
2a519311 | 10184 | |
362a415d JB |
10185 | /* ignore errors and send incomplete event anyway */ |
10186 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10187 | |
10188 | return genlmsg_end(msg, hdr); | |
10189 | ||
10190 | nla_put_failure: | |
10191 | genlmsg_cancel(msg, hdr); | |
10192 | return -EMSGSIZE; | |
10193 | } | |
10194 | ||
807f8a8c LC |
10195 | static int |
10196 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10197 | struct cfg80211_registered_device *rdev, | |
10198 | struct net_device *netdev, | |
15e47304 | 10199 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10200 | { |
10201 | void *hdr; | |
10202 | ||
15e47304 | 10203 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10204 | if (!hdr) |
10205 | return -1; | |
10206 | ||
9360ffd1 DM |
10207 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10208 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10209 | goto nla_put_failure; | |
807f8a8c LC |
10210 | |
10211 | return genlmsg_end(msg, hdr); | |
10212 | ||
10213 | nla_put_failure: | |
10214 | genlmsg_cancel(msg, hdr); | |
10215 | return -EMSGSIZE; | |
10216 | } | |
10217 | ||
a538e2d5 | 10218 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10219 | struct wireless_dev *wdev) |
a538e2d5 JB |
10220 | { |
10221 | struct sk_buff *msg; | |
10222 | ||
58050fce | 10223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10224 | if (!msg) |
10225 | return; | |
10226 | ||
fd014284 | 10227 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10228 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10229 | nlmsg_free(msg); | |
10230 | return; | |
10231 | } | |
10232 | ||
68eb5503 | 10233 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10234 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10235 | } |
10236 | ||
f9d15d16 JB |
10237 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
10238 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
10239 | { |
10240 | struct sk_buff *msg; | |
10241 | ||
fd2120ca | 10242 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 10243 | if (!msg) |
f9d15d16 | 10244 | return NULL; |
2a519311 | 10245 | |
fd014284 | 10246 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
10247 | aborted ? NL80211_CMD_SCAN_ABORTED : |
10248 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 10249 | nlmsg_free(msg); |
f9d15d16 | 10250 | return NULL; |
2a519311 JB |
10251 | } |
10252 | ||
f9d15d16 | 10253 | return msg; |
2a519311 JB |
10254 | } |
10255 | ||
f9d15d16 JB |
10256 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
10257 | struct sk_buff *msg) | |
2a519311 | 10258 | { |
2a519311 JB |
10259 | if (!msg) |
10260 | return; | |
10261 | ||
68eb5503 | 10262 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10263 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10264 | } |
10265 | ||
807f8a8c LC |
10266 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10267 | struct net_device *netdev) | |
10268 | { | |
10269 | struct sk_buff *msg; | |
10270 | ||
10271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10272 | if (!msg) | |
10273 | return; | |
10274 | ||
10275 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10276 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10277 | nlmsg_free(msg); | |
10278 | return; | |
10279 | } | |
10280 | ||
68eb5503 | 10281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10282 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10283 | } |
10284 | ||
10285 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10286 | struct net_device *netdev, u32 cmd) | |
10287 | { | |
10288 | struct sk_buff *msg; | |
10289 | ||
58050fce | 10290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10291 | if (!msg) |
10292 | return; | |
10293 | ||
10294 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10295 | nlmsg_free(msg); | |
10296 | return; | |
10297 | } | |
10298 | ||
68eb5503 | 10299 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10300 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10301 | } |
10302 | ||
73d54c9e LR |
10303 | /* |
10304 | * This can happen on global regulatory changes or device specific settings | |
10305 | * based on custom world regulatory domains. | |
10306 | */ | |
10307 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10308 | { | |
10309 | struct sk_buff *msg; | |
10310 | void *hdr; | |
10311 | ||
fd2120ca | 10312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10313 | if (!msg) |
10314 | return; | |
10315 | ||
10316 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10317 | if (!hdr) { | |
10318 | nlmsg_free(msg); | |
10319 | return; | |
10320 | } | |
10321 | ||
10322 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10323 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10324 | goto nla_put_failure; | |
10325 | ||
10326 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10327 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10328 | NL80211_REGDOM_TYPE_WORLD)) | |
10329 | goto nla_put_failure; | |
10330 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10331 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10332 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10333 | goto nla_put_failure; | |
10334 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10335 | request->intersect) { | |
10336 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10337 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10338 | goto nla_put_failure; | |
10339 | } else { | |
10340 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10341 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10342 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10343 | request->alpha2)) | |
10344 | goto nla_put_failure; | |
10345 | } | |
10346 | ||
f4173766 | 10347 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10348 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10349 | goto nla_put_failure; | |
73d54c9e | 10350 | |
3b7b72ee | 10351 | genlmsg_end(msg, hdr); |
73d54c9e | 10352 | |
bc43b28c | 10353 | rcu_read_lock(); |
68eb5503 | 10354 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10355 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10356 | rcu_read_unlock(); |
73d54c9e LR |
10357 | |
10358 | return; | |
10359 | ||
10360 | nla_put_failure: | |
10361 | genlmsg_cancel(msg, hdr); | |
10362 | nlmsg_free(msg); | |
10363 | } | |
10364 | ||
6039f6d2 JM |
10365 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10366 | struct net_device *netdev, | |
10367 | const u8 *buf, size_t len, | |
e6d6e342 | 10368 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
10369 | { |
10370 | struct sk_buff *msg; | |
10371 | void *hdr; | |
10372 | ||
e6d6e342 | 10373 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10374 | if (!msg) |
10375 | return; | |
10376 | ||
10377 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10378 | if (!hdr) { | |
10379 | nlmsg_free(msg); | |
10380 | return; | |
10381 | } | |
10382 | ||
9360ffd1 DM |
10383 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10384 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10385 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10386 | goto nla_put_failure; | |
6039f6d2 | 10387 | |
3b7b72ee | 10388 | genlmsg_end(msg, hdr); |
6039f6d2 | 10389 | |
68eb5503 | 10390 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10391 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10392 | return; |
10393 | ||
10394 | nla_put_failure: | |
10395 | genlmsg_cancel(msg, hdr); | |
10396 | nlmsg_free(msg); | |
10397 | } | |
10398 | ||
10399 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10400 | struct net_device *netdev, const u8 *buf, |
10401 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10402 | { |
10403 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10404 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
10405 | } |
10406 | ||
10407 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10408 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10409 | size_t len, gfp_t gfp) |
6039f6d2 | 10410 | { |
e6d6e342 JB |
10411 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
10412 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
10413 | } |
10414 | ||
53b46b84 | 10415 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10416 | struct net_device *netdev, const u8 *buf, |
10417 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10418 | { |
10419 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10420 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
10421 | } |
10422 | ||
53b46b84 JM |
10423 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10424 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10425 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10426 | { |
10427 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10428 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
10429 | } |
10430 | ||
6ff57cf8 JB |
10431 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10432 | size_t len) | |
cf4e594e | 10433 | { |
947add36 JB |
10434 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10435 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 10436 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
10437 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10438 | u32 cmd; | |
947add36 | 10439 | |
6ff57cf8 JB |
10440 | if (WARN_ON(len < 2)) |
10441 | return; | |
cf4e594e | 10442 | |
6ff57cf8 JB |
10443 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10444 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10445 | else | |
10446 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10447 | |
6ff57cf8 JB |
10448 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
10449 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 10450 | } |
6ff57cf8 | 10451 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10452 | |
1b06bb40 LR |
10453 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10454 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10455 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10456 | { |
10457 | struct sk_buff *msg; | |
10458 | void *hdr; | |
10459 | ||
e6d6e342 | 10460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
10461 | if (!msg) |
10462 | return; | |
10463 | ||
10464 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10465 | if (!hdr) { | |
10466 | nlmsg_free(msg); | |
10467 | return; | |
10468 | } | |
10469 | ||
9360ffd1 DM |
10470 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10471 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10472 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
10473 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10474 | goto nla_put_failure; | |
1965c853 | 10475 | |
3b7b72ee | 10476 | genlmsg_end(msg, hdr); |
1965c853 | 10477 | |
68eb5503 | 10478 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10479 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
10480 | return; |
10481 | ||
10482 | nla_put_failure: | |
10483 | genlmsg_cancel(msg, hdr); | |
10484 | nlmsg_free(msg); | |
10485 | } | |
10486 | ||
10487 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10488 | struct net_device *netdev, const u8 *addr, |
10489 | gfp_t gfp) | |
1965c853 JM |
10490 | { |
10491 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10492 | addr, gfp); |
1965c853 JM |
10493 | } |
10494 | ||
10495 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10496 | struct net_device *netdev, const u8 *addr, |
10497 | gfp_t gfp) | |
1965c853 | 10498 | { |
e6d6e342 JB |
10499 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10500 | addr, gfp); | |
1965c853 JM |
10501 | } |
10502 | ||
b23aa676 SO |
10503 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10504 | struct net_device *netdev, const u8 *bssid, | |
10505 | const u8 *req_ie, size_t req_ie_len, | |
10506 | const u8 *resp_ie, size_t resp_ie_len, | |
10507 | u16 status, gfp_t gfp) | |
10508 | { | |
10509 | struct sk_buff *msg; | |
10510 | void *hdr; | |
10511 | ||
58050fce | 10512 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10513 | if (!msg) |
10514 | return; | |
10515 | ||
10516 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10517 | if (!hdr) { | |
10518 | nlmsg_free(msg); | |
10519 | return; | |
10520 | } | |
10521 | ||
9360ffd1 DM |
10522 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10523 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10524 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10525 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10526 | (req_ie && | |
10527 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10528 | (resp_ie && | |
10529 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10530 | goto nla_put_failure; | |
b23aa676 | 10531 | |
3b7b72ee | 10532 | genlmsg_end(msg, hdr); |
b23aa676 | 10533 | |
68eb5503 | 10534 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10535 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10536 | return; |
10537 | ||
10538 | nla_put_failure: | |
10539 | genlmsg_cancel(msg, hdr); | |
10540 | nlmsg_free(msg); | |
10541 | ||
10542 | } | |
10543 | ||
10544 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10545 | struct net_device *netdev, const u8 *bssid, | |
10546 | const u8 *req_ie, size_t req_ie_len, | |
10547 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10548 | { | |
10549 | struct sk_buff *msg; | |
10550 | void *hdr; | |
10551 | ||
58050fce | 10552 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10553 | if (!msg) |
10554 | return; | |
10555 | ||
10556 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10557 | if (!hdr) { | |
10558 | nlmsg_free(msg); | |
10559 | return; | |
10560 | } | |
10561 | ||
9360ffd1 DM |
10562 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10563 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10564 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10565 | (req_ie && | |
10566 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10567 | (resp_ie && | |
10568 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10569 | goto nla_put_failure; | |
b23aa676 | 10570 | |
3b7b72ee | 10571 | genlmsg_end(msg, hdr); |
b23aa676 | 10572 | |
68eb5503 | 10573 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10574 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10575 | return; |
10576 | ||
10577 | nla_put_failure: | |
10578 | genlmsg_cancel(msg, hdr); | |
10579 | nlmsg_free(msg); | |
10580 | ||
10581 | } | |
10582 | ||
10583 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10584 | struct net_device *netdev, u16 reason, | |
667503dd | 10585 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10586 | { |
10587 | struct sk_buff *msg; | |
10588 | void *hdr; | |
10589 | ||
58050fce | 10590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10591 | if (!msg) |
10592 | return; | |
10593 | ||
10594 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10595 | if (!hdr) { | |
10596 | nlmsg_free(msg); | |
10597 | return; | |
10598 | } | |
10599 | ||
9360ffd1 DM |
10600 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10601 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10602 | (from_ap && reason && | |
10603 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10604 | (from_ap && | |
10605 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10606 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10607 | goto nla_put_failure; | |
b23aa676 | 10608 | |
3b7b72ee | 10609 | genlmsg_end(msg, hdr); |
b23aa676 | 10610 | |
68eb5503 | 10611 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10612 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
10613 | return; |
10614 | ||
10615 | nla_put_failure: | |
10616 | genlmsg_cancel(msg, hdr); | |
10617 | nlmsg_free(msg); | |
10618 | ||
10619 | } | |
10620 | ||
04a773ad JB |
10621 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10622 | struct net_device *netdev, const u8 *bssid, | |
10623 | gfp_t gfp) | |
10624 | { | |
10625 | struct sk_buff *msg; | |
10626 | void *hdr; | |
10627 | ||
fd2120ca | 10628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10629 | if (!msg) |
10630 | return; | |
10631 | ||
10632 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10633 | if (!hdr) { | |
10634 | nlmsg_free(msg); | |
10635 | return; | |
10636 | } | |
10637 | ||
9360ffd1 DM |
10638 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10639 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10640 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10641 | goto nla_put_failure; | |
04a773ad | 10642 | |
3b7b72ee | 10643 | genlmsg_end(msg, hdr); |
04a773ad | 10644 | |
68eb5503 | 10645 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10646 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
10647 | return; |
10648 | ||
10649 | nla_put_failure: | |
10650 | genlmsg_cancel(msg, hdr); | |
10651 | nlmsg_free(msg); | |
10652 | } | |
10653 | ||
947add36 JB |
10654 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10655 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10656 | { |
947add36 | 10657 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 10658 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
10659 | struct sk_buff *msg; |
10660 | void *hdr; | |
10661 | ||
947add36 JB |
10662 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10663 | return; | |
10664 | ||
10665 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10666 | ||
c93b5e71 JC |
10667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10668 | if (!msg) | |
10669 | return; | |
10670 | ||
10671 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10672 | if (!hdr) { | |
10673 | nlmsg_free(msg); | |
10674 | return; | |
10675 | } | |
10676 | ||
9360ffd1 | 10677 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10678 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10679 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10680 | (ie_len && ie && |
10681 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10682 | goto nla_put_failure; | |
c93b5e71 | 10683 | |
3b7b72ee | 10684 | genlmsg_end(msg, hdr); |
c93b5e71 | 10685 | |
68eb5503 | 10686 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10687 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
10688 | return; |
10689 | ||
10690 | nla_put_failure: | |
10691 | genlmsg_cancel(msg, hdr); | |
10692 | nlmsg_free(msg); | |
10693 | } | |
947add36 | 10694 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10695 | |
a3b8b056 JM |
10696 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10697 | struct net_device *netdev, const u8 *addr, | |
10698 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10699 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10700 | { |
10701 | struct sk_buff *msg; | |
10702 | void *hdr; | |
10703 | ||
e6d6e342 | 10704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10705 | if (!msg) |
10706 | return; | |
10707 | ||
10708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10709 | if (!hdr) { | |
10710 | nlmsg_free(msg); | |
10711 | return; | |
10712 | } | |
10713 | ||
9360ffd1 DM |
10714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10716 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10717 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10718 | (key_id != -1 && | |
10719 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10720 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10721 | goto nla_put_failure; | |
a3b8b056 | 10722 | |
3b7b72ee | 10723 | genlmsg_end(msg, hdr); |
a3b8b056 | 10724 | |
68eb5503 | 10725 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10726 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
10727 | return; |
10728 | ||
10729 | nla_put_failure: | |
10730 | genlmsg_cancel(msg, hdr); | |
10731 | nlmsg_free(msg); | |
10732 | } | |
10733 | ||
6bad8766 LR |
10734 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10735 | struct ieee80211_channel *channel_before, | |
10736 | struct ieee80211_channel *channel_after) | |
10737 | { | |
10738 | struct sk_buff *msg; | |
10739 | void *hdr; | |
10740 | struct nlattr *nl_freq; | |
10741 | ||
fd2120ca | 10742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10743 | if (!msg) |
10744 | return; | |
10745 | ||
10746 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10747 | if (!hdr) { | |
10748 | nlmsg_free(msg); | |
10749 | return; | |
10750 | } | |
10751 | ||
10752 | /* | |
10753 | * Since we are applying the beacon hint to a wiphy we know its | |
10754 | * wiphy_idx is valid | |
10755 | */ | |
9360ffd1 DM |
10756 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10757 | goto nla_put_failure; | |
6bad8766 LR |
10758 | |
10759 | /* Before */ | |
10760 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10761 | if (!nl_freq) | |
10762 | goto nla_put_failure; | |
cdc89b97 | 10763 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10764 | goto nla_put_failure; |
10765 | nla_nest_end(msg, nl_freq); | |
10766 | ||
10767 | /* After */ | |
10768 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10769 | if (!nl_freq) | |
10770 | goto nla_put_failure; | |
cdc89b97 | 10771 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10772 | goto nla_put_failure; |
10773 | nla_nest_end(msg, nl_freq); | |
10774 | ||
3b7b72ee | 10775 | genlmsg_end(msg, hdr); |
6bad8766 | 10776 | |
463d0183 | 10777 | rcu_read_lock(); |
68eb5503 | 10778 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10779 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 10780 | rcu_read_unlock(); |
6bad8766 LR |
10781 | |
10782 | return; | |
10783 | ||
10784 | nla_put_failure: | |
10785 | genlmsg_cancel(msg, hdr); | |
10786 | nlmsg_free(msg); | |
10787 | } | |
10788 | ||
9588bbd5 JM |
10789 | static void nl80211_send_remain_on_chan_event( |
10790 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10791 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10792 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10793 | unsigned int duration, gfp_t gfp) |
10794 | { | |
10795 | struct sk_buff *msg; | |
10796 | void *hdr; | |
10797 | ||
10798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10799 | if (!msg) | |
10800 | return; | |
10801 | ||
10802 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10803 | if (!hdr) { | |
10804 | nlmsg_free(msg); | |
10805 | return; | |
10806 | } | |
10807 | ||
9360ffd1 | 10808 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10809 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10810 | wdev->netdev->ifindex)) || | |
00f53350 | 10811 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10812 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10813 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10814 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10815 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10816 | goto nla_put_failure; | |
9588bbd5 | 10817 | |
9360ffd1 DM |
10818 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10819 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10820 | goto nla_put_failure; | |
9588bbd5 | 10821 | |
3b7b72ee | 10822 | genlmsg_end(msg, hdr); |
9588bbd5 | 10823 | |
68eb5503 | 10824 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10825 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
10826 | return; |
10827 | ||
10828 | nla_put_failure: | |
10829 | genlmsg_cancel(msg, hdr); | |
10830 | nlmsg_free(msg); | |
10831 | } | |
10832 | ||
947add36 JB |
10833 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10834 | struct ieee80211_channel *chan, | |
10835 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10836 | { |
947add36 | 10837 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 10838 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
10839 | |
10840 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10841 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10842 | rdev, wdev, cookie, chan, |
42d97a59 | 10843 | duration, gfp); |
9588bbd5 | 10844 | } |
947add36 | 10845 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10846 | |
947add36 JB |
10847 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10848 | struct ieee80211_channel *chan, | |
10849 | gfp_t gfp) | |
9588bbd5 | 10850 | { |
947add36 | 10851 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 10852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
10853 | |
10854 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10855 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10856 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10857 | } |
947add36 | 10858 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10859 | |
947add36 JB |
10860 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10861 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10862 | { |
947add36 | 10863 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10864 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
10865 | struct sk_buff *msg; |
10866 | ||
947add36 JB |
10867 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10868 | ||
58050fce | 10869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10870 | if (!msg) |
10871 | return; | |
10872 | ||
66266b3a JL |
10873 | if (nl80211_send_station(msg, 0, 0, 0, |
10874 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10875 | nlmsg_free(msg); |
10876 | return; | |
10877 | } | |
10878 | ||
68eb5503 | 10879 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10880 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 10881 | } |
947add36 | 10882 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10883 | |
947add36 | 10884 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10885 | { |
947add36 | 10886 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10887 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b JM |
10888 | struct sk_buff *msg; |
10889 | void *hdr; | |
10890 | ||
947add36 JB |
10891 | trace_cfg80211_del_sta(dev, mac_addr); |
10892 | ||
58050fce | 10893 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10894 | if (!msg) |
10895 | return; | |
10896 | ||
10897 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10898 | if (!hdr) { | |
10899 | nlmsg_free(msg); | |
10900 | return; | |
10901 | } | |
10902 | ||
9360ffd1 DM |
10903 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10904 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10905 | goto nla_put_failure; | |
ec15e68b | 10906 | |
3b7b72ee | 10907 | genlmsg_end(msg, hdr); |
ec15e68b | 10908 | |
68eb5503 | 10909 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10910 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
10911 | return; |
10912 | ||
10913 | nla_put_failure: | |
10914 | genlmsg_cancel(msg, hdr); | |
10915 | nlmsg_free(msg); | |
10916 | } | |
947add36 | 10917 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10918 | |
947add36 JB |
10919 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10920 | enum nl80211_connect_failed_reason reason, | |
10921 | gfp_t gfp) | |
ed44a951 | 10922 | { |
947add36 | 10923 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10924 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
10925 | struct sk_buff *msg; |
10926 | void *hdr; | |
10927 | ||
10928 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10929 | if (!msg) | |
10930 | return; | |
10931 | ||
10932 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10933 | if (!hdr) { | |
10934 | nlmsg_free(msg); | |
10935 | return; | |
10936 | } | |
10937 | ||
10938 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10939 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10940 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10941 | goto nla_put_failure; | |
10942 | ||
10943 | genlmsg_end(msg, hdr); | |
10944 | ||
68eb5503 | 10945 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10946 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
10947 | return; |
10948 | ||
10949 | nla_put_failure: | |
10950 | genlmsg_cancel(msg, hdr); | |
10951 | nlmsg_free(msg); | |
10952 | } | |
947add36 | 10953 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10954 | |
b92ab5d8 JB |
10955 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10956 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10957 | { |
10958 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 10959 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
10960 | struct sk_buff *msg; |
10961 | void *hdr; | |
15e47304 | 10962 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10963 | |
15e47304 | 10964 | if (!nlportid) |
28946da7 JB |
10965 | return false; |
10966 | ||
10967 | msg = nlmsg_new(100, gfp); | |
10968 | if (!msg) | |
10969 | return true; | |
10970 | ||
b92ab5d8 | 10971 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10972 | if (!hdr) { |
10973 | nlmsg_free(msg); | |
10974 | return true; | |
10975 | } | |
10976 | ||
9360ffd1 DM |
10977 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10978 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10979 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10980 | goto nla_put_failure; | |
28946da7 | 10981 | |
9c90a9f6 | 10982 | genlmsg_end(msg, hdr); |
15e47304 | 10983 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10984 | return true; |
10985 | ||
10986 | nla_put_failure: | |
10987 | genlmsg_cancel(msg, hdr); | |
10988 | nlmsg_free(msg); | |
10989 | return true; | |
10990 | } | |
10991 | ||
947add36 JB |
10992 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10993 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10994 | { |
947add36 JB |
10995 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10996 | bool ret; | |
10997 | ||
10998 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10999 | ||
11000 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11001 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11002 | trace_cfg80211_return_bool(false); | |
11003 | return false; | |
11004 | } | |
11005 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11006 | addr, gfp); | |
11007 | trace_cfg80211_return_bool(ret); | |
11008 | return ret; | |
b92ab5d8 | 11009 | } |
947add36 | 11010 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11011 | |
947add36 JB |
11012 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11013 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11014 | { |
947add36 JB |
11015 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11016 | bool ret; | |
11017 | ||
11018 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11019 | ||
11020 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11021 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11022 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11023 | trace_cfg80211_return_bool(false); | |
11024 | return false; | |
11025 | } | |
11026 | ret = __nl80211_unexpected_frame(dev, | |
11027 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11028 | addr, gfp); | |
11029 | trace_cfg80211_return_bool(ret); | |
11030 | return ret; | |
b92ab5d8 | 11031 | } |
947add36 | 11032 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11033 | |
2e161f78 | 11034 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11035 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11036 | int freq, int sig_dbm, |
19504cf5 | 11037 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11038 | { |
71bbc994 | 11039 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11040 | struct sk_buff *msg; |
11041 | void *hdr; | |
026331c4 JM |
11042 | |
11043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11044 | if (!msg) | |
11045 | return -ENOMEM; | |
11046 | ||
2e161f78 | 11047 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11048 | if (!hdr) { |
11049 | nlmsg_free(msg); | |
11050 | return -ENOMEM; | |
11051 | } | |
11052 | ||
9360ffd1 | 11053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11054 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11055 | netdev->ifindex)) || | |
a838490b | 11056 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11057 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11058 | (sig_dbm && | |
11059 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11060 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11061 | (flags && | |
11062 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11063 | goto nla_put_failure; |
026331c4 | 11064 | |
3b7b72ee | 11065 | genlmsg_end(msg, hdr); |
026331c4 | 11066 | |
15e47304 | 11067 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11068 | |
11069 | nla_put_failure: | |
11070 | genlmsg_cancel(msg, hdr); | |
11071 | nlmsg_free(msg); | |
11072 | return -ENOBUFS; | |
11073 | } | |
11074 | ||
947add36 JB |
11075 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11076 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11077 | { |
947add36 | 11078 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11079 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11080 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11081 | struct sk_buff *msg; |
11082 | void *hdr; | |
11083 | ||
947add36 JB |
11084 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11085 | ||
026331c4 JM |
11086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11087 | if (!msg) | |
11088 | return; | |
11089 | ||
2e161f78 | 11090 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11091 | if (!hdr) { |
11092 | nlmsg_free(msg); | |
11093 | return; | |
11094 | } | |
11095 | ||
9360ffd1 | 11096 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11097 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11098 | netdev->ifindex)) || | |
a838490b | 11099 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11100 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11101 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11102 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11103 | goto nla_put_failure; | |
026331c4 | 11104 | |
3b7b72ee | 11105 | genlmsg_end(msg, hdr); |
026331c4 | 11106 | |
68eb5503 | 11107 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11108 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11109 | return; |
11110 | ||
11111 | nla_put_failure: | |
11112 | genlmsg_cancel(msg, hdr); | |
11113 | nlmsg_free(msg); | |
11114 | } | |
947add36 | 11115 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11116 | |
947add36 JB |
11117 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
11118 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11119 | gfp_t gfp) | |
d6dc1a38 | 11120 | { |
947add36 JB |
11121 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11122 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11123 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
d6dc1a38 JO |
11124 | struct sk_buff *msg; |
11125 | struct nlattr *pinfoattr; | |
11126 | void *hdr; | |
11127 | ||
947add36 JB |
11128 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
11129 | ||
58050fce | 11130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
11131 | if (!msg) |
11132 | return; | |
11133 | ||
11134 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11135 | if (!hdr) { | |
11136 | nlmsg_free(msg); | |
11137 | return; | |
11138 | } | |
11139 | ||
9360ffd1 | 11140 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11141 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11142 | goto nla_put_failure; |
d6dc1a38 JO |
11143 | |
11144 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11145 | if (!pinfoattr) | |
11146 | goto nla_put_failure; | |
11147 | ||
9360ffd1 DM |
11148 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
11149 | rssi_event)) | |
11150 | goto nla_put_failure; | |
d6dc1a38 JO |
11151 | |
11152 | nla_nest_end(msg, pinfoattr); | |
11153 | ||
3b7b72ee | 11154 | genlmsg_end(msg, hdr); |
d6dc1a38 | 11155 | |
68eb5503 | 11156 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11157 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
11158 | return; |
11159 | ||
11160 | nla_put_failure: | |
11161 | genlmsg_cancel(msg, hdr); | |
11162 | nlmsg_free(msg); | |
11163 | } | |
947add36 | 11164 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 11165 | |
947add36 JB |
11166 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
11167 | struct net_device *netdev, const u8 *bssid, | |
11168 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
11169 | { |
11170 | struct sk_buff *msg; | |
11171 | struct nlattr *rekey_attr; | |
11172 | void *hdr; | |
11173 | ||
58050fce | 11174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
11175 | if (!msg) |
11176 | return; | |
11177 | ||
11178 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
11179 | if (!hdr) { | |
11180 | nlmsg_free(msg); | |
11181 | return; | |
11182 | } | |
11183 | ||
9360ffd1 DM |
11184 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11185 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11186 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11187 | goto nla_put_failure; | |
e5497d76 JB |
11188 | |
11189 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
11190 | if (!rekey_attr) | |
11191 | goto nla_put_failure; | |
11192 | ||
9360ffd1 DM |
11193 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
11194 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
11195 | goto nla_put_failure; | |
e5497d76 JB |
11196 | |
11197 | nla_nest_end(msg, rekey_attr); | |
11198 | ||
3b7b72ee | 11199 | genlmsg_end(msg, hdr); |
e5497d76 | 11200 | |
68eb5503 | 11201 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11202 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
11203 | return; |
11204 | ||
11205 | nla_put_failure: | |
11206 | genlmsg_cancel(msg, hdr); | |
11207 | nlmsg_free(msg); | |
11208 | } | |
11209 | ||
947add36 JB |
11210 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
11211 | const u8 *replay_ctr, gfp_t gfp) | |
11212 | { | |
11213 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11214 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11215 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11216 | |
11217 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11218 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11219 | } | |
11220 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11221 | ||
11222 | static void | |
11223 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11224 | struct net_device *netdev, int index, | |
11225 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11226 | { |
11227 | struct sk_buff *msg; | |
11228 | struct nlattr *attr; | |
11229 | void *hdr; | |
11230 | ||
58050fce | 11231 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11232 | if (!msg) |
11233 | return; | |
11234 | ||
11235 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11236 | if (!hdr) { | |
11237 | nlmsg_free(msg); | |
11238 | return; | |
11239 | } | |
11240 | ||
9360ffd1 DM |
11241 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11242 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11243 | goto nla_put_failure; | |
c9df56b4 JM |
11244 | |
11245 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11246 | if (!attr) | |
11247 | goto nla_put_failure; | |
11248 | ||
9360ffd1 DM |
11249 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11250 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11251 | (preauth && | |
11252 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11253 | goto nla_put_failure; | |
c9df56b4 JM |
11254 | |
11255 | nla_nest_end(msg, attr); | |
11256 | ||
3b7b72ee | 11257 | genlmsg_end(msg, hdr); |
c9df56b4 | 11258 | |
68eb5503 | 11259 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11260 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11261 | return; |
11262 | ||
11263 | nla_put_failure: | |
11264 | genlmsg_cancel(msg, hdr); | |
11265 | nlmsg_free(msg); | |
11266 | } | |
11267 | ||
947add36 JB |
11268 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11269 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11270 | { | |
11271 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11272 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11273 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11274 | |
11275 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11276 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11277 | } | |
11278 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11279 | ||
11280 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11281 | struct net_device *netdev, | |
11282 | struct cfg80211_chan_def *chandef, | |
11283 | gfp_t gfp) | |
5314526b TP |
11284 | { |
11285 | struct sk_buff *msg; | |
11286 | void *hdr; | |
11287 | ||
58050fce | 11288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11289 | if (!msg) |
11290 | return; | |
11291 | ||
11292 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
11293 | if (!hdr) { | |
11294 | nlmsg_free(msg); | |
11295 | return; | |
11296 | } | |
11297 | ||
683b6d3b JB |
11298 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11299 | goto nla_put_failure; | |
11300 | ||
11301 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11302 | goto nla_put_failure; |
5314526b TP |
11303 | |
11304 | genlmsg_end(msg, hdr); | |
11305 | ||
68eb5503 | 11306 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11307 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11308 | return; |
11309 | ||
11310 | nla_put_failure: | |
11311 | genlmsg_cancel(msg, hdr); | |
11312 | nlmsg_free(msg); | |
11313 | } | |
11314 | ||
947add36 JB |
11315 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11316 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11317 | { |
947add36 JB |
11318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11319 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11320 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 11321 | |
e487eaeb | 11322 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11323 | |
e487eaeb | 11324 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
11325 | |
11326 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 11327 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
11328 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
11329 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 11330 | return; |
947add36 | 11331 | |
9e0e2961 | 11332 | wdev->chandef = *chandef; |
96f55f12 | 11333 | wdev->preset_chandef = *chandef; |
947add36 | 11334 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
947add36 JB |
11335 | } |
11336 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11337 | ||
11338 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
11339 | const u8 *peer, u32 num_packets, | |
11340 | u32 rate, u32 intvl, gfp_t gfp) | |
11341 | { | |
11342 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11343 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11344 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
84f10708 TP |
11345 | struct sk_buff *msg; |
11346 | struct nlattr *pinfoattr; | |
11347 | void *hdr; | |
11348 | ||
11349 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11350 | if (!msg) | |
11351 | return; | |
11352 | ||
11353 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11354 | if (!hdr) { | |
11355 | nlmsg_free(msg); | |
11356 | return; | |
11357 | } | |
11358 | ||
11359 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11360 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11361 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11362 | goto nla_put_failure; | |
11363 | ||
11364 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11365 | if (!pinfoattr) | |
11366 | goto nla_put_failure; | |
11367 | ||
11368 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11369 | goto nla_put_failure; | |
11370 | ||
11371 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11372 | goto nla_put_failure; | |
11373 | ||
11374 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11375 | goto nla_put_failure; | |
11376 | ||
11377 | nla_nest_end(msg, pinfoattr); | |
11378 | ||
11379 | genlmsg_end(msg, hdr); | |
11380 | ||
68eb5503 | 11381 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11382 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11383 | return; |
11384 | ||
11385 | nla_put_failure: | |
11386 | genlmsg_cancel(msg, hdr); | |
11387 | nlmsg_free(msg); | |
11388 | } | |
947add36 | 11389 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11390 | |
04f39047 SW |
11391 | void |
11392 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11393 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11394 | enum nl80211_radar_event event, |
11395 | struct net_device *netdev, gfp_t gfp) | |
11396 | { | |
11397 | struct sk_buff *msg; | |
11398 | void *hdr; | |
11399 | ||
11400 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11401 | if (!msg) | |
11402 | return; | |
11403 | ||
11404 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11405 | if (!hdr) { | |
11406 | nlmsg_free(msg); | |
11407 | return; | |
11408 | } | |
11409 | ||
11410 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11411 | goto nla_put_failure; | |
11412 | ||
11413 | /* NOP and radar events don't need a netdev parameter */ | |
11414 | if (netdev) { | |
11415 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11416 | ||
11417 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11418 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11419 | goto nla_put_failure; | |
11420 | } | |
11421 | ||
11422 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11423 | goto nla_put_failure; | |
11424 | ||
11425 | if (nl80211_send_chandef(msg, chandef)) | |
11426 | goto nla_put_failure; | |
11427 | ||
9c90a9f6 | 11428 | genlmsg_end(msg, hdr); |
04f39047 | 11429 | |
68eb5503 | 11430 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11431 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11432 | return; |
11433 | ||
11434 | nla_put_failure: | |
11435 | genlmsg_cancel(msg, hdr); | |
11436 | nlmsg_free(msg); | |
11437 | } | |
11438 | ||
947add36 JB |
11439 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11440 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11441 | { |
947add36 JB |
11442 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11443 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11444 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
c063dbf5 JB |
11445 | struct sk_buff *msg; |
11446 | struct nlattr *pinfoattr; | |
11447 | void *hdr; | |
11448 | ||
947add36 JB |
11449 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
11450 | ||
58050fce | 11451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
11452 | if (!msg) |
11453 | return; | |
11454 | ||
11455 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11456 | if (!hdr) { | |
11457 | nlmsg_free(msg); | |
11458 | return; | |
11459 | } | |
11460 | ||
9360ffd1 | 11461 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11462 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
11463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11464 | goto nla_put_failure; | |
c063dbf5 JB |
11465 | |
11466 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11467 | if (!pinfoattr) | |
11468 | goto nla_put_failure; | |
11469 | ||
9360ffd1 DM |
11470 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
11471 | goto nla_put_failure; | |
c063dbf5 JB |
11472 | |
11473 | nla_nest_end(msg, pinfoattr); | |
11474 | ||
3b7b72ee | 11475 | genlmsg_end(msg, hdr); |
c063dbf5 | 11476 | |
68eb5503 | 11477 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11478 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
11479 | return; |
11480 | ||
11481 | nla_put_failure: | |
11482 | genlmsg_cancel(msg, hdr); | |
11483 | nlmsg_free(msg); | |
11484 | } | |
947add36 | 11485 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 11486 | |
7f6cf311 JB |
11487 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11488 | u64 cookie, bool acked, gfp_t gfp) | |
11489 | { | |
11490 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11491 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
11492 | struct sk_buff *msg; |
11493 | void *hdr; | |
7f6cf311 | 11494 | |
4ee3e063 BL |
11495 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11496 | ||
58050fce | 11497 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11498 | |
7f6cf311 JB |
11499 | if (!msg) |
11500 | return; | |
11501 | ||
11502 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11503 | if (!hdr) { | |
11504 | nlmsg_free(msg); | |
11505 | return; | |
11506 | } | |
11507 | ||
9360ffd1 DM |
11508 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11509 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11510 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11511 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11512 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11513 | goto nla_put_failure; | |
7f6cf311 | 11514 | |
9c90a9f6 | 11515 | genlmsg_end(msg, hdr); |
7f6cf311 | 11516 | |
68eb5503 | 11517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11518 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
11519 | return; |
11520 | ||
11521 | nla_put_failure: | |
11522 | genlmsg_cancel(msg, hdr); | |
11523 | nlmsg_free(msg); | |
11524 | } | |
11525 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11526 | ||
5e760230 JB |
11527 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11528 | const u8 *frame, size_t len, | |
37c73b5f | 11529 | int freq, int sig_dbm) |
5e760230 | 11530 | { |
f26cbf40 | 11531 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
11532 | struct sk_buff *msg; |
11533 | void *hdr; | |
37c73b5f | 11534 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11535 | |
4ee3e063 BL |
11536 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11537 | ||
37c73b5f BG |
11538 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11539 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11540 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11541 | if (!msg) { | |
11542 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11543 | return; | |
11544 | } | |
5e760230 | 11545 | |
37c73b5f BG |
11546 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11547 | if (!hdr) | |
11548 | goto nla_put_failure; | |
5e760230 | 11549 | |
37c73b5f BG |
11550 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11551 | (freq && | |
11552 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11553 | (sig_dbm && | |
11554 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11555 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11556 | goto nla_put_failure; | |
5e760230 | 11557 | |
37c73b5f | 11558 | genlmsg_end(msg, hdr); |
5e760230 | 11559 | |
37c73b5f BG |
11560 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11561 | } | |
11562 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11563 | return; |
11564 | ||
11565 | nla_put_failure: | |
37c73b5f BG |
11566 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11567 | if (hdr) | |
11568 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11569 | nlmsg_free(msg); |
11570 | } | |
11571 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11572 | ||
cd8f7cb4 JB |
11573 | #ifdef CONFIG_PM |
11574 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11575 | struct cfg80211_wowlan_wakeup *wakeup, | |
11576 | gfp_t gfp) | |
11577 | { | |
f26cbf40 | 11578 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
11579 | struct sk_buff *msg; |
11580 | void *hdr; | |
9c90a9f6 | 11581 | int size = 200; |
cd8f7cb4 JB |
11582 | |
11583 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11584 | ||
11585 | if (wakeup) | |
11586 | size += wakeup->packet_present_len; | |
11587 | ||
11588 | msg = nlmsg_new(size, gfp); | |
11589 | if (!msg) | |
11590 | return; | |
11591 | ||
11592 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11593 | if (!hdr) | |
11594 | goto free_msg; | |
11595 | ||
11596 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11597 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11598 | goto free_msg; | |
11599 | ||
11600 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11601 | wdev->netdev->ifindex)) | |
11602 | goto free_msg; | |
11603 | ||
11604 | if (wakeup) { | |
11605 | struct nlattr *reasons; | |
11606 | ||
11607 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
11608 | if (!reasons) |
11609 | goto free_msg; | |
cd8f7cb4 JB |
11610 | |
11611 | if (wakeup->disconnect && | |
11612 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11613 | goto free_msg; | |
11614 | if (wakeup->magic_pkt && | |
11615 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11616 | goto free_msg; | |
11617 | if (wakeup->gtk_rekey_failure && | |
11618 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11619 | goto free_msg; | |
11620 | if (wakeup->eap_identity_req && | |
11621 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11622 | goto free_msg; | |
11623 | if (wakeup->four_way_handshake && | |
11624 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11625 | goto free_msg; | |
11626 | if (wakeup->rfkill_release && | |
11627 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11628 | goto free_msg; | |
11629 | ||
11630 | if (wakeup->pattern_idx >= 0 && | |
11631 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11632 | wakeup->pattern_idx)) | |
11633 | goto free_msg; | |
11634 | ||
ae917c9f JB |
11635 | if (wakeup->tcp_match && |
11636 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
11637 | goto free_msg; | |
2a0e047e | 11638 | |
ae917c9f JB |
11639 | if (wakeup->tcp_connlost && |
11640 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
11641 | goto free_msg; | |
2a0e047e | 11642 | |
ae917c9f JB |
11643 | if (wakeup->tcp_nomoretokens && |
11644 | nla_put_flag(msg, | |
11645 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
11646 | goto free_msg; | |
2a0e047e | 11647 | |
cd8f7cb4 JB |
11648 | if (wakeup->packet) { |
11649 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11650 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11651 | ||
11652 | if (!wakeup->packet_80211) { | |
11653 | pkt_attr = | |
11654 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11655 | len_attr = | |
11656 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11657 | } | |
11658 | ||
11659 | if (wakeup->packet_len && | |
11660 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11661 | goto free_msg; | |
11662 | ||
11663 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11664 | wakeup->packet)) | |
11665 | goto free_msg; | |
11666 | } | |
11667 | ||
11668 | nla_nest_end(msg, reasons); | |
11669 | } | |
11670 | ||
9c90a9f6 | 11671 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 11672 | |
68eb5503 | 11673 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11674 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
11675 | return; |
11676 | ||
11677 | free_msg: | |
11678 | nlmsg_free(msg); | |
11679 | } | |
11680 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11681 | #endif | |
11682 | ||
3475b094 JM |
11683 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11684 | enum nl80211_tdls_operation oper, | |
11685 | u16 reason_code, gfp_t gfp) | |
11686 | { | |
11687 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11688 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
11689 | struct sk_buff *msg; |
11690 | void *hdr; | |
3475b094 JM |
11691 | |
11692 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11693 | reason_code); | |
11694 | ||
11695 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11696 | if (!msg) | |
11697 | return; | |
11698 | ||
11699 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11700 | if (!hdr) { | |
11701 | nlmsg_free(msg); | |
11702 | return; | |
11703 | } | |
11704 | ||
11705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11707 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11708 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11709 | (reason_code > 0 && | |
11710 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11711 | goto nla_put_failure; | |
11712 | ||
9c90a9f6 | 11713 | genlmsg_end(msg, hdr); |
3475b094 | 11714 | |
68eb5503 | 11715 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11716 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
11717 | return; |
11718 | ||
11719 | nla_put_failure: | |
11720 | genlmsg_cancel(msg, hdr); | |
11721 | nlmsg_free(msg); | |
11722 | } | |
11723 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11724 | ||
026331c4 JM |
11725 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11726 | unsigned long state, | |
11727 | void *_notify) | |
11728 | { | |
11729 | struct netlink_notify *notify = _notify; | |
11730 | struct cfg80211_registered_device *rdev; | |
11731 | struct wireless_dev *wdev; | |
37c73b5f | 11732 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11733 | |
11734 | if (state != NETLINK_URELEASE) | |
11735 | return NOTIFY_DONE; | |
11736 | ||
11737 | rcu_read_lock(); | |
11738 | ||
5e760230 | 11739 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a JB |
11740 | bool schedule_destroy_work = false; |
11741 | ||
11742 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 11743 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 11744 | |
78f22b6a JB |
11745 | if (wdev->owner_nlportid == notify->portid) |
11746 | schedule_destroy_work = true; | |
11747 | } | |
11748 | ||
37c73b5f BG |
11749 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11750 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11751 | list) { | |
11752 | if (reg->nlportid == notify->portid) { | |
11753 | list_del(®->list); | |
11754 | kfree(reg); | |
11755 | break; | |
11756 | } | |
11757 | } | |
11758 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
11759 | |
11760 | if (schedule_destroy_work) { | |
11761 | struct cfg80211_iface_destroy *destroy; | |
11762 | ||
11763 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
11764 | if (destroy) { | |
11765 | destroy->nlportid = notify->portid; | |
11766 | spin_lock(&rdev->destroy_list_lock); | |
11767 | list_add(&destroy->list, &rdev->destroy_list); | |
11768 | spin_unlock(&rdev->destroy_list_lock); | |
11769 | schedule_work(&rdev->destroy_work); | |
11770 | } | |
11771 | } | |
5e760230 | 11772 | } |
026331c4 JM |
11773 | |
11774 | rcu_read_unlock(); | |
11775 | ||
6784c7db | 11776 | return NOTIFY_OK; |
026331c4 JM |
11777 | } |
11778 | ||
11779 | static struct notifier_block nl80211_netlink_notifier = { | |
11780 | .notifier_call = nl80211_netlink_notify, | |
11781 | }; | |
11782 | ||
355199e0 JM |
11783 | void cfg80211_ft_event(struct net_device *netdev, |
11784 | struct cfg80211_ft_event_params *ft_event) | |
11785 | { | |
11786 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 11787 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
11788 | struct sk_buff *msg; |
11789 | void *hdr; | |
355199e0 JM |
11790 | |
11791 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11792 | ||
11793 | if (!ft_event->target_ap) | |
11794 | return; | |
11795 | ||
11796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11797 | if (!msg) | |
11798 | return; | |
11799 | ||
11800 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
11801 | if (!hdr) |
11802 | goto out; | |
355199e0 | 11803 | |
ae917c9f JB |
11804 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11805 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11806 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
11807 | goto out; | |
355199e0 | 11808 | |
ae917c9f JB |
11809 | if (ft_event->ies && |
11810 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
11811 | goto out; | |
11812 | if (ft_event->ric_ies && | |
11813 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11814 | ft_event->ric_ies)) | |
11815 | goto out; | |
355199e0 | 11816 | |
9c90a9f6 | 11817 | genlmsg_end(msg, hdr); |
355199e0 | 11818 | |
68eb5503 | 11819 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11820 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
11821 | return; |
11822 | out: | |
11823 | nlmsg_free(msg); | |
355199e0 JM |
11824 | } |
11825 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11826 | ||
5de17984 AS |
11827 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11828 | { | |
11829 | struct cfg80211_registered_device *rdev; | |
11830 | struct sk_buff *msg; | |
11831 | void *hdr; | |
11832 | u32 nlportid; | |
11833 | ||
f26cbf40 | 11834 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
11835 | if (!rdev->crit_proto_nlportid) |
11836 | return; | |
11837 | ||
11838 | nlportid = rdev->crit_proto_nlportid; | |
11839 | rdev->crit_proto_nlportid = 0; | |
11840 | ||
11841 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11842 | if (!msg) | |
11843 | return; | |
11844 | ||
11845 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11846 | if (!hdr) | |
11847 | goto nla_put_failure; | |
11848 | ||
11849 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11850 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11851 | goto nla_put_failure; | |
11852 | ||
11853 | genlmsg_end(msg, hdr); | |
11854 | ||
11855 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11856 | return; | |
11857 | ||
11858 | nla_put_failure: | |
11859 | if (hdr) | |
11860 | genlmsg_cancel(msg, hdr); | |
11861 | nlmsg_free(msg); | |
11862 | ||
11863 | } | |
11864 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11865 | ||
348baf0e JB |
11866 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
11867 | { | |
11868 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11869 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
11870 | struct sk_buff *msg; |
11871 | void *hdr; | |
11872 | ||
11873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11874 | if (!msg) | |
11875 | return; | |
11876 | ||
11877 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
11878 | if (!hdr) | |
11879 | goto out; | |
11880 | ||
11881 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11882 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
11883 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11884 | goto out; | |
11885 | ||
11886 | genlmsg_end(msg, hdr); | |
11887 | ||
11888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
11889 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
11890 | return; | |
11891 | out: | |
11892 | nlmsg_free(msg); | |
11893 | } | |
11894 | ||
55682965 JB |
11895 | /* initialisation/exit functions */ |
11896 | ||
11897 | int nl80211_init(void) | |
11898 | { | |
0d63cbb5 | 11899 | int err; |
55682965 | 11900 | |
2a94fe48 JB |
11901 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
11902 | nl80211_mcgrps); | |
55682965 JB |
11903 | if (err) |
11904 | return err; | |
11905 | ||
026331c4 JM |
11906 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11907 | if (err) | |
11908 | goto err_out; | |
11909 | ||
55682965 JB |
11910 | return 0; |
11911 | err_out: | |
11912 | genl_unregister_family(&nl80211_fam); | |
11913 | return err; | |
11914 | } | |
11915 | ||
11916 | void nl80211_exit(void) | |
11917 | { | |
026331c4 | 11918 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11919 | genl_unregister_family(&nl80211_fam); |
11920 | } |