]>
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 | ||
4c476991 JB |
33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
34 | struct genl_info *info); | |
35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
36 | struct genl_info *info); | |
37 | ||
55682965 JB |
38 | /* the netlink family */ |
39 | static struct genl_family nl80211_fam = { | |
40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
41 | .name = "nl80211", /* have users key off the name instead */ | |
42 | .hdrsize = 0, /* no private header */ | |
43 | .version = 1, /* no particular meaning now */ | |
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 | ||
89a54e48 JB |
50 | /* returns ERR_PTR values */ |
51 | static struct wireless_dev * | |
52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 53 | { |
89a54e48 JB |
54 | struct cfg80211_registered_device *rdev; |
55 | struct wireless_dev *result = NULL; | |
56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
58 | u64 wdev_id; | |
59 | int wiphy_idx = -1; | |
60 | int ifidx = -1; | |
55682965 | 61 | |
89a54e48 | 62 | assert_cfg80211_lock(); |
55682965 | 63 | |
89a54e48 JB |
64 | if (!have_ifidx && !have_wdev_id) |
65 | return ERR_PTR(-EINVAL); | |
55682965 | 66 | |
89a54e48 JB |
67 | if (have_ifidx) |
68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
69 | if (have_wdev_id) { | |
70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
71 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
72 | } |
73 | ||
89a54e48 JB |
74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
75 | struct wireless_dev *wdev; | |
76 | ||
77 | if (wiphy_net(&rdev->wiphy) != netns) | |
78 | continue; | |
79 | ||
80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
81 | continue; | |
82 | ||
83 | mutex_lock(&rdev->devlist_mtx); | |
84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { | |
85 | if (have_ifidx && wdev->netdev && | |
86 | wdev->netdev->ifindex == ifidx) { | |
87 | result = wdev; | |
88 | break; | |
89 | } | |
90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
91 | result = wdev; | |
92 | break; | |
93 | } | |
94 | } | |
95 | mutex_unlock(&rdev->devlist_mtx); | |
96 | ||
97 | if (result) | |
98 | break; | |
99 | } | |
100 | ||
101 | if (result) | |
102 | return result; | |
103 | return ERR_PTR(-ENODEV); | |
55682965 JB |
104 | } |
105 | ||
a9455408 | 106 | static struct cfg80211_registered_device * |
878d9ec7 | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 108 | { |
7fee4778 JB |
109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
110 | struct net_device *netdev; | |
a9455408 JB |
111 | |
112 | assert_cfg80211_lock(); | |
113 | ||
878d9ec7 | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
115 | !attrs[NL80211_ATTR_IFINDEX] && |
116 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
117 | return ERR_PTR(-EINVAL); |
118 | ||
878d9ec7 | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 122 | |
89a54e48 JB |
123 | if (attrs[NL80211_ATTR_WDEV]) { |
124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
125 | struct wireless_dev *wdev; | |
126 | bool found = false; | |
127 | ||
128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
129 | if (tmp) { | |
130 | /* make sure wdev exists */ | |
131 | mutex_lock(&tmp->devlist_mtx); | |
132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { | |
133 | if (wdev->identifier != (u32)wdev_id) | |
134 | continue; | |
135 | found = true; | |
136 | break; | |
137 | } | |
138 | mutex_unlock(&tmp->devlist_mtx); | |
139 | ||
140 | if (!found) | |
141 | tmp = NULL; | |
142 | ||
143 | if (rdev && tmp != rdev) | |
144 | return ERR_PTR(-EINVAL); | |
145 | rdev = tmp; | |
146 | } | |
147 | } | |
148 | ||
878d9ec7 JB |
149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
4f7eff10 | 151 | netdev = dev_get_by_index(netns, ifindex); |
7fee4778 JB |
152 | if (netdev) { |
153 | if (netdev->ieee80211_ptr) | |
154 | tmp = wiphy_to_dev( | |
155 | netdev->ieee80211_ptr->wiphy); | |
156 | else | |
157 | tmp = NULL; | |
158 | ||
159 | dev_put(netdev); | |
160 | ||
161 | /* not wireless device -- return error */ | |
162 | if (!tmp) | |
163 | return ERR_PTR(-EINVAL); | |
164 | ||
165 | /* mismatch -- return error */ | |
166 | if (rdev && tmp != rdev) | |
167 | return ERR_PTR(-EINVAL); | |
168 | ||
169 | rdev = tmp; | |
a9455408 | 170 | } |
a9455408 | 171 | } |
a9455408 | 172 | |
4f7eff10 JB |
173 | if (!rdev) |
174 | return ERR_PTR(-ENODEV); | |
a9455408 | 175 | |
4f7eff10 JB |
176 | if (netns != wiphy_net(&rdev->wiphy)) |
177 | return ERR_PTR(-ENODEV); | |
178 | ||
179 | return rdev; | |
a9455408 JB |
180 | } |
181 | ||
182 | /* | |
183 | * This function returns a pointer to the driver | |
184 | * that the genl_info item that is passed refers to. | |
185 | * If successful, it returns non-NULL and also locks | |
186 | * the driver's mutex! | |
187 | * | |
188 | * This means that you need to call cfg80211_unlock_rdev() | |
189 | * before being allowed to acquire &cfg80211_mutex! | |
190 | * | |
191 | * This is necessary because we need to lock the global | |
192 | * mutex to get an item off the list safely, and then | |
193 | * we lock the rdev mutex so it doesn't go away under us. | |
194 | * | |
195 | * We don't want to keep cfg80211_mutex locked | |
196 | * for all the time in order to allow requests on | |
197 | * other interfaces to go through at the same time. | |
198 | * | |
199 | * The result of this can be a PTR_ERR and hence must | |
200 | * be checked with IS_ERR() for errors. | |
201 | */ | |
202 | static struct cfg80211_registered_device * | |
4f7eff10 | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 JB |
204 | { |
205 | struct cfg80211_registered_device *rdev; | |
206 | ||
207 | mutex_lock(&cfg80211_mutex); | |
878d9ec7 | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | |
210 | /* if it is not an error we grab the lock on | |
211 | * it to assure it won't be going away while | |
212 | * we operate on it */ | |
213 | if (!IS_ERR(rdev)) | |
214 | mutex_lock(&rdev->mtx); | |
215 | ||
216 | mutex_unlock(&cfg80211_mutex); | |
217 | ||
218 | return rdev; | |
219 | } | |
220 | ||
55682965 | 221 | /* policy for the attributes */ |
b54452b0 | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 225 | .len = 20-1 }, |
31888487 | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 227 | |
72bdcf34 | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
233 | ||
b9a5f8ca JM |
234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
239 | |
240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 243 | |
e007b857 EP |
244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 246 | |
b9454e83 | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
249 | .len = WLAN_MAX_KEY_LEN }, | |
250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
255 | |
256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
259 | .len = IEEE80211_MAX_DATA_LEN }, | |
260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
261 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
266 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 273 | |
b2e1b302 LR |
274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
276 | ||
9f1ba906 JM |
277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
281 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 283 | |
24bdd9f4 | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 286 | |
6c739419 | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
288 | |
289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
291 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
294 | |
295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
296 | .len = IEEE80211_MAX_SSID_LEN }, | |
297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
302 | [NL80211_ATTR_STA_FLAGS2] = { |
303 | .len = sizeof(struct nl80211_sta_flag_update), | |
304 | }, | |
3f77316c | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
314 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
319 | .len = IEEE80211_MAX_DATA_LEN }, | |
320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
340 | .len = IEEE80211_MAX_DATA_LEN }, | |
341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
342 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
353 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
357 | .len = NL80211_HT_CAPABILITY_LEN | |
358 | }, | |
1d9d9213 | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 373 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
374 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
375 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
376 | .len = NL80211_VHT_CAPABILITY_LEN, | |
377 | }, | |
355199e0 JM |
378 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
379 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
380 | .len = IEEE80211_MAX_DATA_LEN }, | |
55682965 JB |
381 | }; |
382 | ||
e31b8213 | 383 | /* policy for the key attributes */ |
b54452b0 | 384 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 385 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
386 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
387 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 388 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
389 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
390 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 391 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
392 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
393 | }; | |
394 | ||
395 | /* policy for the key default flags */ | |
396 | static const struct nla_policy | |
397 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
398 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
399 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
400 | }; |
401 | ||
ff1b6e69 JB |
402 | /* policy for WoWLAN attributes */ |
403 | static const struct nla_policy | |
404 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
405 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
406 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
407 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
408 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
409 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
410 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
411 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
412 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
413 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
414 | }; | |
415 | ||
416 | static const struct nla_policy | |
417 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
418 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
419 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
420 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
421 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
422 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
423 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
424 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
425 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
426 | }, | |
427 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
428 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
429 | }, | |
430 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
431 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
432 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
433 | }; |
434 | ||
e5497d76 JB |
435 | /* policy for GTK rekey offload attributes */ |
436 | static const struct nla_policy | |
437 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
438 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
439 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
440 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
441 | }; | |
442 | ||
a1f1c21c LC |
443 | static const struct nla_policy |
444 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 445 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 446 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 447 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
448 | }; |
449 | ||
97990a06 JB |
450 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
451 | struct netlink_callback *cb, | |
452 | struct cfg80211_registered_device **rdev, | |
453 | struct wireless_dev **wdev) | |
a043897a | 454 | { |
97990a06 | 455 | int err; |
a043897a | 456 | |
97990a06 JB |
457 | rtnl_lock(); |
458 | mutex_lock(&cfg80211_mutex); | |
a043897a | 459 | |
97990a06 JB |
460 | if (!cb->args[0]) { |
461 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
462 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
463 | nl80211_policy); | |
464 | if (err) | |
465 | goto out_unlock; | |
67748893 | 466 | |
97990a06 JB |
467 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
468 | nl80211_fam.attrbuf); | |
469 | if (IS_ERR(*wdev)) { | |
470 | err = PTR_ERR(*wdev); | |
471 | goto out_unlock; | |
472 | } | |
473 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
474 | cb->args[0] = (*rdev)->wiphy_idx; | |
475 | cb->args[1] = (*wdev)->identifier; | |
476 | } else { | |
477 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); | |
478 | struct wireless_dev *tmp; | |
67748893 | 479 | |
97990a06 JB |
480 | if (!wiphy) { |
481 | err = -ENODEV; | |
482 | goto out_unlock; | |
483 | } | |
484 | *rdev = wiphy_to_dev(wiphy); | |
485 | *wdev = NULL; | |
67748893 | 486 | |
97990a06 JB |
487 | mutex_lock(&(*rdev)->devlist_mtx); |
488 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { | |
489 | if (tmp->identifier == cb->args[1]) { | |
490 | *wdev = tmp; | |
491 | break; | |
492 | } | |
493 | } | |
494 | mutex_unlock(&(*rdev)->devlist_mtx); | |
67748893 | 495 | |
97990a06 JB |
496 | if (!*wdev) { |
497 | err = -ENODEV; | |
498 | goto out_unlock; | |
499 | } | |
67748893 JB |
500 | } |
501 | ||
97990a06 | 502 | cfg80211_lock_rdev(*rdev); |
67748893 | 503 | |
97990a06 | 504 | mutex_unlock(&cfg80211_mutex); |
67748893 | 505 | return 0; |
97990a06 JB |
506 | out_unlock: |
507 | mutex_unlock(&cfg80211_mutex); | |
67748893 JB |
508 | rtnl_unlock(); |
509 | return err; | |
510 | } | |
511 | ||
97990a06 | 512 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 JB |
513 | { |
514 | cfg80211_unlock_rdev(rdev); | |
515 | rtnl_unlock(); | |
516 | } | |
517 | ||
f4a11bb0 JB |
518 | /* IE validation */ |
519 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
520 | { | |
521 | const u8 *pos; | |
522 | int len; | |
523 | ||
524 | if (!attr) | |
525 | return true; | |
526 | ||
527 | pos = nla_data(attr); | |
528 | len = nla_len(attr); | |
529 | ||
530 | while (len) { | |
531 | u8 elemlen; | |
532 | ||
533 | if (len < 2) | |
534 | return false; | |
535 | len -= 2; | |
536 | ||
537 | elemlen = pos[1]; | |
538 | if (elemlen > len) | |
539 | return false; | |
540 | ||
541 | len -= elemlen; | |
542 | pos += 2 + elemlen; | |
543 | } | |
544 | ||
545 | return true; | |
546 | } | |
547 | ||
55682965 | 548 | /* message building helper */ |
15e47304 | 549 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
550 | int flags, u8 cmd) |
551 | { | |
552 | /* since there is no private header just add the generic one */ | |
15e47304 | 553 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
554 | } |
555 | ||
5dab3b8a | 556 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
557 | struct ieee80211_channel *chan, |
558 | bool large) | |
5dab3b8a | 559 | { |
9360ffd1 DM |
560 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
561 | chan->center_freq)) | |
562 | goto nla_put_failure; | |
5dab3b8a | 563 | |
9360ffd1 DM |
564 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
565 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
566 | goto nla_put_failure; | |
567 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
569 | goto nla_put_failure; | |
570 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
572 | goto nla_put_failure; | |
cdc89b97 JB |
573 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
574 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
575 | goto nla_put_failure; | |
576 | if (large) { | |
577 | u32 time; | |
578 | ||
579 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
580 | ||
581 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
582 | chan->dfs_state)) | |
583 | goto nla_put_failure; | |
584 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
585 | time)) | |
586 | goto nla_put_failure; | |
587 | } | |
588 | } | |
5dab3b8a | 589 | |
fe1abafd JB |
590 | if (large) { |
591 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
592 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
593 | goto nla_put_failure; | |
594 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
595 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
596 | goto nla_put_failure; | |
597 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
598 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
599 | goto nla_put_failure; | |
600 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
601 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
602 | goto nla_put_failure; | |
603 | } | |
604 | ||
9360ffd1 DM |
605 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
606 | DBM_TO_MBM(chan->max_power))) | |
607 | goto nla_put_failure; | |
5dab3b8a LR |
608 | |
609 | return 0; | |
610 | ||
611 | nla_put_failure: | |
612 | return -ENOBUFS; | |
613 | } | |
614 | ||
55682965 JB |
615 | /* netlink command implementations */ |
616 | ||
b9454e83 JB |
617 | struct key_parse { |
618 | struct key_params p; | |
619 | int idx; | |
e31b8213 | 620 | int type; |
b9454e83 | 621 | bool def, defmgmt; |
dbd2fd65 | 622 | bool def_uni, def_multi; |
b9454e83 JB |
623 | }; |
624 | ||
625 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
626 | { | |
627 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
628 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
629 | nl80211_key_policy); | |
630 | if (err) | |
631 | return err; | |
632 | ||
633 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
634 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
635 | ||
dbd2fd65 JB |
636 | if (k->def) { |
637 | k->def_uni = true; | |
638 | k->def_multi = true; | |
639 | } | |
640 | if (k->defmgmt) | |
641 | k->def_multi = true; | |
642 | ||
b9454e83 JB |
643 | if (tb[NL80211_KEY_IDX]) |
644 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
645 | ||
646 | if (tb[NL80211_KEY_DATA]) { | |
647 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
648 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
649 | } | |
650 | ||
651 | if (tb[NL80211_KEY_SEQ]) { | |
652 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
653 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
654 | } | |
655 | ||
656 | if (tb[NL80211_KEY_CIPHER]) | |
657 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
658 | ||
e31b8213 JB |
659 | if (tb[NL80211_KEY_TYPE]) { |
660 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
661 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
662 | return -EINVAL; | |
663 | } | |
664 | ||
dbd2fd65 JB |
665 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
666 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
667 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
668 | tb[NL80211_KEY_DEFAULT_TYPES], | |
669 | nl80211_key_default_policy); | |
dbd2fd65 JB |
670 | if (err) |
671 | return err; | |
672 | ||
673 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
674 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
675 | } | |
676 | ||
b9454e83 JB |
677 | return 0; |
678 | } | |
679 | ||
680 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
681 | { | |
682 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
683 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
684 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
685 | } | |
686 | ||
687 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
688 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
689 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
690 | } | |
691 | ||
692 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
693 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
694 | ||
695 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
696 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
697 | ||
698 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
699 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
700 | ||
dbd2fd65 JB |
701 | if (k->def) { |
702 | k->def_uni = true; | |
703 | k->def_multi = true; | |
704 | } | |
705 | if (k->defmgmt) | |
706 | k->def_multi = true; | |
707 | ||
e31b8213 JB |
708 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
709 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
710 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
711 | return -EINVAL; | |
712 | } | |
713 | ||
dbd2fd65 JB |
714 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
715 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
716 | int err = nla_parse_nested( | |
717 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
718 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
719 | nl80211_key_default_policy); | |
720 | if (err) | |
721 | return err; | |
722 | ||
723 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
724 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
725 | } | |
726 | ||
b9454e83 JB |
727 | return 0; |
728 | } | |
729 | ||
730 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
731 | { | |
732 | int err; | |
733 | ||
734 | memset(k, 0, sizeof(*k)); | |
735 | k->idx = -1; | |
e31b8213 | 736 | k->type = -1; |
b9454e83 JB |
737 | |
738 | if (info->attrs[NL80211_ATTR_KEY]) | |
739 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
740 | else | |
741 | err = nl80211_parse_key_old(info, k); | |
742 | ||
743 | if (err) | |
744 | return err; | |
745 | ||
746 | if (k->def && k->defmgmt) | |
747 | return -EINVAL; | |
748 | ||
dbd2fd65 JB |
749 | if (k->defmgmt) { |
750 | if (k->def_uni || !k->def_multi) | |
751 | return -EINVAL; | |
752 | } | |
753 | ||
b9454e83 JB |
754 | if (k->idx != -1) { |
755 | if (k->defmgmt) { | |
756 | if (k->idx < 4 || k->idx > 5) | |
757 | return -EINVAL; | |
758 | } else if (k->def) { | |
759 | if (k->idx < 0 || k->idx > 3) | |
760 | return -EINVAL; | |
761 | } else { | |
762 | if (k->idx < 0 || k->idx > 5) | |
763 | return -EINVAL; | |
764 | } | |
765 | } | |
766 | ||
767 | return 0; | |
768 | } | |
769 | ||
fffd0934 JB |
770 | static struct cfg80211_cached_keys * |
771 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 772 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
773 | { |
774 | struct key_parse parse; | |
775 | struct nlattr *key; | |
776 | struct cfg80211_cached_keys *result; | |
777 | int rem, err, def = 0; | |
778 | ||
779 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
780 | if (!result) | |
781 | return ERR_PTR(-ENOMEM); | |
782 | ||
783 | result->def = -1; | |
784 | result->defmgmt = -1; | |
785 | ||
786 | nla_for_each_nested(key, keys, rem) { | |
787 | memset(&parse, 0, sizeof(parse)); | |
788 | parse.idx = -1; | |
789 | ||
790 | err = nl80211_parse_key_new(key, &parse); | |
791 | if (err) | |
792 | goto error; | |
793 | err = -EINVAL; | |
794 | if (!parse.p.key) | |
795 | goto error; | |
796 | if (parse.idx < 0 || parse.idx > 4) | |
797 | goto error; | |
798 | if (parse.def) { | |
799 | if (def) | |
800 | goto error; | |
801 | def = 1; | |
802 | result->def = parse.idx; | |
dbd2fd65 JB |
803 | if (!parse.def_uni || !parse.def_multi) |
804 | goto error; | |
fffd0934 JB |
805 | } else if (parse.defmgmt) |
806 | goto error; | |
807 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 808 | parse.idx, false, NULL); |
fffd0934 JB |
809 | if (err) |
810 | goto error; | |
811 | result->params[parse.idx].cipher = parse.p.cipher; | |
812 | result->params[parse.idx].key_len = parse.p.key_len; | |
813 | result->params[parse.idx].key = result->data[parse.idx]; | |
814 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
815 | |
816 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
817 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
818 | if (no_ht) | |
819 | *no_ht = true; | |
820 | } | |
fffd0934 JB |
821 | } |
822 | ||
823 | return result; | |
824 | error: | |
825 | kfree(result); | |
826 | return ERR_PTR(err); | |
827 | } | |
828 | ||
829 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
830 | { | |
831 | ASSERT_WDEV_LOCK(wdev); | |
832 | ||
fffd0934 JB |
833 | switch (wdev->iftype) { |
834 | case NL80211_IFTYPE_AP: | |
835 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 836 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 837 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
838 | break; |
839 | case NL80211_IFTYPE_ADHOC: | |
840 | if (!wdev->current_bss) | |
841 | return -ENOLINK; | |
842 | break; | |
843 | case NL80211_IFTYPE_STATION: | |
074ac8df | 844 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
845 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
846 | return -ENOLINK; | |
847 | break; | |
848 | default: | |
849 | return -EINVAL; | |
850 | } | |
851 | ||
852 | return 0; | |
853 | } | |
854 | ||
7527a782 JB |
855 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
856 | { | |
857 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
858 | int i; | |
859 | ||
860 | if (!nl_modes) | |
861 | goto nla_put_failure; | |
862 | ||
863 | i = 0; | |
864 | while (ifmodes) { | |
9360ffd1 DM |
865 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
866 | goto nla_put_failure; | |
7527a782 JB |
867 | ifmodes >>= 1; |
868 | i++; | |
869 | } | |
870 | ||
871 | nla_nest_end(msg, nl_modes); | |
872 | return 0; | |
873 | ||
874 | nla_put_failure: | |
875 | return -ENOBUFS; | |
876 | } | |
877 | ||
878 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
879 | struct sk_buff *msg, |
880 | bool large) | |
7527a782 JB |
881 | { |
882 | struct nlattr *nl_combis; | |
883 | int i, j; | |
884 | ||
885 | nl_combis = nla_nest_start(msg, | |
886 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
887 | if (!nl_combis) | |
888 | goto nla_put_failure; | |
889 | ||
890 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
891 | const struct ieee80211_iface_combination *c; | |
892 | struct nlattr *nl_combi, *nl_limits; | |
893 | ||
894 | c = &wiphy->iface_combinations[i]; | |
895 | ||
896 | nl_combi = nla_nest_start(msg, i + 1); | |
897 | if (!nl_combi) | |
898 | goto nla_put_failure; | |
899 | ||
900 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
901 | if (!nl_limits) | |
902 | goto nla_put_failure; | |
903 | ||
904 | for (j = 0; j < c->n_limits; j++) { | |
905 | struct nlattr *nl_limit; | |
906 | ||
907 | nl_limit = nla_nest_start(msg, j + 1); | |
908 | if (!nl_limit) | |
909 | goto nla_put_failure; | |
9360ffd1 DM |
910 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
911 | c->limits[j].max)) | |
912 | goto nla_put_failure; | |
7527a782 JB |
913 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
914 | c->limits[j].types)) | |
915 | goto nla_put_failure; | |
916 | nla_nest_end(msg, nl_limit); | |
917 | } | |
918 | ||
919 | nla_nest_end(msg, nl_limits); | |
920 | ||
9360ffd1 DM |
921 | if (c->beacon_int_infra_match && |
922 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
923 | goto nla_put_failure; | |
924 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
925 | c->num_different_channels) || | |
926 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
927 | c->max_interfaces)) | |
928 | goto nla_put_failure; | |
cdc89b97 JB |
929 | if (large && |
930 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
931 | c->radar_detect_widths)) | |
932 | goto nla_put_failure; | |
7527a782 JB |
933 | |
934 | nla_nest_end(msg, nl_combi); | |
935 | } | |
936 | ||
937 | nla_nest_end(msg, nl_combis); | |
938 | ||
939 | return 0; | |
940 | nla_put_failure: | |
941 | return -ENOBUFS; | |
942 | } | |
943 | ||
3713b4e3 | 944 | #ifdef CONFIG_PM |
b56cf720 JB |
945 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
946 | struct sk_buff *msg) | |
947 | { | |
948 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; | |
949 | struct nlattr *nl_tcp; | |
950 | ||
951 | if (!tcp) | |
952 | return 0; | |
953 | ||
954 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
955 | if (!nl_tcp) | |
956 | return -ENOBUFS; | |
957 | ||
958 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
959 | tcp->data_payload_max)) | |
960 | return -ENOBUFS; | |
961 | ||
962 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
963 | tcp->data_payload_max)) | |
964 | return -ENOBUFS; | |
965 | ||
966 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
967 | return -ENOBUFS; | |
968 | ||
969 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
970 | sizeof(*tcp->tok), tcp->tok)) | |
971 | return -ENOBUFS; | |
972 | ||
973 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
974 | tcp->data_interval_max)) | |
975 | return -ENOBUFS; | |
976 | ||
977 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
978 | tcp->wake_payload_max)) | |
979 | return -ENOBUFS; | |
980 | ||
981 | nla_nest_end(msg, nl_tcp); | |
982 | return 0; | |
983 | } | |
984 | ||
3713b4e3 | 985 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
986 | struct cfg80211_registered_device *dev, |
987 | bool large) | |
55682965 | 988 | { |
3713b4e3 | 989 | struct nlattr *nl_wowlan; |
55682965 | 990 | |
3713b4e3 JB |
991 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
992 | return 0; | |
55682965 | 993 | |
3713b4e3 JB |
994 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
995 | if (!nl_wowlan) | |
996 | return -ENOBUFS; | |
9360ffd1 | 997 | |
3713b4e3 JB |
998 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
999 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
1000 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
1001 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
1002 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
1003 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
1004 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
1005 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
1006 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
1007 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
1008 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
1009 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1010 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1011 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1012 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1013 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1014 | return -ENOBUFS; | |
9360ffd1 | 1015 | |
3713b4e3 JB |
1016 | if (dev->wiphy.wowlan.n_patterns) { |
1017 | struct nl80211_wowlan_pattern_support pat = { | |
1018 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1019 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, | |
1020 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, | |
1021 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, | |
1022 | }; | |
9360ffd1 | 1023 | |
3713b4e3 JB |
1024 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1025 | sizeof(pat), &pat)) | |
1026 | return -ENOBUFS; | |
1027 | } | |
9360ffd1 | 1028 | |
b56cf720 JB |
1029 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1030 | return -ENOBUFS; | |
1031 | ||
3713b4e3 | 1032 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1033 | |
3713b4e3 JB |
1034 | return 0; |
1035 | } | |
1036 | #endif | |
9360ffd1 | 1037 | |
3713b4e3 JB |
1038 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1039 | struct ieee80211_supported_band *sband) | |
1040 | { | |
1041 | struct nlattr *nl_rates, *nl_rate; | |
1042 | struct ieee80211_rate *rate; | |
1043 | int i; | |
87bbbe22 | 1044 | |
3713b4e3 JB |
1045 | /* add HT info */ |
1046 | if (sband->ht_cap.ht_supported && | |
1047 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1048 | sizeof(sband->ht_cap.mcs), | |
1049 | &sband->ht_cap.mcs) || | |
1050 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1051 | sband->ht_cap.cap) || | |
1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1053 | sband->ht_cap.ampdu_factor) || | |
1054 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1055 | sband->ht_cap.ampdu_density))) | |
1056 | return -ENOBUFS; | |
afe0cbf8 | 1057 | |
3713b4e3 JB |
1058 | /* add VHT info */ |
1059 | if (sband->vht_cap.vht_supported && | |
1060 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1061 | sizeof(sband->vht_cap.vht_mcs), | |
1062 | &sband->vht_cap.vht_mcs) || | |
1063 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1064 | sband->vht_cap.cap))) | |
1065 | return -ENOBUFS; | |
f59ac048 | 1066 | |
3713b4e3 JB |
1067 | /* add bitrates */ |
1068 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1069 | if (!nl_rates) | |
1070 | return -ENOBUFS; | |
ee688b00 | 1071 | |
3713b4e3 JB |
1072 | for (i = 0; i < sband->n_bitrates; i++) { |
1073 | nl_rate = nla_nest_start(msg, i); | |
1074 | if (!nl_rate) | |
1075 | return -ENOBUFS; | |
ee688b00 | 1076 | |
3713b4e3 JB |
1077 | rate = &sband->bitrates[i]; |
1078 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1079 | rate->bitrate)) | |
1080 | return -ENOBUFS; | |
1081 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1082 | nla_put_flag(msg, | |
1083 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1084 | return -ENOBUFS; | |
ee688b00 | 1085 | |
3713b4e3 JB |
1086 | nla_nest_end(msg, nl_rate); |
1087 | } | |
d51626df | 1088 | |
3713b4e3 | 1089 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1090 | |
3713b4e3 JB |
1091 | return 0; |
1092 | } | |
ee688b00 | 1093 | |
3713b4e3 JB |
1094 | static int |
1095 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1096 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1097 | { | |
1098 | u16 stypes; | |
1099 | struct nlattr *nl_ftypes, *nl_ifs; | |
1100 | enum nl80211_iftype ift; | |
1101 | int i; | |
ee688b00 | 1102 | |
3713b4e3 JB |
1103 | if (!mgmt_stypes) |
1104 | return 0; | |
5dab3b8a | 1105 | |
3713b4e3 JB |
1106 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1107 | if (!nl_ifs) | |
1108 | return -ENOBUFS; | |
e2f367f2 | 1109 | |
3713b4e3 JB |
1110 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1111 | nl_ftypes = nla_nest_start(msg, ift); | |
1112 | if (!nl_ftypes) | |
1113 | return -ENOBUFS; | |
1114 | i = 0; | |
1115 | stypes = mgmt_stypes[ift].tx; | |
1116 | while (stypes) { | |
1117 | if ((stypes & 1) && | |
1118 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1119 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1120 | return -ENOBUFS; | |
1121 | stypes >>= 1; | |
1122 | i++; | |
ee688b00 | 1123 | } |
3713b4e3 JB |
1124 | nla_nest_end(msg, nl_ftypes); |
1125 | } | |
ee688b00 | 1126 | |
3713b4e3 | 1127 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1128 | |
3713b4e3 JB |
1129 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1130 | if (!nl_ifs) | |
1131 | return -ENOBUFS; | |
ee688b00 | 1132 | |
3713b4e3 JB |
1133 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1134 | nl_ftypes = nla_nest_start(msg, ift); | |
1135 | if (!nl_ftypes) | |
1136 | return -ENOBUFS; | |
1137 | i = 0; | |
1138 | stypes = mgmt_stypes[ift].rx; | |
1139 | while (stypes) { | |
1140 | if ((stypes & 1) && | |
1141 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1142 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1143 | return -ENOBUFS; | |
1144 | stypes >>= 1; | |
1145 | i++; | |
1146 | } | |
1147 | nla_nest_end(msg, nl_ftypes); | |
1148 | } | |
1149 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1150 | |
3713b4e3 JB |
1151 | return 0; |
1152 | } | |
ee688b00 | 1153 | |
3713b4e3 JB |
1154 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1155 | struct sk_buff *msg, u32 portid, u32 seq, | |
1156 | int flags, bool split, long *split_start, | |
1157 | long *band_start, long *chan_start) | |
1158 | { | |
1159 | void *hdr; | |
1160 | struct nlattr *nl_bands, *nl_band; | |
1161 | struct nlattr *nl_freqs, *nl_freq; | |
1162 | struct nlattr *nl_cmds; | |
1163 | enum ieee80211_band band; | |
1164 | struct ieee80211_channel *chan; | |
1165 | int i; | |
1166 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1167 | dev->wiphy.mgmt_stypes; | |
1168 | long start = 0, start_chan = 0, start_band = 0; | |
fe1abafd | 1169 | u32 features; |
ee688b00 | 1170 | |
3713b4e3 JB |
1171 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1172 | if (!hdr) | |
1173 | return -ENOBUFS; | |
ee688b00 | 1174 | |
3713b4e3 JB |
1175 | /* allow always using the variables */ |
1176 | if (!split) { | |
1177 | split_start = &start; | |
1178 | band_start = &start_band; | |
1179 | chan_start = &start_chan; | |
ee688b00 | 1180 | } |
ee688b00 | 1181 | |
3713b4e3 JB |
1182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1183 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1184 | wiphy_name(&dev->wiphy)) || | |
1185 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1186 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1187 | goto nla_put_failure; |
1188 | ||
3713b4e3 JB |
1189 | switch (*split_start) { |
1190 | case 0: | |
1191 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1192 | dev->wiphy.retry_short) || | |
1193 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1194 | dev->wiphy.retry_long) || | |
1195 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1196 | dev->wiphy.frag_threshold) || | |
1197 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1198 | dev->wiphy.rts_threshold) || | |
1199 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1200 | dev->wiphy.coverage_class) || | |
1201 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1202 | dev->wiphy.max_scan_ssids) || | |
1203 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1204 | dev->wiphy.max_sched_scan_ssids) || | |
1205 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1206 | dev->wiphy.max_scan_ie_len) || | |
1207 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1208 | dev->wiphy.max_sched_scan_ie_len) || | |
1209 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1210 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1211 | goto nla_put_failure; |
3713b4e3 JB |
1212 | |
1213 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1214 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1215 | goto nla_put_failure; |
3713b4e3 JB |
1216 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1217 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1218 | goto nla_put_failure; | |
1219 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1220 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1221 | goto nla_put_failure; | |
1222 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1223 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1224 | goto nla_put_failure; | |
1225 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1226 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1227 | goto nla_put_failure; | |
1228 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1229 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1230 | goto nla_put_failure; |
8fdc621d | 1231 | |
3713b4e3 JB |
1232 | (*split_start)++; |
1233 | if (split) | |
1234 | break; | |
1235 | case 1: | |
1236 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1237 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1238 | dev->wiphy.cipher_suites)) | |
1239 | goto nla_put_failure; | |
4745fc09 | 1240 | |
3713b4e3 JB |
1241 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1242 | dev->wiphy.max_num_pmkids)) | |
1243 | goto nla_put_failure; | |
b23aa676 | 1244 | |
3713b4e3 JB |
1245 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1246 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1247 | goto nla_put_failure; |
b23aa676 | 1248 | |
3713b4e3 JB |
1249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1250 | dev->wiphy.available_antennas_tx) || | |
1251 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1252 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1253 | goto nla_put_failure; |
b23aa676 | 1254 | |
3713b4e3 JB |
1255 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1256 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1257 | dev->wiphy.probe_resp_offload)) | |
1258 | goto nla_put_failure; | |
8fdc621d | 1259 | |
3713b4e3 JB |
1260 | if ((dev->wiphy.available_antennas_tx || |
1261 | dev->wiphy.available_antennas_rx) && | |
1262 | dev->ops->get_antenna) { | |
1263 | u32 tx_ant = 0, rx_ant = 0; | |
1264 | int res; | |
1265 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1266 | if (!res) { | |
1267 | if (nla_put_u32(msg, | |
1268 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1269 | tx_ant) || | |
1270 | nla_put_u32(msg, | |
1271 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1272 | rx_ant)) | |
1273 | goto nla_put_failure; | |
1274 | } | |
1275 | } | |
a293911d | 1276 | |
3713b4e3 JB |
1277 | (*split_start)++; |
1278 | if (split) | |
1279 | break; | |
1280 | case 2: | |
1281 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1282 | dev->wiphy.interface_modes)) | |
1283 | goto nla_put_failure; | |
1284 | (*split_start)++; | |
1285 | if (split) | |
1286 | break; | |
1287 | case 3: | |
1288 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1289 | if (!nl_bands) | |
1290 | goto nla_put_failure; | |
f7ca38df | 1291 | |
3713b4e3 JB |
1292 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
1293 | struct ieee80211_supported_band *sband; | |
2e161f78 | 1294 | |
3713b4e3 | 1295 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1296 | |
3713b4e3 JB |
1297 | if (!sband) |
1298 | continue; | |
1299 | ||
1300 | nl_band = nla_nest_start(msg, band); | |
1301 | if (!nl_band) | |
2e161f78 | 1302 | goto nla_put_failure; |
3713b4e3 JB |
1303 | |
1304 | switch (*chan_start) { | |
1305 | case 0: | |
1306 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1307 | goto nla_put_failure; |
3713b4e3 JB |
1308 | (*chan_start)++; |
1309 | if (split) | |
1310 | break; | |
1311 | default: | |
1312 | /* add frequencies */ | |
1313 | nl_freqs = nla_nest_start( | |
1314 | msg, NL80211_BAND_ATTR_FREQS); | |
1315 | if (!nl_freqs) | |
1316 | goto nla_put_failure; | |
1317 | ||
1318 | for (i = *chan_start - 1; | |
1319 | i < sband->n_channels; | |
1320 | i++) { | |
1321 | nl_freq = nla_nest_start(msg, i); | |
1322 | if (!nl_freq) | |
1323 | goto nla_put_failure; | |
1324 | ||
1325 | chan = &sband->channels[i]; | |
1326 | ||
cdc89b97 JB |
1327 | if (nl80211_msg_put_channel(msg, chan, |
1328 | split)) | |
3713b4e3 JB |
1329 | goto nla_put_failure; |
1330 | ||
1331 | nla_nest_end(msg, nl_freq); | |
1332 | if (split) | |
1333 | break; | |
1334 | } | |
1335 | if (i < sband->n_channels) | |
1336 | *chan_start = i + 2; | |
1337 | else | |
1338 | *chan_start = 0; | |
1339 | nla_nest_end(msg, nl_freqs); | |
1340 | } | |
1341 | ||
1342 | nla_nest_end(msg, nl_band); | |
1343 | ||
1344 | if (split) { | |
1345 | /* start again here */ | |
1346 | if (*chan_start) | |
1347 | band--; | |
1348 | break; | |
2e161f78 | 1349 | } |
2e161f78 | 1350 | } |
3713b4e3 | 1351 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1352 | |
3713b4e3 JB |
1353 | if (band < IEEE80211_NUM_BANDS) |
1354 | *band_start = band + 1; | |
1355 | else | |
1356 | *band_start = 0; | |
74b70a4e | 1357 | |
3713b4e3 JB |
1358 | /* if bands & channels are done, continue outside */ |
1359 | if (*band_start == 0 && *chan_start == 0) | |
1360 | (*split_start)++; | |
1361 | if (split) | |
1362 | break; | |
1363 | case 4: | |
1364 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1365 | if (!nl_cmds) | |
2e161f78 JB |
1366 | goto nla_put_failure; |
1367 | ||
3713b4e3 JB |
1368 | i = 0; |
1369 | #define CMD(op, n) \ | |
1370 | do { \ | |
1371 | if (dev->ops->op) { \ | |
1372 | i++; \ | |
1373 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1374 | goto nla_put_failure; \ | |
1375 | } \ | |
1376 | } while (0) | |
1377 | ||
1378 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1379 | CMD(change_virtual_intf, SET_INTERFACE); | |
1380 | CMD(add_key, NEW_KEY); | |
1381 | CMD(start_ap, START_AP); | |
1382 | CMD(add_station, NEW_STATION); | |
1383 | CMD(add_mpath, NEW_MPATH); | |
1384 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1385 | CMD(change_bss, SET_BSS); | |
1386 | CMD(auth, AUTHENTICATE); | |
1387 | CMD(assoc, ASSOCIATE); | |
1388 | CMD(deauth, DEAUTHENTICATE); | |
1389 | CMD(disassoc, DISASSOCIATE); | |
1390 | CMD(join_ibss, JOIN_IBSS); | |
1391 | CMD(join_mesh, JOIN_MESH); | |
1392 | CMD(set_pmksa, SET_PMKSA); | |
1393 | CMD(del_pmksa, DEL_PMKSA); | |
1394 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1395 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1396 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1397 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1398 | CMD(mgmt_tx, FRAME); | |
1399 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1400 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1401 | i++; | |
1402 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1403 | goto nla_put_failure; |
2e161f78 | 1404 | } |
3713b4e3 JB |
1405 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1406 | dev->ops->join_mesh) { | |
1407 | i++; | |
1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1409 | goto nla_put_failure; | |
1410 | } | |
1411 | CMD(set_wds_peer, SET_WDS_PEER); | |
1412 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1413 | CMD(tdls_mgmt, TDLS_MGMT); | |
1414 | CMD(tdls_oper, TDLS_OPER); | |
1415 | } | |
1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1417 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1418 | CMD(probe_client, PROBE_CLIENT); | |
1419 | CMD(set_noack_map, SET_NOACK_MAP); | |
1420 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1421 | i++; | |
1422 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1423 | goto nla_put_failure; | |
1424 | } | |
1425 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1426 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
2e161f78 | 1427 | |
3713b4e3 JB |
1428 | #ifdef CONFIG_NL80211_TESTMODE |
1429 | CMD(testmode_cmd, TESTMODE); | |
1430 | #endif | |
ff1b6e69 | 1431 | |
3713b4e3 | 1432 | #undef CMD |
ff1b6e69 | 1433 | |
3713b4e3 JB |
1434 | if (dev->ops->connect || dev->ops->auth) { |
1435 | i++; | |
1436 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1437 | goto nla_put_failure; |
ff1b6e69 JB |
1438 | } |
1439 | ||
3713b4e3 JB |
1440 | if (dev->ops->disconnect || dev->ops->deauth) { |
1441 | i++; | |
1442 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1443 | goto nla_put_failure; | |
1444 | } | |
1445 | ||
1446 | nla_nest_end(msg, nl_cmds); | |
1447 | (*split_start)++; | |
1448 | if (split) | |
1449 | break; | |
1450 | case 5: | |
1451 | if (dev->ops->remain_on_channel && | |
1452 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1453 | nla_put_u32(msg, | |
1454 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1455 | dev->wiphy.max_remain_on_channel_duration)) | |
1456 | goto nla_put_failure; | |
1457 | ||
1458 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1459 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1460 | goto nla_put_failure; | |
1461 | ||
1462 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1463 | goto nla_put_failure; | |
1464 | (*split_start)++; | |
1465 | if (split) | |
1466 | break; | |
1467 | case 6: | |
1468 | #ifdef CONFIG_PM | |
b56cf720 | 1469 | if (nl80211_send_wowlan(msg, dev, split)) |
3713b4e3 JB |
1470 | goto nla_put_failure; |
1471 | (*split_start)++; | |
1472 | if (split) | |
1473 | break; | |
1474 | #else | |
1475 | (*split_start)++; | |
dfb89c56 | 1476 | #endif |
3713b4e3 JB |
1477 | case 7: |
1478 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1479 | dev->wiphy.software_iftypes)) | |
1480 | goto nla_put_failure; | |
ff1b6e69 | 1481 | |
cdc89b97 | 1482 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
3713b4e3 | 1483 | goto nla_put_failure; |
7527a782 | 1484 | |
3713b4e3 JB |
1485 | (*split_start)++; |
1486 | if (split) | |
1487 | break; | |
1488 | case 8: | |
1489 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1490 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1491 | dev->wiphy.ap_sme_capa)) | |
1492 | goto nla_put_failure; | |
7527a782 | 1493 | |
fe1abafd JB |
1494 | features = dev->wiphy.features; |
1495 | /* | |
1496 | * We can only add the per-channel limit information if the | |
1497 | * dump is split, otherwise it makes it too big. Therefore | |
1498 | * only advertise it in that case. | |
1499 | */ | |
1500 | if (split) | |
1501 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | |
1502 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1503 | goto nla_put_failure; |
562a7480 | 1504 | |
3713b4e3 JB |
1505 | if (dev->wiphy.ht_capa_mod_mask && |
1506 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1507 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1508 | dev->wiphy.ht_capa_mod_mask)) | |
1509 | goto nla_put_failure; | |
1f074bd8 | 1510 | |
3713b4e3 JB |
1511 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1512 | dev->wiphy.max_acl_mac_addrs && | |
1513 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1514 | dev->wiphy.max_acl_mac_addrs)) | |
1515 | goto nla_put_failure; | |
7e7c8926 | 1516 | |
3713b4e3 JB |
1517 | /* |
1518 | * Any information below this point is only available to | |
1519 | * applications that can deal with it being split. This | |
1520 | * helps ensure that newly added capabilities don't break | |
1521 | * older tools by overrunning their buffers. | |
1522 | * | |
1523 | * We still increment split_start so that in the split | |
1524 | * case we'll continue with more data in the next round, | |
1525 | * but break unconditionally so unsplit data stops here. | |
1526 | */ | |
1527 | (*split_start)++; | |
1528 | break; | |
1529 | case 9: | |
fe1abafd JB |
1530 | if (dev->wiphy.extended_capabilities && |
1531 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1532 | dev->wiphy.extended_capabilities_len, | |
1533 | dev->wiphy.extended_capabilities) || | |
1534 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1535 | dev->wiphy.extended_capabilities_len, | |
1536 | dev->wiphy.extended_capabilities_mask))) | |
1537 | goto nla_put_failure; | |
a50df0c4 | 1538 | |
ee2aca34 JB |
1539 | if (dev->wiphy.vht_capa_mod_mask && |
1540 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1541 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1542 | dev->wiphy.vht_capa_mod_mask)) | |
1543 | goto nla_put_failure; | |
1544 | ||
3713b4e3 JB |
1545 | /* done */ |
1546 | *split_start = 0; | |
1547 | break; | |
1548 | } | |
55682965 JB |
1549 | return genlmsg_end(msg, hdr); |
1550 | ||
1551 | nla_put_failure: | |
bc3ed28c TG |
1552 | genlmsg_cancel(msg, hdr); |
1553 | return -EMSGSIZE; | |
55682965 JB |
1554 | } |
1555 | ||
1556 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1557 | { | |
645e77de | 1558 | int idx = 0, ret; |
55682965 JB |
1559 | int start = cb->args[0]; |
1560 | struct cfg80211_registered_device *dev; | |
3713b4e3 JB |
1561 | s64 filter_wiphy = -1; |
1562 | bool split = false; | |
1563 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1564 | int res; | |
55682965 | 1565 | |
a1794390 | 1566 | mutex_lock(&cfg80211_mutex); |
3713b4e3 JB |
1567 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
1568 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1569 | if (res == 0) { | |
1570 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1571 | if (tb[NL80211_ATTR_WIPHY]) | |
1572 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1573 | if (tb[NL80211_ATTR_WDEV]) | |
1574 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1575 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1576 | struct net_device *netdev; | |
1577 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1578 | ||
1579 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1580 | if (!netdev) { | |
1581 | mutex_unlock(&cfg80211_mutex); | |
1582 | return -ENODEV; | |
1583 | } | |
1584 | if (netdev->ieee80211_ptr) { | |
1585 | dev = wiphy_to_dev( | |
1586 | netdev->ieee80211_ptr->wiphy); | |
1587 | filter_wiphy = dev->wiphy_idx; | |
1588 | } | |
1589 | dev_put(netdev); | |
1590 | } | |
1591 | } | |
1592 | ||
79c97e97 | 1593 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1594 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1595 | continue; | |
b4637271 | 1596 | if (++idx <= start) |
55682965 | 1597 | continue; |
3713b4e3 JB |
1598 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
1599 | continue; | |
1600 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1601 | do { | |
1602 | ret = nl80211_send_wiphy(dev, skb, | |
1603 | NETLINK_CB(cb->skb).portid, | |
1604 | cb->nlh->nlmsg_seq, | |
1605 | NLM_F_MULTI, | |
1606 | split, &cb->args[1], | |
1607 | &cb->args[2], | |
1608 | &cb->args[3]); | |
1609 | if (ret < 0) { | |
1610 | /* | |
1611 | * If sending the wiphy data didn't fit (ENOBUFS | |
1612 | * or EMSGSIZE returned), this SKB is still | |
1613 | * empty (so it's not too big because another | |
1614 | * wiphy dataset is already in the skb) and | |
1615 | * we've not tried to adjust the dump allocation | |
1616 | * yet ... then adjust the alloc size to be | |
1617 | * bigger, and return 1 but with the empty skb. | |
1618 | * This results in an empty message being RX'ed | |
1619 | * in userspace, but that is ignored. | |
1620 | * | |
1621 | * We can then retry with the larger buffer. | |
1622 | */ | |
1623 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1624 | !skb->len && | |
1625 | cb->min_dump_alloc < 4096) { | |
1626 | cb->min_dump_alloc = 4096; | |
1627 | mutex_unlock(&cfg80211_mutex); | |
1628 | return 1; | |
1629 | } | |
1630 | idx--; | |
1631 | break; | |
645e77de | 1632 | } |
3713b4e3 JB |
1633 | } while (cb->args[1] > 0); |
1634 | break; | |
55682965 | 1635 | } |
a1794390 | 1636 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1637 | |
1638 | cb->args[0] = idx; | |
1639 | ||
1640 | return skb->len; | |
1641 | } | |
1642 | ||
1643 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1644 | { | |
1645 | struct sk_buff *msg; | |
4c476991 | 1646 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1647 | |
645e77de | 1648 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1649 | if (!msg) |
4c476991 | 1650 | return -ENOMEM; |
55682965 | 1651 | |
3713b4e3 JB |
1652 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
1653 | false, NULL, NULL, NULL) < 0) { | |
4c476991 JB |
1654 | nlmsg_free(msg); |
1655 | return -ENOBUFS; | |
1656 | } | |
55682965 | 1657 | |
134e6375 | 1658 | return genlmsg_reply(msg, info); |
55682965 JB |
1659 | } |
1660 | ||
31888487 JM |
1661 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1662 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1663 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1664 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1665 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1666 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1667 | }; | |
1668 | ||
1669 | static int parse_txq_params(struct nlattr *tb[], | |
1670 | struct ieee80211_txq_params *txq_params) | |
1671 | { | |
a3304b0a | 1672 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1673 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1674 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1675 | return -EINVAL; | |
1676 | ||
a3304b0a | 1677 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1678 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1679 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1680 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1681 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1682 | ||
a3304b0a JB |
1683 | if (txq_params->ac >= NL80211_NUM_ACS) |
1684 | return -EINVAL; | |
1685 | ||
31888487 JM |
1686 | return 0; |
1687 | } | |
1688 | ||
f444de05 JB |
1689 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1690 | { | |
1691 | /* | |
cc1d2806 JB |
1692 | * You can only set the channel explicitly for WDS interfaces, |
1693 | * all others have their channel managed via their respective | |
1694 | * "establish a connection" command (connect, join, ...) | |
1695 | * | |
1696 | * For AP/GO and mesh mode, the channel can be set with the | |
1697 | * channel userspace API, but is only stored and passed to the | |
1698 | * low-level driver when the AP starts or the mesh is joined. | |
1699 | * This is for backward compatibility, userspace can also give | |
1700 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1701 | * |
1702 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1703 | * whatever else is going on, so they have their own special |
1704 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1705 | */ |
1706 | return !wdev || | |
1707 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1708 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1709 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1710 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1711 | } |
1712 | ||
683b6d3b JB |
1713 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1714 | struct genl_info *info, | |
1715 | struct cfg80211_chan_def *chandef) | |
1716 | { | |
dbeca2ea | 1717 | u32 control_freq; |
683b6d3b JB |
1718 | |
1719 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1720 | return -EINVAL; | |
1721 | ||
1722 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1723 | ||
1724 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1725 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1726 | chandef->center_freq1 = control_freq; | |
1727 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1728 | |
1729 | /* Primary channel not allowed */ | |
1730 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1731 | return -EINVAL; | |
1732 | ||
3d9d1d66 JB |
1733 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1734 | enum nl80211_channel_type chantype; | |
1735 | ||
1736 | chantype = nla_get_u32( | |
1737 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1738 | ||
1739 | switch (chantype) { | |
1740 | case NL80211_CHAN_NO_HT: | |
1741 | case NL80211_CHAN_HT20: | |
1742 | case NL80211_CHAN_HT40PLUS: | |
1743 | case NL80211_CHAN_HT40MINUS: | |
1744 | cfg80211_chandef_create(chandef, chandef->chan, | |
1745 | chantype); | |
1746 | break; | |
1747 | default: | |
1748 | return -EINVAL; | |
1749 | } | |
1750 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1751 | chandef->width = | |
1752 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1753 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1754 | chandef->center_freq1 = | |
1755 | nla_get_u32( | |
1756 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1757 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1758 | chandef->center_freq2 = | |
1759 | nla_get_u32( | |
1760 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1761 | } | |
1762 | ||
9f5e8f6e | 1763 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1764 | return -EINVAL; |
1765 | ||
9f5e8f6e JB |
1766 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1767 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1768 | return -EINVAL; |
1769 | ||
683b6d3b JB |
1770 | return 0; |
1771 | } | |
1772 | ||
f444de05 JB |
1773 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1774 | struct wireless_dev *wdev, | |
1775 | struct genl_info *info) | |
1776 | { | |
683b6d3b | 1777 | struct cfg80211_chan_def chandef; |
f444de05 | 1778 | int result; |
e8c9bd5b JB |
1779 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1780 | ||
1781 | if (wdev) | |
1782 | iftype = wdev->iftype; | |
f444de05 | 1783 | |
f444de05 JB |
1784 | if (!nl80211_can_set_dev_channel(wdev)) |
1785 | return -EOPNOTSUPP; | |
1786 | ||
683b6d3b JB |
1787 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1788 | if (result) | |
1789 | return result; | |
f444de05 JB |
1790 | |
1791 | mutex_lock(&rdev->devlist_mtx); | |
e8c9bd5b | 1792 | switch (iftype) { |
aa430da4 JB |
1793 | case NL80211_IFTYPE_AP: |
1794 | case NL80211_IFTYPE_P2P_GO: | |
1795 | if (wdev->beacon_interval) { | |
1796 | result = -EBUSY; | |
1797 | break; | |
1798 | } | |
683b6d3b | 1799 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1800 | result = -EINVAL; |
1801 | break; | |
1802 | } | |
683b6d3b | 1803 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1804 | result = 0; |
1805 | break; | |
cc1d2806 | 1806 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1807 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1808 | break; |
e8c9bd5b | 1809 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1810 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1811 | break; |
aa430da4 | 1812 | default: |
e8c9bd5b | 1813 | result = -EINVAL; |
f444de05 JB |
1814 | } |
1815 | mutex_unlock(&rdev->devlist_mtx); | |
1816 | ||
1817 | return result; | |
1818 | } | |
1819 | ||
1820 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1821 | { | |
4c476991 JB |
1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1823 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1824 | |
4c476991 | 1825 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1826 | } |
1827 | ||
e8347eba BJ |
1828 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1829 | { | |
43b19952 JB |
1830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1831 | struct net_device *dev = info->user_ptr[1]; | |
1832 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1833 | const u8 *bssid; |
e8347eba BJ |
1834 | |
1835 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1836 | return -EINVAL; | |
1837 | ||
43b19952 JB |
1838 | if (netif_running(dev)) |
1839 | return -EBUSY; | |
e8347eba | 1840 | |
43b19952 JB |
1841 | if (!rdev->ops->set_wds_peer) |
1842 | return -EOPNOTSUPP; | |
e8347eba | 1843 | |
43b19952 JB |
1844 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1845 | return -EOPNOTSUPP; | |
e8347eba BJ |
1846 | |
1847 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1848 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1849 | } |
1850 | ||
1851 | ||
55682965 JB |
1852 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1853 | { | |
1854 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1855 | struct net_device *netdev = NULL; |
1856 | struct wireless_dev *wdev; | |
a1e567c8 | 1857 | int result = 0, rem_txq_params = 0; |
31888487 | 1858 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1859 | u32 changed; |
1860 | u8 retry_short = 0, retry_long = 0; | |
1861 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1862 | u8 coverage_class = 0; |
55682965 | 1863 | |
f444de05 JB |
1864 | /* |
1865 | * Try to find the wiphy and netdev. Normally this | |
1866 | * function shouldn't need the netdev, but this is | |
1867 | * done for backward compatibility -- previously | |
1868 | * setting the channel was done per wiphy, but now | |
1869 | * it is per netdev. Previous userland like hostapd | |
1870 | * also passed a netdev to set_wiphy, so that it is | |
1871 | * possible to let that go to the right netdev! | |
1872 | */ | |
4bbf4d56 JB |
1873 | mutex_lock(&cfg80211_mutex); |
1874 | ||
f444de05 JB |
1875 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1876 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1877 | ||
1878 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1879 | if (netdev && netdev->ieee80211_ptr) { | |
1880 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1881 | mutex_lock(&rdev->mtx); | |
1882 | } else | |
1883 | netdev = NULL; | |
4bbf4d56 JB |
1884 | } |
1885 | ||
f444de05 | 1886 | if (!netdev) { |
878d9ec7 JB |
1887 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1888 | info->attrs); | |
f444de05 JB |
1889 | if (IS_ERR(rdev)) { |
1890 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1891 | return PTR_ERR(rdev); |
f444de05 JB |
1892 | } |
1893 | wdev = NULL; | |
1894 | netdev = NULL; | |
1895 | result = 0; | |
1896 | ||
1897 | mutex_lock(&rdev->mtx); | |
71fe96bf | 1898 | } else |
f444de05 | 1899 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1900 | |
1901 | /* | |
1902 | * end workaround code, by now the rdev is available | |
1903 | * and locked, and wdev may or may not be NULL. | |
1904 | */ | |
4bbf4d56 JB |
1905 | |
1906 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1907 | result = cfg80211_dev_rename( |
1908 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1909 | |
1910 | mutex_unlock(&cfg80211_mutex); | |
1911 | ||
1912 | if (result) | |
1913 | goto bad_res; | |
31888487 JM |
1914 | |
1915 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1916 | struct ieee80211_txq_params txq_params; | |
1917 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1918 | ||
1919 | if (!rdev->ops->set_txq_params) { | |
1920 | result = -EOPNOTSUPP; | |
1921 | goto bad_res; | |
1922 | } | |
1923 | ||
f70f01c2 EP |
1924 | if (!netdev) { |
1925 | result = -EINVAL; | |
1926 | goto bad_res; | |
1927 | } | |
1928 | ||
133a3ff2 JB |
1929 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1930 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1931 | result = -EINVAL; | |
1932 | goto bad_res; | |
1933 | } | |
1934 | ||
2b5f8b0b JB |
1935 | if (!netif_running(netdev)) { |
1936 | result = -ENETDOWN; | |
1937 | goto bad_res; | |
1938 | } | |
1939 | ||
31888487 JM |
1940 | nla_for_each_nested(nl_txq_params, |
1941 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1942 | rem_txq_params) { | |
1943 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1944 | nla_data(nl_txq_params), | |
1945 | nla_len(nl_txq_params), | |
1946 | txq_params_policy); | |
1947 | result = parse_txq_params(tb, &txq_params); | |
1948 | if (result) | |
1949 | goto bad_res; | |
1950 | ||
e35e4d28 HG |
1951 | result = rdev_set_txq_params(rdev, netdev, |
1952 | &txq_params); | |
31888487 JM |
1953 | if (result) |
1954 | goto bad_res; | |
1955 | } | |
1956 | } | |
55682965 | 1957 | |
72bdcf34 | 1958 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1959 | result = __nl80211_set_channel(rdev, |
1960 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1961 | info); | |
72bdcf34 JM |
1962 | if (result) |
1963 | goto bad_res; | |
1964 | } | |
1965 | ||
98d2ff8b | 1966 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1967 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1968 | enum nl80211_tx_power_setting type; |
1969 | int idx, mbm = 0; | |
1970 | ||
c8442118 JB |
1971 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
1972 | txp_wdev = NULL; | |
1973 | ||
98d2ff8b | 1974 | if (!rdev->ops->set_tx_power) { |
60ea385f | 1975 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1976 | goto bad_res; |
1977 | } | |
1978 | ||
1979 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1980 | type = nla_get_u32(info->attrs[idx]); | |
1981 | ||
1982 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1983 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1984 | result = -EINVAL; | |
1985 | goto bad_res; | |
1986 | } | |
1987 | ||
1988 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1989 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1990 | mbm = nla_get_u32(info->attrs[idx]); | |
1991 | } | |
1992 | ||
c8442118 | 1993 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
1994 | if (result) |
1995 | goto bad_res; | |
1996 | } | |
1997 | ||
afe0cbf8 BR |
1998 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1999 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2000 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2001 | if ((!rdev->wiphy.available_antennas_tx && |
2002 | !rdev->wiphy.available_antennas_rx) || | |
2003 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
2004 | result = -EOPNOTSUPP; |
2005 | goto bad_res; | |
2006 | } | |
2007 | ||
2008 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2009 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2010 | ||
a7ffac95 | 2011 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2012 | * available antenna masks, except for the "all" mask */ |
2013 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2014 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2015 | result = -EINVAL; |
2016 | goto bad_res; | |
2017 | } | |
2018 | ||
7f531e03 BR |
2019 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2020 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2021 | |
e35e4d28 | 2022 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2023 | if (result) |
2024 | goto bad_res; | |
2025 | } | |
2026 | ||
b9a5f8ca JM |
2027 | changed = 0; |
2028 | ||
2029 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2030 | retry_short = nla_get_u8( | |
2031 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2032 | if (retry_short == 0) { | |
2033 | result = -EINVAL; | |
2034 | goto bad_res; | |
2035 | } | |
2036 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2037 | } | |
2038 | ||
2039 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2040 | retry_long = nla_get_u8( | |
2041 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2042 | if (retry_long == 0) { | |
2043 | result = -EINVAL; | |
2044 | goto bad_res; | |
2045 | } | |
2046 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2047 | } | |
2048 | ||
2049 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2050 | frag_threshold = nla_get_u32( | |
2051 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2052 | if (frag_threshold < 256) { | |
2053 | result = -EINVAL; | |
2054 | goto bad_res; | |
2055 | } | |
2056 | if (frag_threshold != (u32) -1) { | |
2057 | /* | |
2058 | * Fragments (apart from the last one) are required to | |
2059 | * have even length. Make the fragmentation code | |
2060 | * simpler by stripping LSB should someone try to use | |
2061 | * odd threshold value. | |
2062 | */ | |
2063 | frag_threshold &= ~0x1; | |
2064 | } | |
2065 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2066 | } | |
2067 | ||
2068 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2069 | rts_threshold = nla_get_u32( | |
2070 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2071 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2072 | } | |
2073 | ||
81077e82 LT |
2074 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2075 | coverage_class = nla_get_u8( | |
2076 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2077 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2078 | } | |
2079 | ||
b9a5f8ca JM |
2080 | if (changed) { |
2081 | u8 old_retry_short, old_retry_long; | |
2082 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2083 | u8 old_coverage_class; |
b9a5f8ca JM |
2084 | |
2085 | if (!rdev->ops->set_wiphy_params) { | |
2086 | result = -EOPNOTSUPP; | |
2087 | goto bad_res; | |
2088 | } | |
2089 | ||
2090 | old_retry_short = rdev->wiphy.retry_short; | |
2091 | old_retry_long = rdev->wiphy.retry_long; | |
2092 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2093 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2094 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2095 | |
2096 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2097 | rdev->wiphy.retry_short = retry_short; | |
2098 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2099 | rdev->wiphy.retry_long = retry_long; | |
2100 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2101 | rdev->wiphy.frag_threshold = frag_threshold; | |
2102 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2103 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2104 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2105 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2106 | |
e35e4d28 | 2107 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2108 | if (result) { |
2109 | rdev->wiphy.retry_short = old_retry_short; | |
2110 | rdev->wiphy.retry_long = old_retry_long; | |
2111 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2112 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2113 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2114 | } |
2115 | } | |
72bdcf34 | 2116 | |
306d6112 | 2117 | bad_res: |
4bbf4d56 | 2118 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
2119 | if (netdev) |
2120 | dev_put(netdev); | |
55682965 JB |
2121 | return result; |
2122 | } | |
2123 | ||
71bbc994 JB |
2124 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2125 | { | |
2126 | return (u64)wdev->identifier | | |
2127 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2128 | } | |
55682965 | 2129 | |
683b6d3b JB |
2130 | static int nl80211_send_chandef(struct sk_buff *msg, |
2131 | struct cfg80211_chan_def *chandef) | |
2132 | { | |
9f5e8f6e | 2133 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2134 | |
683b6d3b JB |
2135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2136 | chandef->chan->center_freq)) | |
2137 | return -ENOBUFS; | |
3d9d1d66 JB |
2138 | switch (chandef->width) { |
2139 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2140 | case NL80211_CHAN_WIDTH_20: | |
2141 | case NL80211_CHAN_WIDTH_40: | |
2142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2143 | cfg80211_get_chandef_type(chandef))) | |
2144 | return -ENOBUFS; | |
2145 | break; | |
2146 | default: | |
2147 | break; | |
2148 | } | |
2149 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2150 | return -ENOBUFS; | |
2151 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2152 | return -ENOBUFS; | |
2153 | if (chandef->center_freq2 && | |
2154 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2155 | return -ENOBUFS; |
2156 | return 0; | |
2157 | } | |
2158 | ||
15e47304 | 2159 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2160 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2161 | struct wireless_dev *wdev) |
55682965 | 2162 | { |
72fb2abc | 2163 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2164 | void *hdr; |
2165 | ||
15e47304 | 2166 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2167 | if (!hdr) |
2168 | return -1; | |
2169 | ||
72fb2abc JB |
2170 | if (dev && |
2171 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2172 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2173 | goto nla_put_failure; |
2174 | ||
2175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2176 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2177 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2178 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2179 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2180 | rdev->devlist_generation ^ | |
2181 | (cfg80211_rdev_list_generation << 2))) | |
2182 | goto nla_put_failure; | |
f5ea9120 | 2183 | |
5b7ccaf3 | 2184 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2185 | int ret; |
2186 | struct cfg80211_chan_def chandef; | |
2187 | ||
2188 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2189 | if (ret == 0) { | |
2190 | if (nl80211_send_chandef(msg, &chandef)) | |
2191 | goto nla_put_failure; | |
2192 | } | |
d91df0e3 PF |
2193 | } |
2194 | ||
b84e7a05 AQ |
2195 | if (wdev->ssid_len) { |
2196 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2197 | goto nla_put_failure; | |
2198 | } | |
2199 | ||
55682965 JB |
2200 | return genlmsg_end(msg, hdr); |
2201 | ||
2202 | nla_put_failure: | |
bc3ed28c TG |
2203 | genlmsg_cancel(msg, hdr); |
2204 | return -EMSGSIZE; | |
55682965 JB |
2205 | } |
2206 | ||
2207 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2208 | { | |
2209 | int wp_idx = 0; | |
2210 | int if_idx = 0; | |
2211 | int wp_start = cb->args[0]; | |
2212 | int if_start = cb->args[1]; | |
f5ea9120 | 2213 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2214 | struct wireless_dev *wdev; |
2215 | ||
a1794390 | 2216 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
2217 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2218 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2219 | continue; |
bba95fef JB |
2220 | if (wp_idx < wp_start) { |
2221 | wp_idx++; | |
55682965 | 2222 | continue; |
bba95fef | 2223 | } |
55682965 JB |
2224 | if_idx = 0; |
2225 | ||
f5ea9120 | 2226 | mutex_lock(&rdev->devlist_mtx); |
89a54e48 | 2227 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2228 | if (if_idx < if_start) { |
2229 | if_idx++; | |
55682965 | 2230 | continue; |
bba95fef | 2231 | } |
15e47304 | 2232 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2233 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2234 | rdev, wdev) < 0) { |
f5ea9120 | 2235 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2236 | goto out; |
2237 | } | |
2238 | if_idx++; | |
55682965 | 2239 | } |
f5ea9120 | 2240 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2241 | |
2242 | wp_idx++; | |
55682965 | 2243 | } |
bba95fef | 2244 | out: |
a1794390 | 2245 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
2246 | |
2247 | cb->args[0] = wp_idx; | |
2248 | cb->args[1] = if_idx; | |
2249 | ||
2250 | return skb->len; | |
2251 | } | |
2252 | ||
2253 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2254 | { | |
2255 | struct sk_buff *msg; | |
4c476991 | 2256 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2257 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2258 | |
fd2120ca | 2259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2260 | if (!msg) |
4c476991 | 2261 | return -ENOMEM; |
55682965 | 2262 | |
15e47304 | 2263 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2264 | dev, wdev) < 0) { |
4c476991 JB |
2265 | nlmsg_free(msg); |
2266 | return -ENOBUFS; | |
2267 | } | |
55682965 | 2268 | |
134e6375 | 2269 | return genlmsg_reply(msg, info); |
55682965 JB |
2270 | } |
2271 | ||
66f7ac50 MW |
2272 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2273 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2274 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2275 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2276 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2277 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
2278 | }; | |
2279 | ||
2280 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2281 | { | |
2282 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2283 | int flag; | |
2284 | ||
2285 | *mntrflags = 0; | |
2286 | ||
2287 | if (!nla) | |
2288 | return -EINVAL; | |
2289 | ||
2290 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2291 | nla, mntr_flags_policy)) | |
2292 | return -EINVAL; | |
2293 | ||
2294 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2295 | if (flags[flag]) | |
2296 | *mntrflags |= (1<<flag); | |
2297 | ||
2298 | return 0; | |
2299 | } | |
2300 | ||
9bc383de | 2301 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2302 | struct net_device *netdev, u8 use_4addr, |
2303 | enum nl80211_iftype iftype) | |
9bc383de | 2304 | { |
ad4bb6f8 | 2305 | if (!use_4addr) { |
f350a0a8 | 2306 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2307 | return -EBUSY; |
9bc383de | 2308 | return 0; |
ad4bb6f8 | 2309 | } |
9bc383de JB |
2310 | |
2311 | switch (iftype) { | |
2312 | case NL80211_IFTYPE_AP_VLAN: | |
2313 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2314 | return 0; | |
2315 | break; | |
2316 | case NL80211_IFTYPE_STATION: | |
2317 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2318 | return 0; | |
2319 | break; | |
2320 | default: | |
2321 | break; | |
2322 | } | |
2323 | ||
2324 | return -EOPNOTSUPP; | |
2325 | } | |
2326 | ||
55682965 JB |
2327 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2328 | { | |
4c476991 | 2329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2330 | struct vif_params params; |
e36d56b6 | 2331 | int err; |
04a773ad | 2332 | enum nl80211_iftype otype, ntype; |
4c476991 | 2333 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2334 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2335 | bool change = false; |
55682965 | 2336 | |
2ec600d6 LCC |
2337 | memset(¶ms, 0, sizeof(params)); |
2338 | ||
04a773ad | 2339 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2340 | |
723b038d | 2341 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2342 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2343 | if (otype != ntype) |
ac7f9cfa | 2344 | change = true; |
4c476991 JB |
2345 | if (ntype > NL80211_IFTYPE_MAX) |
2346 | return -EINVAL; | |
723b038d JB |
2347 | } |
2348 | ||
92ffe055 | 2349 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2350 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2351 | ||
4c476991 JB |
2352 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2353 | return -EINVAL; | |
29cbe68c JB |
2354 | if (netif_running(dev)) |
2355 | return -EBUSY; | |
2356 | ||
2357 | wdev_lock(wdev); | |
2358 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2359 | IEEE80211_MAX_MESH_ID_LEN); | |
2360 | wdev->mesh_id_up_len = | |
2361 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2362 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2363 | wdev->mesh_id_up_len); | |
2364 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2365 | } |
2366 | ||
8b787643 FF |
2367 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2368 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2369 | change = true; | |
ad4bb6f8 | 2370 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2371 | if (err) |
4c476991 | 2372 | return err; |
8b787643 FF |
2373 | } else { |
2374 | params.use_4addr = -1; | |
2375 | } | |
2376 | ||
92ffe055 | 2377 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2378 | if (ntype != NL80211_IFTYPE_MONITOR) |
2379 | return -EINVAL; | |
92ffe055 JB |
2380 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2381 | &_flags); | |
ac7f9cfa | 2382 | if (err) |
4c476991 | 2383 | return err; |
ac7f9cfa JB |
2384 | |
2385 | flags = &_flags; | |
2386 | change = true; | |
92ffe055 | 2387 | } |
3b85875a | 2388 | |
ac7f9cfa | 2389 | if (change) |
3d54d255 | 2390 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2391 | else |
2392 | err = 0; | |
60719ffd | 2393 | |
9bc383de JB |
2394 | if (!err && params.use_4addr != -1) |
2395 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2396 | ||
55682965 JB |
2397 | return err; |
2398 | } | |
2399 | ||
2400 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2401 | { | |
4c476991 | 2402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2403 | struct vif_params params; |
84efbb84 | 2404 | struct wireless_dev *wdev; |
1c90f9d4 | 2405 | struct sk_buff *msg; |
55682965 JB |
2406 | int err; |
2407 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2408 | u32 flags; |
55682965 | 2409 | |
2ec600d6 LCC |
2410 | memset(¶ms, 0, sizeof(params)); |
2411 | ||
55682965 JB |
2412 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2413 | return -EINVAL; | |
2414 | ||
2415 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2416 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2417 | if (type > NL80211_IFTYPE_MAX) | |
2418 | return -EINVAL; | |
2419 | } | |
2420 | ||
79c97e97 | 2421 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2422 | !(rdev->wiphy.interface_modes & (1 << type))) |
2423 | return -EOPNOTSUPP; | |
55682965 | 2424 | |
1c18f145 AS |
2425 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2426 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2427 | ETH_ALEN); | |
2428 | if (!is_valid_ether_addr(params.macaddr)) | |
2429 | return -EADDRNOTAVAIL; | |
2430 | } | |
2431 | ||
9bc383de | 2432 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2433 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2434 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2435 | if (err) |
4c476991 | 2436 | return err; |
9bc383de | 2437 | } |
8b787643 | 2438 | |
1c90f9d4 JB |
2439 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2440 | if (!msg) | |
2441 | return -ENOMEM; | |
2442 | ||
66f7ac50 MW |
2443 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2444 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2445 | &flags); | |
e35e4d28 HG |
2446 | wdev = rdev_add_virtual_intf(rdev, |
2447 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2448 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2449 | if (IS_ERR(wdev)) { |
2450 | nlmsg_free(msg); | |
84efbb84 | 2451 | return PTR_ERR(wdev); |
1c90f9d4 | 2452 | } |
2ec600d6 | 2453 | |
98104fde JB |
2454 | switch (type) { |
2455 | case NL80211_IFTYPE_MESH_POINT: | |
2456 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2457 | break; | |
29cbe68c JB |
2458 | wdev_lock(wdev); |
2459 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2460 | IEEE80211_MAX_MESH_ID_LEN); | |
2461 | wdev->mesh_id_up_len = | |
2462 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2463 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2464 | wdev->mesh_id_up_len); | |
2465 | wdev_unlock(wdev); | |
98104fde JB |
2466 | break; |
2467 | case NL80211_IFTYPE_P2P_DEVICE: | |
2468 | /* | |
2469 | * P2P Device doesn't have a netdev, so doesn't go | |
2470 | * through the netdev notifier and must be added here | |
2471 | */ | |
2472 | mutex_init(&wdev->mtx); | |
2473 | INIT_LIST_HEAD(&wdev->event_list); | |
2474 | spin_lock_init(&wdev->event_lock); | |
2475 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2476 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2477 | ||
2478 | mutex_lock(&rdev->devlist_mtx); | |
2479 | wdev->identifier = ++rdev->wdev_id; | |
2480 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2481 | rdev->devlist_generation++; | |
2482 | mutex_unlock(&rdev->devlist_mtx); | |
2483 | break; | |
2484 | default: | |
2485 | break; | |
29cbe68c JB |
2486 | } |
2487 | ||
15e47304 | 2488 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2489 | rdev, wdev) < 0) { |
2490 | nlmsg_free(msg); | |
2491 | return -ENOBUFS; | |
2492 | } | |
2493 | ||
2494 | return genlmsg_reply(msg, info); | |
55682965 JB |
2495 | } |
2496 | ||
2497 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2498 | { | |
4c476991 | 2499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2500 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2501 | |
4c476991 JB |
2502 | if (!rdev->ops->del_virtual_intf) |
2503 | return -EOPNOTSUPP; | |
55682965 | 2504 | |
84efbb84 JB |
2505 | /* |
2506 | * If we remove a wireless device without a netdev then clear | |
2507 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2508 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2509 | * since the wdev has been freed, unlike with a netdev where | |
2510 | * we need the dev_put() for the netdev to really be freed. | |
2511 | */ | |
2512 | if (!wdev->netdev) | |
2513 | info->user_ptr[1] = NULL; | |
2514 | ||
e35e4d28 | 2515 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2516 | } |
2517 | ||
1d9d9213 SW |
2518 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2519 | { | |
2520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2521 | struct net_device *dev = info->user_ptr[1]; | |
2522 | u16 noack_map; | |
2523 | ||
2524 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2525 | return -EINVAL; | |
2526 | ||
2527 | if (!rdev->ops->set_noack_map) | |
2528 | return -EOPNOTSUPP; | |
2529 | ||
2530 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2531 | ||
e35e4d28 | 2532 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2533 | } |
2534 | ||
41ade00f JB |
2535 | struct get_key_cookie { |
2536 | struct sk_buff *msg; | |
2537 | int error; | |
b9454e83 | 2538 | int idx; |
41ade00f JB |
2539 | }; |
2540 | ||
2541 | static void get_key_callback(void *c, struct key_params *params) | |
2542 | { | |
b9454e83 | 2543 | struct nlattr *key; |
41ade00f JB |
2544 | struct get_key_cookie *cookie = c; |
2545 | ||
9360ffd1 DM |
2546 | if ((params->key && |
2547 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2548 | params->key_len, params->key)) || | |
2549 | (params->seq && | |
2550 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2551 | params->seq_len, params->seq)) || | |
2552 | (params->cipher && | |
2553 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2554 | params->cipher))) | |
2555 | goto nla_put_failure; | |
41ade00f | 2556 | |
b9454e83 JB |
2557 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2558 | if (!key) | |
2559 | goto nla_put_failure; | |
2560 | ||
9360ffd1 DM |
2561 | if ((params->key && |
2562 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2563 | params->key_len, params->key)) || | |
2564 | (params->seq && | |
2565 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2566 | params->seq_len, params->seq)) || | |
2567 | (params->cipher && | |
2568 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2569 | params->cipher))) | |
2570 | goto nla_put_failure; | |
b9454e83 | 2571 | |
9360ffd1 DM |
2572 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2573 | goto nla_put_failure; | |
b9454e83 JB |
2574 | |
2575 | nla_nest_end(cookie->msg, key); | |
2576 | ||
41ade00f JB |
2577 | return; |
2578 | nla_put_failure: | |
2579 | cookie->error = 1; | |
2580 | } | |
2581 | ||
2582 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2583 | { | |
4c476991 | 2584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2585 | int err; |
4c476991 | 2586 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2587 | u8 key_idx = 0; |
e31b8213 JB |
2588 | const u8 *mac_addr = NULL; |
2589 | bool pairwise; | |
41ade00f JB |
2590 | struct get_key_cookie cookie = { |
2591 | .error = 0, | |
2592 | }; | |
2593 | void *hdr; | |
2594 | struct sk_buff *msg; | |
2595 | ||
2596 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2597 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2598 | ||
3cfcf6ac | 2599 | if (key_idx > 5) |
41ade00f JB |
2600 | return -EINVAL; |
2601 | ||
2602 | if (info->attrs[NL80211_ATTR_MAC]) | |
2603 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2604 | ||
e31b8213 JB |
2605 | pairwise = !!mac_addr; |
2606 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2607 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2608 | if (kt >= NUM_NL80211_KEYTYPES) | |
2609 | return -EINVAL; | |
2610 | if (kt != NL80211_KEYTYPE_GROUP && | |
2611 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2612 | return -EINVAL; | |
2613 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2614 | } | |
2615 | ||
4c476991 JB |
2616 | if (!rdev->ops->get_key) |
2617 | return -EOPNOTSUPP; | |
41ade00f | 2618 | |
fd2120ca | 2619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2620 | if (!msg) |
2621 | return -ENOMEM; | |
41ade00f | 2622 | |
15e47304 | 2623 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2624 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2625 | if (IS_ERR(hdr)) |
2626 | return PTR_ERR(hdr); | |
41ade00f JB |
2627 | |
2628 | cookie.msg = msg; | |
b9454e83 | 2629 | cookie.idx = key_idx; |
41ade00f | 2630 | |
9360ffd1 DM |
2631 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2632 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2633 | goto nla_put_failure; | |
2634 | if (mac_addr && | |
2635 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2636 | goto nla_put_failure; | |
41ade00f | 2637 | |
e31b8213 JB |
2638 | if (pairwise && mac_addr && |
2639 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2640 | return -ENOENT; | |
2641 | ||
e35e4d28 HG |
2642 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2643 | get_key_callback); | |
41ade00f JB |
2644 | |
2645 | if (err) | |
6c95e2a2 | 2646 | goto free_msg; |
41ade00f JB |
2647 | |
2648 | if (cookie.error) | |
2649 | goto nla_put_failure; | |
2650 | ||
2651 | genlmsg_end(msg, hdr); | |
4c476991 | 2652 | return genlmsg_reply(msg, info); |
41ade00f JB |
2653 | |
2654 | nla_put_failure: | |
2655 | err = -ENOBUFS; | |
6c95e2a2 | 2656 | free_msg: |
41ade00f | 2657 | nlmsg_free(msg); |
41ade00f JB |
2658 | return err; |
2659 | } | |
2660 | ||
2661 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2662 | { | |
4c476991 | 2663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2664 | struct key_parse key; |
41ade00f | 2665 | int err; |
4c476991 | 2666 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2667 | |
b9454e83 JB |
2668 | err = nl80211_parse_key(info, &key); |
2669 | if (err) | |
2670 | return err; | |
41ade00f | 2671 | |
b9454e83 | 2672 | if (key.idx < 0) |
41ade00f JB |
2673 | return -EINVAL; |
2674 | ||
b9454e83 JB |
2675 | /* only support setting default key */ |
2676 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2677 | return -EINVAL; |
2678 | ||
dbd2fd65 | 2679 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2680 | |
dbd2fd65 JB |
2681 | if (key.def) { |
2682 | if (!rdev->ops->set_default_key) { | |
2683 | err = -EOPNOTSUPP; | |
2684 | goto out; | |
2685 | } | |
41ade00f | 2686 | |
dbd2fd65 JB |
2687 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2688 | if (err) | |
2689 | goto out; | |
2690 | ||
e35e4d28 | 2691 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2692 | key.def_uni, key.def_multi); |
2693 | ||
2694 | if (err) | |
2695 | goto out; | |
fffd0934 | 2696 | |
3d23e349 | 2697 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2698 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2699 | #endif | |
2700 | } else { | |
2701 | if (key.def_uni || !key.def_multi) { | |
2702 | err = -EINVAL; | |
2703 | goto out; | |
2704 | } | |
2705 | ||
2706 | if (!rdev->ops->set_default_mgmt_key) { | |
2707 | err = -EOPNOTSUPP; | |
2708 | goto out; | |
2709 | } | |
2710 | ||
2711 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2712 | if (err) | |
2713 | goto out; | |
2714 | ||
e35e4d28 | 2715 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2716 | if (err) |
2717 | goto out; | |
2718 | ||
2719 | #ifdef CONFIG_CFG80211_WEXT | |
2720 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2721 | #endif |
dbd2fd65 JB |
2722 | } |
2723 | ||
2724 | out: | |
fffd0934 | 2725 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2726 | |
41ade00f JB |
2727 | return err; |
2728 | } | |
2729 | ||
2730 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2731 | { | |
4c476991 | 2732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2733 | int err; |
4c476991 | 2734 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2735 | struct key_parse key; |
e31b8213 | 2736 | const u8 *mac_addr = NULL; |
41ade00f | 2737 | |
b9454e83 JB |
2738 | err = nl80211_parse_key(info, &key); |
2739 | if (err) | |
2740 | return err; | |
41ade00f | 2741 | |
b9454e83 | 2742 | if (!key.p.key) |
41ade00f JB |
2743 | return -EINVAL; |
2744 | ||
41ade00f JB |
2745 | if (info->attrs[NL80211_ATTR_MAC]) |
2746 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2747 | ||
e31b8213 JB |
2748 | if (key.type == -1) { |
2749 | if (mac_addr) | |
2750 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2751 | else | |
2752 | key.type = NL80211_KEYTYPE_GROUP; | |
2753 | } | |
2754 | ||
2755 | /* for now */ | |
2756 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2757 | key.type != NL80211_KEYTYPE_GROUP) | |
2758 | return -EINVAL; | |
2759 | ||
4c476991 JB |
2760 | if (!rdev->ops->add_key) |
2761 | return -EOPNOTSUPP; | |
25e47c18 | 2762 | |
e31b8213 JB |
2763 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2764 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2765 | mac_addr)) | |
4c476991 | 2766 | return -EINVAL; |
41ade00f | 2767 | |
fffd0934 JB |
2768 | wdev_lock(dev->ieee80211_ptr); |
2769 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2770 | if (!err) | |
e35e4d28 HG |
2771 | err = rdev_add_key(rdev, dev, key.idx, |
2772 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2773 | mac_addr, &key.p); | |
fffd0934 | 2774 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2775 | |
41ade00f JB |
2776 | return err; |
2777 | } | |
2778 | ||
2779 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2780 | { | |
4c476991 | 2781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2782 | int err; |
4c476991 | 2783 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2784 | u8 *mac_addr = NULL; |
b9454e83 | 2785 | struct key_parse key; |
41ade00f | 2786 | |
b9454e83 JB |
2787 | err = nl80211_parse_key(info, &key); |
2788 | if (err) | |
2789 | return err; | |
41ade00f JB |
2790 | |
2791 | if (info->attrs[NL80211_ATTR_MAC]) | |
2792 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2793 | ||
e31b8213 JB |
2794 | if (key.type == -1) { |
2795 | if (mac_addr) | |
2796 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2797 | else | |
2798 | key.type = NL80211_KEYTYPE_GROUP; | |
2799 | } | |
2800 | ||
2801 | /* for now */ | |
2802 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2803 | key.type != NL80211_KEYTYPE_GROUP) | |
2804 | return -EINVAL; | |
2805 | ||
4c476991 JB |
2806 | if (!rdev->ops->del_key) |
2807 | return -EOPNOTSUPP; | |
41ade00f | 2808 | |
fffd0934 JB |
2809 | wdev_lock(dev->ieee80211_ptr); |
2810 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2811 | |
2812 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2813 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2814 | err = -ENOENT; | |
2815 | ||
fffd0934 | 2816 | if (!err) |
e35e4d28 HG |
2817 | err = rdev_del_key(rdev, dev, key.idx, |
2818 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2819 | mac_addr); | |
41ade00f | 2820 | |
3d23e349 | 2821 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2822 | if (!err) { |
b9454e83 | 2823 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2824 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2825 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2826 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2827 | } | |
2828 | #endif | |
fffd0934 | 2829 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2830 | |
41ade00f JB |
2831 | return err; |
2832 | } | |
2833 | ||
77765eaf VT |
2834 | /* This function returns an error or the number of nested attributes */ |
2835 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2836 | { | |
2837 | struct nlattr *attr; | |
2838 | int n_entries = 0, tmp; | |
2839 | ||
2840 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2841 | if (nla_len(attr) != ETH_ALEN) | |
2842 | return -EINVAL; | |
2843 | ||
2844 | n_entries++; | |
2845 | } | |
2846 | ||
2847 | return n_entries; | |
2848 | } | |
2849 | ||
2850 | /* | |
2851 | * This function parses ACL information and allocates memory for ACL data. | |
2852 | * On successful return, the calling function is responsible to free the | |
2853 | * ACL buffer returned by this function. | |
2854 | */ | |
2855 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2856 | struct genl_info *info) | |
2857 | { | |
2858 | enum nl80211_acl_policy acl_policy; | |
2859 | struct nlattr *attr; | |
2860 | struct cfg80211_acl_data *acl; | |
2861 | int i = 0, n_entries, tmp; | |
2862 | ||
2863 | if (!wiphy->max_acl_mac_addrs) | |
2864 | return ERR_PTR(-EOPNOTSUPP); | |
2865 | ||
2866 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2867 | return ERR_PTR(-EINVAL); | |
2868 | ||
2869 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2870 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2871 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2872 | return ERR_PTR(-EINVAL); | |
2873 | ||
2874 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2875 | return ERR_PTR(-EINVAL); | |
2876 | ||
2877 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2878 | if (n_entries < 0) | |
2879 | return ERR_PTR(n_entries); | |
2880 | ||
2881 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2882 | return ERR_PTR(-ENOTSUPP); | |
2883 | ||
2884 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2885 | GFP_KERNEL); | |
2886 | if (!acl) | |
2887 | return ERR_PTR(-ENOMEM); | |
2888 | ||
2889 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2890 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2891 | i++; | |
2892 | } | |
2893 | ||
2894 | acl->n_acl_entries = n_entries; | |
2895 | acl->acl_policy = acl_policy; | |
2896 | ||
2897 | return acl; | |
2898 | } | |
2899 | ||
2900 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2901 | { | |
2902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2903 | struct net_device *dev = info->user_ptr[1]; | |
2904 | struct cfg80211_acl_data *acl; | |
2905 | int err; | |
2906 | ||
2907 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2908 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2909 | return -EOPNOTSUPP; | |
2910 | ||
2911 | if (!dev->ieee80211_ptr->beacon_interval) | |
2912 | return -EINVAL; | |
2913 | ||
2914 | acl = parse_acl_data(&rdev->wiphy, info); | |
2915 | if (IS_ERR(acl)) | |
2916 | return PTR_ERR(acl); | |
2917 | ||
2918 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2919 | ||
2920 | kfree(acl); | |
2921 | ||
2922 | return err; | |
2923 | } | |
2924 | ||
8860020e JB |
2925 | static int nl80211_parse_beacon(struct genl_info *info, |
2926 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2927 | { |
8860020e | 2928 | bool haveinfo = false; |
ed1b6cc7 | 2929 | |
9946ecfb JM |
2930 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2931 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2932 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2933 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2934 | return -EINVAL; |
2935 | ||
8860020e | 2936 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2937 | |
ed1b6cc7 | 2938 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2939 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2940 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2941 | if (!bcn->head_len) | |
2942 | return -EINVAL; | |
2943 | haveinfo = true; | |
ed1b6cc7 JB |
2944 | } |
2945 | ||
2946 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2947 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2948 | bcn->tail_len = | |
ed1b6cc7 | 2949 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2950 | haveinfo = true; |
ed1b6cc7 JB |
2951 | } |
2952 | ||
4c476991 JB |
2953 | if (!haveinfo) |
2954 | return -EINVAL; | |
3b85875a | 2955 | |
9946ecfb | 2956 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2957 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2958 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2959 | } |
2960 | ||
2961 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2962 | bcn->proberesp_ies = |
9946ecfb | 2963 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2964 | bcn->proberesp_ies_len = |
9946ecfb JM |
2965 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2966 | } | |
2967 | ||
2968 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2969 | bcn->assocresp_ies = |
9946ecfb | 2970 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2971 | bcn->assocresp_ies_len = |
9946ecfb JM |
2972 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2973 | } | |
2974 | ||
00f740e1 | 2975 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2976 | bcn->probe_resp = |
00f740e1 | 2977 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2978 | bcn->probe_resp_len = |
00f740e1 AN |
2979 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2980 | } | |
2981 | ||
8860020e JB |
2982 | return 0; |
2983 | } | |
2984 | ||
46c1dd0c FF |
2985 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2986 | struct cfg80211_ap_settings *params) | |
2987 | { | |
2988 | struct wireless_dev *wdev; | |
2989 | bool ret = false; | |
2990 | ||
2991 | mutex_lock(&rdev->devlist_mtx); | |
2992 | ||
89a54e48 | 2993 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
2994 | if (wdev->iftype != NL80211_IFTYPE_AP && |
2995 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2996 | continue; | |
2997 | ||
683b6d3b | 2998 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
2999 | continue; |
3000 | ||
683b6d3b | 3001 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3002 | ret = true; |
3003 | break; | |
3004 | } | |
3005 | ||
3006 | mutex_unlock(&rdev->devlist_mtx); | |
3007 | ||
3008 | return ret; | |
3009 | } | |
3010 | ||
e39e5b5e JM |
3011 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3012 | enum nl80211_auth_type auth_type, | |
3013 | enum nl80211_commands cmd) | |
3014 | { | |
3015 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3016 | return false; | |
3017 | ||
3018 | switch (cmd) { | |
3019 | case NL80211_CMD_AUTHENTICATE: | |
3020 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3021 | auth_type == NL80211_AUTHTYPE_SAE) | |
3022 | return false; | |
3023 | return true; | |
3024 | case NL80211_CMD_CONNECT: | |
3025 | case NL80211_CMD_START_AP: | |
3026 | /* SAE not supported yet */ | |
3027 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3028 | return false; | |
3029 | return true; | |
3030 | default: | |
3031 | return false; | |
3032 | } | |
3033 | } | |
3034 | ||
8860020e JB |
3035 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3036 | { | |
3037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3038 | struct net_device *dev = info->user_ptr[1]; | |
3039 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3040 | struct cfg80211_ap_settings params; | |
3041 | int err; | |
04f39047 | 3042 | u8 radar_detect_width = 0; |
8860020e JB |
3043 | |
3044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3046 | return -EOPNOTSUPP; | |
3047 | ||
3048 | if (!rdev->ops->start_ap) | |
3049 | return -EOPNOTSUPP; | |
3050 | ||
3051 | if (wdev->beacon_interval) | |
3052 | return -EALREADY; | |
3053 | ||
3054 | memset(¶ms, 0, sizeof(params)); | |
3055 | ||
3056 | /* these are required for START_AP */ | |
3057 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3058 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3059 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3060 | return -EINVAL; | |
3061 | ||
3062 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
3063 | if (err) | |
3064 | return err; | |
3065 | ||
3066 | params.beacon_interval = | |
3067 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3068 | params.dtim_period = | |
3069 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3070 | ||
3071 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3072 | if (err) | |
3073 | return err; | |
3074 | ||
3075 | /* | |
3076 | * In theory, some of these attributes should be required here | |
3077 | * but since they were not used when the command was originally | |
3078 | * added, keep them optional for old user space programs to let | |
3079 | * them continue to work with drivers that do not need the | |
3080 | * additional information -- drivers must check! | |
3081 | */ | |
3082 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3083 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3084 | params.ssid_len = | |
3085 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3086 | if (params.ssid_len == 0 || | |
3087 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3088 | return -EINVAL; | |
3089 | } | |
3090 | ||
3091 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3092 | params.hidden_ssid = nla_get_u32( | |
3093 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3094 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3095 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3096 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3097 | return -EINVAL; | |
3098 | } | |
3099 | ||
3100 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3101 | ||
3102 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3103 | params.auth_type = nla_get_u32( | |
3104 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3105 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3106 | NL80211_CMD_START_AP)) | |
8860020e JB |
3107 | return -EINVAL; |
3108 | } else | |
3109 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3110 | ||
3111 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3112 | NL80211_MAX_NR_CIPHER_SUITES); | |
3113 | if (err) | |
3114 | return err; | |
3115 | ||
1b658f11 VT |
3116 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3117 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3118 | return -EOPNOTSUPP; | |
3119 | params.inactivity_timeout = nla_get_u16( | |
3120 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3121 | } | |
3122 | ||
53cabad7 JB |
3123 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3124 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3125 | return -EINVAL; | |
3126 | params.p2p_ctwindow = | |
3127 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3128 | if (params.p2p_ctwindow > 127) | |
3129 | return -EINVAL; | |
3130 | if (params.p2p_ctwindow != 0 && | |
3131 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3132 | return -EINVAL; | |
3133 | } | |
3134 | ||
3135 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3136 | u8 tmp; | |
3137 | ||
3138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3139 | return -EINVAL; | |
3140 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3141 | if (tmp > 1) | |
3142 | return -EINVAL; | |
3143 | params.p2p_opp_ps = tmp; | |
3144 | if (params.p2p_opp_ps != 0 && | |
3145 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3146 | return -EINVAL; | |
3147 | } | |
3148 | ||
aa430da4 | 3149 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3150 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3151 | if (err) | |
3152 | return err; | |
3153 | } else if (wdev->preset_chandef.chan) { | |
3154 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3155 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3156 | return -EINVAL; |
3157 | ||
683b6d3b | 3158 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3159 | return -EINVAL; |
3160 | ||
04f39047 SW |
3161 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3162 | if (err < 0) | |
3163 | return err; | |
3164 | if (err) { | |
3165 | radar_detect_width = BIT(params.chandef.width); | |
3166 | params.radar_required = true; | |
3167 | } | |
3168 | ||
e4e32459 | 3169 | mutex_lock(&rdev->devlist_mtx); |
04f39047 SW |
3170 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3171 | params.chandef.chan, | |
3172 | CHAN_MODE_SHARED, | |
3173 | radar_detect_width); | |
e4e32459 MK |
3174 | mutex_unlock(&rdev->devlist_mtx); |
3175 | ||
3176 | if (err) | |
3177 | return err; | |
3178 | ||
77765eaf VT |
3179 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3180 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3181 | if (IS_ERR(params.acl)) | |
3182 | return PTR_ERR(params.acl); | |
3183 | } | |
3184 | ||
e35e4d28 | 3185 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3186 | if (!err) { |
683b6d3b | 3187 | wdev->preset_chandef = params.chandef; |
8860020e | 3188 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3189 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3190 | wdev->ssid_len = params.ssid_len; |
3191 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3192 | } |
77765eaf VT |
3193 | |
3194 | kfree(params.acl); | |
3195 | ||
56d1893d | 3196 | return err; |
ed1b6cc7 JB |
3197 | } |
3198 | ||
8860020e JB |
3199 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3200 | { | |
3201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3202 | struct net_device *dev = info->user_ptr[1]; | |
3203 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3204 | struct cfg80211_beacon_data params; | |
3205 | int err; | |
3206 | ||
3207 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3208 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3209 | return -EOPNOTSUPP; | |
3210 | ||
3211 | if (!rdev->ops->change_beacon) | |
3212 | return -EOPNOTSUPP; | |
3213 | ||
3214 | if (!wdev->beacon_interval) | |
3215 | return -EINVAL; | |
3216 | ||
3217 | err = nl80211_parse_beacon(info, ¶ms); | |
3218 | if (err) | |
3219 | return err; | |
3220 | ||
e35e4d28 | 3221 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3222 | } |
3223 | ||
3224 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3225 | { |
4c476991 JB |
3226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3227 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3228 | |
60771780 | 3229 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3230 | } |
3231 | ||
5727ef1b JB |
3232 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3233 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3234 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3235 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3236 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3237 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3238 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3239 | }; |
3240 | ||
eccb8e8f | 3241 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3242 | enum nl80211_iftype iftype, |
eccb8e8f | 3243 | struct station_parameters *params) |
5727ef1b JB |
3244 | { |
3245 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3246 | struct nlattr *nla; |
5727ef1b JB |
3247 | int flag; |
3248 | ||
eccb8e8f JB |
3249 | /* |
3250 | * Try parsing the new attribute first so userspace | |
3251 | * can specify both for older kernels. | |
3252 | */ | |
3253 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3254 | if (nla) { | |
3255 | struct nl80211_sta_flag_update *sta_flags; | |
3256 | ||
3257 | sta_flags = nla_data(nla); | |
3258 | params->sta_flags_mask = sta_flags->mask; | |
3259 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3260 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3261 | if ((params->sta_flags_mask | |
3262 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3263 | return -EINVAL; | |
3264 | return 0; | |
3265 | } | |
3266 | ||
3267 | /* if present, parse the old attribute */ | |
5727ef1b | 3268 | |
eccb8e8f | 3269 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3270 | if (!nla) |
3271 | return 0; | |
3272 | ||
3273 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3274 | nla, sta_flags_policy)) | |
3275 | return -EINVAL; | |
3276 | ||
bdd3ae3d JB |
3277 | /* |
3278 | * Only allow certain flags for interface types so that | |
3279 | * other attributes are silently ignored. Remember that | |
3280 | * this is backward compatibility code with old userspace | |
3281 | * and shouldn't be hit in other cases anyway. | |
3282 | */ | |
3283 | switch (iftype) { | |
3284 | case NL80211_IFTYPE_AP: | |
3285 | case NL80211_IFTYPE_AP_VLAN: | |
3286 | case NL80211_IFTYPE_P2P_GO: | |
3287 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3288 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3289 | BIT(NL80211_STA_FLAG_WME) | | |
3290 | BIT(NL80211_STA_FLAG_MFP); | |
3291 | break; | |
3292 | case NL80211_IFTYPE_P2P_CLIENT: | |
3293 | case NL80211_IFTYPE_STATION: | |
3294 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3295 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3296 | break; | |
3297 | case NL80211_IFTYPE_MESH_POINT: | |
3298 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3299 | BIT(NL80211_STA_FLAG_MFP) | | |
3300 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3301 | default: | |
3302 | return -EINVAL; | |
3303 | } | |
5727ef1b | 3304 | |
3383b5a6 JB |
3305 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3306 | if (flags[flag]) { | |
eccb8e8f | 3307 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3308 | |
3383b5a6 JB |
3309 | /* no longer support new API additions in old API */ |
3310 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3311 | return -EINVAL; | |
3312 | } | |
3313 | } | |
3314 | ||
5727ef1b JB |
3315 | return 0; |
3316 | } | |
3317 | ||
c8dcfd8a FF |
3318 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3319 | int attr) | |
3320 | { | |
3321 | struct nlattr *rate; | |
8eb41c8d VK |
3322 | u32 bitrate; |
3323 | u16 bitrate_compat; | |
c8dcfd8a FF |
3324 | |
3325 | rate = nla_nest_start(msg, attr); | |
3326 | if (!rate) | |
db9c64cf | 3327 | return false; |
c8dcfd8a FF |
3328 | |
3329 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3330 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3331 | /* report 16-bit bitrate only if we can */ |
3332 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3333 | if (bitrate > 0 && |
3334 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3335 | return false; | |
3336 | if (bitrate_compat > 0 && | |
3337 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3338 | return false; | |
3339 | ||
3340 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3341 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3342 | return false; | |
3343 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3344 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3345 | return false; | |
3346 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3347 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3348 | return false; | |
3349 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3350 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3351 | return false; | |
3352 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3353 | return false; | |
3354 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3355 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3356 | return false; | |
3357 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3358 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3359 | return false; | |
3360 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3361 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3362 | return false; | |
3363 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3364 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3365 | return false; | |
3366 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3367 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3368 | return false; | |
3369 | } | |
c8dcfd8a FF |
3370 | |
3371 | nla_nest_end(msg, rate); | |
3372 | return true; | |
c8dcfd8a FF |
3373 | } |
3374 | ||
15e47304 | 3375 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3376 | int flags, |
3377 | struct cfg80211_registered_device *rdev, | |
3378 | struct net_device *dev, | |
98b62183 | 3379 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3380 | { |
3381 | void *hdr; | |
f4263c98 | 3382 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3383 | |
15e47304 | 3384 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3385 | if (!hdr) |
3386 | return -1; | |
3387 | ||
9360ffd1 DM |
3388 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3391 | goto nla_put_failure; | |
f5ea9120 | 3392 | |
2ec600d6 LCC |
3393 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3394 | if (!sinfoattr) | |
fd5b74dc | 3395 | goto nla_put_failure; |
9360ffd1 DM |
3396 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3397 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3398 | sinfo->connected_time)) | |
3399 | goto nla_put_failure; | |
3400 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3401 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3402 | sinfo->inactive_time)) | |
3403 | goto nla_put_failure; | |
42745e03 VK |
3404 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3405 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3406 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3407 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3408 | goto nla_put_failure; |
42745e03 VK |
3409 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
3410 | NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3411 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3412 | (u32)sinfo->tx_bytes)) |
3413 | goto nla_put_failure; | |
3414 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3415 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3416 | sinfo->rx_bytes)) | |
3417 | goto nla_put_failure; | |
3418 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3419 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3420 | sinfo->tx_bytes)) |
3421 | goto nla_put_failure; | |
3422 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3423 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3424 | goto nla_put_failure; | |
3425 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3426 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3427 | goto nla_put_failure; | |
3428 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3429 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3430 | sinfo->plink_state)) | |
3431 | goto nla_put_failure; | |
66266b3a JL |
3432 | switch (rdev->wiphy.signal_type) { |
3433 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3434 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3435 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3436 | sinfo->signal)) | |
3437 | goto nla_put_failure; | |
3438 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3439 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3440 | sinfo->signal_avg)) | |
3441 | goto nla_put_failure; | |
66266b3a JL |
3442 | break; |
3443 | default: | |
3444 | break; | |
3445 | } | |
420e7fab | 3446 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3447 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3448 | NL80211_STA_INFO_TX_BITRATE)) | |
3449 | goto nla_put_failure; | |
3450 | } | |
3451 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3452 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3453 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3454 | goto nla_put_failure; |
420e7fab | 3455 | } |
9360ffd1 DM |
3456 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3457 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3458 | sinfo->rx_packets)) | |
3459 | goto nla_put_failure; | |
3460 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3461 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3462 | sinfo->tx_packets)) | |
3463 | goto nla_put_failure; | |
3464 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3465 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3466 | sinfo->tx_retries)) | |
3467 | goto nla_put_failure; | |
3468 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3469 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3470 | sinfo->tx_failed)) | |
3471 | goto nla_put_failure; | |
3472 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3473 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3474 | sinfo->beacon_loss_count)) | |
3475 | goto nla_put_failure; | |
3b1c5a53 MP |
3476 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3477 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3478 | sinfo->local_pm)) | |
3479 | goto nla_put_failure; | |
3480 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3481 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3482 | sinfo->peer_pm)) | |
3483 | goto nla_put_failure; | |
3484 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3485 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3486 | sinfo->nonpeer_pm)) | |
3487 | goto nla_put_failure; | |
f4263c98 PS |
3488 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3489 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3490 | if (!bss_param) | |
3491 | goto nla_put_failure; | |
3492 | ||
9360ffd1 DM |
3493 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3494 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3495 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3496 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3497 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3498 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3499 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3500 | sinfo->bss_param.dtim_period) || | |
3501 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3502 | sinfo->bss_param.beacon_interval)) | |
3503 | goto nla_put_failure; | |
f4263c98 PS |
3504 | |
3505 | nla_nest_end(msg, bss_param); | |
3506 | } | |
9360ffd1 DM |
3507 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3508 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3509 | sizeof(struct nl80211_sta_flag_update), | |
3510 | &sinfo->sta_flags)) | |
3511 | goto nla_put_failure; | |
7eab0f64 JL |
3512 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3513 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3514 | sinfo->t_offset)) | |
3515 | goto nla_put_failure; | |
2ec600d6 | 3516 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3517 | |
9360ffd1 DM |
3518 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3519 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3520 | sinfo->assoc_req_ies)) | |
3521 | goto nla_put_failure; | |
50d3dfb7 | 3522 | |
fd5b74dc JB |
3523 | return genlmsg_end(msg, hdr); |
3524 | ||
3525 | nla_put_failure: | |
bc3ed28c TG |
3526 | genlmsg_cancel(msg, hdr); |
3527 | return -EMSGSIZE; | |
fd5b74dc JB |
3528 | } |
3529 | ||
2ec600d6 | 3530 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3531 | struct netlink_callback *cb) |
2ec600d6 | 3532 | { |
2ec600d6 LCC |
3533 | struct station_info sinfo; |
3534 | struct cfg80211_registered_device *dev; | |
97990a06 | 3535 | struct wireless_dev *wdev; |
2ec600d6 | 3536 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3537 | int sta_idx = cb->args[2]; |
2ec600d6 | 3538 | int err; |
2ec600d6 | 3539 | |
97990a06 | 3540 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3541 | if (err) |
3542 | return err; | |
bba95fef | 3543 | |
97990a06 JB |
3544 | if (!wdev->netdev) { |
3545 | err = -EINVAL; | |
3546 | goto out_err; | |
3547 | } | |
3548 | ||
bba95fef | 3549 | if (!dev->ops->dump_station) { |
eec60b03 | 3550 | err = -EOPNOTSUPP; |
bba95fef JB |
3551 | goto out_err; |
3552 | } | |
3553 | ||
bba95fef | 3554 | while (1) { |
f612cedf | 3555 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3556 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3557 | mac_addr, &sinfo); |
bba95fef JB |
3558 | if (err == -ENOENT) |
3559 | break; | |
3560 | if (err) | |
3b85875a | 3561 | goto out_err; |
bba95fef JB |
3562 | |
3563 | if (nl80211_send_station(skb, | |
15e47304 | 3564 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3565 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3566 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3567 | &sinfo) < 0) |
3568 | goto out; | |
3569 | ||
3570 | sta_idx++; | |
3571 | } | |
3572 | ||
3573 | ||
3574 | out: | |
97990a06 | 3575 | cb->args[2] = sta_idx; |
bba95fef | 3576 | err = skb->len; |
bba95fef | 3577 | out_err: |
97990a06 | 3578 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3579 | |
3580 | return err; | |
2ec600d6 | 3581 | } |
fd5b74dc | 3582 | |
5727ef1b JB |
3583 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3584 | { | |
4c476991 JB |
3585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3586 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3587 | struct station_info sinfo; |
fd5b74dc JB |
3588 | struct sk_buff *msg; |
3589 | u8 *mac_addr = NULL; | |
4c476991 | 3590 | int err; |
fd5b74dc | 3591 | |
2ec600d6 | 3592 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3593 | |
3594 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3595 | return -EINVAL; | |
3596 | ||
3597 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3598 | ||
4c476991 JB |
3599 | if (!rdev->ops->get_station) |
3600 | return -EOPNOTSUPP; | |
3b85875a | 3601 | |
e35e4d28 | 3602 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3603 | if (err) |
4c476991 | 3604 | return err; |
2ec600d6 | 3605 | |
fd2120ca | 3606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3607 | if (!msg) |
4c476991 | 3608 | return -ENOMEM; |
fd5b74dc | 3609 | |
15e47304 | 3610 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3611 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3612 | nlmsg_free(msg); |
3613 | return -ENOBUFS; | |
3614 | } | |
3b85875a | 3615 | |
4c476991 | 3616 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3617 | } |
3618 | ||
77ee7c89 JB |
3619 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3620 | struct station_parameters *params, | |
3621 | enum cfg80211_station_type statype) | |
3622 | { | |
3623 | if (params->listen_interval != -1) | |
3624 | return -EINVAL; | |
3625 | if (params->aid) | |
3626 | return -EINVAL; | |
3627 | ||
3628 | /* When you run into this, adjust the code below for the new flag */ | |
3629 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3630 | ||
3631 | switch (statype) { | |
eef941e6 TP |
3632 | case CFG80211_STA_MESH_PEER_KERNEL: |
3633 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3634 | /* |
3635 | * No ignoring the TDLS flag here -- the userspace mesh | |
3636 | * code doesn't have the bug of including TDLS in the | |
3637 | * mask everywhere. | |
3638 | */ | |
3639 | if (params->sta_flags_mask & | |
3640 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3641 | BIT(NL80211_STA_FLAG_MFP) | | |
3642 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3643 | return -EINVAL; | |
3644 | break; | |
3645 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3646 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3647 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3648 | return -EINVAL; | |
3649 | /* ignore since it can't change */ | |
3650 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3651 | break; | |
3652 | default: | |
3653 | /* disallow mesh-specific things */ | |
3654 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3655 | return -EINVAL; | |
3656 | if (params->local_pm) | |
3657 | return -EINVAL; | |
3658 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3659 | return -EINVAL; | |
3660 | } | |
3661 | ||
3662 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3663 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3664 | /* TDLS can't be set, ... */ | |
3665 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3666 | return -EINVAL; | |
3667 | /* | |
3668 | * ... but don't bother the driver with it. This works around | |
3669 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3670 | * TLDS_PEER flag in the mask even for AP mode. | |
3671 | */ | |
3672 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3673 | } | |
3674 | ||
3675 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3676 | /* reject other things that can't change */ | |
3677 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3678 | return -EINVAL; | |
3679 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3680 | return -EINVAL; | |
3681 | if (params->supported_rates) | |
3682 | return -EINVAL; | |
3683 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3684 | return -EINVAL; | |
3685 | } | |
3686 | ||
3687 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3688 | if (params->vlan) | |
3689 | return -EINVAL; | |
3690 | } | |
3691 | ||
3692 | switch (statype) { | |
3693 | case CFG80211_STA_AP_MLME_CLIENT: | |
3694 | /* Use this only for authorizing/unauthorizing a station */ | |
3695 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3696 | return -EOPNOTSUPP; | |
3697 | break; | |
3698 | case CFG80211_STA_AP_CLIENT: | |
3699 | /* accept only the listed bits */ | |
3700 | if (params->sta_flags_mask & | |
3701 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3702 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3703 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3704 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3705 | BIT(NL80211_STA_FLAG_WME) | | |
3706 | BIT(NL80211_STA_FLAG_MFP))) | |
3707 | return -EINVAL; | |
3708 | ||
3709 | /* but authenticated/associated only if driver handles it */ | |
3710 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3711 | params->sta_flags_mask & | |
3712 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3713 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3714 | return -EINVAL; | |
3715 | break; | |
3716 | case CFG80211_STA_IBSS: | |
3717 | case CFG80211_STA_AP_STA: | |
3718 | /* reject any changes other than AUTHORIZED */ | |
3719 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3720 | return -EINVAL; | |
3721 | break; | |
3722 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3723 | /* reject any changes other than AUTHORIZED or WME */ | |
3724 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3725 | BIT(NL80211_STA_FLAG_WME))) | |
3726 | return -EINVAL; | |
3727 | /* force (at least) rates when authorizing */ | |
3728 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3729 | !params->supported_rates) | |
3730 | return -EINVAL; | |
3731 | break; | |
3732 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3733 | /* reject any changes */ | |
3734 | return -EINVAL; | |
eef941e6 | 3735 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3736 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3737 | return -EINVAL; | |
3738 | break; | |
eef941e6 | 3739 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3740 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3741 | return -EINVAL; | |
3742 | break; | |
3743 | } | |
3744 | ||
3745 | return 0; | |
3746 | } | |
3747 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3748 | ||
5727ef1b | 3749 | /* |
c258d2de | 3750 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3751 | */ |
80b99899 JB |
3752 | static struct net_device *get_vlan(struct genl_info *info, |
3753 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3754 | { |
463d0183 | 3755 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3756 | struct net_device *v; |
3757 | int ret; | |
3758 | ||
3759 | if (!vlanattr) | |
3760 | return NULL; | |
3761 | ||
3762 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3763 | if (!v) | |
3764 | return ERR_PTR(-ENODEV); | |
3765 | ||
3766 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3767 | ret = -EINVAL; | |
3768 | goto error; | |
5727ef1b | 3769 | } |
80b99899 | 3770 | |
77ee7c89 JB |
3771 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3772 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3773 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3774 | ret = -EINVAL; | |
3775 | goto error; | |
3776 | } | |
3777 | ||
80b99899 JB |
3778 | if (!netif_running(v)) { |
3779 | ret = -ENETDOWN; | |
3780 | goto error; | |
3781 | } | |
3782 | ||
3783 | return v; | |
3784 | error: | |
3785 | dev_put(v); | |
3786 | return ERR_PTR(ret); | |
5727ef1b JB |
3787 | } |
3788 | ||
df881293 JM |
3789 | static struct nla_policy |
3790 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3791 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3792 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3793 | }; | |
3794 | ||
ff276691 JB |
3795 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3796 | struct station_parameters *params) | |
df881293 | 3797 | { |
df881293 JM |
3798 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3799 | struct nlattr *nla; | |
3800 | int err; | |
3801 | ||
df881293 JM |
3802 | /* parse WME attributes if present */ |
3803 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3804 | return 0; | |
3805 | ||
3806 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3807 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3808 | nl80211_sta_wme_policy); | |
3809 | if (err) | |
3810 | return err; | |
3811 | ||
3812 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3813 | params->uapsd_queues = nla_get_u8( | |
3814 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3815 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3816 | return -EINVAL; | |
3817 | ||
3818 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3819 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3820 | ||
3821 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3822 | return -EINVAL; | |
3823 | ||
3824 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3825 | ||
3826 | return 0; | |
3827 | } | |
3828 | ||
ff276691 JB |
3829 | static int nl80211_set_station_tdls(struct genl_info *info, |
3830 | struct station_parameters *params) | |
3831 | { | |
3832 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
3833 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | |
3834 | params->ht_capa = | |
3835 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3836 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3837 | params->vht_capa = | |
3838 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3839 | ||
3840 | return nl80211_parse_sta_wme(info, params); | |
3841 | } | |
3842 | ||
5727ef1b JB |
3843 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3844 | { | |
4c476991 | 3845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3846 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3847 | struct station_parameters params; |
77ee7c89 JB |
3848 | u8 *mac_addr; |
3849 | int err; | |
5727ef1b JB |
3850 | |
3851 | memset(¶ms, 0, sizeof(params)); | |
3852 | ||
3853 | params.listen_interval = -1; | |
3854 | ||
77ee7c89 JB |
3855 | if (!rdev->ops->change_station) |
3856 | return -EOPNOTSUPP; | |
3857 | ||
5727ef1b JB |
3858 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3859 | return -EINVAL; | |
3860 | ||
3861 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3862 | return -EINVAL; | |
3863 | ||
3864 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3865 | ||
3866 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3867 | params.supported_rates = | |
3868 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3869 | params.supported_rates_len = | |
3870 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3871 | } | |
3872 | ||
9d62a986 JM |
3873 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3874 | params.capability = | |
3875 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3876 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3877 | } | |
3878 | ||
3879 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3880 | params.ext_capab = | |
3881 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3882 | params.ext_capab_len = | |
3883 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3884 | } | |
3885 | ||
df881293 | 3886 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3887 | return -EINVAL; |
36aedc90 | 3888 | |
bdd3ae3d | 3889 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3890 | return -EINVAL; |
3891 | ||
f8bacc21 | 3892 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3893 | params.plink_action = |
f8bacc21 JB |
3894 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3895 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3896 | return -EINVAL; | |
3897 | } | |
2ec600d6 | 3898 | |
f8bacc21 | 3899 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3900 | params.plink_state = |
f8bacc21 JB |
3901 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3902 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3903 | return -EINVAL; | |
3904 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3905 | } | |
9c3990aa | 3906 | |
3b1c5a53 MP |
3907 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3908 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3909 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3910 | ||
3911 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3912 | pm > NL80211_MESH_POWER_MAX) | |
3913 | return -EINVAL; | |
3914 | ||
3915 | params.local_pm = pm; | |
3916 | } | |
3917 | ||
77ee7c89 JB |
3918 | /* Include parameters for TDLS peer (will check later) */ |
3919 | err = nl80211_set_station_tdls(info, ¶ms); | |
3920 | if (err) | |
3921 | return err; | |
3922 | ||
3923 | params.vlan = get_vlan(info, rdev); | |
3924 | if (IS_ERR(params.vlan)) | |
3925 | return PTR_ERR(params.vlan); | |
3926 | ||
a97f4424 JB |
3927 | switch (dev->ieee80211_ptr->iftype) { |
3928 | case NL80211_IFTYPE_AP: | |
3929 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3930 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3931 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3932 | case NL80211_IFTYPE_STATION: |
267335d6 | 3933 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3934 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3935 | break; |
3936 | default: | |
77ee7c89 JB |
3937 | err = -EOPNOTSUPP; |
3938 | goto out_put_vlan; | |
034d655e JB |
3939 | } |
3940 | ||
77ee7c89 | 3941 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 3942 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3943 | |
77ee7c89 | 3944 | out_put_vlan: |
5727ef1b JB |
3945 | if (params.vlan) |
3946 | dev_put(params.vlan); | |
3b85875a | 3947 | |
5727ef1b JB |
3948 | return err; |
3949 | } | |
3950 | ||
3951 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
3952 | { | |
4c476991 | 3953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3954 | int err; |
4c476991 | 3955 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3956 | struct station_parameters params; |
3957 | u8 *mac_addr = NULL; | |
3958 | ||
3959 | memset(¶ms, 0, sizeof(params)); | |
3960 | ||
984c311b JB |
3961 | if (!rdev->ops->add_station) |
3962 | return -EOPNOTSUPP; | |
3963 | ||
5727ef1b JB |
3964 | if (!info->attrs[NL80211_ATTR_MAC]) |
3965 | return -EINVAL; | |
3966 | ||
5727ef1b JB |
3967 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3968 | return -EINVAL; | |
3969 | ||
3970 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3971 | return -EINVAL; | |
3972 | ||
0e956c13 TLSC |
3973 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
3974 | return -EINVAL; | |
3975 | ||
5727ef1b JB |
3976 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3977 | params.supported_rates = | |
3978 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3979 | params.supported_rates_len = | |
3980 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3981 | params.listen_interval = | |
3982 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3983 | |
0e956c13 TLSC |
3984 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
3985 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
3986 | return -EINVAL; | |
51b50fbe | 3987 | |
9d62a986 JM |
3988 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3989 | params.capability = | |
3990 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3991 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3992 | } | |
3993 | ||
3994 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3995 | params.ext_capab = | |
3996 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3997 | params.ext_capab_len = | |
3998 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3999 | } | |
4000 | ||
36aedc90 JM |
4001 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4002 | params.ht_capa = | |
4003 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4004 | |
f461be3e MP |
4005 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4006 | params.vht_capa = | |
4007 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4008 | ||
f8bacc21 | 4009 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4010 | params.plink_action = |
f8bacc21 JB |
4011 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4012 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4013 | return -EINVAL; | |
4014 | } | |
96b78dff | 4015 | |
ff276691 JB |
4016 | err = nl80211_parse_sta_wme(info, ¶ms); |
4017 | if (err) | |
4018 | return err; | |
bdd90d5e | 4019 | |
bdd3ae3d | 4020 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4021 | return -EINVAL; |
4022 | ||
77ee7c89 JB |
4023 | /* When you run into this, adjust the code below for the new flag */ |
4024 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4025 | ||
bdd90d5e JB |
4026 | switch (dev->ieee80211_ptr->iftype) { |
4027 | case NL80211_IFTYPE_AP: | |
4028 | case NL80211_IFTYPE_AP_VLAN: | |
4029 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4030 | /* ignore WME attributes if iface/sta is not capable */ |
4031 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4032 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4033 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4034 | |
bdd90d5e JB |
4035 | /* TDLS peers cannot be added */ |
4036 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 4037 | return -EINVAL; |
bdd90d5e JB |
4038 | /* but don't bother the driver with it */ |
4039 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4040 | |
d582cffb JB |
4041 | /* allow authenticated/associated only if driver handles it */ |
4042 | if (!(rdev->wiphy.features & | |
4043 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4044 | params.sta_flags_mask & | |
4045 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4046 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4047 | return -EINVAL; | |
4048 | ||
bdd90d5e JB |
4049 | /* must be last in here for error handling */ |
4050 | params.vlan = get_vlan(info, rdev); | |
4051 | if (IS_ERR(params.vlan)) | |
4052 | return PTR_ERR(params.vlan); | |
4053 | break; | |
4054 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4055 | /* ignore uAPSD data */ |
4056 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4057 | ||
d582cffb JB |
4058 | /* associated is disallowed */ |
4059 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4060 | return -EINVAL; | |
bdd90d5e JB |
4061 | /* TDLS peers cannot be added */ |
4062 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4063 | return -EINVAL; | |
4064 | break; | |
4065 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4066 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4067 | /* ignore uAPSD data */ |
4068 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4069 | ||
77ee7c89 JB |
4070 | /* these are disallowed */ |
4071 | if (params.sta_flags_mask & | |
4072 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4073 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4074 | return -EINVAL; |
bdd90d5e JB |
4075 | /* Only TDLS peers can be added */ |
4076 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4077 | return -EINVAL; | |
4078 | /* Can only add if TDLS ... */ | |
4079 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4080 | return -EOPNOTSUPP; | |
4081 | /* ... with external setup is supported */ | |
4082 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4083 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4084 | /* |
4085 | * Older wpa_supplicant versions always mark the TDLS peer | |
4086 | * as authorized, but it shouldn't yet be. | |
4087 | */ | |
4088 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4089 | break; |
4090 | default: | |
4091 | return -EOPNOTSUPP; | |
c75786c9 EP |
4092 | } |
4093 | ||
bdd90d5e | 4094 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4095 | |
e35e4d28 | 4096 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4097 | |
5727ef1b JB |
4098 | if (params.vlan) |
4099 | dev_put(params.vlan); | |
5727ef1b JB |
4100 | return err; |
4101 | } | |
4102 | ||
4103 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4104 | { | |
4c476991 JB |
4105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4106 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4107 | u8 *mac_addr = NULL; |
4108 | ||
4109 | if (info->attrs[NL80211_ATTR_MAC]) | |
4110 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4111 | ||
e80cf853 | 4112 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4113 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4114 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4115 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4116 | return -EINVAL; | |
5727ef1b | 4117 | |
4c476991 JB |
4118 | if (!rdev->ops->del_station) |
4119 | return -EOPNOTSUPP; | |
3b85875a | 4120 | |
e35e4d28 | 4121 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4122 | } |
4123 | ||
15e47304 | 4124 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4125 | int flags, struct net_device *dev, |
4126 | u8 *dst, u8 *next_hop, | |
4127 | struct mpath_info *pinfo) | |
4128 | { | |
4129 | void *hdr; | |
4130 | struct nlattr *pinfoattr; | |
4131 | ||
15e47304 | 4132 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4133 | if (!hdr) |
4134 | return -1; | |
4135 | ||
9360ffd1 DM |
4136 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4137 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4138 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4139 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4140 | goto nla_put_failure; | |
f5ea9120 | 4141 | |
2ec600d6 LCC |
4142 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4143 | if (!pinfoattr) | |
4144 | goto nla_put_failure; | |
9360ffd1 DM |
4145 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4146 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4147 | pinfo->frame_qlen)) | |
4148 | goto nla_put_failure; | |
4149 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4150 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4151 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4152 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4153 | pinfo->metric)) || | |
4154 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4155 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4156 | pinfo->exptime)) || | |
4157 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4158 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4159 | pinfo->flags)) || | |
4160 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4161 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4162 | pinfo->discovery_timeout)) || | |
4163 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4164 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4165 | pinfo->discovery_retries))) | |
4166 | goto nla_put_failure; | |
2ec600d6 LCC |
4167 | |
4168 | nla_nest_end(msg, pinfoattr); | |
4169 | ||
4170 | return genlmsg_end(msg, hdr); | |
4171 | ||
4172 | nla_put_failure: | |
bc3ed28c TG |
4173 | genlmsg_cancel(msg, hdr); |
4174 | return -EMSGSIZE; | |
2ec600d6 LCC |
4175 | } |
4176 | ||
4177 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4178 | struct netlink_callback *cb) |
2ec600d6 | 4179 | { |
2ec600d6 LCC |
4180 | struct mpath_info pinfo; |
4181 | struct cfg80211_registered_device *dev; | |
97990a06 | 4182 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4183 | u8 dst[ETH_ALEN]; |
4184 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4185 | int path_idx = cb->args[2]; |
2ec600d6 | 4186 | int err; |
2ec600d6 | 4187 | |
97990a06 | 4188 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4189 | if (err) |
4190 | return err; | |
bba95fef JB |
4191 | |
4192 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4193 | err = -EOPNOTSUPP; |
bba95fef JB |
4194 | goto out_err; |
4195 | } | |
4196 | ||
97990a06 | 4197 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4198 | err = -EOPNOTSUPP; |
0448b5fc | 4199 | goto out_err; |
eec60b03 JM |
4200 | } |
4201 | ||
bba95fef | 4202 | while (1) { |
97990a06 JB |
4203 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4204 | next_hop, &pinfo); | |
bba95fef | 4205 | if (err == -ENOENT) |
2ec600d6 | 4206 | break; |
bba95fef | 4207 | if (err) |
3b85875a | 4208 | goto out_err; |
2ec600d6 | 4209 | |
15e47304 | 4210 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4211 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4212 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4213 | &pinfo) < 0) |
4214 | goto out; | |
2ec600d6 | 4215 | |
bba95fef | 4216 | path_idx++; |
2ec600d6 | 4217 | } |
2ec600d6 | 4218 | |
2ec600d6 | 4219 | |
bba95fef | 4220 | out: |
97990a06 | 4221 | cb->args[2] = path_idx; |
bba95fef | 4222 | err = skb->len; |
bba95fef | 4223 | out_err: |
97990a06 | 4224 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4225 | return err; |
2ec600d6 LCC |
4226 | } |
4227 | ||
4228 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4229 | { | |
4c476991 | 4230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4231 | int err; |
4c476991 | 4232 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4233 | struct mpath_info pinfo; |
4234 | struct sk_buff *msg; | |
4235 | u8 *dst = NULL; | |
4236 | u8 next_hop[ETH_ALEN]; | |
4237 | ||
4238 | memset(&pinfo, 0, sizeof(pinfo)); | |
4239 | ||
4240 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4241 | return -EINVAL; | |
4242 | ||
4243 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4244 | ||
4c476991 JB |
4245 | if (!rdev->ops->get_mpath) |
4246 | return -EOPNOTSUPP; | |
2ec600d6 | 4247 | |
4c476991 JB |
4248 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4249 | return -EOPNOTSUPP; | |
eec60b03 | 4250 | |
e35e4d28 | 4251 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4252 | if (err) |
4c476991 | 4253 | return err; |
2ec600d6 | 4254 | |
fd2120ca | 4255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4256 | if (!msg) |
4c476991 | 4257 | return -ENOMEM; |
2ec600d6 | 4258 | |
15e47304 | 4259 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4260 | dev, dst, next_hop, &pinfo) < 0) { |
4261 | nlmsg_free(msg); | |
4262 | return -ENOBUFS; | |
4263 | } | |
3b85875a | 4264 | |
4c476991 | 4265 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4266 | } |
4267 | ||
4268 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4269 | { | |
4c476991 JB |
4270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4271 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4272 | u8 *dst = NULL; |
4273 | u8 *next_hop = NULL; | |
4274 | ||
4275 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4276 | return -EINVAL; | |
4277 | ||
4278 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4279 | return -EINVAL; | |
4280 | ||
4281 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4282 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4283 | ||
4c476991 JB |
4284 | if (!rdev->ops->change_mpath) |
4285 | return -EOPNOTSUPP; | |
35a8efe1 | 4286 | |
4c476991 JB |
4287 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4288 | return -EOPNOTSUPP; | |
2ec600d6 | 4289 | |
e35e4d28 | 4290 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4291 | } |
4c476991 | 4292 | |
2ec600d6 LCC |
4293 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4294 | { | |
4c476991 JB |
4295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4296 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4297 | u8 *dst = NULL; |
4298 | u8 *next_hop = NULL; | |
4299 | ||
4300 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4301 | return -EINVAL; | |
4302 | ||
4303 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4304 | return -EINVAL; | |
4305 | ||
4306 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4307 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4308 | ||
4c476991 JB |
4309 | if (!rdev->ops->add_mpath) |
4310 | return -EOPNOTSUPP; | |
35a8efe1 | 4311 | |
4c476991 JB |
4312 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4313 | return -EOPNOTSUPP; | |
2ec600d6 | 4314 | |
e35e4d28 | 4315 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4316 | } |
4317 | ||
4318 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4319 | { | |
4c476991 JB |
4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4321 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4322 | u8 *dst = NULL; |
4323 | ||
4324 | if (info->attrs[NL80211_ATTR_MAC]) | |
4325 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4326 | ||
4c476991 JB |
4327 | if (!rdev->ops->del_mpath) |
4328 | return -EOPNOTSUPP; | |
3b85875a | 4329 | |
e35e4d28 | 4330 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4331 | } |
4332 | ||
9f1ba906 JM |
4333 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4334 | { | |
4c476991 JB |
4335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4336 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4337 | struct bss_parameters params; |
4338 | ||
4339 | memset(¶ms, 0, sizeof(params)); | |
4340 | /* default to not changing parameters */ | |
4341 | params.use_cts_prot = -1; | |
4342 | params.use_short_preamble = -1; | |
4343 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4344 | params.ap_isolate = -1; |
50b12f59 | 4345 | params.ht_opmode = -1; |
53cabad7 JB |
4346 | params.p2p_ctwindow = -1; |
4347 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4348 | |
4349 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4350 | params.use_cts_prot = | |
4351 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4352 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4353 | params.use_short_preamble = | |
4354 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4355 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4356 | params.use_short_slot_time = | |
4357 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4358 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4359 | params.basic_rates = | |
4360 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4361 | params.basic_rates_len = | |
4362 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4363 | } | |
fd8aaaf3 FF |
4364 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4365 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4366 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4367 | params.ht_opmode = | |
4368 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4369 | |
53cabad7 JB |
4370 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4372 | return -EINVAL; | |
4373 | params.p2p_ctwindow = | |
4374 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4375 | if (params.p2p_ctwindow < 0) | |
4376 | return -EINVAL; | |
4377 | if (params.p2p_ctwindow != 0 && | |
4378 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4379 | return -EINVAL; | |
4380 | } | |
4381 | ||
4382 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4383 | u8 tmp; | |
4384 | ||
4385 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4386 | return -EINVAL; | |
4387 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4388 | if (tmp > 1) | |
4389 | return -EINVAL; | |
4390 | params.p2p_opp_ps = tmp; | |
4391 | if (params.p2p_opp_ps && | |
4392 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4393 | return -EINVAL; | |
4394 | } | |
4395 | ||
4c476991 JB |
4396 | if (!rdev->ops->change_bss) |
4397 | return -EOPNOTSUPP; | |
9f1ba906 | 4398 | |
074ac8df | 4399 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4400 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4401 | return -EOPNOTSUPP; | |
3b85875a | 4402 | |
e35e4d28 | 4403 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4404 | } |
4405 | ||
b54452b0 | 4406 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4407 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4408 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4409 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4410 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4411 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4412 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4413 | }; | |
4414 | ||
4415 | static int parse_reg_rule(struct nlattr *tb[], | |
4416 | struct ieee80211_reg_rule *reg_rule) | |
4417 | { | |
4418 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4419 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4420 | ||
4421 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4422 | return -EINVAL; | |
4423 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4424 | return -EINVAL; | |
4425 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4426 | return -EINVAL; | |
4427 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4428 | return -EINVAL; | |
4429 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4430 | return -EINVAL; | |
4431 | ||
4432 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4433 | ||
4434 | freq_range->start_freq_khz = | |
4435 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4436 | freq_range->end_freq_khz = | |
4437 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4438 | freq_range->max_bandwidth_khz = | |
4439 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4440 | ||
4441 | power_rule->max_eirp = | |
4442 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4443 | ||
4444 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4445 | power_rule->max_antenna_gain = | |
4446 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4447 | ||
4448 | return 0; | |
4449 | } | |
4450 | ||
4451 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4452 | { | |
4453 | int r; | |
4454 | char *data = NULL; | |
57b5ce07 | 4455 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4456 | |
80778f18 LR |
4457 | /* |
4458 | * You should only get this when cfg80211 hasn't yet initialized | |
4459 | * completely when built-in to the kernel right between the time | |
4460 | * window between nl80211_init() and regulatory_init(), if that is | |
4461 | * even possible. | |
4462 | */ | |
458f4f9e | 4463 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4464 | return -EINPROGRESS; |
80778f18 | 4465 | |
fe33eb39 LR |
4466 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4467 | return -EINVAL; | |
b2e1b302 LR |
4468 | |
4469 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4470 | ||
57b5ce07 LR |
4471 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4472 | user_reg_hint_type = | |
4473 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4474 | else | |
4475 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4476 | ||
4477 | switch (user_reg_hint_type) { | |
4478 | case NL80211_USER_REG_HINT_USER: | |
4479 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4480 | break; | |
4481 | default: | |
4482 | return -EINVAL; | |
4483 | } | |
4484 | ||
4485 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4486 | |
b2e1b302 LR |
4487 | return r; |
4488 | } | |
4489 | ||
24bdd9f4 | 4490 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4491 | struct genl_info *info) |
93da9cc1 | 4492 | { |
4c476991 | 4493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4494 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4495 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4496 | struct mesh_config cur_params; | |
4497 | int err = 0; | |
93da9cc1 | 4498 | void *hdr; |
4499 | struct nlattr *pinfoattr; | |
4500 | struct sk_buff *msg; | |
4501 | ||
29cbe68c JB |
4502 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4503 | return -EOPNOTSUPP; | |
4504 | ||
24bdd9f4 | 4505 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4506 | return -EOPNOTSUPP; |
f3f92586 | 4507 | |
29cbe68c JB |
4508 | wdev_lock(wdev); |
4509 | /* If not connected, get default parameters */ | |
4510 | if (!wdev->mesh_id_len) | |
4511 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4512 | else | |
e35e4d28 | 4513 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4514 | wdev_unlock(wdev); |
4515 | ||
93da9cc1 | 4516 | if (err) |
4c476991 | 4517 | return err; |
93da9cc1 | 4518 | |
4519 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4521 | if (!msg) |
4522 | return -ENOMEM; | |
15e47304 | 4523 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4524 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4525 | if (!hdr) |
efe1cf0c | 4526 | goto out; |
24bdd9f4 | 4527 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4528 | if (!pinfoattr) |
4529 | goto nla_put_failure; | |
9360ffd1 DM |
4530 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4531 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4532 | cur_params.dot11MeshRetryTimeout) || | |
4533 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4534 | cur_params.dot11MeshConfirmTimeout) || | |
4535 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4536 | cur_params.dot11MeshHoldingTimeout) || | |
4537 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4538 | cur_params.dot11MeshMaxPeerLinks) || | |
4539 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4540 | cur_params.dot11MeshMaxRetries) || | |
4541 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4542 | cur_params.dot11MeshTTL) || | |
4543 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4544 | cur_params.element_ttl) || | |
4545 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4546 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4547 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4548 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4549 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4550 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4551 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4552 | cur_params.path_refresh_time) || | |
4553 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4554 | cur_params.min_discovery_timeout) || | |
4555 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4556 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4557 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4558 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4559 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4560 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4561 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4562 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4563 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4564 | cur_params.dot11MeshHWMPRootMode) || | |
4565 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4566 | cur_params.dot11MeshHWMPRannInterval) || | |
4567 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4568 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4569 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4570 | cur_params.dot11MeshForwarding) || | |
4571 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4572 | cur_params.rssi_threshold) || |
4573 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4574 | cur_params.ht_opmode) || |
4575 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4576 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4577 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4578 | cur_params.dot11MeshHWMProotInterval) || |
4579 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4580 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4581 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4582 | cur_params.power_mode) || | |
4583 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
4584 | cur_params.dot11MeshAwakeWindowDuration)) | |
9360ffd1 | 4585 | goto nla_put_failure; |
93da9cc1 | 4586 | nla_nest_end(msg, pinfoattr); |
4587 | genlmsg_end(msg, hdr); | |
4c476991 | 4588 | return genlmsg_reply(msg, info); |
93da9cc1 | 4589 | |
3b85875a | 4590 | nla_put_failure: |
93da9cc1 | 4591 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4592 | out: |
d080e275 | 4593 | nlmsg_free(msg); |
4c476991 | 4594 | return -ENOBUFS; |
93da9cc1 | 4595 | } |
4596 | ||
b54452b0 | 4597 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4598 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4599 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4600 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4601 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4602 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4603 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4604 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4605 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4606 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4607 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4608 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4609 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4610 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4611 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4612 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4613 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4614 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4615 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4616 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4617 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4618 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4619 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4620 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4621 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4622 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4623 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4624 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
93da9cc1 | 4625 | }; |
4626 | ||
c80d545d JC |
4627 | static const struct nla_policy |
4628 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4629 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4630 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4631 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4632 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
bb2798d4 | 4633 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4634 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4635 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4636 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4637 | }; |
4638 | ||
24bdd9f4 | 4639 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4640 | struct mesh_config *cfg, |
4641 | u32 *mask_out) | |
93da9cc1 | 4642 | { |
93da9cc1 | 4643 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4644 | u32 mask = 0; |
93da9cc1 | 4645 | |
ea54fba2 MP |
4646 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4647 | do { \ | |
4648 | if (tb[attr]) { \ | |
4649 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4650 | return -EINVAL; \ | |
4651 | cfg->param = fn(tb[attr]); \ | |
4652 | mask |= (1 << (attr - 1)); \ | |
4653 | } \ | |
4654 | } while (0) | |
bd90fdcc JB |
4655 | |
4656 | ||
24bdd9f4 | 4657 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4658 | return -EINVAL; |
4659 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4660 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4661 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4662 | return -EINVAL; |
4663 | ||
93da9cc1 | 4664 | /* This makes sure that there aren't more than 32 mesh config |
4665 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4666 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4667 | ||
4668 | /* Fill in the params struct */ | |
ea54fba2 | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4670 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4671 | nla_get_u16); | |
ea54fba2 | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4673 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4674 | nla_get_u16); | |
ea54fba2 | 4675 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4676 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4677 | nla_get_u16); | |
ea54fba2 | 4678 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4679 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4680 | nla_get_u16); | |
ea54fba2 | 4681 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4682 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4683 | nla_get_u8); | |
ea54fba2 | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4685 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4686 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4687 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4688 | nla_get_u8); | |
ea54fba2 | 4689 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4690 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4691 | nla_get_u8); | |
ea54fba2 MP |
4692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4693 | 1, 255, mask, | |
a4f606ea CYY |
4694 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4695 | nla_get_u32); | |
ea54fba2 | 4696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4697 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4698 | nla_get_u8); | |
ea54fba2 | 4699 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4700 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4701 | nla_get_u32); | |
ea54fba2 | 4702 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4703 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4704 | nla_get_u16); | |
ea54fba2 MP |
4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4706 | 1, 65535, mask, | |
a4f606ea CYY |
4707 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4708 | nla_get_u32); | |
93da9cc1 | 4709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4710 | 1, 65535, mask, |
4711 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4712 | nla_get_u16); |
dca7e943 | 4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4714 | 1, 65535, mask, |
4715 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4716 | nla_get_u16); |
93da9cc1 | 4717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4718 | dot11MeshHWMPnetDiameterTraversalTime, |
4719 | 1, 65535, mask, | |
a4f606ea CYY |
4720 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4721 | nla_get_u16); | |
ea54fba2 MP |
4722 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4723 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4724 | nla_get_u8); | |
4725 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4726 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4727 | nla_get_u16); |
63c5723b | 4728 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4729 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4730 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4731 | nla_get_u8); |
ea54fba2 | 4732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4733 | mask, NL80211_MESHCONF_FORWARDING, |
4734 | nla_get_u8); | |
ea54fba2 | 4735 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4736 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4737 | nla_get_u32); | |
ea54fba2 | 4738 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4739 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4740 | nla_get_u16); |
4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4742 | 1, 65535, mask, |
ac1073a6 CYY |
4743 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4744 | nla_get_u32); | |
ea54fba2 | 4745 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4746 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4747 | nla_get_u16); |
4748 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4749 | dot11MeshHWMPconfirmationInterval, |
4750 | 1, 65535, mask, | |
728b19e5 | 4751 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4752 | nla_get_u16); |
3b1c5a53 MP |
4753 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4754 | NL80211_MESH_POWER_ACTIVE, | |
4755 | NL80211_MESH_POWER_MAX, | |
4756 | mask, NL80211_MESHCONF_POWER_MODE, | |
4757 | nla_get_u32); | |
4758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4759 | 0, 65535, mask, | |
4760 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
bd90fdcc JB |
4761 | if (mask_out) |
4762 | *mask_out = mask; | |
c80d545d | 4763 | |
bd90fdcc JB |
4764 | return 0; |
4765 | ||
4766 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4767 | } | |
4768 | ||
c80d545d JC |
4769 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4770 | struct mesh_setup *setup) | |
4771 | { | |
bb2798d4 | 4772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4773 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4774 | ||
4775 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4776 | return -EINVAL; | |
4777 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4778 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4779 | nl80211_mesh_setup_params_policy)) | |
4780 | return -EINVAL; | |
4781 | ||
d299a1f2 JC |
4782 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4783 | setup->sync_method = | |
4784 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4785 | IEEE80211_SYNC_METHOD_VENDOR : | |
4786 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4787 | ||
c80d545d JC |
4788 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4789 | setup->path_sel_proto = | |
4790 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4791 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4792 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4793 | ||
4794 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4795 | setup->path_metric = | |
4796 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4797 | IEEE80211_PATH_METRIC_VENDOR : | |
4798 | IEEE80211_PATH_METRIC_AIRTIME; | |
4799 | ||
581a8b0f JC |
4800 | |
4801 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4802 | struct nlattr *ieattr = |
581a8b0f | 4803 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4804 | if (!is_valid_ie_attr(ieattr)) |
4805 | return -EINVAL; | |
581a8b0f JC |
4806 | setup->ie = nla_data(ieattr); |
4807 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4808 | } |
bb2798d4 TP |
4809 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4810 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4811 | return -EINVAL; | |
4812 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4813 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4814 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4815 | if (setup->is_secure) |
4816 | setup->user_mpm = true; | |
c80d545d JC |
4817 | |
4818 | return 0; | |
4819 | } | |
4820 | ||
24bdd9f4 | 4821 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4822 | struct genl_info *info) |
bd90fdcc JB |
4823 | { |
4824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4825 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4826 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4827 | struct mesh_config cfg; |
4828 | u32 mask; | |
4829 | int err; | |
4830 | ||
29cbe68c JB |
4831 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4832 | return -EOPNOTSUPP; | |
4833 | ||
24bdd9f4 | 4834 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4835 | return -EOPNOTSUPP; |
4836 | ||
24bdd9f4 | 4837 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4838 | if (err) |
4839 | return err; | |
4840 | ||
29cbe68c JB |
4841 | wdev_lock(wdev); |
4842 | if (!wdev->mesh_id_len) | |
4843 | err = -ENOLINK; | |
4844 | ||
4845 | if (!err) | |
e35e4d28 | 4846 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4847 | |
4848 | wdev_unlock(wdev); | |
4849 | ||
4850 | return err; | |
93da9cc1 | 4851 | } |
4852 | ||
f130347c LR |
4853 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4854 | { | |
458f4f9e | 4855 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4856 | struct sk_buff *msg; |
4857 | void *hdr = NULL; | |
4858 | struct nlattr *nl_reg_rules; | |
4859 | unsigned int i; | |
4860 | int err = -EINVAL; | |
4861 | ||
a1794390 | 4862 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
4863 | |
4864 | if (!cfg80211_regdomain) | |
4865 | goto out; | |
4866 | ||
fd2120ca | 4867 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
4868 | if (!msg) { |
4869 | err = -ENOBUFS; | |
4870 | goto out; | |
4871 | } | |
4872 | ||
15e47304 | 4873 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4874 | NL80211_CMD_GET_REG); |
4875 | if (!hdr) | |
efe1cf0c | 4876 | goto put_failure; |
f130347c | 4877 | |
57b5ce07 LR |
4878 | if (reg_last_request_cell_base() && |
4879 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4880 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4881 | goto nla_put_failure; | |
4882 | ||
458f4f9e JB |
4883 | rcu_read_lock(); |
4884 | regdom = rcu_dereference(cfg80211_regdomain); | |
4885 | ||
4886 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4887 | (regdom->dfs_region && | |
4888 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4889 | goto nla_put_failure_rcu; | |
4890 | ||
f130347c LR |
4891 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4892 | if (!nl_reg_rules) | |
458f4f9e | 4893 | goto nla_put_failure_rcu; |
f130347c | 4894 | |
458f4f9e | 4895 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4896 | struct nlattr *nl_reg_rule; |
4897 | const struct ieee80211_reg_rule *reg_rule; | |
4898 | const struct ieee80211_freq_range *freq_range; | |
4899 | const struct ieee80211_power_rule *power_rule; | |
4900 | ||
458f4f9e | 4901 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4902 | freq_range = ®_rule->freq_range; |
4903 | power_rule = ®_rule->power_rule; | |
4904 | ||
4905 | nl_reg_rule = nla_nest_start(msg, i); | |
4906 | if (!nl_reg_rule) | |
458f4f9e | 4907 | goto nla_put_failure_rcu; |
f130347c | 4908 | |
9360ffd1 DM |
4909 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4910 | reg_rule->flags) || | |
4911 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4912 | freq_range->start_freq_khz) || | |
4913 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4914 | freq_range->end_freq_khz) || | |
4915 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4916 | freq_range->max_bandwidth_khz) || | |
4917 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4918 | power_rule->max_antenna_gain) || | |
4919 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4920 | power_rule->max_eirp)) | |
458f4f9e | 4921 | goto nla_put_failure_rcu; |
f130347c LR |
4922 | |
4923 | nla_nest_end(msg, nl_reg_rule); | |
4924 | } | |
458f4f9e | 4925 | rcu_read_unlock(); |
f130347c LR |
4926 | |
4927 | nla_nest_end(msg, nl_reg_rules); | |
4928 | ||
4929 | genlmsg_end(msg, hdr); | |
134e6375 | 4930 | err = genlmsg_reply(msg, info); |
f130347c LR |
4931 | goto out; |
4932 | ||
458f4f9e JB |
4933 | nla_put_failure_rcu: |
4934 | rcu_read_unlock(); | |
f130347c LR |
4935 | nla_put_failure: |
4936 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4937 | put_failure: |
d080e275 | 4938 | nlmsg_free(msg); |
f130347c LR |
4939 | err = -EMSGSIZE; |
4940 | out: | |
a1794390 | 4941 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
4942 | return err; |
4943 | } | |
4944 | ||
b2e1b302 LR |
4945 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
4946 | { | |
4947 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
4948 | struct nlattr *nl_reg_rule; | |
4949 | char *alpha2 = NULL; | |
4950 | int rem_reg_rules = 0, r = 0; | |
4951 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 4952 | u8 dfs_region = 0; |
b2e1b302 LR |
4953 | struct ieee80211_regdomain *rd = NULL; |
4954 | ||
4955 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
4956 | return -EINVAL; | |
4957 | ||
4958 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
4959 | return -EINVAL; | |
4960 | ||
4961 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4962 | ||
8b60b078 LR |
4963 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
4964 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
4965 | ||
b2e1b302 | 4966 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4967 | rem_reg_rules) { |
b2e1b302 LR |
4968 | num_rules++; |
4969 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 4970 | return -EINVAL; |
b2e1b302 LR |
4971 | } |
4972 | ||
b2e1b302 | 4973 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 4974 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
4975 | |
4976 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
4977 | if (!rd) |
4978 | return -ENOMEM; | |
b2e1b302 LR |
4979 | |
4980 | rd->n_reg_rules = num_rules; | |
4981 | rd->alpha2[0] = alpha2[0]; | |
4982 | rd->alpha2[1] = alpha2[1]; | |
4983 | ||
8b60b078 LR |
4984 | /* |
4985 | * Disable DFS master mode if the DFS region was | |
4986 | * not supported or known on this kernel. | |
4987 | */ | |
4988 | if (reg_supported_dfs_region(dfs_region)) | |
4989 | rd->dfs_region = dfs_region; | |
4990 | ||
b2e1b302 | 4991 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4992 | rem_reg_rules) { |
b2e1b302 | 4993 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
4994 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
4995 | reg_rule_policy); | |
b2e1b302 LR |
4996 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
4997 | if (r) | |
4998 | goto bad_reg; | |
4999 | ||
5000 | rule_idx++; | |
5001 | ||
d0e18f83 LR |
5002 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5003 | r = -EINVAL; | |
b2e1b302 | 5004 | goto bad_reg; |
d0e18f83 | 5005 | } |
b2e1b302 LR |
5006 | } |
5007 | ||
6913b49a JB |
5008 | mutex_lock(&cfg80211_mutex); |
5009 | ||
b2e1b302 | 5010 | r = set_regdom(rd); |
6913b49a | 5011 | /* set_regdom took ownership */ |
1a919318 | 5012 | rd = NULL; |
6913b49a | 5013 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 5014 | |
d2372b31 | 5015 | bad_reg: |
b2e1b302 | 5016 | kfree(rd); |
d0e18f83 | 5017 | return r; |
b2e1b302 LR |
5018 | } |
5019 | ||
83f5e2cf JB |
5020 | static int validate_scan_freqs(struct nlattr *freqs) |
5021 | { | |
5022 | struct nlattr *attr1, *attr2; | |
5023 | int n_channels = 0, tmp1, tmp2; | |
5024 | ||
5025 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5026 | n_channels++; | |
5027 | /* | |
5028 | * Some hardware has a limited channel list for | |
5029 | * scanning, and it is pretty much nonsensical | |
5030 | * to scan for a channel twice, so disallow that | |
5031 | * and don't require drivers to check that the | |
5032 | * channel list they get isn't longer than what | |
5033 | * they can scan, as long as they can scan all | |
5034 | * the channels they registered at once. | |
5035 | */ | |
5036 | nla_for_each_nested(attr2, freqs, tmp2) | |
5037 | if (attr1 != attr2 && | |
5038 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5039 | return 0; | |
5040 | } | |
5041 | ||
5042 | return n_channels; | |
5043 | } | |
5044 | ||
2a519311 JB |
5045 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5046 | { | |
4c476991 | 5047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5048 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5049 | struct cfg80211_scan_request *request; |
2a519311 JB |
5050 | struct nlattr *attr; |
5051 | struct wiphy *wiphy; | |
83f5e2cf | 5052 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5053 | size_t ie_len; |
2a519311 | 5054 | |
f4a11bb0 JB |
5055 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5056 | return -EINVAL; | |
5057 | ||
79c97e97 | 5058 | wiphy = &rdev->wiphy; |
2a519311 | 5059 | |
4c476991 JB |
5060 | if (!rdev->ops->scan) |
5061 | return -EOPNOTSUPP; | |
2a519311 | 5062 | |
f9f47529 JB |
5063 | mutex_lock(&rdev->sched_scan_mtx); |
5064 | if (rdev->scan_req) { | |
5065 | err = -EBUSY; | |
5066 | goto unlock; | |
5067 | } | |
2a519311 JB |
5068 | |
5069 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5070 | n_channels = validate_scan_freqs( |
5071 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5072 | if (!n_channels) { |
5073 | err = -EINVAL; | |
5074 | goto unlock; | |
5075 | } | |
2a519311 | 5076 | } else { |
34850ab2 | 5077 | enum ieee80211_band band; |
83f5e2cf JB |
5078 | n_channels = 0; |
5079 | ||
2a519311 JB |
5080 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5081 | if (wiphy->bands[band]) | |
5082 | n_channels += wiphy->bands[band]->n_channels; | |
5083 | } | |
5084 | ||
5085 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5086 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5087 | n_ssids++; | |
5088 | ||
f9f47529 JB |
5089 | if (n_ssids > wiphy->max_scan_ssids) { |
5090 | err = -EINVAL; | |
5091 | goto unlock; | |
5092 | } | |
2a519311 | 5093 | |
70692ad2 JM |
5094 | if (info->attrs[NL80211_ATTR_IE]) |
5095 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5096 | else | |
5097 | ie_len = 0; | |
5098 | ||
f9f47529 JB |
5099 | if (ie_len > wiphy->max_scan_ie_len) { |
5100 | err = -EINVAL; | |
5101 | goto unlock; | |
5102 | } | |
18a83659 | 5103 | |
2a519311 | 5104 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5105 | + sizeof(*request->ssids) * n_ssids |
5106 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5107 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5108 | if (!request) { |
5109 | err = -ENOMEM; | |
5110 | goto unlock; | |
5111 | } | |
2a519311 | 5112 | |
2a519311 | 5113 | if (n_ssids) |
5ba63533 | 5114 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5115 | request->n_ssids = n_ssids; |
70692ad2 JM |
5116 | if (ie_len) { |
5117 | if (request->ssids) | |
5118 | request->ie = (void *)(request->ssids + n_ssids); | |
5119 | else | |
5120 | request->ie = (void *)(request->channels + n_channels); | |
5121 | } | |
2a519311 | 5122 | |
584991dc | 5123 | i = 0; |
2a519311 JB |
5124 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5125 | /* user specified, bail out if channel not found */ | |
2a519311 | 5126 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5127 | struct ieee80211_channel *chan; |
5128 | ||
5129 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5130 | ||
5131 | if (!chan) { | |
2a519311 JB |
5132 | err = -EINVAL; |
5133 | goto out_free; | |
5134 | } | |
584991dc JB |
5135 | |
5136 | /* ignore disabled channels */ | |
5137 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5138 | continue; | |
5139 | ||
5140 | request->channels[i] = chan; | |
2a519311 JB |
5141 | i++; |
5142 | } | |
5143 | } else { | |
34850ab2 JB |
5144 | enum ieee80211_band band; |
5145 | ||
2a519311 | 5146 | /* all channels */ |
2a519311 JB |
5147 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5148 | int j; | |
5149 | if (!wiphy->bands[band]) | |
5150 | continue; | |
5151 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5152 | struct ieee80211_channel *chan; |
5153 | ||
5154 | chan = &wiphy->bands[band]->channels[j]; | |
5155 | ||
5156 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5157 | continue; | |
5158 | ||
5159 | request->channels[i] = chan; | |
2a519311 JB |
5160 | i++; |
5161 | } | |
5162 | } | |
5163 | } | |
5164 | ||
584991dc JB |
5165 | if (!i) { |
5166 | err = -EINVAL; | |
5167 | goto out_free; | |
5168 | } | |
5169 | ||
5170 | request->n_channels = i; | |
5171 | ||
2a519311 JB |
5172 | i = 0; |
5173 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5174 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5175 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5176 | err = -EINVAL; |
5177 | goto out_free; | |
5178 | } | |
57a27e1d | 5179 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5180 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5181 | i++; |
5182 | } | |
5183 | } | |
5184 | ||
70692ad2 JM |
5185 | if (info->attrs[NL80211_ATTR_IE]) { |
5186 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5187 | memcpy((void *)request->ie, |
5188 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5189 | request->ie_len); |
5190 | } | |
5191 | ||
34850ab2 | 5192 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5193 | if (wiphy->bands[i]) |
5194 | request->rates[i] = | |
5195 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5196 | |
5197 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5198 | nla_for_each_nested(attr, | |
5199 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5200 | tmp) { | |
5201 | enum ieee80211_band band = nla_type(attr); | |
5202 | ||
84404623 | 5203 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5204 | err = -EINVAL; |
5205 | goto out_free; | |
5206 | } | |
5207 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5208 | nla_data(attr), | |
5209 | nla_len(attr), | |
5210 | &request->rates[band]); | |
5211 | if (err) | |
5212 | goto out_free; | |
5213 | } | |
5214 | } | |
5215 | ||
46856bbf | 5216 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5217 | request->flags = nla_get_u32( |
5218 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5219 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5220 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5221 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5222 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5223 | err = -EOPNOTSUPP; |
5224 | goto out_free; | |
5225 | } | |
5226 | } | |
ed473771 | 5227 | |
e9f935e3 RM |
5228 | request->no_cck = |
5229 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5230 | ||
fd014284 | 5231 | request->wdev = wdev; |
79c97e97 | 5232 | request->wiphy = &rdev->wiphy; |
15d6030b | 5233 | request->scan_start = jiffies; |
2a519311 | 5234 | |
79c97e97 | 5235 | rdev->scan_req = request; |
e35e4d28 | 5236 | err = rdev_scan(rdev, request); |
2a519311 | 5237 | |
463d0183 | 5238 | if (!err) { |
fd014284 JB |
5239 | nl80211_send_scan_start(rdev, wdev); |
5240 | if (wdev->netdev) | |
5241 | dev_hold(wdev->netdev); | |
4c476991 | 5242 | } else { |
2a519311 | 5243 | out_free: |
79c97e97 | 5244 | rdev->scan_req = NULL; |
2a519311 JB |
5245 | kfree(request); |
5246 | } | |
3b85875a | 5247 | |
f9f47529 JB |
5248 | unlock: |
5249 | mutex_unlock(&rdev->sched_scan_mtx); | |
2a519311 JB |
5250 | return err; |
5251 | } | |
5252 | ||
807f8a8c LC |
5253 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5254 | struct genl_info *info) | |
5255 | { | |
5256 | struct cfg80211_sched_scan_request *request; | |
5257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5258 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5259 | struct nlattr *attr; |
5260 | struct wiphy *wiphy; | |
a1f1c21c | 5261 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5262 | u32 interval; |
807f8a8c LC |
5263 | enum ieee80211_band band; |
5264 | size_t ie_len; | |
a1f1c21c | 5265 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5266 | |
5267 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5268 | !rdev->ops->sched_scan_start) | |
5269 | return -EOPNOTSUPP; | |
5270 | ||
5271 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5272 | return -EINVAL; | |
5273 | ||
bbe6ad6d LC |
5274 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5275 | return -EINVAL; | |
5276 | ||
5277 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5278 | if (interval == 0) | |
5279 | return -EINVAL; | |
5280 | ||
807f8a8c LC |
5281 | wiphy = &rdev->wiphy; |
5282 | ||
5283 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5284 | n_channels = validate_scan_freqs( | |
5285 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5286 | if (!n_channels) | |
5287 | return -EINVAL; | |
5288 | } else { | |
5289 | n_channels = 0; | |
5290 | ||
5291 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5292 | if (wiphy->bands[band]) | |
5293 | n_channels += wiphy->bands[band]->n_channels; | |
5294 | } | |
5295 | ||
5296 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5297 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5298 | tmp) | |
5299 | n_ssids++; | |
5300 | ||
93b6aa69 | 5301 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5302 | return -EINVAL; |
5303 | ||
a1f1c21c LC |
5304 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5305 | nla_for_each_nested(attr, | |
5306 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5307 | tmp) | |
5308 | n_match_sets++; | |
5309 | ||
5310 | if (n_match_sets > wiphy->max_match_sets) | |
5311 | return -EINVAL; | |
5312 | ||
807f8a8c LC |
5313 | if (info->attrs[NL80211_ATTR_IE]) |
5314 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5315 | else | |
5316 | ie_len = 0; | |
5317 | ||
5a865bad | 5318 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5319 | return -EINVAL; |
5320 | ||
c10841ca LC |
5321 | mutex_lock(&rdev->sched_scan_mtx); |
5322 | ||
5323 | if (rdev->sched_scan_req) { | |
5324 | err = -EINPROGRESS; | |
5325 | goto out; | |
5326 | } | |
5327 | ||
807f8a8c | 5328 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5329 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5330 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5331 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5332 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5333 | if (!request) { |
5334 | err = -ENOMEM; | |
5335 | goto out; | |
5336 | } | |
807f8a8c LC |
5337 | |
5338 | if (n_ssids) | |
5339 | request->ssids = (void *)&request->channels[n_channels]; | |
5340 | request->n_ssids = n_ssids; | |
5341 | if (ie_len) { | |
5342 | if (request->ssids) | |
5343 | request->ie = (void *)(request->ssids + n_ssids); | |
5344 | else | |
5345 | request->ie = (void *)(request->channels + n_channels); | |
5346 | } | |
5347 | ||
a1f1c21c LC |
5348 | if (n_match_sets) { |
5349 | if (request->ie) | |
5350 | request->match_sets = (void *)(request->ie + ie_len); | |
5351 | else if (request->ssids) | |
5352 | request->match_sets = | |
5353 | (void *)(request->ssids + n_ssids); | |
5354 | else | |
5355 | request->match_sets = | |
5356 | (void *)(request->channels + n_channels); | |
5357 | } | |
5358 | request->n_match_sets = n_match_sets; | |
5359 | ||
807f8a8c LC |
5360 | i = 0; |
5361 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5362 | /* user specified, bail out if channel not found */ | |
5363 | nla_for_each_nested(attr, | |
5364 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5365 | tmp) { | |
5366 | struct ieee80211_channel *chan; | |
5367 | ||
5368 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5369 | ||
5370 | if (!chan) { | |
5371 | err = -EINVAL; | |
5372 | goto out_free; | |
5373 | } | |
5374 | ||
5375 | /* ignore disabled channels */ | |
5376 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5377 | continue; | |
5378 | ||
5379 | request->channels[i] = chan; | |
5380 | i++; | |
5381 | } | |
5382 | } else { | |
5383 | /* all channels */ | |
5384 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5385 | int j; | |
5386 | if (!wiphy->bands[band]) | |
5387 | continue; | |
5388 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5389 | struct ieee80211_channel *chan; | |
5390 | ||
5391 | chan = &wiphy->bands[band]->channels[j]; | |
5392 | ||
5393 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5394 | continue; | |
5395 | ||
5396 | request->channels[i] = chan; | |
5397 | i++; | |
5398 | } | |
5399 | } | |
5400 | } | |
5401 | ||
5402 | if (!i) { | |
5403 | err = -EINVAL; | |
5404 | goto out_free; | |
5405 | } | |
5406 | ||
5407 | request->n_channels = i; | |
5408 | ||
5409 | i = 0; | |
5410 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5411 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5412 | tmp) { | |
57a27e1d | 5413 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5414 | err = -EINVAL; |
5415 | goto out_free; | |
5416 | } | |
57a27e1d | 5417 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5418 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5419 | nla_len(attr)); | |
807f8a8c LC |
5420 | i++; |
5421 | } | |
5422 | } | |
5423 | ||
a1f1c21c LC |
5424 | i = 0; |
5425 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5426 | nla_for_each_nested(attr, | |
5427 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5428 | tmp) { | |
88e920b4 | 5429 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5430 | |
5431 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5432 | nla_data(attr), nla_len(attr), | |
5433 | nl80211_match_policy); | |
4a4ab0d7 | 5434 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5435 | if (ssid) { |
5436 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5437 | err = -EINVAL; | |
5438 | goto out_free; | |
5439 | } | |
5440 | memcpy(request->match_sets[i].ssid.ssid, | |
5441 | nla_data(ssid), nla_len(ssid)); | |
5442 | request->match_sets[i].ssid.ssid_len = | |
5443 | nla_len(ssid); | |
5444 | } | |
88e920b4 TP |
5445 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5446 | if (rssi) | |
5447 | request->rssi_thold = nla_get_u32(rssi); | |
5448 | else | |
5449 | request->rssi_thold = | |
5450 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5451 | i++; |
5452 | } | |
5453 | } | |
5454 | ||
807f8a8c LC |
5455 | if (info->attrs[NL80211_ATTR_IE]) { |
5456 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5457 | memcpy((void *)request->ie, | |
5458 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5459 | request->ie_len); | |
5460 | } | |
5461 | ||
46856bbf | 5462 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5463 | request->flags = nla_get_u32( |
5464 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5465 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5466 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5467 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5468 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5469 | err = -EOPNOTSUPP; |
5470 | goto out_free; | |
5471 | } | |
5472 | } | |
ed473771 | 5473 | |
807f8a8c LC |
5474 | request->dev = dev; |
5475 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5476 | request->interval = interval; |
15d6030b | 5477 | request->scan_start = jiffies; |
807f8a8c | 5478 | |
e35e4d28 | 5479 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5480 | if (!err) { |
5481 | rdev->sched_scan_req = request; | |
5482 | nl80211_send_sched_scan(rdev, dev, | |
5483 | NL80211_CMD_START_SCHED_SCAN); | |
5484 | goto out; | |
5485 | } | |
5486 | ||
5487 | out_free: | |
5488 | kfree(request); | |
5489 | out: | |
c10841ca | 5490 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
5491 | return err; |
5492 | } | |
5493 | ||
5494 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5495 | struct genl_info *info) | |
5496 | { | |
5497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 5498 | int err; |
807f8a8c LC |
5499 | |
5500 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5501 | !rdev->ops->sched_scan_stop) | |
5502 | return -EOPNOTSUPP; | |
5503 | ||
c10841ca LC |
5504 | mutex_lock(&rdev->sched_scan_mtx); |
5505 | err = __cfg80211_stop_sched_scan(rdev, false); | |
5506 | mutex_unlock(&rdev->sched_scan_mtx); | |
5507 | ||
5508 | return err; | |
807f8a8c LC |
5509 | } |
5510 | ||
04f39047 SW |
5511 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5512 | struct genl_info *info) | |
5513 | { | |
5514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5515 | struct net_device *dev = info->user_ptr[1]; | |
5516 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5517 | struct cfg80211_chan_def chandef; | |
5518 | int err; | |
5519 | ||
5520 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5521 | if (err) | |
5522 | return err; | |
5523 | ||
5524 | if (wdev->cac_started) | |
5525 | return -EBUSY; | |
5526 | ||
5527 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5528 | if (err < 0) | |
5529 | return err; | |
5530 | ||
5531 | if (err == 0) | |
5532 | return -EINVAL; | |
5533 | ||
5534 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5535 | return -EINVAL; | |
5536 | ||
5537 | if (!rdev->ops->start_radar_detection) | |
5538 | return -EOPNOTSUPP; | |
5539 | ||
5540 | mutex_lock(&rdev->devlist_mtx); | |
5541 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5542 | chandef.chan, CHAN_MODE_SHARED, | |
5543 | BIT(chandef.width)); | |
5544 | if (err) | |
5545 | goto err_locked; | |
5546 | ||
5547 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5548 | if (!err) { | |
5549 | wdev->channel = chandef.chan; | |
5550 | wdev->cac_started = true; | |
5551 | wdev->cac_start_time = jiffies; | |
5552 | } | |
5553 | err_locked: | |
5554 | mutex_unlock(&rdev->devlist_mtx); | |
5555 | ||
5556 | return err; | |
5557 | } | |
5558 | ||
9720bb3a JB |
5559 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5560 | u32 seq, int flags, | |
2a519311 | 5561 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5562 | struct wireless_dev *wdev, |
5563 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5564 | { |
48ab905d | 5565 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5566 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5567 | void *hdr; |
5568 | struct nlattr *bss; | |
8cef2c9d | 5569 | bool tsf = false; |
48ab905d JB |
5570 | |
5571 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5572 | |
15e47304 | 5573 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5574 | NL80211_CMD_NEW_SCAN_RESULTS); |
5575 | if (!hdr) | |
5576 | return -1; | |
5577 | ||
9720bb3a JB |
5578 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5579 | ||
97990a06 JB |
5580 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5581 | goto nla_put_failure; | |
5582 | if (wdev->netdev && | |
9360ffd1 DM |
5583 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5584 | goto nla_put_failure; | |
97990a06 JB |
5585 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5586 | goto nla_put_failure; | |
2a519311 JB |
5587 | |
5588 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5589 | if (!bss) | |
5590 | goto nla_put_failure; | |
9360ffd1 | 5591 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5592 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5593 | goto nla_put_failure; |
9caf0364 JB |
5594 | |
5595 | rcu_read_lock(); | |
5596 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5597 | if (ies) { |
5598 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5599 | goto fail_unlock_rcu; | |
5600 | tsf = true; | |
5601 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5602 | ies->len, ies->data)) | |
5603 | goto fail_unlock_rcu; | |
9caf0364 JB |
5604 | } |
5605 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5606 | if (ies) { |
5607 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5608 | goto fail_unlock_rcu; | |
5609 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5610 | ies->len, ies->data)) | |
5611 | goto fail_unlock_rcu; | |
9caf0364 JB |
5612 | } |
5613 | rcu_read_unlock(); | |
5614 | ||
9360ffd1 DM |
5615 | if (res->beacon_interval && |
5616 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5617 | goto nla_put_failure; | |
5618 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5619 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5620 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5621 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5622 | goto nla_put_failure; | |
2a519311 | 5623 | |
77965c97 | 5624 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5625 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5626 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5627 | goto nla_put_failure; | |
2a519311 JB |
5628 | break; |
5629 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5630 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5631 | goto nla_put_failure; | |
2a519311 JB |
5632 | break; |
5633 | default: | |
5634 | break; | |
5635 | } | |
5636 | ||
48ab905d | 5637 | switch (wdev->iftype) { |
074ac8df | 5638 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5639 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5640 | if (intbss == wdev->current_bss && |
5641 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5642 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5643 | goto nla_put_failure; | |
48ab905d JB |
5644 | break; |
5645 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5646 | if (intbss == wdev->current_bss && |
5647 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5648 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5649 | goto nla_put_failure; | |
48ab905d JB |
5650 | break; |
5651 | default: | |
5652 | break; | |
5653 | } | |
5654 | ||
2a519311 JB |
5655 | nla_nest_end(msg, bss); |
5656 | ||
5657 | return genlmsg_end(msg, hdr); | |
5658 | ||
8cef2c9d JB |
5659 | fail_unlock_rcu: |
5660 | rcu_read_unlock(); | |
2a519311 JB |
5661 | nla_put_failure: |
5662 | genlmsg_cancel(msg, hdr); | |
5663 | return -EMSGSIZE; | |
5664 | } | |
5665 | ||
97990a06 | 5666 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5667 | { |
48ab905d | 5668 | struct cfg80211_registered_device *rdev; |
2a519311 | 5669 | struct cfg80211_internal_bss *scan; |
48ab905d | 5670 | struct wireless_dev *wdev; |
97990a06 | 5671 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5672 | int err; |
5673 | ||
97990a06 | 5674 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5675 | if (err) |
5676 | return err; | |
2a519311 | 5677 | |
48ab905d JB |
5678 | wdev_lock(wdev); |
5679 | spin_lock_bh(&rdev->bss_lock); | |
5680 | cfg80211_bss_expire(rdev); | |
5681 | ||
9720bb3a JB |
5682 | cb->seq = rdev->bss_generation; |
5683 | ||
48ab905d | 5684 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5685 | if (++idx <= start) |
5686 | continue; | |
9720bb3a | 5687 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5688 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5689 | rdev, wdev, scan) < 0) { |
2a519311 | 5690 | idx--; |
67748893 | 5691 | break; |
2a519311 JB |
5692 | } |
5693 | } | |
5694 | ||
48ab905d JB |
5695 | spin_unlock_bh(&rdev->bss_lock); |
5696 | wdev_unlock(wdev); | |
2a519311 | 5697 | |
97990a06 JB |
5698 | cb->args[2] = idx; |
5699 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5700 | |
67748893 | 5701 | return skb->len; |
2a519311 JB |
5702 | } |
5703 | ||
15e47304 | 5704 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5705 | int flags, struct net_device *dev, |
5706 | struct survey_info *survey) | |
5707 | { | |
5708 | void *hdr; | |
5709 | struct nlattr *infoattr; | |
5710 | ||
15e47304 | 5711 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5712 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5713 | if (!hdr) | |
5714 | return -ENOMEM; | |
5715 | ||
9360ffd1 DM |
5716 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5717 | goto nla_put_failure; | |
61fa713c HS |
5718 | |
5719 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5720 | if (!infoattr) | |
5721 | goto nla_put_failure; | |
5722 | ||
9360ffd1 DM |
5723 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5724 | survey->channel->center_freq)) | |
5725 | goto nla_put_failure; | |
5726 | ||
5727 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5728 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5729 | goto nla_put_failure; | |
5730 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5731 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5732 | goto nla_put_failure; | |
5733 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5734 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5735 | survey->channel_time)) | |
5736 | goto nla_put_failure; | |
5737 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5738 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5739 | survey->channel_time_busy)) | |
5740 | goto nla_put_failure; | |
5741 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5742 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5743 | survey->channel_time_ext_busy)) | |
5744 | goto nla_put_failure; | |
5745 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5746 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5747 | survey->channel_time_rx)) | |
5748 | goto nla_put_failure; | |
5749 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5750 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5751 | survey->channel_time_tx)) | |
5752 | goto nla_put_failure; | |
61fa713c HS |
5753 | |
5754 | nla_nest_end(msg, infoattr); | |
5755 | ||
5756 | return genlmsg_end(msg, hdr); | |
5757 | ||
5758 | nla_put_failure: | |
5759 | genlmsg_cancel(msg, hdr); | |
5760 | return -EMSGSIZE; | |
5761 | } | |
5762 | ||
5763 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5764 | struct netlink_callback *cb) | |
5765 | { | |
5766 | struct survey_info survey; | |
5767 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5768 | struct wireless_dev *wdev; |
5769 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5770 | int res; |
5771 | ||
97990a06 | 5772 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5773 | if (res) |
5774 | return res; | |
61fa713c | 5775 | |
97990a06 JB |
5776 | if (!wdev->netdev) { |
5777 | res = -EINVAL; | |
5778 | goto out_err; | |
5779 | } | |
5780 | ||
61fa713c HS |
5781 | if (!dev->ops->dump_survey) { |
5782 | res = -EOPNOTSUPP; | |
5783 | goto out_err; | |
5784 | } | |
5785 | ||
5786 | while (1) { | |
180cdc79 LR |
5787 | struct ieee80211_channel *chan; |
5788 | ||
97990a06 | 5789 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5790 | if (res == -ENOENT) |
5791 | break; | |
5792 | if (res) | |
5793 | goto out_err; | |
5794 | ||
180cdc79 LR |
5795 | /* Survey without a channel doesn't make sense */ |
5796 | if (!survey.channel) { | |
5797 | res = -EINVAL; | |
5798 | goto out; | |
5799 | } | |
5800 | ||
5801 | chan = ieee80211_get_channel(&dev->wiphy, | |
5802 | survey.channel->center_freq); | |
5803 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5804 | survey_idx++; | |
5805 | continue; | |
5806 | } | |
5807 | ||
61fa713c | 5808 | if (nl80211_send_survey(skb, |
15e47304 | 5809 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5810 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5811 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5812 | goto out; |
5813 | survey_idx++; | |
5814 | } | |
5815 | ||
5816 | out: | |
97990a06 | 5817 | cb->args[2] = survey_idx; |
61fa713c HS |
5818 | res = skb->len; |
5819 | out_err: | |
97990a06 | 5820 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5821 | return res; |
5822 | } | |
5823 | ||
b23aa676 SO |
5824 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5825 | { | |
5826 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5827 | NL80211_WPA_VERSION_2)); | |
5828 | } | |
5829 | ||
636a5d36 JM |
5830 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5831 | { | |
4c476991 JB |
5832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5833 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5834 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5835 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5836 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5837 | enum nl80211_auth_type auth_type; |
fffd0934 | 5838 | struct key_parse key; |
d5cdfacb | 5839 | bool local_state_change; |
636a5d36 | 5840 | |
f4a11bb0 JB |
5841 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5842 | return -EINVAL; | |
5843 | ||
5844 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5845 | return -EINVAL; | |
5846 | ||
1778092e JM |
5847 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5848 | return -EINVAL; | |
5849 | ||
19957bb3 JB |
5850 | if (!info->attrs[NL80211_ATTR_SSID]) |
5851 | return -EINVAL; | |
5852 | ||
5853 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5854 | return -EINVAL; | |
5855 | ||
fffd0934 JB |
5856 | err = nl80211_parse_key(info, &key); |
5857 | if (err) | |
5858 | return err; | |
5859 | ||
5860 | if (key.idx >= 0) { | |
e31b8213 JB |
5861 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5862 | return -EINVAL; | |
fffd0934 JB |
5863 | if (!key.p.key || !key.p.key_len) |
5864 | return -EINVAL; | |
5865 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5866 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5867 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5868 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5869 | return -EINVAL; | |
5870 | if (key.idx > 4) | |
5871 | return -EINVAL; | |
5872 | } else { | |
5873 | key.p.key_len = 0; | |
5874 | key.p.key = NULL; | |
5875 | } | |
5876 | ||
afea0b7a JB |
5877 | if (key.idx >= 0) { |
5878 | int i; | |
5879 | bool ok = false; | |
5880 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5881 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5882 | ok = true; | |
5883 | break; | |
5884 | } | |
5885 | } | |
4c476991 JB |
5886 | if (!ok) |
5887 | return -EINVAL; | |
afea0b7a JB |
5888 | } |
5889 | ||
4c476991 JB |
5890 | if (!rdev->ops->auth) |
5891 | return -EOPNOTSUPP; | |
636a5d36 | 5892 | |
074ac8df | 5893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5894 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5895 | return -EOPNOTSUPP; | |
eec60b03 | 5896 | |
19957bb3 | 5897 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5898 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5899 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5900 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5901 | return -EINVAL; | |
636a5d36 | 5902 | |
19957bb3 JB |
5903 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5904 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5905 | |
5906 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5907 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5908 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5909 | } |
5910 | ||
19957bb3 | 5911 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5912 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5913 | return -EINVAL; |
636a5d36 | 5914 | |
e39e5b5e JM |
5915 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5916 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5917 | return -EINVAL; | |
5918 | ||
5919 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5920 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5921 | return -EINVAL; | |
5922 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5923 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5924 | /* need to include at least Auth Transaction and Status Code */ | |
5925 | if (sae_data_len < 4) | |
5926 | return -EINVAL; | |
5927 | } | |
5928 | ||
d5cdfacb JM |
5929 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5930 | ||
95de817b JB |
5931 | /* |
5932 | * Since we no longer track auth state, ignore | |
5933 | * requests to only change local state. | |
5934 | */ | |
5935 | if (local_state_change) | |
5936 | return 0; | |
5937 | ||
4c476991 JB |
5938 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
5939 | ssid, ssid_len, ie, ie_len, | |
e39e5b5e JM |
5940 | key.p.key, key.p.key_len, key.idx, |
5941 | sae_data, sae_data_len); | |
636a5d36 JM |
5942 | } |
5943 | ||
c0692b8f JB |
5944 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
5945 | struct genl_info *info, | |
3dc27d25 JB |
5946 | struct cfg80211_crypto_settings *settings, |
5947 | int cipher_limit) | |
b23aa676 | 5948 | { |
c0b2bbd8 JB |
5949 | memset(settings, 0, sizeof(*settings)); |
5950 | ||
b23aa676 SO |
5951 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
5952 | ||
c0692b8f JB |
5953 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
5954 | u16 proto; | |
5955 | proto = nla_get_u16( | |
5956 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
5957 | settings->control_port_ethertype = cpu_to_be16(proto); | |
5958 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
5959 | proto != ETH_P_PAE) | |
5960 | return -EINVAL; | |
5961 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
5962 | settings->control_port_no_encrypt = true; | |
5963 | } else | |
5964 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
5965 | ||
b23aa676 SO |
5966 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
5967 | void *data; | |
5968 | int len, i; | |
5969 | ||
5970 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5971 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5972 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
5973 | ||
5974 | if (len % sizeof(u32)) | |
5975 | return -EINVAL; | |
5976 | ||
3dc27d25 | 5977 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
5978 | return -EINVAL; |
5979 | ||
5980 | memcpy(settings->ciphers_pairwise, data, len); | |
5981 | ||
5982 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
5983 | if (!cfg80211_supported_cipher_suite( |
5984 | &rdev->wiphy, | |
b23aa676 SO |
5985 | settings->ciphers_pairwise[i])) |
5986 | return -EINVAL; | |
5987 | } | |
5988 | ||
5989 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
5990 | settings->cipher_group = | |
5991 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
5992 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
5993 | settings->cipher_group)) | |
b23aa676 SO |
5994 | return -EINVAL; |
5995 | } | |
5996 | ||
5997 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
5998 | settings->wpa_versions = | |
5999 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6000 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6001 | return -EINVAL; | |
6002 | } | |
6003 | ||
6004 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6005 | void *data; | |
6d30240e | 6006 | int len; |
b23aa676 SO |
6007 | |
6008 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6009 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6010 | settings->n_akm_suites = len / sizeof(u32); | |
6011 | ||
6012 | if (len % sizeof(u32)) | |
6013 | return -EINVAL; | |
6014 | ||
1b9ca027 JM |
6015 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6016 | return -EINVAL; | |
6017 | ||
b23aa676 | 6018 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6019 | } |
6020 | ||
6021 | return 0; | |
6022 | } | |
6023 | ||
636a5d36 JM |
6024 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6025 | { | |
4c476991 JB |
6026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6027 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6028 | struct ieee80211_channel *chan; |
f62fab73 JB |
6029 | struct cfg80211_assoc_request req = {}; |
6030 | const u8 *bssid, *ssid; | |
6031 | int err, ssid_len = 0; | |
636a5d36 | 6032 | |
f4a11bb0 JB |
6033 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6034 | return -EINVAL; | |
6035 | ||
6036 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6037 | !info->attrs[NL80211_ATTR_SSID] || |
6038 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6039 | return -EINVAL; |
6040 | ||
4c476991 JB |
6041 | if (!rdev->ops->assoc) |
6042 | return -EOPNOTSUPP; | |
636a5d36 | 6043 | |
074ac8df | 6044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6046 | return -EOPNOTSUPP; | |
eec60b03 | 6047 | |
19957bb3 | 6048 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6049 | |
19957bb3 JB |
6050 | chan = ieee80211_get_channel(&rdev->wiphy, |
6051 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6052 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6053 | return -EINVAL; | |
636a5d36 | 6054 | |
19957bb3 JB |
6055 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6056 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6057 | |
6058 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6059 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6060 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6061 | } |
6062 | ||
dc6382ce | 6063 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6064 | enum nl80211_mfp mfp = |
dc6382ce | 6065 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6066 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6067 | req.use_mfp = true; |
4c476991 JB |
6068 | else if (mfp != NL80211_MFP_NO) |
6069 | return -EINVAL; | |
dc6382ce JM |
6070 | } |
6071 | ||
3e5d7649 | 6072 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6073 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6074 | |
7e7c8926 | 6075 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6076 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6077 | |
6078 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6079 | memcpy(&req.ht_capa_mask, |
6080 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6081 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6082 | |
6083 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6084 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6085 | return -EINVAL; |
f62fab73 JB |
6086 | memcpy(&req.ht_capa, |
6087 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6088 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6089 | } |
6090 | ||
ee2aca34 | 6091 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6092 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6093 | |
6094 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6095 | memcpy(&req.vht_capa_mask, |
6096 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6097 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6098 | |
6099 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6100 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6101 | return -EINVAL; |
f62fab73 JB |
6102 | memcpy(&req.vht_capa, |
6103 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6104 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6105 | } |
6106 | ||
f62fab73 | 6107 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
b23aa676 | 6108 | if (!err) |
f62fab73 JB |
6109 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6110 | ssid, ssid_len, &req); | |
636a5d36 | 6111 | |
636a5d36 JM |
6112 | return err; |
6113 | } | |
6114 | ||
6115 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6116 | { | |
4c476991 JB |
6117 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6118 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6119 | const u8 *ie = NULL, *bssid; |
4c476991 | 6120 | int ie_len = 0; |
19957bb3 | 6121 | u16 reason_code; |
d5cdfacb | 6122 | bool local_state_change; |
636a5d36 | 6123 | |
f4a11bb0 JB |
6124 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6125 | return -EINVAL; | |
6126 | ||
6127 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6128 | return -EINVAL; | |
6129 | ||
6130 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6131 | return -EINVAL; | |
6132 | ||
4c476991 JB |
6133 | if (!rdev->ops->deauth) |
6134 | return -EOPNOTSUPP; | |
636a5d36 | 6135 | |
074ac8df | 6136 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6137 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6138 | return -EOPNOTSUPP; | |
eec60b03 | 6139 | |
19957bb3 | 6140 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6141 | |
19957bb3 JB |
6142 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6143 | if (reason_code == 0) { | |
f4a11bb0 | 6144 | /* Reason Code 0 is reserved */ |
4c476991 | 6145 | return -EINVAL; |
255e737e | 6146 | } |
636a5d36 JM |
6147 | |
6148 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6149 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6150 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6151 | } |
6152 | ||
d5cdfacb JM |
6153 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6154 | ||
4c476991 JB |
6155 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
6156 | local_state_change); | |
636a5d36 JM |
6157 | } |
6158 | ||
6159 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6160 | { | |
4c476991 JB |
6161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6162 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6163 | const u8 *ie = NULL, *bssid; |
4c476991 | 6164 | int ie_len = 0; |
19957bb3 | 6165 | u16 reason_code; |
d5cdfacb | 6166 | bool local_state_change; |
636a5d36 | 6167 | |
f4a11bb0 JB |
6168 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6169 | return -EINVAL; | |
6170 | ||
6171 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6172 | return -EINVAL; | |
6173 | ||
6174 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6175 | return -EINVAL; | |
6176 | ||
4c476991 JB |
6177 | if (!rdev->ops->disassoc) |
6178 | return -EOPNOTSUPP; | |
636a5d36 | 6179 | |
074ac8df | 6180 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6181 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6182 | return -EOPNOTSUPP; | |
eec60b03 | 6183 | |
19957bb3 | 6184 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6185 | |
19957bb3 JB |
6186 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6187 | if (reason_code == 0) { | |
f4a11bb0 | 6188 | /* Reason Code 0 is reserved */ |
4c476991 | 6189 | return -EINVAL; |
255e737e | 6190 | } |
636a5d36 JM |
6191 | |
6192 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6193 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6194 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6195 | } |
6196 | ||
d5cdfacb JM |
6197 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6198 | ||
4c476991 JB |
6199 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
6200 | local_state_change); | |
636a5d36 JM |
6201 | } |
6202 | ||
dd5b4cc7 FF |
6203 | static bool |
6204 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6205 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6206 | int rateval) | |
6207 | { | |
6208 | struct wiphy *wiphy = &rdev->wiphy; | |
6209 | bool found = false; | |
6210 | int band, i; | |
6211 | ||
6212 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6213 | struct ieee80211_supported_band *sband; | |
6214 | ||
6215 | sband = wiphy->bands[band]; | |
6216 | if (!sband) | |
6217 | continue; | |
6218 | ||
6219 | for (i = 0; i < sband->n_bitrates; i++) { | |
6220 | if (sband->bitrates[i].bitrate == rateval) { | |
6221 | mcast_rate[band] = i + 1; | |
6222 | found = true; | |
6223 | break; | |
6224 | } | |
6225 | } | |
6226 | } | |
6227 | ||
6228 | return found; | |
6229 | } | |
6230 | ||
04a773ad JB |
6231 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6232 | { | |
4c476991 JB |
6233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6234 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6235 | struct cfg80211_ibss_params ibss; |
6236 | struct wiphy *wiphy; | |
fffd0934 | 6237 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6238 | int err; |
6239 | ||
8e30bc55 JB |
6240 | memset(&ibss, 0, sizeof(ibss)); |
6241 | ||
04a773ad JB |
6242 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6243 | return -EINVAL; | |
6244 | ||
683b6d3b | 6245 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6246 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6247 | return -EINVAL; | |
6248 | ||
8e30bc55 JB |
6249 | ibss.beacon_interval = 100; |
6250 | ||
6251 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6252 | ibss.beacon_interval = | |
6253 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6254 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6255 | return -EINVAL; | |
6256 | } | |
6257 | ||
4c476991 JB |
6258 | if (!rdev->ops->join_ibss) |
6259 | return -EOPNOTSUPP; | |
04a773ad | 6260 | |
4c476991 JB |
6261 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6262 | return -EOPNOTSUPP; | |
04a773ad | 6263 | |
79c97e97 | 6264 | wiphy = &rdev->wiphy; |
04a773ad | 6265 | |
39193498 | 6266 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6267 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6268 | |
6269 | if (!is_valid_ether_addr(ibss.bssid)) | |
6270 | return -EINVAL; | |
6271 | } | |
04a773ad JB |
6272 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6273 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6274 | ||
6275 | if (info->attrs[NL80211_ATTR_IE]) { | |
6276 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6277 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6278 | } | |
6279 | ||
683b6d3b JB |
6280 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6281 | if (err) | |
6282 | return err; | |
04a773ad | 6283 | |
683b6d3b | 6284 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6285 | return -EINVAL; |
6286 | ||
db9c64cf JB |
6287 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
6288 | return -EINVAL; | |
6289 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
6290 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
c04d6150 | 6291 | return -EINVAL; |
db9c64cf | 6292 | |
04a773ad | 6293 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6294 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6295 | ||
fbd2c8dc TP |
6296 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6297 | u8 *rates = | |
6298 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6299 | int n_rates = | |
6300 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6301 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6302 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6303 | |
34850ab2 JB |
6304 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6305 | &ibss.basic_rates); | |
6306 | if (err) | |
6307 | return err; | |
fbd2c8dc | 6308 | } |
dd5b4cc7 FF |
6309 | |
6310 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
6311 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6312 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6313 | return -EINVAL; | |
fbd2c8dc | 6314 | |
4c476991 | 6315 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6316 | bool no_ht = false; |
6317 | ||
4c476991 | 6318 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6319 | info->attrs[NL80211_ATTR_KEYS], |
6320 | &no_ht); | |
4c476991 JB |
6321 | if (IS_ERR(connkeys)) |
6322 | return PTR_ERR(connkeys); | |
de7044ee | 6323 | |
3d9d1d66 JB |
6324 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6325 | no_ht) { | |
de7044ee SM |
6326 | kfree(connkeys); |
6327 | return -EINVAL; | |
6328 | } | |
4c476991 | 6329 | } |
04a773ad | 6330 | |
267335d6 AQ |
6331 | ibss.control_port = |
6332 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6333 | ||
4c476991 | 6334 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6335 | if (err) |
6336 | kfree(connkeys); | |
04a773ad JB |
6337 | return err; |
6338 | } | |
6339 | ||
6340 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6341 | { | |
4c476991 JB |
6342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6343 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6344 | |
4c476991 JB |
6345 | if (!rdev->ops->leave_ibss) |
6346 | return -EOPNOTSUPP; | |
04a773ad | 6347 | |
4c476991 JB |
6348 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6349 | return -EOPNOTSUPP; | |
04a773ad | 6350 | |
4c476991 | 6351 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6352 | } |
6353 | ||
f4e583c8 AQ |
6354 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6355 | { | |
6356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6357 | struct net_device *dev = info->user_ptr[1]; | |
6358 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6359 | u32 nla_rate; | |
6360 | int err; | |
6361 | ||
6362 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6363 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6364 | return -EOPNOTSUPP; | |
6365 | ||
6366 | if (!rdev->ops->set_mcast_rate) | |
6367 | return -EOPNOTSUPP; | |
6368 | ||
6369 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6370 | ||
6371 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6372 | return -EINVAL; | |
6373 | ||
6374 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6375 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6376 | return -EINVAL; | |
6377 | ||
6378 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6379 | ||
6380 | return err; | |
6381 | } | |
6382 | ||
6383 | ||
aff89a9b JB |
6384 | #ifdef CONFIG_NL80211_TESTMODE |
6385 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6386 | .name = "testmode", | |
6387 | }; | |
6388 | ||
6389 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6390 | { | |
4c476991 | 6391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6392 | int err; |
6393 | ||
6394 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6395 | return -EINVAL; | |
6396 | ||
aff89a9b JB |
6397 | err = -EOPNOTSUPP; |
6398 | if (rdev->ops->testmode_cmd) { | |
6399 | rdev->testmode_info = info; | |
e35e4d28 | 6400 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6401 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6402 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6403 | rdev->testmode_info = NULL; | |
6404 | } | |
6405 | ||
aff89a9b JB |
6406 | return err; |
6407 | } | |
6408 | ||
71063f0e WYG |
6409 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6410 | struct netlink_callback *cb) | |
6411 | { | |
00918d33 | 6412 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6413 | int err; |
6414 | long phy_idx; | |
6415 | void *data = NULL; | |
6416 | int data_len = 0; | |
6417 | ||
6418 | if (cb->args[0]) { | |
6419 | /* | |
6420 | * 0 is a valid index, but not valid for args[0], | |
6421 | * so we need to offset by 1. | |
6422 | */ | |
6423 | phy_idx = cb->args[0] - 1; | |
6424 | } else { | |
6425 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6426 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6427 | nl80211_policy); | |
6428 | if (err) | |
6429 | return err; | |
00918d33 | 6430 | |
2bd7e35d JB |
6431 | mutex_lock(&cfg80211_mutex); |
6432 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
6433 | nl80211_fam.attrbuf); | |
6434 | if (IS_ERR(rdev)) { | |
6435 | mutex_unlock(&cfg80211_mutex); | |
6436 | return PTR_ERR(rdev); | |
00918d33 | 6437 | } |
2bd7e35d JB |
6438 | phy_idx = rdev->wiphy_idx; |
6439 | rdev = NULL; | |
6440 | mutex_unlock(&cfg80211_mutex); | |
6441 | ||
71063f0e WYG |
6442 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6443 | cb->args[1] = | |
6444 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6445 | } | |
6446 | ||
6447 | if (cb->args[1]) { | |
6448 | data = nla_data((void *)cb->args[1]); | |
6449 | data_len = nla_len((void *)cb->args[1]); | |
6450 | } | |
6451 | ||
6452 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
6453 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6454 | if (!rdev) { | |
71063f0e WYG |
6455 | mutex_unlock(&cfg80211_mutex); |
6456 | return -ENOENT; | |
6457 | } | |
00918d33 | 6458 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
6459 | mutex_unlock(&cfg80211_mutex); |
6460 | ||
00918d33 | 6461 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6462 | err = -EOPNOTSUPP; |
6463 | goto out_err; | |
6464 | } | |
6465 | ||
6466 | while (1) { | |
15e47304 | 6467 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6468 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6469 | NL80211_CMD_TESTMODE); | |
6470 | struct nlattr *tmdata; | |
6471 | ||
9360ffd1 | 6472 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6473 | genlmsg_cancel(skb, hdr); |
6474 | break; | |
6475 | } | |
6476 | ||
6477 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6478 | if (!tmdata) { | |
6479 | genlmsg_cancel(skb, hdr); | |
6480 | break; | |
6481 | } | |
e35e4d28 | 6482 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6483 | nla_nest_end(skb, tmdata); |
6484 | ||
6485 | if (err == -ENOBUFS || err == -ENOENT) { | |
6486 | genlmsg_cancel(skb, hdr); | |
6487 | break; | |
6488 | } else if (err) { | |
6489 | genlmsg_cancel(skb, hdr); | |
6490 | goto out_err; | |
6491 | } | |
6492 | ||
6493 | genlmsg_end(skb, hdr); | |
6494 | } | |
6495 | ||
6496 | err = skb->len; | |
6497 | /* see above */ | |
6498 | cb->args[0] = phy_idx + 1; | |
6499 | out_err: | |
00918d33 | 6500 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
6501 | return err; |
6502 | } | |
6503 | ||
aff89a9b JB |
6504 | static struct sk_buff * |
6505 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6506 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6507 | { |
6508 | struct sk_buff *skb; | |
6509 | void *hdr; | |
6510 | struct nlattr *data; | |
6511 | ||
6512 | skb = nlmsg_new(approxlen + 100, gfp); | |
6513 | if (!skb) | |
6514 | return NULL; | |
6515 | ||
15e47304 | 6516 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6517 | if (!hdr) { |
6518 | kfree_skb(skb); | |
6519 | return NULL; | |
6520 | } | |
6521 | ||
9360ffd1 DM |
6522 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6523 | goto nla_put_failure; | |
aff89a9b JB |
6524 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6525 | ||
6526 | ((void **)skb->cb)[0] = rdev; | |
6527 | ((void **)skb->cb)[1] = hdr; | |
6528 | ((void **)skb->cb)[2] = data; | |
6529 | ||
6530 | return skb; | |
6531 | ||
6532 | nla_put_failure: | |
6533 | kfree_skb(skb); | |
6534 | return NULL; | |
6535 | } | |
6536 | ||
6537 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6538 | int approxlen) | |
6539 | { | |
6540 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6541 | ||
6542 | if (WARN_ON(!rdev->testmode_info)) | |
6543 | return NULL; | |
6544 | ||
6545 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6546 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6547 | rdev->testmode_info->snd_seq, |
6548 | GFP_KERNEL); | |
6549 | } | |
6550 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6551 | ||
6552 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6553 | { | |
6554 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6555 | void *hdr = ((void **)skb->cb)[1]; | |
6556 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6557 | ||
6558 | if (WARN_ON(!rdev->testmode_info)) { | |
6559 | kfree_skb(skb); | |
6560 | return -EINVAL; | |
6561 | } | |
6562 | ||
6563 | nla_nest_end(skb, data); | |
6564 | genlmsg_end(skb, hdr); | |
6565 | return genlmsg_reply(skb, rdev->testmode_info); | |
6566 | } | |
6567 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6568 | ||
6569 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6570 | int approxlen, gfp_t gfp) | |
6571 | { | |
6572 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6573 | ||
6574 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6575 | } | |
6576 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6577 | ||
6578 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6579 | { | |
6580 | void *hdr = ((void **)skb->cb)[1]; | |
6581 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6582 | ||
6583 | nla_nest_end(skb, data); | |
6584 | genlmsg_end(skb, hdr); | |
6585 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6586 | } | |
6587 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6588 | #endif | |
6589 | ||
b23aa676 SO |
6590 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6591 | { | |
4c476991 JB |
6592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6593 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6594 | struct cfg80211_connect_params connect; |
6595 | struct wiphy *wiphy; | |
fffd0934 | 6596 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6597 | int err; |
6598 | ||
6599 | memset(&connect, 0, sizeof(connect)); | |
6600 | ||
6601 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6602 | return -EINVAL; | |
6603 | ||
6604 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6605 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6606 | return -EINVAL; | |
6607 | ||
6608 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6609 | connect.auth_type = | |
6610 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6611 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6612 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6613 | return -EINVAL; |
6614 | } else | |
6615 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6616 | ||
6617 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6618 | ||
c0692b8f | 6619 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6620 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6621 | if (err) |
6622 | return err; | |
b23aa676 | 6623 | |
074ac8df | 6624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6625 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6626 | return -EOPNOTSUPP; | |
b23aa676 | 6627 | |
79c97e97 | 6628 | wiphy = &rdev->wiphy; |
b23aa676 | 6629 | |
4486ea98 BS |
6630 | connect.bg_scan_period = -1; |
6631 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6632 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6633 | connect.bg_scan_period = | |
6634 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6635 | } | |
6636 | ||
b23aa676 SO |
6637 | if (info->attrs[NL80211_ATTR_MAC]) |
6638 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6639 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6640 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6641 | ||
6642 | if (info->attrs[NL80211_ATTR_IE]) { | |
6643 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6644 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6645 | } | |
6646 | ||
cee00a95 JM |
6647 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6648 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6649 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6650 | connect.mfp != NL80211_MFP_NO) | |
6651 | return -EINVAL; | |
6652 | } else { | |
6653 | connect.mfp = NL80211_MFP_NO; | |
6654 | } | |
6655 | ||
b23aa676 SO |
6656 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6657 | connect.channel = | |
6658 | ieee80211_get_channel(wiphy, | |
6659 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6660 | if (!connect.channel || | |
4c476991 JB |
6661 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6662 | return -EINVAL; | |
b23aa676 SO |
6663 | } |
6664 | ||
fffd0934 JB |
6665 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6666 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6667 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6668 | if (IS_ERR(connkeys)) |
6669 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6670 | } |
6671 | ||
7e7c8926 BG |
6672 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6673 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6674 | ||
6675 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6676 | memcpy(&connect.ht_capa_mask, | |
6677 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6678 | sizeof(connect.ht_capa_mask)); | |
6679 | ||
6680 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6681 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6682 | kfree(connkeys); | |
7e7c8926 | 6683 | return -EINVAL; |
b4e4f47e | 6684 | } |
7e7c8926 BG |
6685 | memcpy(&connect.ht_capa, |
6686 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6687 | sizeof(connect.ht_capa)); | |
6688 | } | |
6689 | ||
ee2aca34 JB |
6690 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6691 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6692 | ||
6693 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6694 | memcpy(&connect.vht_capa_mask, | |
6695 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6696 | sizeof(connect.vht_capa_mask)); | |
6697 | ||
6698 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6699 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6700 | kfree(connkeys); | |
6701 | return -EINVAL; | |
6702 | } | |
6703 | memcpy(&connect.vht_capa, | |
6704 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6705 | sizeof(connect.vht_capa)); | |
6706 | } | |
6707 | ||
fffd0934 | 6708 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
6709 | if (err) |
6710 | kfree(connkeys); | |
b23aa676 SO |
6711 | return err; |
6712 | } | |
6713 | ||
6714 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6715 | { | |
4c476991 JB |
6716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6717 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6718 | u16 reason; |
6719 | ||
6720 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6721 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6722 | else | |
6723 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6724 | ||
6725 | if (reason == 0) | |
6726 | return -EINVAL; | |
6727 | ||
074ac8df | 6728 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6729 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6730 | return -EOPNOTSUPP; | |
b23aa676 | 6731 | |
4c476991 | 6732 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
6733 | } |
6734 | ||
463d0183 JB |
6735 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6736 | { | |
4c476991 | 6737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6738 | struct net *net; |
6739 | int err; | |
6740 | u32 pid; | |
6741 | ||
6742 | if (!info->attrs[NL80211_ATTR_PID]) | |
6743 | return -EINVAL; | |
6744 | ||
6745 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6746 | ||
463d0183 | 6747 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6748 | if (IS_ERR(net)) |
6749 | return PTR_ERR(net); | |
463d0183 JB |
6750 | |
6751 | err = 0; | |
6752 | ||
6753 | /* check if anything to do */ | |
4c476991 JB |
6754 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6755 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6756 | |
463d0183 | 6757 | put_net(net); |
463d0183 JB |
6758 | return err; |
6759 | } | |
6760 | ||
67fbb16b SO |
6761 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6762 | { | |
4c476991 | 6763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6764 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6765 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6766 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6767 | struct cfg80211_pmksa pmksa; |
6768 | ||
6769 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6770 | ||
6771 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6772 | return -EINVAL; | |
6773 | ||
6774 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6775 | return -EINVAL; | |
6776 | ||
67fbb16b SO |
6777 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6778 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6779 | ||
074ac8df | 6780 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6781 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6782 | return -EOPNOTSUPP; | |
67fbb16b SO |
6783 | |
6784 | switch (info->genlhdr->cmd) { | |
6785 | case NL80211_CMD_SET_PMKSA: | |
6786 | rdev_ops = rdev->ops->set_pmksa; | |
6787 | break; | |
6788 | case NL80211_CMD_DEL_PMKSA: | |
6789 | rdev_ops = rdev->ops->del_pmksa; | |
6790 | break; | |
6791 | default: | |
6792 | WARN_ON(1); | |
6793 | break; | |
6794 | } | |
6795 | ||
4c476991 JB |
6796 | if (!rdev_ops) |
6797 | return -EOPNOTSUPP; | |
67fbb16b | 6798 | |
4c476991 | 6799 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6800 | } |
6801 | ||
6802 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6803 | { | |
4c476991 JB |
6804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6805 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6806 | |
074ac8df | 6807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6808 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6809 | return -EOPNOTSUPP; | |
67fbb16b | 6810 | |
4c476991 JB |
6811 | if (!rdev->ops->flush_pmksa) |
6812 | return -EOPNOTSUPP; | |
67fbb16b | 6813 | |
e35e4d28 | 6814 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6815 | } |
6816 | ||
109086ce AN |
6817 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6818 | { | |
6819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6820 | struct net_device *dev = info->user_ptr[1]; | |
6821 | u8 action_code, dialog_token; | |
6822 | u16 status_code; | |
6823 | u8 *peer; | |
6824 | ||
6825 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6826 | !rdev->ops->tdls_mgmt) | |
6827 | return -EOPNOTSUPP; | |
6828 | ||
6829 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6830 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6831 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6832 | !info->attrs[NL80211_ATTR_IE] || | |
6833 | !info->attrs[NL80211_ATTR_MAC]) | |
6834 | return -EINVAL; | |
6835 | ||
6836 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6837 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6838 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6839 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6840 | ||
e35e4d28 HG |
6841 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6842 | dialog_token, status_code, | |
6843 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6844 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6845 | } |
6846 | ||
6847 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6848 | { | |
6849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6850 | struct net_device *dev = info->user_ptr[1]; | |
6851 | enum nl80211_tdls_operation operation; | |
6852 | u8 *peer; | |
6853 | ||
6854 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6855 | !rdev->ops->tdls_oper) | |
6856 | return -EOPNOTSUPP; | |
6857 | ||
6858 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6859 | !info->attrs[NL80211_ATTR_MAC]) | |
6860 | return -EINVAL; | |
6861 | ||
6862 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6863 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6864 | ||
e35e4d28 | 6865 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6866 | } |
6867 | ||
9588bbd5 JM |
6868 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6869 | struct genl_info *info) | |
6870 | { | |
4c476991 | 6871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6872 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6873 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6874 | struct sk_buff *msg; |
6875 | void *hdr; | |
6876 | u64 cookie; | |
683b6d3b | 6877 | u32 duration; |
9588bbd5 JM |
6878 | int err; |
6879 | ||
6880 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6881 | !info->attrs[NL80211_ATTR_DURATION]) | |
6882 | return -EINVAL; | |
6883 | ||
6884 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6885 | ||
ebf348fc JB |
6886 | if (!rdev->ops->remain_on_channel || |
6887 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6888 | return -EOPNOTSUPP; | |
6889 | ||
9588bbd5 | 6890 | /* |
ebf348fc JB |
6891 | * We should be on that channel for at least a minimum amount of |
6892 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6893 | */ |
ebf348fc | 6894 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6895 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6896 | return -EINVAL; |
6897 | ||
683b6d3b JB |
6898 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6899 | if (err) | |
6900 | return err; | |
9588bbd5 JM |
6901 | |
6902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6903 | if (!msg) |
6904 | return -ENOMEM; | |
9588bbd5 | 6905 | |
15e47304 | 6906 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6907 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6908 | ||
6909 | if (IS_ERR(hdr)) { | |
6910 | err = PTR_ERR(hdr); | |
6911 | goto free_msg; | |
6912 | } | |
6913 | ||
683b6d3b JB |
6914 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6915 | duration, &cookie); | |
9588bbd5 JM |
6916 | |
6917 | if (err) | |
6918 | goto free_msg; | |
6919 | ||
9360ffd1 DM |
6920 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6921 | goto nla_put_failure; | |
9588bbd5 JM |
6922 | |
6923 | genlmsg_end(msg, hdr); | |
4c476991 JB |
6924 | |
6925 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
6926 | |
6927 | nla_put_failure: | |
6928 | err = -ENOBUFS; | |
6929 | free_msg: | |
6930 | nlmsg_free(msg); | |
9588bbd5 JM |
6931 | return err; |
6932 | } | |
6933 | ||
6934 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
6935 | struct genl_info *info) | |
6936 | { | |
4c476991 | 6937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6938 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 6939 | u64 cookie; |
9588bbd5 JM |
6940 | |
6941 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6942 | return -EINVAL; | |
6943 | ||
4c476991 JB |
6944 | if (!rdev->ops->cancel_remain_on_channel) |
6945 | return -EOPNOTSUPP; | |
9588bbd5 | 6946 | |
9588bbd5 JM |
6947 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
6948 | ||
e35e4d28 | 6949 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
6950 | } |
6951 | ||
13ae75b1 JM |
6952 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
6953 | u8 *rates, u8 rates_len) | |
6954 | { | |
6955 | u8 i; | |
6956 | u32 mask = 0; | |
6957 | ||
6958 | for (i = 0; i < rates_len; i++) { | |
6959 | int rate = (rates[i] & 0x7f) * 5; | |
6960 | int ridx; | |
6961 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
6962 | struct ieee80211_rate *srate = | |
6963 | &sband->bitrates[ridx]; | |
6964 | if (rate == srate->bitrate) { | |
6965 | mask |= 1 << ridx; | |
6966 | break; | |
6967 | } | |
6968 | } | |
6969 | if (ridx == sband->n_bitrates) | |
6970 | return 0; /* rate not found */ | |
6971 | } | |
6972 | ||
6973 | return mask; | |
6974 | } | |
6975 | ||
24db78c0 SW |
6976 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
6977 | u8 *rates, u8 rates_len, | |
6978 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
6979 | { | |
6980 | u8 i; | |
6981 | ||
6982 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
6983 | ||
6984 | for (i = 0; i < rates_len; i++) { | |
6985 | int ridx, rbit; | |
6986 | ||
6987 | ridx = rates[i] / 8; | |
6988 | rbit = BIT(rates[i] % 8); | |
6989 | ||
6990 | /* check validity */ | |
910570b5 | 6991 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
6992 | return false; |
6993 | ||
6994 | /* check availability */ | |
6995 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
6996 | mcs[ridx] |= rbit; | |
6997 | else | |
6998 | return false; | |
6999 | } | |
7000 | ||
7001 | return true; | |
7002 | } | |
7003 | ||
b54452b0 | 7004 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7005 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7006 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7007 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7008 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7009 | }; |
7010 | ||
7011 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7012 | struct genl_info *info) | |
7013 | { | |
7014 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7016 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7017 | int rem, i; |
7018 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7019 | struct nlattr *tx_rates; |
7020 | struct ieee80211_supported_band *sband; | |
7021 | ||
7022 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7023 | return -EINVAL; | |
7024 | ||
4c476991 JB |
7025 | if (!rdev->ops->set_bitrate_mask) |
7026 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7027 | |
7028 | memset(&mask, 0, sizeof(mask)); | |
7029 | /* Default to all rates enabled */ | |
7030 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7031 | sband = rdev->wiphy.bands[i]; | |
7032 | mask.control[i].legacy = | |
7033 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7034 | if (sband) |
7035 | memcpy(mask.control[i].mcs, | |
7036 | sband->ht_cap.mcs.rx_mask, | |
7037 | sizeof(mask.control[i].mcs)); | |
7038 | else | |
7039 | memset(mask.control[i].mcs, 0, | |
7040 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7041 | } |
7042 | ||
7043 | /* | |
7044 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7045 | * directly to the enum ieee80211_band values used in cfg80211. | |
7046 | */ | |
24db78c0 | 7047 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7048 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7049 | { | |
7050 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7051 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7052 | return -EINVAL; | |
13ae75b1 | 7053 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7054 | if (sband == NULL) |
7055 | return -EINVAL; | |
13ae75b1 JM |
7056 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7057 | nla_len(tx_rates), nl80211_txattr_policy); | |
7058 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7059 | mask.control[band].legacy = rateset_to_mask( | |
7060 | sband, | |
7061 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7062 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7063 | if ((mask.control[band].legacy == 0) && |
7064 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7065 | return -EINVAL; | |
24db78c0 SW |
7066 | } |
7067 | if (tb[NL80211_TXRATE_MCS]) { | |
7068 | if (!ht_rateset_to_mask( | |
7069 | sband, | |
7070 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7071 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7072 | mask.control[band].mcs)) | |
7073 | return -EINVAL; | |
7074 | } | |
7075 | ||
7076 | if (mask.control[band].legacy == 0) { | |
7077 | /* don't allow empty legacy rates if HT | |
7078 | * is not even supported. */ | |
7079 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7080 | return -EINVAL; | |
7081 | ||
7082 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7083 | if (mask.control[band].mcs[i]) | |
7084 | break; | |
7085 | ||
7086 | /* legacy and mcs rates may not be both empty */ | |
7087 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7088 | return -EINVAL; |
13ae75b1 JM |
7089 | } |
7090 | } | |
7091 | ||
e35e4d28 | 7092 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7093 | } |
7094 | ||
2e161f78 | 7095 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7096 | { |
4c476991 | 7097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7098 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7099 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7100 | |
7101 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7102 | return -EINVAL; | |
7103 | ||
2e161f78 JB |
7104 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7105 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7106 | |
71bbc994 JB |
7107 | switch (wdev->iftype) { |
7108 | case NL80211_IFTYPE_STATION: | |
7109 | case NL80211_IFTYPE_ADHOC: | |
7110 | case NL80211_IFTYPE_P2P_CLIENT: | |
7111 | case NL80211_IFTYPE_AP: | |
7112 | case NL80211_IFTYPE_AP_VLAN: | |
7113 | case NL80211_IFTYPE_MESH_POINT: | |
7114 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7115 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7116 | break; |
7117 | default: | |
4c476991 | 7118 | return -EOPNOTSUPP; |
71bbc994 | 7119 | } |
026331c4 JM |
7120 | |
7121 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7122 | if (!rdev->ops->mgmt_tx) |
7123 | return -EOPNOTSUPP; | |
026331c4 | 7124 | |
15e47304 | 7125 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7126 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7127 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7128 | } |
7129 | ||
2e161f78 | 7130 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7131 | { |
4c476991 | 7132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7133 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7134 | struct cfg80211_chan_def chandef; |
026331c4 | 7135 | int err; |
d64d373f | 7136 | void *hdr = NULL; |
026331c4 | 7137 | u64 cookie; |
e247bd90 | 7138 | struct sk_buff *msg = NULL; |
f7ca38df | 7139 | unsigned int wait = 0; |
e247bd90 JB |
7140 | bool offchan, no_cck, dont_wait_for_ack; |
7141 | ||
7142 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7143 | |
683b6d3b | 7144 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7145 | return -EINVAL; |
7146 | ||
4c476991 JB |
7147 | if (!rdev->ops->mgmt_tx) |
7148 | return -EOPNOTSUPP; | |
026331c4 | 7149 | |
71bbc994 JB |
7150 | switch (wdev->iftype) { |
7151 | case NL80211_IFTYPE_STATION: | |
7152 | case NL80211_IFTYPE_ADHOC: | |
7153 | case NL80211_IFTYPE_P2P_CLIENT: | |
7154 | case NL80211_IFTYPE_AP: | |
7155 | case NL80211_IFTYPE_AP_VLAN: | |
7156 | case NL80211_IFTYPE_MESH_POINT: | |
7157 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7158 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7159 | break; |
7160 | default: | |
4c476991 | 7161 | return -EOPNOTSUPP; |
71bbc994 | 7162 | } |
026331c4 | 7163 | |
f7ca38df | 7164 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7165 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7166 | return -EINVAL; |
7167 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7168 | |
7169 | /* | |
7170 | * We should wait on the channel for at least a minimum amount | |
7171 | * of time (10ms) but no longer than the driver supports. | |
7172 | */ | |
7173 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7174 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7175 | return -EINVAL; | |
7176 | ||
f7ca38df JB |
7177 | } |
7178 | ||
f7ca38df JB |
7179 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7180 | ||
7c4ef712 JB |
7181 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7182 | return -EINVAL; | |
7183 | ||
e9f935e3 RM |
7184 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7185 | ||
683b6d3b JB |
7186 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7187 | if (err) | |
7188 | return err; | |
026331c4 | 7189 | |
e247bd90 JB |
7190 | if (!dont_wait_for_ack) { |
7191 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7192 | if (!msg) | |
7193 | return -ENOMEM; | |
026331c4 | 7194 | |
15e47304 | 7195 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7196 | NL80211_CMD_FRAME); |
026331c4 | 7197 | |
e247bd90 JB |
7198 | if (IS_ERR(hdr)) { |
7199 | err = PTR_ERR(hdr); | |
7200 | goto free_msg; | |
7201 | } | |
026331c4 | 7202 | } |
e247bd90 | 7203 | |
683b6d3b | 7204 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7205 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7206 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7207 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7208 | if (err) |
7209 | goto free_msg; | |
7210 | ||
e247bd90 | 7211 | if (msg) { |
9360ffd1 DM |
7212 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7213 | goto nla_put_failure; | |
026331c4 | 7214 | |
e247bd90 JB |
7215 | genlmsg_end(msg, hdr); |
7216 | return genlmsg_reply(msg, info); | |
7217 | } | |
7218 | ||
7219 | return 0; | |
026331c4 JM |
7220 | |
7221 | nla_put_failure: | |
7222 | err = -ENOBUFS; | |
7223 | free_msg: | |
7224 | nlmsg_free(msg); | |
026331c4 JM |
7225 | return err; |
7226 | } | |
7227 | ||
f7ca38df JB |
7228 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7229 | { | |
7230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7231 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7232 | u64 cookie; |
7233 | ||
7234 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7235 | return -EINVAL; | |
7236 | ||
7237 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7238 | return -EOPNOTSUPP; | |
7239 | ||
71bbc994 JB |
7240 | switch (wdev->iftype) { |
7241 | case NL80211_IFTYPE_STATION: | |
7242 | case NL80211_IFTYPE_ADHOC: | |
7243 | case NL80211_IFTYPE_P2P_CLIENT: | |
7244 | case NL80211_IFTYPE_AP: | |
7245 | case NL80211_IFTYPE_AP_VLAN: | |
7246 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7247 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7248 | break; |
7249 | default: | |
f7ca38df | 7250 | return -EOPNOTSUPP; |
71bbc994 | 7251 | } |
f7ca38df JB |
7252 | |
7253 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7254 | ||
e35e4d28 | 7255 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7256 | } |
7257 | ||
ffb9eb3d KV |
7258 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7259 | { | |
4c476991 | 7260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7261 | struct wireless_dev *wdev; |
4c476991 | 7262 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7263 | u8 ps_state; |
7264 | bool state; | |
7265 | int err; | |
7266 | ||
4c476991 JB |
7267 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7268 | return -EINVAL; | |
ffb9eb3d KV |
7269 | |
7270 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7271 | ||
4c476991 JB |
7272 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7273 | return -EINVAL; | |
ffb9eb3d KV |
7274 | |
7275 | wdev = dev->ieee80211_ptr; | |
7276 | ||
4c476991 JB |
7277 | if (!rdev->ops->set_power_mgmt) |
7278 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7279 | |
7280 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7281 | ||
7282 | if (state == wdev->ps) | |
4c476991 | 7283 | return 0; |
ffb9eb3d | 7284 | |
e35e4d28 | 7285 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7286 | if (!err) |
7287 | wdev->ps = state; | |
ffb9eb3d KV |
7288 | return err; |
7289 | } | |
7290 | ||
7291 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7292 | { | |
4c476991 | 7293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7294 | enum nl80211_ps_state ps_state; |
7295 | struct wireless_dev *wdev; | |
4c476991 | 7296 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7297 | struct sk_buff *msg; |
7298 | void *hdr; | |
7299 | int err; | |
7300 | ||
ffb9eb3d KV |
7301 | wdev = dev->ieee80211_ptr; |
7302 | ||
4c476991 JB |
7303 | if (!rdev->ops->set_power_mgmt) |
7304 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7305 | |
7306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7307 | if (!msg) |
7308 | return -ENOMEM; | |
ffb9eb3d | 7309 | |
15e47304 | 7310 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7311 | NL80211_CMD_GET_POWER_SAVE); |
7312 | if (!hdr) { | |
4c476991 | 7313 | err = -ENOBUFS; |
ffb9eb3d KV |
7314 | goto free_msg; |
7315 | } | |
7316 | ||
7317 | if (wdev->ps) | |
7318 | ps_state = NL80211_PS_ENABLED; | |
7319 | else | |
7320 | ps_state = NL80211_PS_DISABLED; | |
7321 | ||
9360ffd1 DM |
7322 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7323 | goto nla_put_failure; | |
ffb9eb3d KV |
7324 | |
7325 | genlmsg_end(msg, hdr); | |
4c476991 | 7326 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7327 | |
4c476991 | 7328 | nla_put_failure: |
ffb9eb3d | 7329 | err = -ENOBUFS; |
4c476991 | 7330 | free_msg: |
ffb9eb3d | 7331 | nlmsg_free(msg); |
ffb9eb3d KV |
7332 | return err; |
7333 | } | |
7334 | ||
d6dc1a38 JO |
7335 | static struct nla_policy |
7336 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7337 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7338 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7339 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7340 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7341 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7342 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7343 | }; |
7344 | ||
84f10708 | 7345 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7346 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7347 | { |
7348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7349 | struct wireless_dev *wdev; | |
7350 | struct net_device *dev = info->user_ptr[1]; | |
7351 | ||
d9d8b019 | 7352 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7353 | return -EINVAL; |
7354 | ||
7355 | wdev = dev->ieee80211_ptr; | |
7356 | ||
7357 | if (!rdev->ops->set_cqm_txe_config) | |
7358 | return -EOPNOTSUPP; | |
7359 | ||
7360 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7361 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7362 | return -EOPNOTSUPP; | |
7363 | ||
e35e4d28 | 7364 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7365 | } |
7366 | ||
d6dc1a38 JO |
7367 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7368 | s32 threshold, u32 hysteresis) | |
7369 | { | |
4c476991 | 7370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7371 | struct wireless_dev *wdev; |
4c476991 | 7372 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7373 | |
7374 | if (threshold > 0) | |
7375 | return -EINVAL; | |
7376 | ||
d6dc1a38 JO |
7377 | wdev = dev->ieee80211_ptr; |
7378 | ||
4c476991 JB |
7379 | if (!rdev->ops->set_cqm_rssi_config) |
7380 | return -EOPNOTSUPP; | |
d6dc1a38 | 7381 | |
074ac8df | 7382 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7383 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7384 | return -EOPNOTSUPP; | |
d6dc1a38 | 7385 | |
e35e4d28 | 7386 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7387 | } |
7388 | ||
7389 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7390 | { | |
7391 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7392 | struct nlattr *cqm; | |
7393 | int err; | |
7394 | ||
7395 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7396 | if (!cqm) { | |
7397 | err = -EINVAL; | |
7398 | goto out; | |
7399 | } | |
7400 | ||
7401 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7402 | nl80211_attr_cqm_policy); | |
7403 | if (err) | |
7404 | goto out; | |
7405 | ||
7406 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7407 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7408 | s32 threshold; | |
7409 | u32 hysteresis; | |
7410 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7411 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7412 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7413 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7414 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7415 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7416 | u32 rate, pkts, intvl; | |
7417 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7418 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7419 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7420 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7421 | } else |
7422 | err = -EINVAL; | |
7423 | ||
7424 | out: | |
7425 | return err; | |
7426 | } | |
7427 | ||
29cbe68c JB |
7428 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7429 | { | |
7430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7431 | struct net_device *dev = info->user_ptr[1]; | |
7432 | struct mesh_config cfg; | |
c80d545d | 7433 | struct mesh_setup setup; |
29cbe68c JB |
7434 | int err; |
7435 | ||
7436 | /* start with default */ | |
7437 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7438 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7439 | |
24bdd9f4 | 7440 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7441 | /* and parse parameters if given */ |
24bdd9f4 | 7442 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7443 | if (err) |
7444 | return err; | |
7445 | } | |
7446 | ||
7447 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7448 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7449 | return -EINVAL; | |
7450 | ||
c80d545d JC |
7451 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7452 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7453 | ||
4bb62344 CYY |
7454 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7455 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7456 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7457 | return -EINVAL; | |
7458 | ||
9bdbf04d MP |
7459 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7460 | setup.beacon_interval = | |
7461 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7462 | if (setup.beacon_interval < 10 || | |
7463 | setup.beacon_interval > 10000) | |
7464 | return -EINVAL; | |
7465 | } | |
7466 | ||
7467 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7468 | setup.dtim_period = | |
7469 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7470 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7471 | return -EINVAL; | |
7472 | } | |
7473 | ||
c80d545d JC |
7474 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7475 | /* parse additional setup parameters if given */ | |
7476 | err = nl80211_parse_mesh_setup(info, &setup); | |
7477 | if (err) | |
7478 | return err; | |
7479 | } | |
7480 | ||
d37bb18a TP |
7481 | if (setup.user_mpm) |
7482 | cfg.auto_open_plinks = false; | |
7483 | ||
cc1d2806 | 7484 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7485 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7486 | if (err) | |
7487 | return err; | |
cc1d2806 JB |
7488 | } else { |
7489 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7490 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7491 | } |
7492 | ||
c80d545d | 7493 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7494 | } |
7495 | ||
7496 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7497 | { | |
7498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7499 | struct net_device *dev = info->user_ptr[1]; | |
7500 | ||
7501 | return cfg80211_leave_mesh(rdev, dev); | |
7502 | } | |
7503 | ||
dfb89c56 | 7504 | #ifdef CONFIG_PM |
bb92d199 AK |
7505 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7506 | struct cfg80211_registered_device *rdev) | |
7507 | { | |
7508 | struct nlattr *nl_pats, *nl_pat; | |
7509 | int i, pat_len; | |
7510 | ||
7511 | if (!rdev->wowlan->n_patterns) | |
7512 | return 0; | |
7513 | ||
7514 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7515 | if (!nl_pats) | |
7516 | return -ENOBUFS; | |
7517 | ||
7518 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
7519 | nl_pat = nla_nest_start(msg, i + 1); | |
7520 | if (!nl_pat) | |
7521 | return -ENOBUFS; | |
7522 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
7523 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
7524 | DIV_ROUND_UP(pat_len, 8), | |
7525 | rdev->wowlan->patterns[i].mask) || | |
7526 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
7527 | pat_len, rdev->wowlan->patterns[i].pattern) || | |
7528 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, | |
7529 | rdev->wowlan->patterns[i].pkt_offset)) | |
7530 | return -ENOBUFS; | |
7531 | nla_nest_end(msg, nl_pat); | |
7532 | } | |
7533 | nla_nest_end(msg, nl_pats); | |
7534 | ||
7535 | return 0; | |
7536 | } | |
7537 | ||
2a0e047e JB |
7538 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7539 | struct cfg80211_wowlan_tcp *tcp) | |
7540 | { | |
7541 | struct nlattr *nl_tcp; | |
7542 | ||
7543 | if (!tcp) | |
7544 | return 0; | |
7545 | ||
7546 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7547 | if (!nl_tcp) | |
7548 | return -ENOBUFS; | |
7549 | ||
7550 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7551 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7552 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7553 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7554 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7555 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7556 | tcp->payload_len, tcp->payload) || | |
7557 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7558 | tcp->data_interval) || | |
7559 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7560 | tcp->wake_len, tcp->wake_data) || | |
7561 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7562 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7563 | return -ENOBUFS; | |
7564 | ||
7565 | if (tcp->payload_seq.len && | |
7566 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7567 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7568 | return -ENOBUFS; | |
7569 | ||
7570 | if (tcp->payload_tok.len && | |
7571 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7572 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7573 | &tcp->payload_tok)) | |
7574 | return -ENOBUFS; | |
7575 | ||
7576 | return 0; | |
7577 | } | |
7578 | ||
ff1b6e69 JB |
7579 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7580 | { | |
7581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7582 | struct sk_buff *msg; | |
7583 | void *hdr; | |
2a0e047e | 7584 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7585 | |
2a0e047e JB |
7586 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7587 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7588 | return -EOPNOTSUPP; |
7589 | ||
2a0e047e JB |
7590 | if (rdev->wowlan && rdev->wowlan->tcp) { |
7591 | /* adjust size to have room for all the data */ | |
7592 | size += rdev->wowlan->tcp->tokens_size + | |
7593 | rdev->wowlan->tcp->payload_len + | |
7594 | rdev->wowlan->tcp->wake_len + | |
7595 | rdev->wowlan->tcp->wake_len / 8; | |
7596 | } | |
7597 | ||
7598 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7599 | if (!msg) |
7600 | return -ENOMEM; | |
7601 | ||
15e47304 | 7602 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7603 | NL80211_CMD_GET_WOWLAN); |
7604 | if (!hdr) | |
7605 | goto nla_put_failure; | |
7606 | ||
7607 | if (rdev->wowlan) { | |
7608 | struct nlattr *nl_wowlan; | |
7609 | ||
7610 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7611 | if (!nl_wowlan) | |
7612 | goto nla_put_failure; | |
7613 | ||
9360ffd1 DM |
7614 | if ((rdev->wowlan->any && |
7615 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7616 | (rdev->wowlan->disconnect && | |
7617 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7618 | (rdev->wowlan->magic_pkt && | |
7619 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7620 | (rdev->wowlan->gtk_rekey_failure && | |
7621 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7622 | (rdev->wowlan->eap_identity_req && | |
7623 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7624 | (rdev->wowlan->four_way_handshake && | |
7625 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7626 | (rdev->wowlan->rfkill_release && | |
7627 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
7628 | goto nla_put_failure; | |
2a0e047e | 7629 | |
bb92d199 AK |
7630 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7631 | goto nla_put_failure; | |
2a0e047e JB |
7632 | |
7633 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) | |
7634 | goto nla_put_failure; | |
7635 | ||
ff1b6e69 JB |
7636 | nla_nest_end(msg, nl_wowlan); |
7637 | } | |
7638 | ||
7639 | genlmsg_end(msg, hdr); | |
7640 | return genlmsg_reply(msg, info); | |
7641 | ||
7642 | nla_put_failure: | |
7643 | nlmsg_free(msg); | |
7644 | return -ENOBUFS; | |
7645 | } | |
7646 | ||
2a0e047e JB |
7647 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7648 | struct nlattr *attr, | |
7649 | struct cfg80211_wowlan *trig) | |
7650 | { | |
7651 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7652 | struct cfg80211_wowlan_tcp *cfg; | |
7653 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7654 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7655 | u32 size; | |
7656 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7657 | int err, port; | |
7658 | ||
7659 | if (!rdev->wiphy.wowlan.tcp) | |
7660 | return -EINVAL; | |
7661 | ||
7662 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7663 | nla_data(attr), nla_len(attr), | |
7664 | nl80211_wowlan_tcp_policy); | |
7665 | if (err) | |
7666 | return err; | |
7667 | ||
7668 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7669 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7670 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7671 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7672 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7673 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7674 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7675 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7676 | return -EINVAL; | |
7677 | ||
7678 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
7679 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) | |
7680 | return -EINVAL; | |
7681 | ||
7682 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
723d568a JB |
7683 | rdev->wiphy.wowlan.tcp->data_interval_max || |
7684 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) | |
2a0e047e JB |
7685 | return -EINVAL; |
7686 | ||
7687 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
7688 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) | |
7689 | return -EINVAL; | |
7690 | ||
7691 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7692 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7693 | return -EINVAL; | |
7694 | ||
7695 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7696 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7697 | ||
7698 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7699 | tokens_size = tokln - sizeof(*tok); | |
7700 | ||
7701 | if (!tok->len || tokens_size % tok->len) | |
7702 | return -EINVAL; | |
7703 | if (!rdev->wiphy.wowlan.tcp->tok) | |
7704 | return -EINVAL; | |
7705 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) | |
7706 | return -EINVAL; | |
7707 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) | |
7708 | return -EINVAL; | |
7709 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) | |
7710 | return -EINVAL; | |
7711 | if (tok->offset + tok->len > data_size) | |
7712 | return -EINVAL; | |
7713 | } | |
7714 | ||
7715 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7716 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
7717 | if (!rdev->wiphy.wowlan.tcp->seq) | |
7718 | return -EINVAL; | |
7719 | if (seq->len == 0 || seq->len > 4) | |
7720 | return -EINVAL; | |
7721 | if (seq->len + seq->offset > data_size) | |
7722 | return -EINVAL; | |
7723 | } | |
7724 | ||
7725 | size = sizeof(*cfg); | |
7726 | size += data_size; | |
7727 | size += wake_size + wake_mask_size; | |
7728 | size += tokens_size; | |
7729 | ||
7730 | cfg = kzalloc(size, GFP_KERNEL); | |
7731 | if (!cfg) | |
7732 | return -ENOMEM; | |
7733 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7734 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7735 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7736 | ETH_ALEN); | |
7737 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7738 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7739 | else | |
7740 | port = 0; | |
7741 | #ifdef CONFIG_INET | |
7742 | /* allocate a socket and port for it and use it */ | |
7743 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7744 | IPPROTO_TCP, &cfg->sock, 1); | |
7745 | if (err) { | |
7746 | kfree(cfg); | |
7747 | return err; | |
7748 | } | |
7749 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7750 | sock_release(cfg->sock); | |
7751 | kfree(cfg); | |
7752 | return -EADDRINUSE; | |
7753 | } | |
7754 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7755 | #else | |
7756 | if (!port) { | |
7757 | kfree(cfg); | |
7758 | return -EINVAL; | |
7759 | } | |
7760 | cfg->src_port = port; | |
7761 | #endif | |
7762 | ||
7763 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7764 | cfg->payload_len = data_size; | |
7765 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7766 | memcpy((void *)cfg->payload, | |
7767 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7768 | data_size); | |
7769 | if (seq) | |
7770 | cfg->payload_seq = *seq; | |
7771 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7772 | cfg->wake_len = wake_size; | |
7773 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7774 | memcpy((void *)cfg->wake_data, | |
7775 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7776 | wake_size); | |
7777 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7778 | data_size + wake_size; | |
7779 | memcpy((void *)cfg->wake_mask, | |
7780 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7781 | wake_mask_size); | |
7782 | if (tok) { | |
7783 | cfg->tokens_size = tokens_size; | |
7784 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7785 | } | |
7786 | ||
7787 | trig->tcp = cfg; | |
7788 | ||
7789 | return 0; | |
7790 | } | |
7791 | ||
ff1b6e69 JB |
7792 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7793 | { | |
7794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7795 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7796 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7797 | struct cfg80211_wowlan *ntrig; |
ff1b6e69 JB |
7798 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
7799 | int err, i; | |
6d52563f | 7800 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 | 7801 | |
2a0e047e JB |
7802 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7803 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7804 | return -EOPNOTSUPP; |
7805 | ||
ae33bd81 JB |
7806 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7807 | cfg80211_rdev_free_wowlan(rdev); | |
7808 | rdev->wowlan = NULL; | |
7809 | goto set_wakeup; | |
7810 | } | |
ff1b6e69 JB |
7811 | |
7812 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7813 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7814 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7815 | nl80211_wowlan_policy); | |
7816 | if (err) | |
7817 | return err; | |
7818 | ||
7819 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7820 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7821 | return -EINVAL; | |
7822 | new_triggers.any = true; | |
7823 | } | |
7824 | ||
7825 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7826 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7827 | return -EINVAL; | |
7828 | new_triggers.disconnect = true; | |
7829 | } | |
7830 | ||
7831 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7832 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7833 | return -EINVAL; | |
7834 | new_triggers.magic_pkt = true; | |
7835 | } | |
7836 | ||
77dbbb13 JB |
7837 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7838 | return -EINVAL; | |
7839 | ||
7840 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7841 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7842 | return -EINVAL; | |
7843 | new_triggers.gtk_rekey_failure = true; | |
7844 | } | |
7845 | ||
7846 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7847 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7848 | return -EINVAL; | |
7849 | new_triggers.eap_identity_req = true; | |
7850 | } | |
7851 | ||
7852 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7853 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7854 | return -EINVAL; | |
7855 | new_triggers.four_way_handshake = true; | |
7856 | } | |
7857 | ||
7858 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7859 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7860 | return -EINVAL; | |
7861 | new_triggers.rfkill_release = true; | |
7862 | } | |
7863 | ||
ff1b6e69 JB |
7864 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7865 | struct nlattr *pat; | |
7866 | int n_patterns = 0; | |
bb92d199 | 7867 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7868 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7869 | ||
7870 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7871 | rem) | |
7872 | n_patterns++; | |
7873 | if (n_patterns > wowlan->n_patterns) | |
7874 | return -EINVAL; | |
7875 | ||
7876 | new_triggers.patterns = kcalloc(n_patterns, | |
7877 | sizeof(new_triggers.patterns[0]), | |
7878 | GFP_KERNEL); | |
7879 | if (!new_triggers.patterns) | |
7880 | return -ENOMEM; | |
7881 | ||
7882 | new_triggers.n_patterns = n_patterns; | |
7883 | i = 0; | |
7884 | ||
7885 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7886 | rem) { | |
7887 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7888 | nla_data(pat), nla_len(pat), NULL); | |
7889 | err = -EINVAL; | |
7890 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7891 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7892 | goto error; | |
7893 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7894 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7895 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7896 | mask_len) | |
7897 | goto error; | |
7898 | if (pat_len > wowlan->pattern_max_len || | |
7899 | pat_len < wowlan->pattern_min_len) | |
7900 | goto error; | |
7901 | ||
bb92d199 AK |
7902 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7903 | pkt_offset = 0; | |
7904 | else | |
7905 | pkt_offset = nla_get_u32( | |
7906 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7907 | if (pkt_offset > wowlan->max_pkt_offset) | |
7908 | goto error; | |
7909 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7910 | ||
ff1b6e69 JB |
7911 | new_triggers.patterns[i].mask = |
7912 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7913 | if (!new_triggers.patterns[i].mask) { | |
7914 | err = -ENOMEM; | |
7915 | goto error; | |
7916 | } | |
7917 | new_triggers.patterns[i].pattern = | |
7918 | new_triggers.patterns[i].mask + mask_len; | |
7919 | memcpy(new_triggers.patterns[i].mask, | |
7920 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
7921 | mask_len); | |
7922 | new_triggers.patterns[i].pattern_len = pat_len; | |
7923 | memcpy(new_triggers.patterns[i].pattern, | |
7924 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
7925 | pat_len); | |
7926 | i++; | |
7927 | } | |
7928 | } | |
7929 | ||
2a0e047e JB |
7930 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
7931 | err = nl80211_parse_wowlan_tcp( | |
7932 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
7933 | &new_triggers); | |
7934 | if (err) | |
7935 | goto error; | |
7936 | } | |
7937 | ||
ae33bd81 JB |
7938 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
7939 | if (!ntrig) { | |
7940 | err = -ENOMEM; | |
7941 | goto error; | |
ff1b6e69 | 7942 | } |
ae33bd81 JB |
7943 | cfg80211_rdev_free_wowlan(rdev); |
7944 | rdev->wowlan = ntrig; | |
ff1b6e69 | 7945 | |
ae33bd81 | 7946 | set_wakeup: |
6d52563f | 7947 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
e35e4d28 | 7948 | rdev_set_wakeup(rdev, rdev->wowlan); |
6d52563f | 7949 | |
ff1b6e69 JB |
7950 | return 0; |
7951 | error: | |
7952 | for (i = 0; i < new_triggers.n_patterns; i++) | |
7953 | kfree(new_triggers.patterns[i].mask); | |
7954 | kfree(new_triggers.patterns); | |
2a0e047e JB |
7955 | if (new_triggers.tcp && new_triggers.tcp->sock) |
7956 | sock_release(new_triggers.tcp->sock); | |
7957 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
7958 | return err; |
7959 | } | |
dfb89c56 | 7960 | #endif |
ff1b6e69 | 7961 | |
e5497d76 JB |
7962 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
7963 | { | |
7964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7965 | struct net_device *dev = info->user_ptr[1]; | |
7966 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7967 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
7968 | struct cfg80211_gtk_rekey_data rekey_data; | |
7969 | int err; | |
7970 | ||
7971 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
7972 | return -EINVAL; | |
7973 | ||
7974 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
7975 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7976 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7977 | nl80211_rekey_policy); | |
7978 | if (err) | |
7979 | return err; | |
7980 | ||
7981 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
7982 | return -ERANGE; | |
7983 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
7984 | return -ERANGE; | |
7985 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
7986 | return -ERANGE; | |
7987 | ||
7988 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
7989 | NL80211_KEK_LEN); | |
7990 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
7991 | NL80211_KCK_LEN); | |
7992 | memcpy(rekey_data.replay_ctr, | |
7993 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
7994 | NL80211_REPLAY_CTR_LEN); | |
7995 | ||
7996 | wdev_lock(wdev); | |
7997 | if (!wdev->current_bss) { | |
7998 | err = -ENOTCONN; | |
7999 | goto out; | |
8000 | } | |
8001 | ||
8002 | if (!rdev->ops->set_rekey_data) { | |
8003 | err = -EOPNOTSUPP; | |
8004 | goto out; | |
8005 | } | |
8006 | ||
e35e4d28 | 8007 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8008 | out: |
8009 | wdev_unlock(wdev); | |
8010 | return err; | |
8011 | } | |
8012 | ||
28946da7 JB |
8013 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8014 | struct genl_info *info) | |
8015 | { | |
8016 | struct net_device *dev = info->user_ptr[1]; | |
8017 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8018 | ||
8019 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8020 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8021 | return -EINVAL; | |
8022 | ||
15e47304 | 8023 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8024 | return -EBUSY; |
8025 | ||
15e47304 | 8026 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8027 | return 0; |
8028 | } | |
8029 | ||
7f6cf311 JB |
8030 | static int nl80211_probe_client(struct sk_buff *skb, |
8031 | struct genl_info *info) | |
8032 | { | |
8033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8034 | struct net_device *dev = info->user_ptr[1]; | |
8035 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8036 | struct sk_buff *msg; | |
8037 | void *hdr; | |
8038 | const u8 *addr; | |
8039 | u64 cookie; | |
8040 | int err; | |
8041 | ||
8042 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8043 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8044 | return -EOPNOTSUPP; | |
8045 | ||
8046 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8047 | return -EINVAL; | |
8048 | ||
8049 | if (!rdev->ops->probe_client) | |
8050 | return -EOPNOTSUPP; | |
8051 | ||
8052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8053 | if (!msg) | |
8054 | return -ENOMEM; | |
8055 | ||
15e47304 | 8056 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8057 | NL80211_CMD_PROBE_CLIENT); |
8058 | ||
8059 | if (IS_ERR(hdr)) { | |
8060 | err = PTR_ERR(hdr); | |
8061 | goto free_msg; | |
8062 | } | |
8063 | ||
8064 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8065 | ||
e35e4d28 | 8066 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8067 | if (err) |
8068 | goto free_msg; | |
8069 | ||
9360ffd1 DM |
8070 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8071 | goto nla_put_failure; | |
7f6cf311 JB |
8072 | |
8073 | genlmsg_end(msg, hdr); | |
8074 | ||
8075 | return genlmsg_reply(msg, info); | |
8076 | ||
8077 | nla_put_failure: | |
8078 | err = -ENOBUFS; | |
8079 | free_msg: | |
8080 | nlmsg_free(msg); | |
8081 | return err; | |
8082 | } | |
8083 | ||
5e760230 JB |
8084 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8085 | { | |
8086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8087 | struct cfg80211_beacon_registration *reg, *nreg; |
8088 | int rv; | |
5e760230 JB |
8089 | |
8090 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8091 | return -EOPNOTSUPP; | |
8092 | ||
37c73b5f BG |
8093 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8094 | if (!nreg) | |
8095 | return -ENOMEM; | |
8096 | ||
8097 | /* First, check if already registered. */ | |
8098 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8099 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8100 | if (reg->nlportid == info->snd_portid) { | |
8101 | rv = -EALREADY; | |
8102 | goto out_err; | |
8103 | } | |
8104 | } | |
8105 | /* Add it to the list */ | |
8106 | nreg->nlportid = info->snd_portid; | |
8107 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8108 | |
37c73b5f | 8109 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8110 | |
8111 | return 0; | |
37c73b5f BG |
8112 | out_err: |
8113 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8114 | kfree(nreg); | |
8115 | return rv; | |
5e760230 JB |
8116 | } |
8117 | ||
98104fde JB |
8118 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8119 | { | |
8120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8121 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8122 | int err; | |
8123 | ||
8124 | if (!rdev->ops->start_p2p_device) | |
8125 | return -EOPNOTSUPP; | |
8126 | ||
8127 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8128 | return -EOPNOTSUPP; | |
8129 | ||
8130 | if (wdev->p2p_started) | |
8131 | return 0; | |
8132 | ||
8133 | mutex_lock(&rdev->devlist_mtx); | |
8134 | err = cfg80211_can_add_interface(rdev, wdev->iftype); | |
8135 | mutex_unlock(&rdev->devlist_mtx); | |
8136 | if (err) | |
8137 | return err; | |
8138 | ||
eeb126e9 | 8139 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8140 | if (err) |
8141 | return err; | |
8142 | ||
8143 | wdev->p2p_started = true; | |
8144 | mutex_lock(&rdev->devlist_mtx); | |
8145 | rdev->opencount++; | |
8146 | mutex_unlock(&rdev->devlist_mtx); | |
8147 | ||
8148 | return 0; | |
8149 | } | |
8150 | ||
8151 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8152 | { | |
8153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8154 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8155 | ||
8156 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8157 | return -EOPNOTSUPP; | |
8158 | ||
8159 | if (!rdev->ops->stop_p2p_device) | |
8160 | return -EOPNOTSUPP; | |
8161 | ||
65e8d5b8 | 8162 | mutex_lock(&rdev->devlist_mtx); |
f9f47529 JB |
8163 | mutex_lock(&rdev->sched_scan_mtx); |
8164 | cfg80211_stop_p2p_device(rdev, wdev); | |
8165 | mutex_unlock(&rdev->sched_scan_mtx); | |
65e8d5b8 | 8166 | mutex_unlock(&rdev->devlist_mtx); |
98104fde JB |
8167 | |
8168 | return 0; | |
8169 | } | |
8170 | ||
3713b4e3 JB |
8171 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8172 | struct genl_info *info) | |
8173 | { | |
8174 | void *hdr; | |
8175 | struct sk_buff *msg; | |
8176 | ||
8177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8178 | if (!msg) | |
8179 | return -ENOMEM; | |
8180 | ||
8181 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8182 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8183 | if (!hdr) | |
8184 | goto nla_put_failure; | |
8185 | ||
8186 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8187 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8188 | goto nla_put_failure; | |
8189 | ||
8190 | genlmsg_end(msg, hdr); | |
8191 | return genlmsg_reply(msg, info); | |
8192 | ||
8193 | nla_put_failure: | |
8194 | kfree_skb(msg); | |
8195 | return -ENOBUFS; | |
8196 | } | |
8197 | ||
355199e0 JM |
8198 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8199 | { | |
8200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8201 | struct cfg80211_update_ft_ies_params ft_params; | |
8202 | struct net_device *dev = info->user_ptr[1]; | |
8203 | ||
8204 | if (!rdev->ops->update_ft_ies) | |
8205 | return -EOPNOTSUPP; | |
8206 | ||
8207 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8208 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8209 | return -EINVAL; | |
8210 | ||
8211 | memset(&ft_params, 0, sizeof(ft_params)); | |
8212 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8213 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8214 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8215 | ||
8216 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8217 | } | |
8218 | ||
4c476991 JB |
8219 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8220 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8221 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8222 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8223 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8224 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8225 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8226 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8227 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8228 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8229 | |
8230 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8231 | struct genl_info *info) | |
8232 | { | |
8233 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8234 | struct wireless_dev *wdev; |
4c476991 | 8235 | struct net_device *dev; |
4c476991 JB |
8236 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8237 | ||
8238 | if (rtnl) | |
8239 | rtnl_lock(); | |
8240 | ||
8241 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8242 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8243 | if (IS_ERR(rdev)) { |
8244 | if (rtnl) | |
8245 | rtnl_unlock(); | |
8246 | return PTR_ERR(rdev); | |
8247 | } | |
8248 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8249 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8250 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
89a54e48 JB |
8251 | mutex_lock(&cfg80211_mutex); |
8252 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | |
8253 | info->attrs); | |
8254 | if (IS_ERR(wdev)) { | |
8255 | mutex_unlock(&cfg80211_mutex); | |
4c476991 JB |
8256 | if (rtnl) |
8257 | rtnl_unlock(); | |
89a54e48 | 8258 | return PTR_ERR(wdev); |
4c476991 | 8259 | } |
89a54e48 | 8260 | |
89a54e48 JB |
8261 | dev = wdev->netdev; |
8262 | rdev = wiphy_to_dev(wdev->wiphy); | |
8263 | ||
1bf614ef JB |
8264 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8265 | if (!dev) { | |
8266 | mutex_unlock(&cfg80211_mutex); | |
8267 | if (rtnl) | |
8268 | rtnl_unlock(); | |
8269 | return -EINVAL; | |
8270 | } | |
8271 | ||
8272 | info->user_ptr[1] = dev; | |
8273 | } else { | |
8274 | info->user_ptr[1] = wdev; | |
41265714 | 8275 | } |
1bf614ef JB |
8276 | |
8277 | if (dev) { | |
8278 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8279 | !netif_running(dev)) { | |
8280 | mutex_unlock(&cfg80211_mutex); | |
8281 | if (rtnl) | |
8282 | rtnl_unlock(); | |
8283 | return -ENETDOWN; | |
8284 | } | |
8285 | ||
8286 | dev_hold(dev); | |
98104fde JB |
8287 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8288 | if (!wdev->p2p_started) { | |
8289 | mutex_unlock(&cfg80211_mutex); | |
8290 | if (rtnl) | |
8291 | rtnl_unlock(); | |
8292 | return -ENETDOWN; | |
8293 | } | |
41265714 | 8294 | } |
89a54e48 | 8295 | |
89a54e48 JB |
8296 | cfg80211_lock_rdev(rdev); |
8297 | ||
8298 | mutex_unlock(&cfg80211_mutex); | |
8299 | ||
4c476991 | 8300 | info->user_ptr[0] = rdev; |
4c476991 JB |
8301 | } |
8302 | ||
8303 | return 0; | |
8304 | } | |
8305 | ||
8306 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8307 | struct genl_info *info) | |
8308 | { | |
8309 | if (info->user_ptr[0]) | |
8310 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
1bf614ef JB |
8311 | if (info->user_ptr[1]) { |
8312 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8313 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8314 | ||
8315 | if (wdev->netdev) | |
8316 | dev_put(wdev->netdev); | |
8317 | } else { | |
8318 | dev_put(info->user_ptr[1]); | |
8319 | } | |
8320 | } | |
4c476991 JB |
8321 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8322 | rtnl_unlock(); | |
8323 | } | |
8324 | ||
55682965 JB |
8325 | static struct genl_ops nl80211_ops[] = { |
8326 | { | |
8327 | .cmd = NL80211_CMD_GET_WIPHY, | |
8328 | .doit = nl80211_get_wiphy, | |
8329 | .dumpit = nl80211_dump_wiphy, | |
8330 | .policy = nl80211_policy, | |
8331 | /* can be retrieved by unprivileged users */ | |
4c476991 | 8332 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
8333 | }, |
8334 | { | |
8335 | .cmd = NL80211_CMD_SET_WIPHY, | |
8336 | .doit = nl80211_set_wiphy, | |
8337 | .policy = nl80211_policy, | |
8338 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8339 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8340 | }, |
8341 | { | |
8342 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8343 | .doit = nl80211_get_interface, | |
8344 | .dumpit = nl80211_dump_interface, | |
8345 | .policy = nl80211_policy, | |
8346 | /* can be retrieved by unprivileged users */ | |
72fb2abc | 8347 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
55682965 JB |
8348 | }, |
8349 | { | |
8350 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8351 | .doit = nl80211_set_interface, | |
8352 | .policy = nl80211_policy, | |
8353 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8354 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8355 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8356 | }, |
8357 | { | |
8358 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8359 | .doit = nl80211_new_interface, | |
8360 | .policy = nl80211_policy, | |
8361 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8362 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8363 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8364 | }, |
8365 | { | |
8366 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8367 | .doit = nl80211_del_interface, | |
8368 | .policy = nl80211_policy, | |
41ade00f | 8369 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8370 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8371 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8372 | }, |
8373 | { | |
8374 | .cmd = NL80211_CMD_GET_KEY, | |
8375 | .doit = nl80211_get_key, | |
8376 | .policy = nl80211_policy, | |
8377 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8378 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8379 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8380 | }, |
8381 | { | |
8382 | .cmd = NL80211_CMD_SET_KEY, | |
8383 | .doit = nl80211_set_key, | |
8384 | .policy = nl80211_policy, | |
8385 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8386 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8387 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8388 | }, |
8389 | { | |
8390 | .cmd = NL80211_CMD_NEW_KEY, | |
8391 | .doit = nl80211_new_key, | |
8392 | .policy = nl80211_policy, | |
8393 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8395 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8396 | }, |
8397 | { | |
8398 | .cmd = NL80211_CMD_DEL_KEY, | |
8399 | .doit = nl80211_del_key, | |
8400 | .policy = nl80211_policy, | |
55682965 | 8401 | .flags = GENL_ADMIN_PERM, |
41265714 | 8402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8403 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8404 | }, |
ed1b6cc7 JB |
8405 | { |
8406 | .cmd = NL80211_CMD_SET_BEACON, | |
8407 | .policy = nl80211_policy, | |
8408 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8409 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8411 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8412 | }, |
8413 | { | |
8860020e | 8414 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8415 | .policy = nl80211_policy, |
8416 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8417 | .doit = nl80211_start_ap, |
2b5f8b0b | 8418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8419 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8420 | }, |
8421 | { | |
8860020e | 8422 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8423 | .policy = nl80211_policy, |
8424 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8425 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8427 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8428 | }, |
5727ef1b JB |
8429 | { |
8430 | .cmd = NL80211_CMD_GET_STATION, | |
8431 | .doit = nl80211_get_station, | |
2ec600d6 | 8432 | .dumpit = nl80211_dump_station, |
5727ef1b | 8433 | .policy = nl80211_policy, |
4c476991 JB |
8434 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8435 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8436 | }, |
8437 | { | |
8438 | .cmd = NL80211_CMD_SET_STATION, | |
8439 | .doit = nl80211_set_station, | |
8440 | .policy = nl80211_policy, | |
8441 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8443 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8444 | }, |
8445 | { | |
8446 | .cmd = NL80211_CMD_NEW_STATION, | |
8447 | .doit = nl80211_new_station, | |
8448 | .policy = nl80211_policy, | |
8449 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8451 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8452 | }, |
8453 | { | |
8454 | .cmd = NL80211_CMD_DEL_STATION, | |
8455 | .doit = nl80211_del_station, | |
8456 | .policy = nl80211_policy, | |
2ec600d6 | 8457 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8459 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8460 | }, |
8461 | { | |
8462 | .cmd = NL80211_CMD_GET_MPATH, | |
8463 | .doit = nl80211_get_mpath, | |
8464 | .dumpit = nl80211_dump_mpath, | |
8465 | .policy = nl80211_policy, | |
8466 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8468 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8469 | }, |
8470 | { | |
8471 | .cmd = NL80211_CMD_SET_MPATH, | |
8472 | .doit = nl80211_set_mpath, | |
8473 | .policy = nl80211_policy, | |
8474 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8476 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8477 | }, |
8478 | { | |
8479 | .cmd = NL80211_CMD_NEW_MPATH, | |
8480 | .doit = nl80211_new_mpath, | |
8481 | .policy = nl80211_policy, | |
8482 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8484 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8485 | }, |
8486 | { | |
8487 | .cmd = NL80211_CMD_DEL_MPATH, | |
8488 | .doit = nl80211_del_mpath, | |
8489 | .policy = nl80211_policy, | |
9f1ba906 | 8490 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8492 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8493 | }, |
8494 | { | |
8495 | .cmd = NL80211_CMD_SET_BSS, | |
8496 | .doit = nl80211_set_bss, | |
8497 | .policy = nl80211_policy, | |
b2e1b302 | 8498 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8500 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8501 | }, |
f130347c LR |
8502 | { |
8503 | .cmd = NL80211_CMD_GET_REG, | |
8504 | .doit = nl80211_get_reg, | |
8505 | .policy = nl80211_policy, | |
8506 | /* can be retrieved by unprivileged users */ | |
8507 | }, | |
b2e1b302 LR |
8508 | { |
8509 | .cmd = NL80211_CMD_SET_REG, | |
8510 | .doit = nl80211_set_reg, | |
8511 | .policy = nl80211_policy, | |
8512 | .flags = GENL_ADMIN_PERM, | |
8513 | }, | |
8514 | { | |
8515 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8516 | .doit = nl80211_req_set_reg, | |
8517 | .policy = nl80211_policy, | |
93da9cc1 | 8518 | .flags = GENL_ADMIN_PERM, |
8519 | }, | |
8520 | { | |
24bdd9f4 JC |
8521 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8522 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8523 | .policy = nl80211_policy, |
8524 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8526 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8527 | }, |
8528 | { | |
24bdd9f4 JC |
8529 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8530 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8531 | .policy = nl80211_policy, |
9aed3cc1 | 8532 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8534 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8535 | }, |
2a519311 JB |
8536 | { |
8537 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8538 | .doit = nl80211_trigger_scan, | |
8539 | .policy = nl80211_policy, | |
8540 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8541 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8542 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8543 | }, |
8544 | { | |
8545 | .cmd = NL80211_CMD_GET_SCAN, | |
8546 | .policy = nl80211_policy, | |
8547 | .dumpit = nl80211_dump_scan, | |
8548 | }, | |
807f8a8c LC |
8549 | { |
8550 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8551 | .doit = nl80211_start_sched_scan, | |
8552 | .policy = nl80211_policy, | |
8553 | .flags = GENL_ADMIN_PERM, | |
8554 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8555 | NL80211_FLAG_NEED_RTNL, | |
8556 | }, | |
8557 | { | |
8558 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8559 | .doit = nl80211_stop_sched_scan, | |
8560 | .policy = nl80211_policy, | |
8561 | .flags = GENL_ADMIN_PERM, | |
8562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8563 | NL80211_FLAG_NEED_RTNL, | |
8564 | }, | |
636a5d36 JM |
8565 | { |
8566 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8567 | .doit = nl80211_authenticate, | |
8568 | .policy = nl80211_policy, | |
8569 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8570 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8571 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8572 | }, |
8573 | { | |
8574 | .cmd = NL80211_CMD_ASSOCIATE, | |
8575 | .doit = nl80211_associate, | |
8576 | .policy = nl80211_policy, | |
8577 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8579 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8580 | }, |
8581 | { | |
8582 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8583 | .doit = nl80211_deauthenticate, | |
8584 | .policy = nl80211_policy, | |
8585 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8587 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8588 | }, |
8589 | { | |
8590 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8591 | .doit = nl80211_disassociate, | |
8592 | .policy = nl80211_policy, | |
8593 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8595 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8596 | }, |
04a773ad JB |
8597 | { |
8598 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8599 | .doit = nl80211_join_ibss, | |
8600 | .policy = nl80211_policy, | |
8601 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8603 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8604 | }, |
8605 | { | |
8606 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8607 | .doit = nl80211_leave_ibss, | |
8608 | .policy = nl80211_policy, | |
8609 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8611 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8612 | }, |
aff89a9b JB |
8613 | #ifdef CONFIG_NL80211_TESTMODE |
8614 | { | |
8615 | .cmd = NL80211_CMD_TESTMODE, | |
8616 | .doit = nl80211_testmode_do, | |
71063f0e | 8617 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8618 | .policy = nl80211_policy, |
8619 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8620 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8621 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8622 | }, |
8623 | #endif | |
b23aa676 SO |
8624 | { |
8625 | .cmd = NL80211_CMD_CONNECT, | |
8626 | .doit = nl80211_connect, | |
8627 | .policy = nl80211_policy, | |
8628 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8629 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8630 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8631 | }, |
8632 | { | |
8633 | .cmd = NL80211_CMD_DISCONNECT, | |
8634 | .doit = nl80211_disconnect, | |
8635 | .policy = nl80211_policy, | |
8636 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8638 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8639 | }, |
463d0183 JB |
8640 | { |
8641 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8642 | .doit = nl80211_wiphy_netns, | |
8643 | .policy = nl80211_policy, | |
8644 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8645 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8646 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8647 | }, |
61fa713c HS |
8648 | { |
8649 | .cmd = NL80211_CMD_GET_SURVEY, | |
8650 | .policy = nl80211_policy, | |
8651 | .dumpit = nl80211_dump_survey, | |
8652 | }, | |
67fbb16b SO |
8653 | { |
8654 | .cmd = NL80211_CMD_SET_PMKSA, | |
8655 | .doit = nl80211_setdel_pmksa, | |
8656 | .policy = nl80211_policy, | |
8657 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8658 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8659 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8660 | }, |
8661 | { | |
8662 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8663 | .doit = nl80211_setdel_pmksa, | |
8664 | .policy = nl80211_policy, | |
8665 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8666 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8667 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8668 | }, |
8669 | { | |
8670 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8671 | .doit = nl80211_flush_pmksa, | |
8672 | .policy = nl80211_policy, | |
8673 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8675 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8676 | }, |
9588bbd5 JM |
8677 | { |
8678 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8679 | .doit = nl80211_remain_on_channel, | |
8680 | .policy = nl80211_policy, | |
8681 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8682 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8683 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8684 | }, |
8685 | { | |
8686 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8687 | .doit = nl80211_cancel_remain_on_channel, | |
8688 | .policy = nl80211_policy, | |
8689 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8690 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8691 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8692 | }, |
13ae75b1 JM |
8693 | { |
8694 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8695 | .doit = nl80211_set_tx_bitrate_mask, | |
8696 | .policy = nl80211_policy, | |
8697 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8698 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8699 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8700 | }, |
026331c4 | 8701 | { |
2e161f78 JB |
8702 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8703 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8704 | .policy = nl80211_policy, |
8705 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8706 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8707 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8708 | }, |
8709 | { | |
2e161f78 JB |
8710 | .cmd = NL80211_CMD_FRAME, |
8711 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8712 | .policy = nl80211_policy, |
f7ca38df | 8713 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8714 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8715 | NL80211_FLAG_NEED_RTNL, |
8716 | }, | |
8717 | { | |
8718 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8719 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8720 | .policy = nl80211_policy, | |
026331c4 | 8721 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8722 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8723 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8724 | }, |
ffb9eb3d KV |
8725 | { |
8726 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8727 | .doit = nl80211_set_power_save, | |
8728 | .policy = nl80211_policy, | |
8729 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8730 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8731 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8732 | }, |
8733 | { | |
8734 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8735 | .doit = nl80211_get_power_save, | |
8736 | .policy = nl80211_policy, | |
8737 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8738 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8739 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8740 | }, |
d6dc1a38 JO |
8741 | { |
8742 | .cmd = NL80211_CMD_SET_CQM, | |
8743 | .doit = nl80211_set_cqm, | |
8744 | .policy = nl80211_policy, | |
8745 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8746 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8747 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8748 | }, |
f444de05 JB |
8749 | { |
8750 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8751 | .doit = nl80211_set_channel, | |
8752 | .policy = nl80211_policy, | |
8753 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8754 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8755 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 8756 | }, |
e8347eba BJ |
8757 | { |
8758 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
8759 | .doit = nl80211_set_wds_peer, | |
8760 | .policy = nl80211_policy, | |
8761 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
8762 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8763 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 8764 | }, |
29cbe68c JB |
8765 | { |
8766 | .cmd = NL80211_CMD_JOIN_MESH, | |
8767 | .doit = nl80211_join_mesh, | |
8768 | .policy = nl80211_policy, | |
8769 | .flags = GENL_ADMIN_PERM, | |
8770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8771 | NL80211_FLAG_NEED_RTNL, | |
8772 | }, | |
8773 | { | |
8774 | .cmd = NL80211_CMD_LEAVE_MESH, | |
8775 | .doit = nl80211_leave_mesh, | |
8776 | .policy = nl80211_policy, | |
8777 | .flags = GENL_ADMIN_PERM, | |
8778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8779 | NL80211_FLAG_NEED_RTNL, | |
8780 | }, | |
dfb89c56 | 8781 | #ifdef CONFIG_PM |
ff1b6e69 JB |
8782 | { |
8783 | .cmd = NL80211_CMD_GET_WOWLAN, | |
8784 | .doit = nl80211_get_wowlan, | |
8785 | .policy = nl80211_policy, | |
8786 | /* can be retrieved by unprivileged users */ | |
8787 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8788 | NL80211_FLAG_NEED_RTNL, | |
8789 | }, | |
8790 | { | |
8791 | .cmd = NL80211_CMD_SET_WOWLAN, | |
8792 | .doit = nl80211_set_wowlan, | |
8793 | .policy = nl80211_policy, | |
8794 | .flags = GENL_ADMIN_PERM, | |
8795 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8796 | NL80211_FLAG_NEED_RTNL, | |
8797 | }, | |
dfb89c56 | 8798 | #endif |
e5497d76 JB |
8799 | { |
8800 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
8801 | .doit = nl80211_set_rekey_data, | |
8802 | .policy = nl80211_policy, | |
8803 | .flags = GENL_ADMIN_PERM, | |
8804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8805 | NL80211_FLAG_NEED_RTNL, | |
8806 | }, | |
109086ce AN |
8807 | { |
8808 | .cmd = NL80211_CMD_TDLS_MGMT, | |
8809 | .doit = nl80211_tdls_mgmt, | |
8810 | .policy = nl80211_policy, | |
8811 | .flags = GENL_ADMIN_PERM, | |
8812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8813 | NL80211_FLAG_NEED_RTNL, | |
8814 | }, | |
8815 | { | |
8816 | .cmd = NL80211_CMD_TDLS_OPER, | |
8817 | .doit = nl80211_tdls_oper, | |
8818 | .policy = nl80211_policy, | |
8819 | .flags = GENL_ADMIN_PERM, | |
8820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8821 | NL80211_FLAG_NEED_RTNL, | |
8822 | }, | |
28946da7 JB |
8823 | { |
8824 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
8825 | .doit = nl80211_register_unexpected_frame, | |
8826 | .policy = nl80211_policy, | |
8827 | .flags = GENL_ADMIN_PERM, | |
8828 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8829 | NL80211_FLAG_NEED_RTNL, | |
8830 | }, | |
7f6cf311 JB |
8831 | { |
8832 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
8833 | .doit = nl80211_probe_client, | |
8834 | .policy = nl80211_policy, | |
8835 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
8837 | NL80211_FLAG_NEED_RTNL, |
8838 | }, | |
5e760230 JB |
8839 | { |
8840 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
8841 | .doit = nl80211_register_beacons, | |
8842 | .policy = nl80211_policy, | |
8843 | .flags = GENL_ADMIN_PERM, | |
8844 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8845 | NL80211_FLAG_NEED_RTNL, | |
8846 | }, | |
1d9d9213 SW |
8847 | { |
8848 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
8849 | .doit = nl80211_set_noack_map, | |
8850 | .policy = nl80211_policy, | |
8851 | .flags = GENL_ADMIN_PERM, | |
8852 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8853 | NL80211_FLAG_NEED_RTNL, | |
8854 | }, | |
98104fde JB |
8855 | { |
8856 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
8857 | .doit = nl80211_start_p2p_device, | |
8858 | .policy = nl80211_policy, | |
8859 | .flags = GENL_ADMIN_PERM, | |
8860 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
8861 | NL80211_FLAG_NEED_RTNL, | |
8862 | }, | |
8863 | { | |
8864 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
8865 | .doit = nl80211_stop_p2p_device, | |
8866 | .policy = nl80211_policy, | |
8867 | .flags = GENL_ADMIN_PERM, | |
8868 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8869 | NL80211_FLAG_NEED_RTNL, | |
8870 | }, | |
f4e583c8 AQ |
8871 | { |
8872 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
8873 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
8874 | .policy = nl80211_policy, |
8875 | .flags = GENL_ADMIN_PERM, | |
8876 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8877 | NL80211_FLAG_NEED_RTNL, | |
8878 | }, | |
8879 | { | |
8880 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
8881 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
8882 | .policy = nl80211_policy, |
8883 | .flags = GENL_ADMIN_PERM, | |
8884 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8885 | NL80211_FLAG_NEED_RTNL, | |
8886 | }, | |
04f39047 SW |
8887 | { |
8888 | .cmd = NL80211_CMD_RADAR_DETECT, | |
8889 | .doit = nl80211_start_radar_detection, | |
8890 | .policy = nl80211_policy, | |
8891 | .flags = GENL_ADMIN_PERM, | |
8892 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8893 | NL80211_FLAG_NEED_RTNL, | |
8894 | }, | |
3713b4e3 JB |
8895 | { |
8896 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
8897 | .doit = nl80211_get_protocol_features, | |
8898 | .policy = nl80211_policy, | |
8899 | }, | |
355199e0 JM |
8900 | { |
8901 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
8902 | .doit = nl80211_update_ft_ies, | |
8903 | .policy = nl80211_policy, | |
8904 | .flags = GENL_ADMIN_PERM, | |
8905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8906 | NL80211_FLAG_NEED_RTNL, | |
8907 | }, | |
55682965 | 8908 | }; |
9588bbd5 | 8909 | |
6039f6d2 JM |
8910 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
8911 | .name = "mlme", | |
8912 | }; | |
55682965 JB |
8913 | |
8914 | /* multicast groups */ | |
8915 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
8916 | .name = "config", | |
8917 | }; | |
2a519311 JB |
8918 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
8919 | .name = "scan", | |
8920 | }; | |
73d54c9e LR |
8921 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
8922 | .name = "regulatory", | |
8923 | }; | |
55682965 JB |
8924 | |
8925 | /* notification functions */ | |
8926 | ||
8927 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
8928 | { | |
8929 | struct sk_buff *msg; | |
8930 | ||
fd2120ca | 8931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
8932 | if (!msg) |
8933 | return; | |
8934 | ||
3713b4e3 JB |
8935 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
8936 | false, NULL, NULL, NULL) < 0) { | |
55682965 JB |
8937 | nlmsg_free(msg); |
8938 | return; | |
8939 | } | |
8940 | ||
463d0183 JB |
8941 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8942 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
8943 | } |
8944 | ||
362a415d JB |
8945 | static int nl80211_add_scan_req(struct sk_buff *msg, |
8946 | struct cfg80211_registered_device *rdev) | |
8947 | { | |
8948 | struct cfg80211_scan_request *req = rdev->scan_req; | |
8949 | struct nlattr *nest; | |
8950 | int i; | |
8951 | ||
f9f47529 | 8952 | lockdep_assert_held(&rdev->sched_scan_mtx); |
667503dd | 8953 | |
362a415d JB |
8954 | if (WARN_ON(!req)) |
8955 | return 0; | |
8956 | ||
8957 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
8958 | if (!nest) | |
8959 | goto nla_put_failure; | |
9360ffd1 DM |
8960 | for (i = 0; i < req->n_ssids; i++) { |
8961 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
8962 | goto nla_put_failure; | |
8963 | } | |
362a415d JB |
8964 | nla_nest_end(msg, nest); |
8965 | ||
8966 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8967 | if (!nest) | |
8968 | goto nla_put_failure; | |
9360ffd1 DM |
8969 | for (i = 0; i < req->n_channels; i++) { |
8970 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
8971 | goto nla_put_failure; | |
8972 | } | |
362a415d JB |
8973 | nla_nest_end(msg, nest); |
8974 | ||
9360ffd1 DM |
8975 | if (req->ie && |
8976 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
8977 | goto nla_put_failure; | |
362a415d | 8978 | |
ed473771 SL |
8979 | if (req->flags) |
8980 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
8981 | ||
362a415d JB |
8982 | return 0; |
8983 | nla_put_failure: | |
8984 | return -ENOBUFS; | |
8985 | } | |
8986 | ||
a538e2d5 JB |
8987 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
8988 | struct cfg80211_registered_device *rdev, | |
fd014284 | 8989 | struct wireless_dev *wdev, |
15e47304 | 8990 | u32 portid, u32 seq, int flags, |
a538e2d5 | 8991 | u32 cmd) |
2a519311 JB |
8992 | { |
8993 | void *hdr; | |
8994 | ||
15e47304 | 8995 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
8996 | if (!hdr) |
8997 | return -1; | |
8998 | ||
9360ffd1 | 8999 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9000 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9001 | wdev->netdev->ifindex)) || | |
9002 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9003 | goto nla_put_failure; |
2a519311 | 9004 | |
362a415d JB |
9005 | /* ignore errors and send incomplete event anyway */ |
9006 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9007 | |
9008 | return genlmsg_end(msg, hdr); | |
9009 | ||
9010 | nla_put_failure: | |
9011 | genlmsg_cancel(msg, hdr); | |
9012 | return -EMSGSIZE; | |
9013 | } | |
9014 | ||
807f8a8c LC |
9015 | static int |
9016 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9017 | struct cfg80211_registered_device *rdev, | |
9018 | struct net_device *netdev, | |
15e47304 | 9019 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9020 | { |
9021 | void *hdr; | |
9022 | ||
15e47304 | 9023 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9024 | if (!hdr) |
9025 | return -1; | |
9026 | ||
9360ffd1 DM |
9027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9028 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9029 | goto nla_put_failure; | |
807f8a8c LC |
9030 | |
9031 | return genlmsg_end(msg, hdr); | |
9032 | ||
9033 | nla_put_failure: | |
9034 | genlmsg_cancel(msg, hdr); | |
9035 | return -EMSGSIZE; | |
9036 | } | |
9037 | ||
a538e2d5 | 9038 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9039 | struct wireless_dev *wdev) |
a538e2d5 JB |
9040 | { |
9041 | struct sk_buff *msg; | |
9042 | ||
58050fce | 9043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9044 | if (!msg) |
9045 | return; | |
9046 | ||
fd014284 | 9047 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9048 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9049 | nlmsg_free(msg); | |
9050 | return; | |
9051 | } | |
9052 | ||
463d0183 JB |
9053 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9054 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9055 | } |
9056 | ||
2a519311 | 9057 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9058 | struct wireless_dev *wdev) |
2a519311 JB |
9059 | { |
9060 | struct sk_buff *msg; | |
9061 | ||
fd2120ca | 9062 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9063 | if (!msg) |
9064 | return; | |
9065 | ||
fd014284 | 9066 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9067 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9068 | nlmsg_free(msg); |
9069 | return; | |
9070 | } | |
9071 | ||
463d0183 JB |
9072 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9073 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9074 | } |
9075 | ||
9076 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9077 | struct wireless_dev *wdev) |
2a519311 JB |
9078 | { |
9079 | struct sk_buff *msg; | |
9080 | ||
fd2120ca | 9081 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9082 | if (!msg) |
9083 | return; | |
9084 | ||
fd014284 | 9085 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9086 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9087 | nlmsg_free(msg); |
9088 | return; | |
9089 | } | |
9090 | ||
463d0183 JB |
9091 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9092 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9093 | } |
9094 | ||
807f8a8c LC |
9095 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9096 | struct net_device *netdev) | |
9097 | { | |
9098 | struct sk_buff *msg; | |
9099 | ||
9100 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9101 | if (!msg) | |
9102 | return; | |
9103 | ||
9104 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9105 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9106 | nlmsg_free(msg); | |
9107 | return; | |
9108 | } | |
9109 | ||
9110 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9111 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9112 | } | |
9113 | ||
9114 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9115 | struct net_device *netdev, u32 cmd) | |
9116 | { | |
9117 | struct sk_buff *msg; | |
9118 | ||
58050fce | 9119 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9120 | if (!msg) |
9121 | return; | |
9122 | ||
9123 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9124 | nlmsg_free(msg); | |
9125 | return; | |
9126 | } | |
9127 | ||
9128 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9129 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9130 | } | |
9131 | ||
73d54c9e LR |
9132 | /* |
9133 | * This can happen on global regulatory changes or device specific settings | |
9134 | * based on custom world regulatory domains. | |
9135 | */ | |
9136 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9137 | { | |
9138 | struct sk_buff *msg; | |
9139 | void *hdr; | |
9140 | ||
fd2120ca | 9141 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9142 | if (!msg) |
9143 | return; | |
9144 | ||
9145 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9146 | if (!hdr) { | |
9147 | nlmsg_free(msg); | |
9148 | return; | |
9149 | } | |
9150 | ||
9151 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9152 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9153 | goto nla_put_failure; | |
9154 | ||
9155 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9156 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9157 | NL80211_REGDOM_TYPE_WORLD)) | |
9158 | goto nla_put_failure; | |
9159 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9160 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9161 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9162 | goto nla_put_failure; | |
9163 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9164 | request->intersect) { | |
9165 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9166 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9167 | goto nla_put_failure; | |
9168 | } else { | |
9169 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9170 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9171 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9172 | request->alpha2)) | |
9173 | goto nla_put_failure; | |
9174 | } | |
9175 | ||
f4173766 | 9176 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9177 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9178 | goto nla_put_failure; | |
73d54c9e | 9179 | |
3b7b72ee | 9180 | genlmsg_end(msg, hdr); |
73d54c9e | 9181 | |
bc43b28c | 9182 | rcu_read_lock(); |
463d0183 | 9183 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9184 | GFP_ATOMIC); |
9185 | rcu_read_unlock(); | |
73d54c9e LR |
9186 | |
9187 | return; | |
9188 | ||
9189 | nla_put_failure: | |
9190 | genlmsg_cancel(msg, hdr); | |
9191 | nlmsg_free(msg); | |
9192 | } | |
9193 | ||
6039f6d2 JM |
9194 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9195 | struct net_device *netdev, | |
9196 | const u8 *buf, size_t len, | |
e6d6e342 | 9197 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9198 | { |
9199 | struct sk_buff *msg; | |
9200 | void *hdr; | |
9201 | ||
e6d6e342 | 9202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9203 | if (!msg) |
9204 | return; | |
9205 | ||
9206 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9207 | if (!hdr) { | |
9208 | nlmsg_free(msg); | |
9209 | return; | |
9210 | } | |
9211 | ||
9360ffd1 DM |
9212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9213 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9214 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9215 | goto nla_put_failure; | |
6039f6d2 | 9216 | |
3b7b72ee | 9217 | genlmsg_end(msg, hdr); |
6039f6d2 | 9218 | |
463d0183 JB |
9219 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9220 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9221 | return; |
9222 | ||
9223 | nla_put_failure: | |
9224 | genlmsg_cancel(msg, hdr); | |
9225 | nlmsg_free(msg); | |
9226 | } | |
9227 | ||
9228 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9229 | struct net_device *netdev, const u8 *buf, |
9230 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9231 | { |
9232 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9233 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9234 | } |
9235 | ||
9236 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9237 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9238 | size_t len, gfp_t gfp) |
6039f6d2 | 9239 | { |
e6d6e342 JB |
9240 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9241 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9242 | } |
9243 | ||
53b46b84 | 9244 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9245 | struct net_device *netdev, const u8 *buf, |
9246 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9247 | { |
9248 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9249 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9250 | } |
9251 | ||
53b46b84 JM |
9252 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9253 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9254 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9255 | { |
9256 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9257 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9258 | } |
9259 | ||
947add36 JB |
9260 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
9261 | size_t len) | |
cf4e594e | 9262 | { |
947add36 JB |
9263 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9264 | struct wiphy *wiphy = wdev->wiphy; | |
9265 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9266 | ||
9267 | trace_cfg80211_send_unprot_deauth(dev); | |
9268 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9269 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); | |
cf4e594e | 9270 | } |
947add36 | 9271 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
cf4e594e | 9272 | |
947add36 JB |
9273 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
9274 | size_t len) | |
cf4e594e | 9275 | { |
947add36 JB |
9276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9277 | struct wiphy *wiphy = wdev->wiphy; | |
9278 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9279 | ||
9280 | trace_cfg80211_send_unprot_disassoc(dev); | |
9281 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9282 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); | |
cf4e594e | 9283 | } |
947add36 | 9284 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
cf4e594e | 9285 | |
1b06bb40 LR |
9286 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9287 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9288 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9289 | { |
9290 | struct sk_buff *msg; | |
9291 | void *hdr; | |
9292 | ||
e6d6e342 | 9293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9294 | if (!msg) |
9295 | return; | |
9296 | ||
9297 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9298 | if (!hdr) { | |
9299 | nlmsg_free(msg); | |
9300 | return; | |
9301 | } | |
9302 | ||
9360ffd1 DM |
9303 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9304 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9305 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9306 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9307 | goto nla_put_failure; | |
1965c853 | 9308 | |
3b7b72ee | 9309 | genlmsg_end(msg, hdr); |
1965c853 | 9310 | |
463d0183 JB |
9311 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9312 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9313 | return; |
9314 | ||
9315 | nla_put_failure: | |
9316 | genlmsg_cancel(msg, hdr); | |
9317 | nlmsg_free(msg); | |
9318 | } | |
9319 | ||
9320 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9321 | struct net_device *netdev, const u8 *addr, |
9322 | gfp_t gfp) | |
1965c853 JM |
9323 | { |
9324 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9325 | addr, gfp); |
1965c853 JM |
9326 | } |
9327 | ||
9328 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9329 | struct net_device *netdev, const u8 *addr, |
9330 | gfp_t gfp) | |
1965c853 | 9331 | { |
e6d6e342 JB |
9332 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9333 | addr, gfp); | |
1965c853 JM |
9334 | } |
9335 | ||
b23aa676 SO |
9336 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9337 | struct net_device *netdev, const u8 *bssid, | |
9338 | const u8 *req_ie, size_t req_ie_len, | |
9339 | const u8 *resp_ie, size_t resp_ie_len, | |
9340 | u16 status, gfp_t gfp) | |
9341 | { | |
9342 | struct sk_buff *msg; | |
9343 | void *hdr; | |
9344 | ||
58050fce | 9345 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9346 | if (!msg) |
9347 | return; | |
9348 | ||
9349 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9350 | if (!hdr) { | |
9351 | nlmsg_free(msg); | |
9352 | return; | |
9353 | } | |
9354 | ||
9360ffd1 DM |
9355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9356 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9357 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9358 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9359 | (req_ie && | |
9360 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9361 | (resp_ie && | |
9362 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9363 | goto nla_put_failure; | |
b23aa676 | 9364 | |
3b7b72ee | 9365 | genlmsg_end(msg, hdr); |
b23aa676 | 9366 | |
463d0183 JB |
9367 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9368 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9369 | return; |
9370 | ||
9371 | nla_put_failure: | |
9372 | genlmsg_cancel(msg, hdr); | |
9373 | nlmsg_free(msg); | |
9374 | ||
9375 | } | |
9376 | ||
9377 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9378 | struct net_device *netdev, const u8 *bssid, | |
9379 | const u8 *req_ie, size_t req_ie_len, | |
9380 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9381 | { | |
9382 | struct sk_buff *msg; | |
9383 | void *hdr; | |
9384 | ||
58050fce | 9385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9386 | if (!msg) |
9387 | return; | |
9388 | ||
9389 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9390 | if (!hdr) { | |
9391 | nlmsg_free(msg); | |
9392 | return; | |
9393 | } | |
9394 | ||
9360ffd1 DM |
9395 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9396 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9397 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9398 | (req_ie && | |
9399 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9400 | (resp_ie && | |
9401 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9402 | goto nla_put_failure; | |
b23aa676 | 9403 | |
3b7b72ee | 9404 | genlmsg_end(msg, hdr); |
b23aa676 | 9405 | |
463d0183 JB |
9406 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9407 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9408 | return; |
9409 | ||
9410 | nla_put_failure: | |
9411 | genlmsg_cancel(msg, hdr); | |
9412 | nlmsg_free(msg); | |
9413 | ||
9414 | } | |
9415 | ||
9416 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9417 | struct net_device *netdev, u16 reason, | |
667503dd | 9418 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9419 | { |
9420 | struct sk_buff *msg; | |
9421 | void *hdr; | |
9422 | ||
58050fce | 9423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9424 | if (!msg) |
9425 | return; | |
9426 | ||
9427 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9428 | if (!hdr) { | |
9429 | nlmsg_free(msg); | |
9430 | return; | |
9431 | } | |
9432 | ||
9360ffd1 DM |
9433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9434 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9435 | (from_ap && reason && | |
9436 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9437 | (from_ap && | |
9438 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9439 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9440 | goto nla_put_failure; | |
b23aa676 | 9441 | |
3b7b72ee | 9442 | genlmsg_end(msg, hdr); |
b23aa676 | 9443 | |
463d0183 JB |
9444 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9445 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9446 | return; |
9447 | ||
9448 | nla_put_failure: | |
9449 | genlmsg_cancel(msg, hdr); | |
9450 | nlmsg_free(msg); | |
9451 | ||
9452 | } | |
9453 | ||
04a773ad JB |
9454 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9455 | struct net_device *netdev, const u8 *bssid, | |
9456 | gfp_t gfp) | |
9457 | { | |
9458 | struct sk_buff *msg; | |
9459 | void *hdr; | |
9460 | ||
fd2120ca | 9461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9462 | if (!msg) |
9463 | return; | |
9464 | ||
9465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9466 | if (!hdr) { | |
9467 | nlmsg_free(msg); | |
9468 | return; | |
9469 | } | |
9470 | ||
9360ffd1 DM |
9471 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9472 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9473 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9474 | goto nla_put_failure; | |
04a773ad | 9475 | |
3b7b72ee | 9476 | genlmsg_end(msg, hdr); |
04a773ad | 9477 | |
463d0183 JB |
9478 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9479 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9480 | return; |
9481 | ||
9482 | nla_put_failure: | |
9483 | genlmsg_cancel(msg, hdr); | |
9484 | nlmsg_free(msg); | |
9485 | } | |
9486 | ||
947add36 JB |
9487 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9488 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9489 | { |
947add36 JB |
9490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9491 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9492 | struct sk_buff *msg; |
9493 | void *hdr; | |
9494 | ||
947add36 JB |
9495 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9496 | return; | |
9497 | ||
9498 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9499 | ||
c93b5e71 JC |
9500 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9501 | if (!msg) | |
9502 | return; | |
9503 | ||
9504 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9505 | if (!hdr) { | |
9506 | nlmsg_free(msg); | |
9507 | return; | |
9508 | } | |
9509 | ||
9360ffd1 | 9510 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9511 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9512 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9513 | (ie_len && ie && |
9514 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9515 | goto nla_put_failure; | |
c93b5e71 | 9516 | |
3b7b72ee | 9517 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9518 | |
9519 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9520 | nl80211_mlme_mcgrp.id, gfp); | |
9521 | return; | |
9522 | ||
9523 | nla_put_failure: | |
9524 | genlmsg_cancel(msg, hdr); | |
9525 | nlmsg_free(msg); | |
9526 | } | |
947add36 | 9527 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9528 | |
a3b8b056 JM |
9529 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9530 | struct net_device *netdev, const u8 *addr, | |
9531 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9532 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9533 | { |
9534 | struct sk_buff *msg; | |
9535 | void *hdr; | |
9536 | ||
e6d6e342 | 9537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9538 | if (!msg) |
9539 | return; | |
9540 | ||
9541 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9542 | if (!hdr) { | |
9543 | nlmsg_free(msg); | |
9544 | return; | |
9545 | } | |
9546 | ||
9360ffd1 DM |
9547 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9548 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9549 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9550 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9551 | (key_id != -1 && | |
9552 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9553 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9554 | goto nla_put_failure; | |
a3b8b056 | 9555 | |
3b7b72ee | 9556 | genlmsg_end(msg, hdr); |
a3b8b056 | 9557 | |
463d0183 JB |
9558 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9559 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9560 | return; |
9561 | ||
9562 | nla_put_failure: | |
9563 | genlmsg_cancel(msg, hdr); | |
9564 | nlmsg_free(msg); | |
9565 | } | |
9566 | ||
6bad8766 LR |
9567 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9568 | struct ieee80211_channel *channel_before, | |
9569 | struct ieee80211_channel *channel_after) | |
9570 | { | |
9571 | struct sk_buff *msg; | |
9572 | void *hdr; | |
9573 | struct nlattr *nl_freq; | |
9574 | ||
fd2120ca | 9575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9576 | if (!msg) |
9577 | return; | |
9578 | ||
9579 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9580 | if (!hdr) { | |
9581 | nlmsg_free(msg); | |
9582 | return; | |
9583 | } | |
9584 | ||
9585 | /* | |
9586 | * Since we are applying the beacon hint to a wiphy we know its | |
9587 | * wiphy_idx is valid | |
9588 | */ | |
9360ffd1 DM |
9589 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9590 | goto nla_put_failure; | |
6bad8766 LR |
9591 | |
9592 | /* Before */ | |
9593 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9594 | if (!nl_freq) | |
9595 | goto nla_put_failure; | |
cdc89b97 | 9596 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
9597 | goto nla_put_failure; |
9598 | nla_nest_end(msg, nl_freq); | |
9599 | ||
9600 | /* After */ | |
9601 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9602 | if (!nl_freq) | |
9603 | goto nla_put_failure; | |
cdc89b97 | 9604 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
9605 | goto nla_put_failure; |
9606 | nla_nest_end(msg, nl_freq); | |
9607 | ||
3b7b72ee | 9608 | genlmsg_end(msg, hdr); |
6bad8766 | 9609 | |
463d0183 JB |
9610 | rcu_read_lock(); |
9611 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9612 | GFP_ATOMIC); | |
9613 | rcu_read_unlock(); | |
6bad8766 LR |
9614 | |
9615 | return; | |
9616 | ||
9617 | nla_put_failure: | |
9618 | genlmsg_cancel(msg, hdr); | |
9619 | nlmsg_free(msg); | |
9620 | } | |
9621 | ||
9588bbd5 JM |
9622 | static void nl80211_send_remain_on_chan_event( |
9623 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9624 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9625 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9626 | unsigned int duration, gfp_t gfp) |
9627 | { | |
9628 | struct sk_buff *msg; | |
9629 | void *hdr; | |
9630 | ||
9631 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9632 | if (!msg) | |
9633 | return; | |
9634 | ||
9635 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9636 | if (!hdr) { | |
9637 | nlmsg_free(msg); | |
9638 | return; | |
9639 | } | |
9640 | ||
9360ffd1 | 9641 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9642 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9643 | wdev->netdev->ifindex)) || | |
00f53350 | 9644 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9645 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9646 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9647 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9648 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9649 | goto nla_put_failure; | |
9588bbd5 | 9650 | |
9360ffd1 DM |
9651 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9652 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9653 | goto nla_put_failure; | |
9588bbd5 | 9654 | |
3b7b72ee | 9655 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9656 | |
9657 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9658 | nl80211_mlme_mcgrp.id, gfp); | |
9659 | return; | |
9660 | ||
9661 | nla_put_failure: | |
9662 | genlmsg_cancel(msg, hdr); | |
9663 | nlmsg_free(msg); | |
9664 | } | |
9665 | ||
947add36 JB |
9666 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
9667 | struct ieee80211_channel *chan, | |
9668 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 9669 | { |
947add36 JB |
9670 | struct wiphy *wiphy = wdev->wiphy; |
9671 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9672 | ||
9673 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 9674 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 9675 | rdev, wdev, cookie, chan, |
42d97a59 | 9676 | duration, gfp); |
9588bbd5 | 9677 | } |
947add36 | 9678 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 9679 | |
947add36 JB |
9680 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
9681 | struct ieee80211_channel *chan, | |
9682 | gfp_t gfp) | |
9588bbd5 | 9683 | { |
947add36 JB |
9684 | struct wiphy *wiphy = wdev->wiphy; |
9685 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9686 | ||
9687 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 9688 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 9689 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 9690 | } |
947add36 | 9691 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 9692 | |
947add36 JB |
9693 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
9694 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 9695 | { |
947add36 JB |
9696 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9697 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
9698 | struct sk_buff *msg; |
9699 | ||
947add36 JB |
9700 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
9701 | ||
58050fce | 9702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9703 | if (!msg) |
9704 | return; | |
9705 | ||
66266b3a JL |
9706 | if (nl80211_send_station(msg, 0, 0, 0, |
9707 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9708 | nlmsg_free(msg); |
9709 | return; | |
9710 | } | |
9711 | ||
9712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9713 | nl80211_mlme_mcgrp.id, gfp); | |
9714 | } | |
947add36 | 9715 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 9716 | |
947add36 | 9717 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 9718 | { |
947add36 JB |
9719 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9720 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
9721 | struct sk_buff *msg; |
9722 | void *hdr; | |
9723 | ||
947add36 JB |
9724 | trace_cfg80211_del_sta(dev, mac_addr); |
9725 | ||
58050fce | 9726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9727 | if (!msg) |
9728 | return; | |
9729 | ||
9730 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
9731 | if (!hdr) { | |
9732 | nlmsg_free(msg); | |
9733 | return; | |
9734 | } | |
9735 | ||
9360ffd1 DM |
9736 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9737 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
9738 | goto nla_put_failure; | |
ec15e68b | 9739 | |
3b7b72ee | 9740 | genlmsg_end(msg, hdr); |
ec15e68b JM |
9741 | |
9742 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9743 | nl80211_mlme_mcgrp.id, gfp); | |
9744 | return; | |
9745 | ||
9746 | nla_put_failure: | |
9747 | genlmsg_cancel(msg, hdr); | |
9748 | nlmsg_free(msg); | |
9749 | } | |
947add36 | 9750 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 9751 | |
947add36 JB |
9752 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
9753 | enum nl80211_connect_failed_reason reason, | |
9754 | gfp_t gfp) | |
ed44a951 | 9755 | { |
947add36 JB |
9756 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9757 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
9758 | struct sk_buff *msg; |
9759 | void *hdr; | |
9760 | ||
9761 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9762 | if (!msg) | |
9763 | return; | |
9764 | ||
9765 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
9766 | if (!hdr) { | |
9767 | nlmsg_free(msg); | |
9768 | return; | |
9769 | } | |
9770 | ||
9771 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9772 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
9773 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
9774 | goto nla_put_failure; | |
9775 | ||
9776 | genlmsg_end(msg, hdr); | |
9777 | ||
9778 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9779 | nl80211_mlme_mcgrp.id, gfp); | |
9780 | return; | |
9781 | ||
9782 | nla_put_failure: | |
9783 | genlmsg_cancel(msg, hdr); | |
9784 | nlmsg_free(msg); | |
9785 | } | |
947add36 | 9786 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 9787 | |
b92ab5d8 JB |
9788 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
9789 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
9790 | { |
9791 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9792 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9793 | struct sk_buff *msg; | |
9794 | void *hdr; | |
9795 | int err; | |
15e47304 | 9796 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 9797 | |
15e47304 | 9798 | if (!nlportid) |
28946da7 JB |
9799 | return false; |
9800 | ||
9801 | msg = nlmsg_new(100, gfp); | |
9802 | if (!msg) | |
9803 | return true; | |
9804 | ||
b92ab5d8 | 9805 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
9806 | if (!hdr) { |
9807 | nlmsg_free(msg); | |
9808 | return true; | |
9809 | } | |
9810 | ||
9360ffd1 DM |
9811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9812 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9814 | goto nla_put_failure; | |
28946da7 JB |
9815 | |
9816 | err = genlmsg_end(msg, hdr); | |
9817 | if (err < 0) { | |
9818 | nlmsg_free(msg); | |
9819 | return true; | |
9820 | } | |
9821 | ||
15e47304 | 9822 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
9823 | return true; |
9824 | ||
9825 | nla_put_failure: | |
9826 | genlmsg_cancel(msg, hdr); | |
9827 | nlmsg_free(msg); | |
9828 | return true; | |
9829 | } | |
9830 | ||
947add36 JB |
9831 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
9832 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9833 | { |
947add36 JB |
9834 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9835 | bool ret; | |
9836 | ||
9837 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
9838 | ||
9839 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9840 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
9841 | trace_cfg80211_return_bool(false); | |
9842 | return false; | |
9843 | } | |
9844 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
9845 | addr, gfp); | |
9846 | trace_cfg80211_return_bool(ret); | |
9847 | return ret; | |
b92ab5d8 | 9848 | } |
947add36 | 9849 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 9850 | |
947add36 JB |
9851 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
9852 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9853 | { |
947add36 JB |
9854 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9855 | bool ret; | |
9856 | ||
9857 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
9858 | ||
9859 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9860 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
9861 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
9862 | trace_cfg80211_return_bool(false); | |
9863 | return false; | |
9864 | } | |
9865 | ret = __nl80211_unexpected_frame(dev, | |
9866 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
9867 | addr, gfp); | |
9868 | trace_cfg80211_return_bool(ret); | |
9869 | return ret; | |
b92ab5d8 | 9870 | } |
947add36 | 9871 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 9872 | |
2e161f78 | 9873 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 9874 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
9875 | int freq, int sig_dbm, |
9876 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 9877 | { |
71bbc994 | 9878 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9879 | struct sk_buff *msg; |
9880 | void *hdr; | |
026331c4 JM |
9881 | |
9882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9883 | if (!msg) | |
9884 | return -ENOMEM; | |
9885 | ||
2e161f78 | 9886 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
9887 | if (!hdr) { |
9888 | nlmsg_free(msg); | |
9889 | return -ENOMEM; | |
9890 | } | |
9891 | ||
9360ffd1 | 9892 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9893 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9894 | netdev->ifindex)) || | |
9360ffd1 DM |
9895 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
9896 | (sig_dbm && | |
9897 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9898 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9899 | goto nla_put_failure; | |
026331c4 | 9900 | |
3b7b72ee | 9901 | genlmsg_end(msg, hdr); |
026331c4 | 9902 | |
15e47304 | 9903 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
9904 | |
9905 | nla_put_failure: | |
9906 | genlmsg_cancel(msg, hdr); | |
9907 | nlmsg_free(msg); | |
9908 | return -ENOBUFS; | |
9909 | } | |
9910 | ||
947add36 JB |
9911 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
9912 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 9913 | { |
947add36 JB |
9914 | struct wiphy *wiphy = wdev->wiphy; |
9915 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 9916 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9917 | struct sk_buff *msg; |
9918 | void *hdr; | |
9919 | ||
947add36 JB |
9920 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
9921 | ||
026331c4 JM |
9922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9923 | if (!msg) | |
9924 | return; | |
9925 | ||
2e161f78 | 9926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
9927 | if (!hdr) { |
9928 | nlmsg_free(msg); | |
9929 | return; | |
9930 | } | |
9931 | ||
9360ffd1 | 9932 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9933 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9934 | netdev->ifindex)) || | |
9360ffd1 DM |
9935 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
9936 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
9937 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
9938 | goto nla_put_failure; | |
026331c4 | 9939 | |
3b7b72ee | 9940 | genlmsg_end(msg, hdr); |
026331c4 JM |
9941 | |
9942 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
9943 | return; | |
9944 | ||
9945 | nla_put_failure: | |
9946 | genlmsg_cancel(msg, hdr); | |
9947 | nlmsg_free(msg); | |
9948 | } | |
947add36 | 9949 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 9950 | |
947add36 JB |
9951 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
9952 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
9953 | gfp_t gfp) | |
d6dc1a38 | 9954 | { |
947add36 JB |
9955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9956 | struct wiphy *wiphy = wdev->wiphy; | |
9957 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
9958 | struct sk_buff *msg; |
9959 | struct nlattr *pinfoattr; | |
9960 | void *hdr; | |
9961 | ||
947add36 JB |
9962 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
9963 | ||
58050fce | 9964 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
9965 | if (!msg) |
9966 | return; | |
9967 | ||
9968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9969 | if (!hdr) { | |
9970 | nlmsg_free(msg); | |
9971 | return; | |
9972 | } | |
9973 | ||
9360ffd1 | 9974 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 9975 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 9976 | goto nla_put_failure; |
d6dc1a38 JO |
9977 | |
9978 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
9979 | if (!pinfoattr) | |
9980 | goto nla_put_failure; | |
9981 | ||
9360ffd1 DM |
9982 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
9983 | rssi_event)) | |
9984 | goto nla_put_failure; | |
d6dc1a38 JO |
9985 | |
9986 | nla_nest_end(msg, pinfoattr); | |
9987 | ||
3b7b72ee | 9988 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
9989 | |
9990 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9991 | nl80211_mlme_mcgrp.id, gfp); | |
9992 | return; | |
9993 | ||
9994 | nla_put_failure: | |
9995 | genlmsg_cancel(msg, hdr); | |
9996 | nlmsg_free(msg); | |
9997 | } | |
947add36 | 9998 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 9999 | |
947add36 JB |
10000 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10001 | struct net_device *netdev, const u8 *bssid, | |
10002 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10003 | { |
10004 | struct sk_buff *msg; | |
10005 | struct nlattr *rekey_attr; | |
10006 | void *hdr; | |
10007 | ||
58050fce | 10008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10009 | if (!msg) |
10010 | return; | |
10011 | ||
10012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10013 | if (!hdr) { | |
10014 | nlmsg_free(msg); | |
10015 | return; | |
10016 | } | |
10017 | ||
9360ffd1 DM |
10018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10019 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10020 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10021 | goto nla_put_failure; | |
e5497d76 JB |
10022 | |
10023 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10024 | if (!rekey_attr) | |
10025 | goto nla_put_failure; | |
10026 | ||
9360ffd1 DM |
10027 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10028 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10029 | goto nla_put_failure; | |
e5497d76 JB |
10030 | |
10031 | nla_nest_end(msg, rekey_attr); | |
10032 | ||
3b7b72ee | 10033 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10034 | |
10035 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10036 | nl80211_mlme_mcgrp.id, gfp); | |
10037 | return; | |
10038 | ||
10039 | nla_put_failure: | |
10040 | genlmsg_cancel(msg, hdr); | |
10041 | nlmsg_free(msg); | |
10042 | } | |
10043 | ||
947add36 JB |
10044 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10045 | const u8 *replay_ctr, gfp_t gfp) | |
10046 | { | |
10047 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10048 | struct wiphy *wiphy = wdev->wiphy; | |
10049 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10050 | ||
10051 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10052 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10053 | } | |
10054 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10055 | ||
10056 | static void | |
10057 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10058 | struct net_device *netdev, int index, | |
10059 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10060 | { |
10061 | struct sk_buff *msg; | |
10062 | struct nlattr *attr; | |
10063 | void *hdr; | |
10064 | ||
58050fce | 10065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10066 | if (!msg) |
10067 | return; | |
10068 | ||
10069 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10070 | if (!hdr) { | |
10071 | nlmsg_free(msg); | |
10072 | return; | |
10073 | } | |
10074 | ||
9360ffd1 DM |
10075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10076 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10077 | goto nla_put_failure; | |
c9df56b4 JM |
10078 | |
10079 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10080 | if (!attr) | |
10081 | goto nla_put_failure; | |
10082 | ||
9360ffd1 DM |
10083 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10084 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10085 | (preauth && | |
10086 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10087 | goto nla_put_failure; | |
c9df56b4 JM |
10088 | |
10089 | nla_nest_end(msg, attr); | |
10090 | ||
3b7b72ee | 10091 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10092 | |
10093 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10094 | nl80211_mlme_mcgrp.id, gfp); | |
10095 | return; | |
10096 | ||
10097 | nla_put_failure: | |
10098 | genlmsg_cancel(msg, hdr); | |
10099 | nlmsg_free(msg); | |
10100 | } | |
10101 | ||
947add36 JB |
10102 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10103 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10104 | { | |
10105 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10106 | struct wiphy *wiphy = wdev->wiphy; | |
10107 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10108 | ||
10109 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10110 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10111 | } | |
10112 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10113 | ||
10114 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10115 | struct net_device *netdev, | |
10116 | struct cfg80211_chan_def *chandef, | |
10117 | gfp_t gfp) | |
5314526b TP |
10118 | { |
10119 | struct sk_buff *msg; | |
10120 | void *hdr; | |
10121 | ||
58050fce | 10122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10123 | if (!msg) |
10124 | return; | |
10125 | ||
10126 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10127 | if (!hdr) { | |
10128 | nlmsg_free(msg); | |
10129 | return; | |
10130 | } | |
10131 | ||
683b6d3b JB |
10132 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10133 | goto nla_put_failure; | |
10134 | ||
10135 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10136 | goto nla_put_failure; |
5314526b TP |
10137 | |
10138 | genlmsg_end(msg, hdr); | |
10139 | ||
10140 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10141 | nl80211_mlme_mcgrp.id, gfp); | |
10142 | return; | |
10143 | ||
10144 | nla_put_failure: | |
10145 | genlmsg_cancel(msg, hdr); | |
10146 | nlmsg_free(msg); | |
10147 | } | |
10148 | ||
947add36 JB |
10149 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10150 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10151 | { |
947add36 JB |
10152 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10153 | struct wiphy *wiphy = wdev->wiphy; | |
10154 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10155 | ||
10156 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10157 | ||
10158 | wdev_lock(wdev); | |
10159 | ||
10160 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10161 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10162 | goto out; | |
10163 | ||
10164 | wdev->channel = chandef->chan; | |
10165 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10166 | out: | |
10167 | wdev_unlock(wdev); | |
10168 | return; | |
10169 | } | |
10170 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10171 | ||
10172 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10173 | const u8 *peer, u32 num_packets, | |
10174 | u32 rate, u32 intvl, gfp_t gfp) | |
10175 | { | |
10176 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10177 | struct wiphy *wiphy = wdev->wiphy; | |
10178 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10179 | struct sk_buff *msg; |
10180 | struct nlattr *pinfoattr; | |
10181 | void *hdr; | |
10182 | ||
10183 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10184 | if (!msg) | |
10185 | return; | |
10186 | ||
10187 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10188 | if (!hdr) { | |
10189 | nlmsg_free(msg); | |
10190 | return; | |
10191 | } | |
10192 | ||
10193 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10194 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10195 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10196 | goto nla_put_failure; | |
10197 | ||
10198 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10199 | if (!pinfoattr) | |
10200 | goto nla_put_failure; | |
10201 | ||
10202 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10203 | goto nla_put_failure; | |
10204 | ||
10205 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10206 | goto nla_put_failure; | |
10207 | ||
10208 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10209 | goto nla_put_failure; | |
10210 | ||
10211 | nla_nest_end(msg, pinfoattr); | |
10212 | ||
10213 | genlmsg_end(msg, hdr); | |
10214 | ||
10215 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10216 | nl80211_mlme_mcgrp.id, gfp); | |
10217 | return; | |
10218 | ||
10219 | nla_put_failure: | |
10220 | genlmsg_cancel(msg, hdr); | |
10221 | nlmsg_free(msg); | |
10222 | } | |
947add36 | 10223 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10224 | |
04f39047 SW |
10225 | void |
10226 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10227 | struct cfg80211_chan_def *chandef, | |
10228 | enum nl80211_radar_event event, | |
10229 | struct net_device *netdev, gfp_t gfp) | |
10230 | { | |
10231 | struct sk_buff *msg; | |
10232 | void *hdr; | |
10233 | ||
10234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10235 | if (!msg) | |
10236 | return; | |
10237 | ||
10238 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10239 | if (!hdr) { | |
10240 | nlmsg_free(msg); | |
10241 | return; | |
10242 | } | |
10243 | ||
10244 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10245 | goto nla_put_failure; | |
10246 | ||
10247 | /* NOP and radar events don't need a netdev parameter */ | |
10248 | if (netdev) { | |
10249 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10250 | ||
10251 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10252 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10253 | goto nla_put_failure; | |
10254 | } | |
10255 | ||
10256 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10257 | goto nla_put_failure; | |
10258 | ||
10259 | if (nl80211_send_chandef(msg, chandef)) | |
10260 | goto nla_put_failure; | |
10261 | ||
10262 | if (genlmsg_end(msg, hdr) < 0) { | |
10263 | nlmsg_free(msg); | |
10264 | return; | |
10265 | } | |
10266 | ||
10267 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10268 | nl80211_mlme_mcgrp.id, gfp); | |
10269 | return; | |
10270 | ||
10271 | nla_put_failure: | |
10272 | genlmsg_cancel(msg, hdr); | |
10273 | nlmsg_free(msg); | |
10274 | } | |
10275 | ||
947add36 JB |
10276 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10277 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10278 | { |
947add36 JB |
10279 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10280 | struct wiphy *wiphy = wdev->wiphy; | |
10281 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10282 | struct sk_buff *msg; |
10283 | struct nlattr *pinfoattr; | |
10284 | void *hdr; | |
10285 | ||
947add36 JB |
10286 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10287 | ||
58050fce | 10288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10289 | if (!msg) |
10290 | return; | |
10291 | ||
10292 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10293 | if (!hdr) { | |
10294 | nlmsg_free(msg); | |
10295 | return; | |
10296 | } | |
10297 | ||
9360ffd1 | 10298 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10299 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10300 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10301 | goto nla_put_failure; | |
c063dbf5 JB |
10302 | |
10303 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10304 | if (!pinfoattr) | |
10305 | goto nla_put_failure; | |
10306 | ||
9360ffd1 DM |
10307 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10308 | goto nla_put_failure; | |
c063dbf5 JB |
10309 | |
10310 | nla_nest_end(msg, pinfoattr); | |
10311 | ||
3b7b72ee | 10312 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10313 | |
10314 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10315 | nl80211_mlme_mcgrp.id, gfp); | |
10316 | return; | |
10317 | ||
10318 | nla_put_failure: | |
10319 | genlmsg_cancel(msg, hdr); | |
10320 | nlmsg_free(msg); | |
10321 | } | |
947add36 | 10322 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10323 | |
7f6cf311 JB |
10324 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10325 | u64 cookie, bool acked, gfp_t gfp) | |
10326 | { | |
10327 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10328 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10329 | struct sk_buff *msg; | |
10330 | void *hdr; | |
10331 | int err; | |
10332 | ||
4ee3e063 BL |
10333 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10334 | ||
58050fce | 10335 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10336 | |
7f6cf311 JB |
10337 | if (!msg) |
10338 | return; | |
10339 | ||
10340 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10341 | if (!hdr) { | |
10342 | nlmsg_free(msg); | |
10343 | return; | |
10344 | } | |
10345 | ||
9360ffd1 DM |
10346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10347 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10348 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10349 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10350 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10351 | goto nla_put_failure; | |
7f6cf311 JB |
10352 | |
10353 | err = genlmsg_end(msg, hdr); | |
10354 | if (err < 0) { | |
10355 | nlmsg_free(msg); | |
10356 | return; | |
10357 | } | |
10358 | ||
10359 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10360 | nl80211_mlme_mcgrp.id, gfp); | |
10361 | return; | |
10362 | ||
10363 | nla_put_failure: | |
10364 | genlmsg_cancel(msg, hdr); | |
10365 | nlmsg_free(msg); | |
10366 | } | |
10367 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10368 | ||
5e760230 JB |
10369 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10370 | const u8 *frame, size_t len, | |
37c73b5f | 10371 | int freq, int sig_dbm) |
5e760230 JB |
10372 | { |
10373 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10374 | struct sk_buff *msg; | |
10375 | void *hdr; | |
37c73b5f | 10376 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10377 | |
4ee3e063 BL |
10378 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10379 | ||
37c73b5f BG |
10380 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10381 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10382 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10383 | if (!msg) { | |
10384 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10385 | return; | |
10386 | } | |
5e760230 | 10387 | |
37c73b5f BG |
10388 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10389 | if (!hdr) | |
10390 | goto nla_put_failure; | |
5e760230 | 10391 | |
37c73b5f BG |
10392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10393 | (freq && | |
10394 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10395 | (sig_dbm && | |
10396 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10397 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10398 | goto nla_put_failure; | |
5e760230 | 10399 | |
37c73b5f | 10400 | genlmsg_end(msg, hdr); |
5e760230 | 10401 | |
37c73b5f BG |
10402 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10403 | } | |
10404 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10405 | return; |
10406 | ||
10407 | nla_put_failure: | |
37c73b5f BG |
10408 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10409 | if (hdr) | |
10410 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10411 | nlmsg_free(msg); |
10412 | } | |
10413 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10414 | ||
cd8f7cb4 JB |
10415 | #ifdef CONFIG_PM |
10416 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10417 | struct cfg80211_wowlan_wakeup *wakeup, | |
10418 | gfp_t gfp) | |
10419 | { | |
10420 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10421 | struct sk_buff *msg; | |
10422 | void *hdr; | |
10423 | int err, size = 200; | |
10424 | ||
10425 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10426 | ||
10427 | if (wakeup) | |
10428 | size += wakeup->packet_present_len; | |
10429 | ||
10430 | msg = nlmsg_new(size, gfp); | |
10431 | if (!msg) | |
10432 | return; | |
10433 | ||
10434 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10435 | if (!hdr) | |
10436 | goto free_msg; | |
10437 | ||
10438 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10439 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10440 | goto free_msg; | |
10441 | ||
10442 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10443 | wdev->netdev->ifindex)) | |
10444 | goto free_msg; | |
10445 | ||
10446 | if (wakeup) { | |
10447 | struct nlattr *reasons; | |
10448 | ||
10449 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10450 | ||
10451 | if (wakeup->disconnect && | |
10452 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10453 | goto free_msg; | |
10454 | if (wakeup->magic_pkt && | |
10455 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10456 | goto free_msg; | |
10457 | if (wakeup->gtk_rekey_failure && | |
10458 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10459 | goto free_msg; | |
10460 | if (wakeup->eap_identity_req && | |
10461 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10462 | goto free_msg; | |
10463 | if (wakeup->four_way_handshake && | |
10464 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10465 | goto free_msg; | |
10466 | if (wakeup->rfkill_release && | |
10467 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10468 | goto free_msg; | |
10469 | ||
10470 | if (wakeup->pattern_idx >= 0 && | |
10471 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10472 | wakeup->pattern_idx)) | |
10473 | goto free_msg; | |
10474 | ||
2a0e047e JB |
10475 | if (wakeup->tcp_match) |
10476 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10477 | ||
10478 | if (wakeup->tcp_connlost) | |
10479 | nla_put_flag(msg, | |
10480 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10481 | ||
10482 | if (wakeup->tcp_nomoretokens) | |
10483 | nla_put_flag(msg, | |
10484 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10485 | ||
cd8f7cb4 JB |
10486 | if (wakeup->packet) { |
10487 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10488 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10489 | ||
10490 | if (!wakeup->packet_80211) { | |
10491 | pkt_attr = | |
10492 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10493 | len_attr = | |
10494 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10495 | } | |
10496 | ||
10497 | if (wakeup->packet_len && | |
10498 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10499 | goto free_msg; | |
10500 | ||
10501 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10502 | wakeup->packet)) | |
10503 | goto free_msg; | |
10504 | } | |
10505 | ||
10506 | nla_nest_end(msg, reasons); | |
10507 | } | |
10508 | ||
10509 | err = genlmsg_end(msg, hdr); | |
10510 | if (err < 0) | |
10511 | goto free_msg; | |
10512 | ||
10513 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10514 | nl80211_mlme_mcgrp.id, gfp); | |
10515 | return; | |
10516 | ||
10517 | free_msg: | |
10518 | nlmsg_free(msg); | |
10519 | } | |
10520 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10521 | #endif | |
10522 | ||
3475b094 JM |
10523 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10524 | enum nl80211_tdls_operation oper, | |
10525 | u16 reason_code, gfp_t gfp) | |
10526 | { | |
10527 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10528 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10529 | struct sk_buff *msg; | |
10530 | void *hdr; | |
10531 | int err; | |
10532 | ||
10533 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10534 | reason_code); | |
10535 | ||
10536 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10537 | if (!msg) | |
10538 | return; | |
10539 | ||
10540 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10541 | if (!hdr) { | |
10542 | nlmsg_free(msg); | |
10543 | return; | |
10544 | } | |
10545 | ||
10546 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10547 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10548 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10549 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10550 | (reason_code > 0 && | |
10551 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10552 | goto nla_put_failure; | |
10553 | ||
10554 | err = genlmsg_end(msg, hdr); | |
10555 | if (err < 0) { | |
10556 | nlmsg_free(msg); | |
10557 | return; | |
10558 | } | |
10559 | ||
10560 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10561 | nl80211_mlme_mcgrp.id, gfp); | |
10562 | return; | |
10563 | ||
10564 | nla_put_failure: | |
10565 | genlmsg_cancel(msg, hdr); | |
10566 | nlmsg_free(msg); | |
10567 | } | |
10568 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10569 | ||
026331c4 JM |
10570 | static int nl80211_netlink_notify(struct notifier_block * nb, |
10571 | unsigned long state, | |
10572 | void *_notify) | |
10573 | { | |
10574 | struct netlink_notify *notify = _notify; | |
10575 | struct cfg80211_registered_device *rdev; | |
10576 | struct wireless_dev *wdev; | |
37c73b5f | 10577 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
10578 | |
10579 | if (state != NETLINK_URELEASE) | |
10580 | return NOTIFY_DONE; | |
10581 | ||
10582 | rcu_read_lock(); | |
10583 | ||
5e760230 | 10584 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 10585 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 10586 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
10587 | |
10588 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10589 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
10590 | list) { | |
10591 | if (reg->nlportid == notify->portid) { | |
10592 | list_del(®->list); | |
10593 | kfree(reg); | |
10594 | break; | |
10595 | } | |
10596 | } | |
10597 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 10598 | } |
026331c4 JM |
10599 | |
10600 | rcu_read_unlock(); | |
10601 | ||
10602 | return NOTIFY_DONE; | |
10603 | } | |
10604 | ||
10605 | static struct notifier_block nl80211_netlink_notifier = { | |
10606 | .notifier_call = nl80211_netlink_notify, | |
10607 | }; | |
10608 | ||
355199e0 JM |
10609 | void cfg80211_ft_event(struct net_device *netdev, |
10610 | struct cfg80211_ft_event_params *ft_event) | |
10611 | { | |
10612 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
10613 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10614 | struct sk_buff *msg; | |
10615 | void *hdr; | |
10616 | int err; | |
10617 | ||
10618 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
10619 | ||
10620 | if (!ft_event->target_ap) | |
10621 | return; | |
10622 | ||
10623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10624 | if (!msg) | |
10625 | return; | |
10626 | ||
10627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
10628 | if (!hdr) { | |
10629 | nlmsg_free(msg); | |
10630 | return; | |
10631 | } | |
10632 | ||
10633 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
10634 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
10635 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
10636 | if (ft_event->ies) | |
10637 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
10638 | if (ft_event->ric_ies) | |
10639 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
10640 | ft_event->ric_ies); | |
10641 | ||
10642 | err = genlmsg_end(msg, hdr); | |
10643 | if (err < 0) { | |
10644 | nlmsg_free(msg); | |
10645 | return; | |
10646 | } | |
10647 | ||
10648 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10649 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
10650 | } | |
10651 | EXPORT_SYMBOL(cfg80211_ft_event); | |
10652 | ||
55682965 JB |
10653 | /* initialisation/exit functions */ |
10654 | ||
10655 | int nl80211_init(void) | |
10656 | { | |
0d63cbb5 | 10657 | int err; |
55682965 | 10658 | |
0d63cbb5 MM |
10659 | err = genl_register_family_with_ops(&nl80211_fam, |
10660 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10661 | if (err) |
10662 | return err; | |
10663 | ||
55682965 JB |
10664 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10665 | if (err) | |
10666 | goto err_out; | |
10667 | ||
2a519311 JB |
10668 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10669 | if (err) | |
10670 | goto err_out; | |
10671 | ||
73d54c9e LR |
10672 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10673 | if (err) | |
10674 | goto err_out; | |
10675 | ||
6039f6d2 JM |
10676 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10677 | if (err) | |
10678 | goto err_out; | |
10679 | ||
aff89a9b JB |
10680 | #ifdef CONFIG_NL80211_TESTMODE |
10681 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10682 | if (err) | |
10683 | goto err_out; | |
10684 | #endif | |
10685 | ||
026331c4 JM |
10686 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
10687 | if (err) | |
10688 | goto err_out; | |
10689 | ||
55682965 JB |
10690 | return 0; |
10691 | err_out: | |
10692 | genl_unregister_family(&nl80211_fam); | |
10693 | return err; | |
10694 | } | |
10695 | ||
10696 | void nl80211_exit(void) | |
10697 | { | |
026331c4 | 10698 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
10699 | genl_unregister_family(&nl80211_fam); |
10700 | } |