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 | ||
a043897a HS |
450 | /* ifidx get helper */ |
451 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
452 | { | |
453 | int res; | |
454 | ||
455 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
456 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
457 | nl80211_policy); | |
458 | if (res) | |
459 | return res; | |
460 | ||
461 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
462 | return -EINVAL; | |
463 | ||
464 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
465 | if (!res) | |
466 | return -EINVAL; | |
467 | return res; | |
468 | } | |
469 | ||
67748893 JB |
470 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
471 | struct netlink_callback *cb, | |
472 | struct cfg80211_registered_device **rdev, | |
473 | struct net_device **dev) | |
474 | { | |
475 | int ifidx = cb->args[0]; | |
476 | int err; | |
477 | ||
478 | if (!ifidx) | |
479 | ifidx = nl80211_get_ifidx(cb); | |
480 | if (ifidx < 0) | |
481 | return ifidx; | |
482 | ||
483 | cb->args[0] = ifidx; | |
484 | ||
485 | rtnl_lock(); | |
486 | ||
487 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
488 | if (!*dev) { | |
489 | err = -ENODEV; | |
490 | goto out_rtnl; | |
491 | } | |
492 | ||
493 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3cc25e51 FF |
494 | if (IS_ERR(*rdev)) { |
495 | err = PTR_ERR(*rdev); | |
67748893 JB |
496 | goto out_rtnl; |
497 | } | |
498 | ||
499 | return 0; | |
500 | out_rtnl: | |
501 | rtnl_unlock(); | |
502 | return err; | |
503 | } | |
504 | ||
505 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | |
506 | { | |
507 | cfg80211_unlock_rdev(rdev); | |
508 | rtnl_unlock(); | |
509 | } | |
510 | ||
f4a11bb0 JB |
511 | /* IE validation */ |
512 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
513 | { | |
514 | const u8 *pos; | |
515 | int len; | |
516 | ||
517 | if (!attr) | |
518 | return true; | |
519 | ||
520 | pos = nla_data(attr); | |
521 | len = nla_len(attr); | |
522 | ||
523 | while (len) { | |
524 | u8 elemlen; | |
525 | ||
526 | if (len < 2) | |
527 | return false; | |
528 | len -= 2; | |
529 | ||
530 | elemlen = pos[1]; | |
531 | if (elemlen > len) | |
532 | return false; | |
533 | ||
534 | len -= elemlen; | |
535 | pos += 2 + elemlen; | |
536 | } | |
537 | ||
538 | return true; | |
539 | } | |
540 | ||
55682965 | 541 | /* message building helper */ |
15e47304 | 542 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
543 | int flags, u8 cmd) |
544 | { | |
545 | /* since there is no private header just add the generic one */ | |
15e47304 | 546 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
547 | } |
548 | ||
5dab3b8a | 549 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
550 | struct ieee80211_channel *chan, |
551 | bool large) | |
5dab3b8a | 552 | { |
9360ffd1 DM |
553 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
554 | chan->center_freq)) | |
555 | goto nla_put_failure; | |
5dab3b8a | 556 | |
9360ffd1 DM |
557 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
559 | goto nla_put_failure; | |
560 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
562 | goto nla_put_failure; | |
563 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
565 | goto nla_put_failure; | |
cdc89b97 JB |
566 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
567 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
568 | goto nla_put_failure; | |
569 | if (large) { | |
570 | u32 time; | |
571 | ||
572 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
573 | ||
574 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
575 | chan->dfs_state)) | |
576 | goto nla_put_failure; | |
577 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
578 | time)) | |
579 | goto nla_put_failure; | |
580 | } | |
581 | } | |
5dab3b8a | 582 | |
fe1abafd JB |
583 | if (large) { |
584 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
585 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
586 | goto nla_put_failure; | |
587 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
588 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
589 | goto nla_put_failure; | |
590 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
591 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
592 | goto nla_put_failure; | |
593 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
594 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
595 | goto nla_put_failure; | |
596 | } | |
597 | ||
9360ffd1 DM |
598 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
599 | DBM_TO_MBM(chan->max_power))) | |
600 | goto nla_put_failure; | |
5dab3b8a LR |
601 | |
602 | return 0; | |
603 | ||
604 | nla_put_failure: | |
605 | return -ENOBUFS; | |
606 | } | |
607 | ||
55682965 JB |
608 | /* netlink command implementations */ |
609 | ||
b9454e83 JB |
610 | struct key_parse { |
611 | struct key_params p; | |
612 | int idx; | |
e31b8213 | 613 | int type; |
b9454e83 | 614 | bool def, defmgmt; |
dbd2fd65 | 615 | bool def_uni, def_multi; |
b9454e83 JB |
616 | }; |
617 | ||
618 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
619 | { | |
620 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
621 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
622 | nl80211_key_policy); | |
623 | if (err) | |
624 | return err; | |
625 | ||
626 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
627 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
628 | ||
dbd2fd65 JB |
629 | if (k->def) { |
630 | k->def_uni = true; | |
631 | k->def_multi = true; | |
632 | } | |
633 | if (k->defmgmt) | |
634 | k->def_multi = true; | |
635 | ||
b9454e83 JB |
636 | if (tb[NL80211_KEY_IDX]) |
637 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
638 | ||
639 | if (tb[NL80211_KEY_DATA]) { | |
640 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
641 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
642 | } | |
643 | ||
644 | if (tb[NL80211_KEY_SEQ]) { | |
645 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
646 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
647 | } | |
648 | ||
649 | if (tb[NL80211_KEY_CIPHER]) | |
650 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
651 | ||
e31b8213 JB |
652 | if (tb[NL80211_KEY_TYPE]) { |
653 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
654 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
655 | return -EINVAL; | |
656 | } | |
657 | ||
dbd2fd65 JB |
658 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
659 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
660 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
661 | tb[NL80211_KEY_DEFAULT_TYPES], | |
662 | nl80211_key_default_policy); | |
dbd2fd65 JB |
663 | if (err) |
664 | return err; | |
665 | ||
666 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
667 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
668 | } | |
669 | ||
b9454e83 JB |
670 | return 0; |
671 | } | |
672 | ||
673 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
674 | { | |
675 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
676 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
677 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
678 | } | |
679 | ||
680 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
681 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
682 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
683 | } | |
684 | ||
685 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
686 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
687 | ||
688 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
689 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
690 | ||
691 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
692 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
693 | ||
dbd2fd65 JB |
694 | if (k->def) { |
695 | k->def_uni = true; | |
696 | k->def_multi = true; | |
697 | } | |
698 | if (k->defmgmt) | |
699 | k->def_multi = true; | |
700 | ||
e31b8213 JB |
701 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
702 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
703 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
704 | return -EINVAL; | |
705 | } | |
706 | ||
dbd2fd65 JB |
707 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
708 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
709 | int err = nla_parse_nested( | |
710 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
711 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
712 | nl80211_key_default_policy); | |
713 | if (err) | |
714 | return err; | |
715 | ||
716 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
717 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
718 | } | |
719 | ||
b9454e83 JB |
720 | return 0; |
721 | } | |
722 | ||
723 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
724 | { | |
725 | int err; | |
726 | ||
727 | memset(k, 0, sizeof(*k)); | |
728 | k->idx = -1; | |
e31b8213 | 729 | k->type = -1; |
b9454e83 JB |
730 | |
731 | if (info->attrs[NL80211_ATTR_KEY]) | |
732 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
733 | else | |
734 | err = nl80211_parse_key_old(info, k); | |
735 | ||
736 | if (err) | |
737 | return err; | |
738 | ||
739 | if (k->def && k->defmgmt) | |
740 | return -EINVAL; | |
741 | ||
dbd2fd65 JB |
742 | if (k->defmgmt) { |
743 | if (k->def_uni || !k->def_multi) | |
744 | return -EINVAL; | |
745 | } | |
746 | ||
b9454e83 JB |
747 | if (k->idx != -1) { |
748 | if (k->defmgmt) { | |
749 | if (k->idx < 4 || k->idx > 5) | |
750 | return -EINVAL; | |
751 | } else if (k->def) { | |
752 | if (k->idx < 0 || k->idx > 3) | |
753 | return -EINVAL; | |
754 | } else { | |
755 | if (k->idx < 0 || k->idx > 5) | |
756 | return -EINVAL; | |
757 | } | |
758 | } | |
759 | ||
760 | return 0; | |
761 | } | |
762 | ||
fffd0934 JB |
763 | static struct cfg80211_cached_keys * |
764 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 765 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
766 | { |
767 | struct key_parse parse; | |
768 | struct nlattr *key; | |
769 | struct cfg80211_cached_keys *result; | |
770 | int rem, err, def = 0; | |
771 | ||
772 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
773 | if (!result) | |
774 | return ERR_PTR(-ENOMEM); | |
775 | ||
776 | result->def = -1; | |
777 | result->defmgmt = -1; | |
778 | ||
779 | nla_for_each_nested(key, keys, rem) { | |
780 | memset(&parse, 0, sizeof(parse)); | |
781 | parse.idx = -1; | |
782 | ||
783 | err = nl80211_parse_key_new(key, &parse); | |
784 | if (err) | |
785 | goto error; | |
786 | err = -EINVAL; | |
787 | if (!parse.p.key) | |
788 | goto error; | |
789 | if (parse.idx < 0 || parse.idx > 4) | |
790 | goto error; | |
791 | if (parse.def) { | |
792 | if (def) | |
793 | goto error; | |
794 | def = 1; | |
795 | result->def = parse.idx; | |
dbd2fd65 JB |
796 | if (!parse.def_uni || !parse.def_multi) |
797 | goto error; | |
fffd0934 JB |
798 | } else if (parse.defmgmt) |
799 | goto error; | |
800 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 801 | parse.idx, false, NULL); |
fffd0934 JB |
802 | if (err) |
803 | goto error; | |
804 | result->params[parse.idx].cipher = parse.p.cipher; | |
805 | result->params[parse.idx].key_len = parse.p.key_len; | |
806 | result->params[parse.idx].key = result->data[parse.idx]; | |
807 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
808 | |
809 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
810 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
811 | if (no_ht) | |
812 | *no_ht = true; | |
813 | } | |
fffd0934 JB |
814 | } |
815 | ||
816 | return result; | |
817 | error: | |
818 | kfree(result); | |
819 | return ERR_PTR(err); | |
820 | } | |
821 | ||
822 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
823 | { | |
824 | ASSERT_WDEV_LOCK(wdev); | |
825 | ||
fffd0934 JB |
826 | switch (wdev->iftype) { |
827 | case NL80211_IFTYPE_AP: | |
828 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 829 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 830 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
831 | break; |
832 | case NL80211_IFTYPE_ADHOC: | |
833 | if (!wdev->current_bss) | |
834 | return -ENOLINK; | |
835 | break; | |
836 | case NL80211_IFTYPE_STATION: | |
074ac8df | 837 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
838 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
839 | return -ENOLINK; | |
840 | break; | |
841 | default: | |
842 | return -EINVAL; | |
843 | } | |
844 | ||
845 | return 0; | |
846 | } | |
847 | ||
7527a782 JB |
848 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
849 | { | |
850 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
851 | int i; | |
852 | ||
853 | if (!nl_modes) | |
854 | goto nla_put_failure; | |
855 | ||
856 | i = 0; | |
857 | while (ifmodes) { | |
9360ffd1 DM |
858 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
859 | goto nla_put_failure; | |
7527a782 JB |
860 | ifmodes >>= 1; |
861 | i++; | |
862 | } | |
863 | ||
864 | nla_nest_end(msg, nl_modes); | |
865 | return 0; | |
866 | ||
867 | nla_put_failure: | |
868 | return -ENOBUFS; | |
869 | } | |
870 | ||
871 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
872 | struct sk_buff *msg, |
873 | bool large) | |
7527a782 JB |
874 | { |
875 | struct nlattr *nl_combis; | |
876 | int i, j; | |
877 | ||
878 | nl_combis = nla_nest_start(msg, | |
879 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
880 | if (!nl_combis) | |
881 | goto nla_put_failure; | |
882 | ||
883 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
884 | const struct ieee80211_iface_combination *c; | |
885 | struct nlattr *nl_combi, *nl_limits; | |
886 | ||
887 | c = &wiphy->iface_combinations[i]; | |
888 | ||
889 | nl_combi = nla_nest_start(msg, i + 1); | |
890 | if (!nl_combi) | |
891 | goto nla_put_failure; | |
892 | ||
893 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
894 | if (!nl_limits) | |
895 | goto nla_put_failure; | |
896 | ||
897 | for (j = 0; j < c->n_limits; j++) { | |
898 | struct nlattr *nl_limit; | |
899 | ||
900 | nl_limit = nla_nest_start(msg, j + 1); | |
901 | if (!nl_limit) | |
902 | goto nla_put_failure; | |
9360ffd1 DM |
903 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
904 | c->limits[j].max)) | |
905 | goto nla_put_failure; | |
7527a782 JB |
906 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
907 | c->limits[j].types)) | |
908 | goto nla_put_failure; | |
909 | nla_nest_end(msg, nl_limit); | |
910 | } | |
911 | ||
912 | nla_nest_end(msg, nl_limits); | |
913 | ||
9360ffd1 DM |
914 | if (c->beacon_int_infra_match && |
915 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
916 | goto nla_put_failure; | |
917 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
918 | c->num_different_channels) || | |
919 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
920 | c->max_interfaces)) | |
921 | goto nla_put_failure; | |
cdc89b97 JB |
922 | if (large && |
923 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
924 | c->radar_detect_widths)) | |
925 | goto nla_put_failure; | |
7527a782 JB |
926 | |
927 | nla_nest_end(msg, nl_combi); | |
928 | } | |
929 | ||
930 | nla_nest_end(msg, nl_combis); | |
931 | ||
932 | return 0; | |
933 | nla_put_failure: | |
934 | return -ENOBUFS; | |
935 | } | |
936 | ||
3713b4e3 | 937 | #ifdef CONFIG_PM |
b56cf720 JB |
938 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
939 | struct sk_buff *msg) | |
940 | { | |
941 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; | |
942 | struct nlattr *nl_tcp; | |
943 | ||
944 | if (!tcp) | |
945 | return 0; | |
946 | ||
947 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
948 | if (!nl_tcp) | |
949 | return -ENOBUFS; | |
950 | ||
951 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
952 | tcp->data_payload_max)) | |
953 | return -ENOBUFS; | |
954 | ||
955 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
956 | tcp->data_payload_max)) | |
957 | return -ENOBUFS; | |
958 | ||
959 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
960 | return -ENOBUFS; | |
961 | ||
962 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
963 | sizeof(*tcp->tok), tcp->tok)) | |
964 | return -ENOBUFS; | |
965 | ||
966 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
967 | tcp->data_interval_max)) | |
968 | return -ENOBUFS; | |
969 | ||
970 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
971 | tcp->wake_payload_max)) | |
972 | return -ENOBUFS; | |
973 | ||
974 | nla_nest_end(msg, nl_tcp); | |
975 | return 0; | |
976 | } | |
977 | ||
3713b4e3 | 978 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
979 | struct cfg80211_registered_device *dev, |
980 | bool large) | |
55682965 | 981 | { |
3713b4e3 | 982 | struct nlattr *nl_wowlan; |
55682965 | 983 | |
3713b4e3 JB |
984 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
985 | return 0; | |
55682965 | 986 | |
3713b4e3 JB |
987 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
988 | if (!nl_wowlan) | |
989 | return -ENOBUFS; | |
9360ffd1 | 990 | |
3713b4e3 JB |
991 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
992 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
993 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
994 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
995 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
996 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
997 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
998 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
999 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
1000 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
1001 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
1002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1003 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1005 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1007 | return -ENOBUFS; | |
9360ffd1 | 1008 | |
3713b4e3 JB |
1009 | if (dev->wiphy.wowlan.n_patterns) { |
1010 | struct nl80211_wowlan_pattern_support pat = { | |
1011 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1012 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, | |
1013 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, | |
1014 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, | |
1015 | }; | |
9360ffd1 | 1016 | |
3713b4e3 JB |
1017 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1018 | sizeof(pat), &pat)) | |
1019 | return -ENOBUFS; | |
1020 | } | |
9360ffd1 | 1021 | |
b56cf720 JB |
1022 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1023 | return -ENOBUFS; | |
1024 | ||
3713b4e3 | 1025 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1026 | |
3713b4e3 JB |
1027 | return 0; |
1028 | } | |
1029 | #endif | |
9360ffd1 | 1030 | |
3713b4e3 JB |
1031 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1032 | struct ieee80211_supported_band *sband) | |
1033 | { | |
1034 | struct nlattr *nl_rates, *nl_rate; | |
1035 | struct ieee80211_rate *rate; | |
1036 | int i; | |
87bbbe22 | 1037 | |
3713b4e3 JB |
1038 | /* add HT info */ |
1039 | if (sband->ht_cap.ht_supported && | |
1040 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1041 | sizeof(sband->ht_cap.mcs), | |
1042 | &sband->ht_cap.mcs) || | |
1043 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1044 | sband->ht_cap.cap) || | |
1045 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1046 | sband->ht_cap.ampdu_factor) || | |
1047 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1048 | sband->ht_cap.ampdu_density))) | |
1049 | return -ENOBUFS; | |
afe0cbf8 | 1050 | |
3713b4e3 JB |
1051 | /* add VHT info */ |
1052 | if (sband->vht_cap.vht_supported && | |
1053 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1054 | sizeof(sband->vht_cap.vht_mcs), | |
1055 | &sband->vht_cap.vht_mcs) || | |
1056 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1057 | sband->vht_cap.cap))) | |
1058 | return -ENOBUFS; | |
f59ac048 | 1059 | |
3713b4e3 JB |
1060 | /* add bitrates */ |
1061 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1062 | if (!nl_rates) | |
1063 | return -ENOBUFS; | |
ee688b00 | 1064 | |
3713b4e3 JB |
1065 | for (i = 0; i < sband->n_bitrates; i++) { |
1066 | nl_rate = nla_nest_start(msg, i); | |
1067 | if (!nl_rate) | |
1068 | return -ENOBUFS; | |
ee688b00 | 1069 | |
3713b4e3 JB |
1070 | rate = &sband->bitrates[i]; |
1071 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1072 | rate->bitrate)) | |
1073 | return -ENOBUFS; | |
1074 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1075 | nla_put_flag(msg, | |
1076 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1077 | return -ENOBUFS; | |
ee688b00 | 1078 | |
3713b4e3 JB |
1079 | nla_nest_end(msg, nl_rate); |
1080 | } | |
d51626df | 1081 | |
3713b4e3 | 1082 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1083 | |
3713b4e3 JB |
1084 | return 0; |
1085 | } | |
ee688b00 | 1086 | |
3713b4e3 JB |
1087 | static int |
1088 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1089 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1090 | { | |
1091 | u16 stypes; | |
1092 | struct nlattr *nl_ftypes, *nl_ifs; | |
1093 | enum nl80211_iftype ift; | |
1094 | int i; | |
ee688b00 | 1095 | |
3713b4e3 JB |
1096 | if (!mgmt_stypes) |
1097 | return 0; | |
5dab3b8a | 1098 | |
3713b4e3 JB |
1099 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1100 | if (!nl_ifs) | |
1101 | return -ENOBUFS; | |
e2f367f2 | 1102 | |
3713b4e3 JB |
1103 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1104 | nl_ftypes = nla_nest_start(msg, ift); | |
1105 | if (!nl_ftypes) | |
1106 | return -ENOBUFS; | |
1107 | i = 0; | |
1108 | stypes = mgmt_stypes[ift].tx; | |
1109 | while (stypes) { | |
1110 | if ((stypes & 1) && | |
1111 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1112 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1113 | return -ENOBUFS; | |
1114 | stypes >>= 1; | |
1115 | i++; | |
ee688b00 | 1116 | } |
3713b4e3 JB |
1117 | nla_nest_end(msg, nl_ftypes); |
1118 | } | |
ee688b00 | 1119 | |
3713b4e3 | 1120 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1121 | |
3713b4e3 JB |
1122 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1123 | if (!nl_ifs) | |
1124 | return -ENOBUFS; | |
ee688b00 | 1125 | |
3713b4e3 JB |
1126 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1127 | nl_ftypes = nla_nest_start(msg, ift); | |
1128 | if (!nl_ftypes) | |
1129 | return -ENOBUFS; | |
1130 | i = 0; | |
1131 | stypes = mgmt_stypes[ift].rx; | |
1132 | while (stypes) { | |
1133 | if ((stypes & 1) && | |
1134 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1135 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1136 | return -ENOBUFS; | |
1137 | stypes >>= 1; | |
1138 | i++; | |
1139 | } | |
1140 | nla_nest_end(msg, nl_ftypes); | |
1141 | } | |
1142 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1143 | |
3713b4e3 JB |
1144 | return 0; |
1145 | } | |
ee688b00 | 1146 | |
3713b4e3 JB |
1147 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1148 | struct sk_buff *msg, u32 portid, u32 seq, | |
1149 | int flags, bool split, long *split_start, | |
1150 | long *band_start, long *chan_start) | |
1151 | { | |
1152 | void *hdr; | |
1153 | struct nlattr *nl_bands, *nl_band; | |
1154 | struct nlattr *nl_freqs, *nl_freq; | |
1155 | struct nlattr *nl_cmds; | |
1156 | enum ieee80211_band band; | |
1157 | struct ieee80211_channel *chan; | |
1158 | int i; | |
1159 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1160 | dev->wiphy.mgmt_stypes; | |
1161 | long start = 0, start_chan = 0, start_band = 0; | |
fe1abafd | 1162 | u32 features; |
ee688b00 | 1163 | |
3713b4e3 JB |
1164 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1165 | if (!hdr) | |
1166 | return -ENOBUFS; | |
ee688b00 | 1167 | |
3713b4e3 JB |
1168 | /* allow always using the variables */ |
1169 | if (!split) { | |
1170 | split_start = &start; | |
1171 | band_start = &start_band; | |
1172 | chan_start = &start_chan; | |
ee688b00 | 1173 | } |
ee688b00 | 1174 | |
3713b4e3 JB |
1175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1176 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1177 | wiphy_name(&dev->wiphy)) || | |
1178 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1179 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1180 | goto nla_put_failure; |
1181 | ||
3713b4e3 JB |
1182 | switch (*split_start) { |
1183 | case 0: | |
1184 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1185 | dev->wiphy.retry_short) || | |
1186 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1187 | dev->wiphy.retry_long) || | |
1188 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1189 | dev->wiphy.frag_threshold) || | |
1190 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1191 | dev->wiphy.rts_threshold) || | |
1192 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1193 | dev->wiphy.coverage_class) || | |
1194 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1195 | dev->wiphy.max_scan_ssids) || | |
1196 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1197 | dev->wiphy.max_sched_scan_ssids) || | |
1198 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1199 | dev->wiphy.max_scan_ie_len) || | |
1200 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1201 | dev->wiphy.max_sched_scan_ie_len) || | |
1202 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1203 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1204 | goto nla_put_failure; |
3713b4e3 JB |
1205 | |
1206 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1207 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1208 | goto nla_put_failure; |
3713b4e3 JB |
1209 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1210 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1211 | goto nla_put_failure; | |
1212 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1213 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1214 | goto nla_put_failure; | |
1215 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1216 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1217 | goto nla_put_failure; | |
1218 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1219 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1220 | goto nla_put_failure; | |
1221 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1222 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1223 | goto nla_put_failure; |
8fdc621d | 1224 | |
3713b4e3 JB |
1225 | (*split_start)++; |
1226 | if (split) | |
1227 | break; | |
1228 | case 1: | |
1229 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1230 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1231 | dev->wiphy.cipher_suites)) | |
1232 | goto nla_put_failure; | |
4745fc09 | 1233 | |
3713b4e3 JB |
1234 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1235 | dev->wiphy.max_num_pmkids)) | |
1236 | goto nla_put_failure; | |
b23aa676 | 1237 | |
3713b4e3 JB |
1238 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1239 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1240 | goto nla_put_failure; |
b23aa676 | 1241 | |
3713b4e3 JB |
1242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1243 | dev->wiphy.available_antennas_tx) || | |
1244 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1245 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1246 | goto nla_put_failure; |
b23aa676 | 1247 | |
3713b4e3 JB |
1248 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1249 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1250 | dev->wiphy.probe_resp_offload)) | |
1251 | goto nla_put_failure; | |
8fdc621d | 1252 | |
3713b4e3 JB |
1253 | if ((dev->wiphy.available_antennas_tx || |
1254 | dev->wiphy.available_antennas_rx) && | |
1255 | dev->ops->get_antenna) { | |
1256 | u32 tx_ant = 0, rx_ant = 0; | |
1257 | int res; | |
1258 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1259 | if (!res) { | |
1260 | if (nla_put_u32(msg, | |
1261 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1262 | tx_ant) || | |
1263 | nla_put_u32(msg, | |
1264 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1265 | rx_ant)) | |
1266 | goto nla_put_failure; | |
1267 | } | |
1268 | } | |
a293911d | 1269 | |
3713b4e3 JB |
1270 | (*split_start)++; |
1271 | if (split) | |
1272 | break; | |
1273 | case 2: | |
1274 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1275 | dev->wiphy.interface_modes)) | |
1276 | goto nla_put_failure; | |
1277 | (*split_start)++; | |
1278 | if (split) | |
1279 | break; | |
1280 | case 3: | |
1281 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1282 | if (!nl_bands) | |
1283 | goto nla_put_failure; | |
f7ca38df | 1284 | |
3713b4e3 JB |
1285 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
1286 | struct ieee80211_supported_band *sband; | |
2e161f78 | 1287 | |
3713b4e3 | 1288 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1289 | |
3713b4e3 JB |
1290 | if (!sband) |
1291 | continue; | |
1292 | ||
1293 | nl_band = nla_nest_start(msg, band); | |
1294 | if (!nl_band) | |
2e161f78 | 1295 | goto nla_put_failure; |
3713b4e3 JB |
1296 | |
1297 | switch (*chan_start) { | |
1298 | case 0: | |
1299 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1300 | goto nla_put_failure; |
3713b4e3 JB |
1301 | (*chan_start)++; |
1302 | if (split) | |
1303 | break; | |
1304 | default: | |
1305 | /* add frequencies */ | |
1306 | nl_freqs = nla_nest_start( | |
1307 | msg, NL80211_BAND_ATTR_FREQS); | |
1308 | if (!nl_freqs) | |
1309 | goto nla_put_failure; | |
1310 | ||
1311 | for (i = *chan_start - 1; | |
1312 | i < sband->n_channels; | |
1313 | i++) { | |
1314 | nl_freq = nla_nest_start(msg, i); | |
1315 | if (!nl_freq) | |
1316 | goto nla_put_failure; | |
1317 | ||
1318 | chan = &sband->channels[i]; | |
1319 | ||
cdc89b97 JB |
1320 | if (nl80211_msg_put_channel(msg, chan, |
1321 | split)) | |
3713b4e3 JB |
1322 | goto nla_put_failure; |
1323 | ||
1324 | nla_nest_end(msg, nl_freq); | |
1325 | if (split) | |
1326 | break; | |
1327 | } | |
1328 | if (i < sband->n_channels) | |
1329 | *chan_start = i + 2; | |
1330 | else | |
1331 | *chan_start = 0; | |
1332 | nla_nest_end(msg, nl_freqs); | |
1333 | } | |
1334 | ||
1335 | nla_nest_end(msg, nl_band); | |
1336 | ||
1337 | if (split) { | |
1338 | /* start again here */ | |
1339 | if (*chan_start) | |
1340 | band--; | |
1341 | break; | |
2e161f78 | 1342 | } |
2e161f78 | 1343 | } |
3713b4e3 | 1344 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1345 | |
3713b4e3 JB |
1346 | if (band < IEEE80211_NUM_BANDS) |
1347 | *band_start = band + 1; | |
1348 | else | |
1349 | *band_start = 0; | |
74b70a4e | 1350 | |
3713b4e3 JB |
1351 | /* if bands & channels are done, continue outside */ |
1352 | if (*band_start == 0 && *chan_start == 0) | |
1353 | (*split_start)++; | |
1354 | if (split) | |
1355 | break; | |
1356 | case 4: | |
1357 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1358 | if (!nl_cmds) | |
2e161f78 JB |
1359 | goto nla_put_failure; |
1360 | ||
3713b4e3 JB |
1361 | i = 0; |
1362 | #define CMD(op, n) \ | |
1363 | do { \ | |
1364 | if (dev->ops->op) { \ | |
1365 | i++; \ | |
1366 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1367 | goto nla_put_failure; \ | |
1368 | } \ | |
1369 | } while (0) | |
1370 | ||
1371 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1372 | CMD(change_virtual_intf, SET_INTERFACE); | |
1373 | CMD(add_key, NEW_KEY); | |
1374 | CMD(start_ap, START_AP); | |
1375 | CMD(add_station, NEW_STATION); | |
1376 | CMD(add_mpath, NEW_MPATH); | |
1377 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1378 | CMD(change_bss, SET_BSS); | |
1379 | CMD(auth, AUTHENTICATE); | |
1380 | CMD(assoc, ASSOCIATE); | |
1381 | CMD(deauth, DEAUTHENTICATE); | |
1382 | CMD(disassoc, DISASSOCIATE); | |
1383 | CMD(join_ibss, JOIN_IBSS); | |
1384 | CMD(join_mesh, JOIN_MESH); | |
1385 | CMD(set_pmksa, SET_PMKSA); | |
1386 | CMD(del_pmksa, DEL_PMKSA); | |
1387 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1388 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1389 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1390 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1391 | CMD(mgmt_tx, FRAME); | |
1392 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1393 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1394 | i++; | |
1395 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1396 | goto nla_put_failure; |
2e161f78 | 1397 | } |
3713b4e3 JB |
1398 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1399 | dev->ops->join_mesh) { | |
1400 | i++; | |
1401 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1402 | goto nla_put_failure; | |
1403 | } | |
1404 | CMD(set_wds_peer, SET_WDS_PEER); | |
1405 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1406 | CMD(tdls_mgmt, TDLS_MGMT); | |
1407 | CMD(tdls_oper, TDLS_OPER); | |
1408 | } | |
1409 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1410 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1411 | CMD(probe_client, PROBE_CLIENT); | |
1412 | CMD(set_noack_map, SET_NOACK_MAP); | |
1413 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1414 | i++; | |
1415 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1416 | goto nla_put_failure; | |
1417 | } | |
1418 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1419 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
2e161f78 | 1420 | |
3713b4e3 JB |
1421 | #ifdef CONFIG_NL80211_TESTMODE |
1422 | CMD(testmode_cmd, TESTMODE); | |
1423 | #endif | |
ff1b6e69 | 1424 | |
3713b4e3 | 1425 | #undef CMD |
ff1b6e69 | 1426 | |
3713b4e3 JB |
1427 | if (dev->ops->connect || dev->ops->auth) { |
1428 | i++; | |
1429 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1430 | goto nla_put_failure; |
ff1b6e69 JB |
1431 | } |
1432 | ||
3713b4e3 JB |
1433 | if (dev->ops->disconnect || dev->ops->deauth) { |
1434 | i++; | |
1435 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1436 | goto nla_put_failure; | |
1437 | } | |
1438 | ||
1439 | nla_nest_end(msg, nl_cmds); | |
1440 | (*split_start)++; | |
1441 | if (split) | |
1442 | break; | |
1443 | case 5: | |
1444 | if (dev->ops->remain_on_channel && | |
1445 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1446 | nla_put_u32(msg, | |
1447 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1448 | dev->wiphy.max_remain_on_channel_duration)) | |
1449 | goto nla_put_failure; | |
1450 | ||
1451 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1452 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1453 | goto nla_put_failure; | |
1454 | ||
1455 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1456 | goto nla_put_failure; | |
1457 | (*split_start)++; | |
1458 | if (split) | |
1459 | break; | |
1460 | case 6: | |
1461 | #ifdef CONFIG_PM | |
b56cf720 | 1462 | if (nl80211_send_wowlan(msg, dev, split)) |
3713b4e3 JB |
1463 | goto nla_put_failure; |
1464 | (*split_start)++; | |
1465 | if (split) | |
1466 | break; | |
1467 | #else | |
1468 | (*split_start)++; | |
dfb89c56 | 1469 | #endif |
3713b4e3 JB |
1470 | case 7: |
1471 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1472 | dev->wiphy.software_iftypes)) | |
1473 | goto nla_put_failure; | |
ff1b6e69 | 1474 | |
cdc89b97 | 1475 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
3713b4e3 | 1476 | goto nla_put_failure; |
7527a782 | 1477 | |
3713b4e3 JB |
1478 | (*split_start)++; |
1479 | if (split) | |
1480 | break; | |
1481 | case 8: | |
1482 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1483 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1484 | dev->wiphy.ap_sme_capa)) | |
1485 | goto nla_put_failure; | |
7527a782 | 1486 | |
fe1abafd JB |
1487 | features = dev->wiphy.features; |
1488 | /* | |
1489 | * We can only add the per-channel limit information if the | |
1490 | * dump is split, otherwise it makes it too big. Therefore | |
1491 | * only advertise it in that case. | |
1492 | */ | |
1493 | if (split) | |
1494 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | |
1495 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1496 | goto nla_put_failure; |
562a7480 | 1497 | |
3713b4e3 JB |
1498 | if (dev->wiphy.ht_capa_mod_mask && |
1499 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1500 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1501 | dev->wiphy.ht_capa_mod_mask)) | |
1502 | goto nla_put_failure; | |
1f074bd8 | 1503 | |
3713b4e3 JB |
1504 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1505 | dev->wiphy.max_acl_mac_addrs && | |
1506 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1507 | dev->wiphy.max_acl_mac_addrs)) | |
1508 | goto nla_put_failure; | |
7e7c8926 | 1509 | |
3713b4e3 JB |
1510 | /* |
1511 | * Any information below this point is only available to | |
1512 | * applications that can deal with it being split. This | |
1513 | * helps ensure that newly added capabilities don't break | |
1514 | * older tools by overrunning their buffers. | |
1515 | * | |
1516 | * We still increment split_start so that in the split | |
1517 | * case we'll continue with more data in the next round, | |
1518 | * but break unconditionally so unsplit data stops here. | |
1519 | */ | |
1520 | (*split_start)++; | |
1521 | break; | |
1522 | case 9: | |
fe1abafd JB |
1523 | if (dev->wiphy.extended_capabilities && |
1524 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1525 | dev->wiphy.extended_capabilities_len, | |
1526 | dev->wiphy.extended_capabilities) || | |
1527 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1528 | dev->wiphy.extended_capabilities_len, | |
1529 | dev->wiphy.extended_capabilities_mask))) | |
1530 | goto nla_put_failure; | |
a50df0c4 | 1531 | |
ee2aca34 JB |
1532 | if (dev->wiphy.vht_capa_mod_mask && |
1533 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1534 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1535 | dev->wiphy.vht_capa_mod_mask)) | |
1536 | goto nla_put_failure; | |
1537 | ||
3713b4e3 JB |
1538 | /* done */ |
1539 | *split_start = 0; | |
1540 | break; | |
1541 | } | |
55682965 JB |
1542 | return genlmsg_end(msg, hdr); |
1543 | ||
1544 | nla_put_failure: | |
bc3ed28c TG |
1545 | genlmsg_cancel(msg, hdr); |
1546 | return -EMSGSIZE; | |
55682965 JB |
1547 | } |
1548 | ||
1549 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1550 | { | |
645e77de | 1551 | int idx = 0, ret; |
55682965 JB |
1552 | int start = cb->args[0]; |
1553 | struct cfg80211_registered_device *dev; | |
3713b4e3 JB |
1554 | s64 filter_wiphy = -1; |
1555 | bool split = false; | |
1556 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1557 | int res; | |
55682965 | 1558 | |
a1794390 | 1559 | mutex_lock(&cfg80211_mutex); |
3713b4e3 JB |
1560 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
1561 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1562 | if (res == 0) { | |
1563 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1564 | if (tb[NL80211_ATTR_WIPHY]) | |
1565 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1566 | if (tb[NL80211_ATTR_WDEV]) | |
1567 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1568 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1569 | struct net_device *netdev; | |
1570 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1571 | ||
1572 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1573 | if (!netdev) { | |
1574 | mutex_unlock(&cfg80211_mutex); | |
1575 | return -ENODEV; | |
1576 | } | |
1577 | if (netdev->ieee80211_ptr) { | |
1578 | dev = wiphy_to_dev( | |
1579 | netdev->ieee80211_ptr->wiphy); | |
1580 | filter_wiphy = dev->wiphy_idx; | |
1581 | } | |
1582 | dev_put(netdev); | |
1583 | } | |
1584 | } | |
1585 | ||
79c97e97 | 1586 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1587 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1588 | continue; | |
b4637271 | 1589 | if (++idx <= start) |
55682965 | 1590 | continue; |
3713b4e3 JB |
1591 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
1592 | continue; | |
1593 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1594 | do { | |
1595 | ret = nl80211_send_wiphy(dev, skb, | |
1596 | NETLINK_CB(cb->skb).portid, | |
1597 | cb->nlh->nlmsg_seq, | |
1598 | NLM_F_MULTI, | |
1599 | split, &cb->args[1], | |
1600 | &cb->args[2], | |
1601 | &cb->args[3]); | |
1602 | if (ret < 0) { | |
1603 | /* | |
1604 | * If sending the wiphy data didn't fit (ENOBUFS | |
1605 | * or EMSGSIZE returned), this SKB is still | |
1606 | * empty (so it's not too big because another | |
1607 | * wiphy dataset is already in the skb) and | |
1608 | * we've not tried to adjust the dump allocation | |
1609 | * yet ... then adjust the alloc size to be | |
1610 | * bigger, and return 1 but with the empty skb. | |
1611 | * This results in an empty message being RX'ed | |
1612 | * in userspace, but that is ignored. | |
1613 | * | |
1614 | * We can then retry with the larger buffer. | |
1615 | */ | |
1616 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1617 | !skb->len && | |
1618 | cb->min_dump_alloc < 4096) { | |
1619 | cb->min_dump_alloc = 4096; | |
1620 | mutex_unlock(&cfg80211_mutex); | |
1621 | return 1; | |
1622 | } | |
1623 | idx--; | |
1624 | break; | |
645e77de | 1625 | } |
3713b4e3 JB |
1626 | } while (cb->args[1] > 0); |
1627 | break; | |
55682965 | 1628 | } |
a1794390 | 1629 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1630 | |
1631 | cb->args[0] = idx; | |
1632 | ||
1633 | return skb->len; | |
1634 | } | |
1635 | ||
1636 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1637 | { | |
1638 | struct sk_buff *msg; | |
4c476991 | 1639 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1640 | |
645e77de | 1641 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1642 | if (!msg) |
4c476991 | 1643 | return -ENOMEM; |
55682965 | 1644 | |
3713b4e3 JB |
1645 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
1646 | false, NULL, NULL, NULL) < 0) { | |
4c476991 JB |
1647 | nlmsg_free(msg); |
1648 | return -ENOBUFS; | |
1649 | } | |
55682965 | 1650 | |
134e6375 | 1651 | return genlmsg_reply(msg, info); |
55682965 JB |
1652 | } |
1653 | ||
31888487 JM |
1654 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1655 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1656 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1657 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1658 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1659 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1660 | }; | |
1661 | ||
1662 | static int parse_txq_params(struct nlattr *tb[], | |
1663 | struct ieee80211_txq_params *txq_params) | |
1664 | { | |
a3304b0a | 1665 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1666 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1667 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1668 | return -EINVAL; | |
1669 | ||
a3304b0a | 1670 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1671 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1672 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1673 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1674 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1675 | ||
a3304b0a JB |
1676 | if (txq_params->ac >= NL80211_NUM_ACS) |
1677 | return -EINVAL; | |
1678 | ||
31888487 JM |
1679 | return 0; |
1680 | } | |
1681 | ||
f444de05 JB |
1682 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1683 | { | |
1684 | /* | |
cc1d2806 JB |
1685 | * You can only set the channel explicitly for WDS interfaces, |
1686 | * all others have their channel managed via their respective | |
1687 | * "establish a connection" command (connect, join, ...) | |
1688 | * | |
1689 | * For AP/GO and mesh mode, the channel can be set with the | |
1690 | * channel userspace API, but is only stored and passed to the | |
1691 | * low-level driver when the AP starts or the mesh is joined. | |
1692 | * This is for backward compatibility, userspace can also give | |
1693 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1694 | * |
1695 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1696 | * whatever else is going on, so they have their own special |
1697 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1698 | */ |
1699 | return !wdev || | |
1700 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1701 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1702 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1703 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1704 | } |
1705 | ||
683b6d3b JB |
1706 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1707 | struct genl_info *info, | |
1708 | struct cfg80211_chan_def *chandef) | |
1709 | { | |
dbeca2ea | 1710 | u32 control_freq; |
683b6d3b JB |
1711 | |
1712 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1713 | return -EINVAL; | |
1714 | ||
1715 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1716 | ||
1717 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1718 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1719 | chandef->center_freq1 = control_freq; | |
1720 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1721 | |
1722 | /* Primary channel not allowed */ | |
1723 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1724 | return -EINVAL; | |
1725 | ||
3d9d1d66 JB |
1726 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1727 | enum nl80211_channel_type chantype; | |
1728 | ||
1729 | chantype = nla_get_u32( | |
1730 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1731 | ||
1732 | switch (chantype) { | |
1733 | case NL80211_CHAN_NO_HT: | |
1734 | case NL80211_CHAN_HT20: | |
1735 | case NL80211_CHAN_HT40PLUS: | |
1736 | case NL80211_CHAN_HT40MINUS: | |
1737 | cfg80211_chandef_create(chandef, chandef->chan, | |
1738 | chantype); | |
1739 | break; | |
1740 | default: | |
1741 | return -EINVAL; | |
1742 | } | |
1743 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1744 | chandef->width = | |
1745 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1746 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1747 | chandef->center_freq1 = | |
1748 | nla_get_u32( | |
1749 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1750 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1751 | chandef->center_freq2 = | |
1752 | nla_get_u32( | |
1753 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1754 | } | |
1755 | ||
9f5e8f6e | 1756 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1757 | return -EINVAL; |
1758 | ||
9f5e8f6e JB |
1759 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1760 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1761 | return -EINVAL; |
1762 | ||
683b6d3b JB |
1763 | return 0; |
1764 | } | |
1765 | ||
f444de05 JB |
1766 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1767 | struct wireless_dev *wdev, | |
1768 | struct genl_info *info) | |
1769 | { | |
683b6d3b | 1770 | struct cfg80211_chan_def chandef; |
f444de05 | 1771 | int result; |
e8c9bd5b JB |
1772 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1773 | ||
1774 | if (wdev) | |
1775 | iftype = wdev->iftype; | |
f444de05 | 1776 | |
f444de05 JB |
1777 | if (!nl80211_can_set_dev_channel(wdev)) |
1778 | return -EOPNOTSUPP; | |
1779 | ||
683b6d3b JB |
1780 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1781 | if (result) | |
1782 | return result; | |
f444de05 JB |
1783 | |
1784 | mutex_lock(&rdev->devlist_mtx); | |
e8c9bd5b | 1785 | switch (iftype) { |
aa430da4 JB |
1786 | case NL80211_IFTYPE_AP: |
1787 | case NL80211_IFTYPE_P2P_GO: | |
1788 | if (wdev->beacon_interval) { | |
1789 | result = -EBUSY; | |
1790 | break; | |
1791 | } | |
683b6d3b | 1792 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1793 | result = -EINVAL; |
1794 | break; | |
1795 | } | |
683b6d3b | 1796 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1797 | result = 0; |
1798 | break; | |
cc1d2806 | 1799 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1800 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1801 | break; |
e8c9bd5b | 1802 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1803 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1804 | break; |
aa430da4 | 1805 | default: |
e8c9bd5b | 1806 | result = -EINVAL; |
f444de05 JB |
1807 | } |
1808 | mutex_unlock(&rdev->devlist_mtx); | |
1809 | ||
1810 | return result; | |
1811 | } | |
1812 | ||
1813 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1814 | { | |
4c476991 JB |
1815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1816 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1817 | |
4c476991 | 1818 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1819 | } |
1820 | ||
e8347eba BJ |
1821 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1822 | { | |
43b19952 JB |
1823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1824 | struct net_device *dev = info->user_ptr[1]; | |
1825 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1826 | const u8 *bssid; |
e8347eba BJ |
1827 | |
1828 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1829 | return -EINVAL; | |
1830 | ||
43b19952 JB |
1831 | if (netif_running(dev)) |
1832 | return -EBUSY; | |
e8347eba | 1833 | |
43b19952 JB |
1834 | if (!rdev->ops->set_wds_peer) |
1835 | return -EOPNOTSUPP; | |
e8347eba | 1836 | |
43b19952 JB |
1837 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1838 | return -EOPNOTSUPP; | |
e8347eba BJ |
1839 | |
1840 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1841 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1842 | } |
1843 | ||
1844 | ||
55682965 JB |
1845 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1846 | { | |
1847 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1848 | struct net_device *netdev = NULL; |
1849 | struct wireless_dev *wdev; | |
a1e567c8 | 1850 | int result = 0, rem_txq_params = 0; |
31888487 | 1851 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1852 | u32 changed; |
1853 | u8 retry_short = 0, retry_long = 0; | |
1854 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1855 | u8 coverage_class = 0; |
55682965 | 1856 | |
f444de05 JB |
1857 | /* |
1858 | * Try to find the wiphy and netdev. Normally this | |
1859 | * function shouldn't need the netdev, but this is | |
1860 | * done for backward compatibility -- previously | |
1861 | * setting the channel was done per wiphy, but now | |
1862 | * it is per netdev. Previous userland like hostapd | |
1863 | * also passed a netdev to set_wiphy, so that it is | |
1864 | * possible to let that go to the right netdev! | |
1865 | */ | |
4bbf4d56 JB |
1866 | mutex_lock(&cfg80211_mutex); |
1867 | ||
f444de05 JB |
1868 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1869 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1870 | ||
1871 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1872 | if (netdev && netdev->ieee80211_ptr) { | |
1873 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1874 | mutex_lock(&rdev->mtx); | |
1875 | } else | |
1876 | netdev = NULL; | |
4bbf4d56 JB |
1877 | } |
1878 | ||
f444de05 | 1879 | if (!netdev) { |
878d9ec7 JB |
1880 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1881 | info->attrs); | |
f444de05 JB |
1882 | if (IS_ERR(rdev)) { |
1883 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1884 | return PTR_ERR(rdev); |
f444de05 JB |
1885 | } |
1886 | wdev = NULL; | |
1887 | netdev = NULL; | |
1888 | result = 0; | |
1889 | ||
1890 | mutex_lock(&rdev->mtx); | |
71fe96bf | 1891 | } else |
f444de05 | 1892 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1893 | |
1894 | /* | |
1895 | * end workaround code, by now the rdev is available | |
1896 | * and locked, and wdev may or may not be NULL. | |
1897 | */ | |
4bbf4d56 JB |
1898 | |
1899 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1900 | result = cfg80211_dev_rename( |
1901 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1902 | |
1903 | mutex_unlock(&cfg80211_mutex); | |
1904 | ||
1905 | if (result) | |
1906 | goto bad_res; | |
31888487 JM |
1907 | |
1908 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1909 | struct ieee80211_txq_params txq_params; | |
1910 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1911 | ||
1912 | if (!rdev->ops->set_txq_params) { | |
1913 | result = -EOPNOTSUPP; | |
1914 | goto bad_res; | |
1915 | } | |
1916 | ||
f70f01c2 EP |
1917 | if (!netdev) { |
1918 | result = -EINVAL; | |
1919 | goto bad_res; | |
1920 | } | |
1921 | ||
133a3ff2 JB |
1922 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1923 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1924 | result = -EINVAL; | |
1925 | goto bad_res; | |
1926 | } | |
1927 | ||
2b5f8b0b JB |
1928 | if (!netif_running(netdev)) { |
1929 | result = -ENETDOWN; | |
1930 | goto bad_res; | |
1931 | } | |
1932 | ||
31888487 JM |
1933 | nla_for_each_nested(nl_txq_params, |
1934 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1935 | rem_txq_params) { | |
1936 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1937 | nla_data(nl_txq_params), | |
1938 | nla_len(nl_txq_params), | |
1939 | txq_params_policy); | |
1940 | result = parse_txq_params(tb, &txq_params); | |
1941 | if (result) | |
1942 | goto bad_res; | |
1943 | ||
e35e4d28 HG |
1944 | result = rdev_set_txq_params(rdev, netdev, |
1945 | &txq_params); | |
31888487 JM |
1946 | if (result) |
1947 | goto bad_res; | |
1948 | } | |
1949 | } | |
55682965 | 1950 | |
72bdcf34 | 1951 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1952 | result = __nl80211_set_channel(rdev, |
1953 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1954 | info); | |
72bdcf34 JM |
1955 | if (result) |
1956 | goto bad_res; | |
1957 | } | |
1958 | ||
98d2ff8b | 1959 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1960 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1961 | enum nl80211_tx_power_setting type; |
1962 | int idx, mbm = 0; | |
1963 | ||
c8442118 JB |
1964 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
1965 | txp_wdev = NULL; | |
1966 | ||
98d2ff8b | 1967 | if (!rdev->ops->set_tx_power) { |
60ea385f | 1968 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1969 | goto bad_res; |
1970 | } | |
1971 | ||
1972 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1973 | type = nla_get_u32(info->attrs[idx]); | |
1974 | ||
1975 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1976 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1977 | result = -EINVAL; | |
1978 | goto bad_res; | |
1979 | } | |
1980 | ||
1981 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1982 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1983 | mbm = nla_get_u32(info->attrs[idx]); | |
1984 | } | |
1985 | ||
c8442118 | 1986 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
1987 | if (result) |
1988 | goto bad_res; | |
1989 | } | |
1990 | ||
afe0cbf8 BR |
1991 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1992 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1993 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1994 | if ((!rdev->wiphy.available_antennas_tx && |
1995 | !rdev->wiphy.available_antennas_rx) || | |
1996 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1997 | result = -EOPNOTSUPP; |
1998 | goto bad_res; | |
1999 | } | |
2000 | ||
2001 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2002 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2003 | ||
a7ffac95 | 2004 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2005 | * available antenna masks, except for the "all" mask */ |
2006 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2007 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2008 | result = -EINVAL; |
2009 | goto bad_res; | |
2010 | } | |
2011 | ||
7f531e03 BR |
2012 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2013 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2014 | |
e35e4d28 | 2015 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2016 | if (result) |
2017 | goto bad_res; | |
2018 | } | |
2019 | ||
b9a5f8ca JM |
2020 | changed = 0; |
2021 | ||
2022 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2023 | retry_short = nla_get_u8( | |
2024 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2025 | if (retry_short == 0) { | |
2026 | result = -EINVAL; | |
2027 | goto bad_res; | |
2028 | } | |
2029 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2030 | } | |
2031 | ||
2032 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2033 | retry_long = nla_get_u8( | |
2034 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2035 | if (retry_long == 0) { | |
2036 | result = -EINVAL; | |
2037 | goto bad_res; | |
2038 | } | |
2039 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2040 | } | |
2041 | ||
2042 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2043 | frag_threshold = nla_get_u32( | |
2044 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2045 | if (frag_threshold < 256) { | |
2046 | result = -EINVAL; | |
2047 | goto bad_res; | |
2048 | } | |
2049 | if (frag_threshold != (u32) -1) { | |
2050 | /* | |
2051 | * Fragments (apart from the last one) are required to | |
2052 | * have even length. Make the fragmentation code | |
2053 | * simpler by stripping LSB should someone try to use | |
2054 | * odd threshold value. | |
2055 | */ | |
2056 | frag_threshold &= ~0x1; | |
2057 | } | |
2058 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2059 | } | |
2060 | ||
2061 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2062 | rts_threshold = nla_get_u32( | |
2063 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2064 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2065 | } | |
2066 | ||
81077e82 LT |
2067 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2068 | coverage_class = nla_get_u8( | |
2069 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2070 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2071 | } | |
2072 | ||
b9a5f8ca JM |
2073 | if (changed) { |
2074 | u8 old_retry_short, old_retry_long; | |
2075 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2076 | u8 old_coverage_class; |
b9a5f8ca JM |
2077 | |
2078 | if (!rdev->ops->set_wiphy_params) { | |
2079 | result = -EOPNOTSUPP; | |
2080 | goto bad_res; | |
2081 | } | |
2082 | ||
2083 | old_retry_short = rdev->wiphy.retry_short; | |
2084 | old_retry_long = rdev->wiphy.retry_long; | |
2085 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2086 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2087 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2088 | |
2089 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2090 | rdev->wiphy.retry_short = retry_short; | |
2091 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2092 | rdev->wiphy.retry_long = retry_long; | |
2093 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2094 | rdev->wiphy.frag_threshold = frag_threshold; | |
2095 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2096 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2097 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2098 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2099 | |
e35e4d28 | 2100 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2101 | if (result) { |
2102 | rdev->wiphy.retry_short = old_retry_short; | |
2103 | rdev->wiphy.retry_long = old_retry_long; | |
2104 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2105 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2106 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2107 | } |
2108 | } | |
72bdcf34 | 2109 | |
306d6112 | 2110 | bad_res: |
4bbf4d56 | 2111 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
2112 | if (netdev) |
2113 | dev_put(netdev); | |
55682965 JB |
2114 | return result; |
2115 | } | |
2116 | ||
71bbc994 JB |
2117 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2118 | { | |
2119 | return (u64)wdev->identifier | | |
2120 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2121 | } | |
55682965 | 2122 | |
683b6d3b JB |
2123 | static int nl80211_send_chandef(struct sk_buff *msg, |
2124 | struct cfg80211_chan_def *chandef) | |
2125 | { | |
9f5e8f6e | 2126 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2127 | |
683b6d3b JB |
2128 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2129 | chandef->chan->center_freq)) | |
2130 | return -ENOBUFS; | |
3d9d1d66 JB |
2131 | switch (chandef->width) { |
2132 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2133 | case NL80211_CHAN_WIDTH_20: | |
2134 | case NL80211_CHAN_WIDTH_40: | |
2135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2136 | cfg80211_get_chandef_type(chandef))) | |
2137 | return -ENOBUFS; | |
2138 | break; | |
2139 | default: | |
2140 | break; | |
2141 | } | |
2142 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2143 | return -ENOBUFS; | |
2144 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2145 | return -ENOBUFS; | |
2146 | if (chandef->center_freq2 && | |
2147 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2148 | return -ENOBUFS; |
2149 | return 0; | |
2150 | } | |
2151 | ||
15e47304 | 2152 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2153 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2154 | struct wireless_dev *wdev) |
55682965 | 2155 | { |
72fb2abc | 2156 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2157 | void *hdr; |
2158 | ||
15e47304 | 2159 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2160 | if (!hdr) |
2161 | return -1; | |
2162 | ||
72fb2abc JB |
2163 | if (dev && |
2164 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2165 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2166 | goto nla_put_failure; |
2167 | ||
2168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2169 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2170 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2171 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2172 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2173 | rdev->devlist_generation ^ | |
2174 | (cfg80211_rdev_list_generation << 2))) | |
2175 | goto nla_put_failure; | |
f5ea9120 | 2176 | |
5b7ccaf3 | 2177 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2178 | int ret; |
2179 | struct cfg80211_chan_def chandef; | |
2180 | ||
2181 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2182 | if (ret == 0) { | |
2183 | if (nl80211_send_chandef(msg, &chandef)) | |
2184 | goto nla_put_failure; | |
2185 | } | |
d91df0e3 PF |
2186 | } |
2187 | ||
b84e7a05 AQ |
2188 | if (wdev->ssid_len) { |
2189 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2190 | goto nla_put_failure; | |
2191 | } | |
2192 | ||
55682965 JB |
2193 | return genlmsg_end(msg, hdr); |
2194 | ||
2195 | nla_put_failure: | |
bc3ed28c TG |
2196 | genlmsg_cancel(msg, hdr); |
2197 | return -EMSGSIZE; | |
55682965 JB |
2198 | } |
2199 | ||
2200 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2201 | { | |
2202 | int wp_idx = 0; | |
2203 | int if_idx = 0; | |
2204 | int wp_start = cb->args[0]; | |
2205 | int if_start = cb->args[1]; | |
f5ea9120 | 2206 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2207 | struct wireless_dev *wdev; |
2208 | ||
a1794390 | 2209 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
2210 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2211 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2212 | continue; |
bba95fef JB |
2213 | if (wp_idx < wp_start) { |
2214 | wp_idx++; | |
55682965 | 2215 | continue; |
bba95fef | 2216 | } |
55682965 JB |
2217 | if_idx = 0; |
2218 | ||
f5ea9120 | 2219 | mutex_lock(&rdev->devlist_mtx); |
89a54e48 | 2220 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2221 | if (if_idx < if_start) { |
2222 | if_idx++; | |
55682965 | 2223 | continue; |
bba95fef | 2224 | } |
15e47304 | 2225 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2226 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2227 | rdev, wdev) < 0) { |
f5ea9120 | 2228 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2229 | goto out; |
2230 | } | |
2231 | if_idx++; | |
55682965 | 2232 | } |
f5ea9120 | 2233 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2234 | |
2235 | wp_idx++; | |
55682965 | 2236 | } |
bba95fef | 2237 | out: |
a1794390 | 2238 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
2239 | |
2240 | cb->args[0] = wp_idx; | |
2241 | cb->args[1] = if_idx; | |
2242 | ||
2243 | return skb->len; | |
2244 | } | |
2245 | ||
2246 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2247 | { | |
2248 | struct sk_buff *msg; | |
4c476991 | 2249 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2250 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2251 | |
fd2120ca | 2252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2253 | if (!msg) |
4c476991 | 2254 | return -ENOMEM; |
55682965 | 2255 | |
15e47304 | 2256 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2257 | dev, wdev) < 0) { |
4c476991 JB |
2258 | nlmsg_free(msg); |
2259 | return -ENOBUFS; | |
2260 | } | |
55682965 | 2261 | |
134e6375 | 2262 | return genlmsg_reply(msg, info); |
55682965 JB |
2263 | } |
2264 | ||
66f7ac50 MW |
2265 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2266 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2267 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2268 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2269 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2270 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
2271 | }; | |
2272 | ||
2273 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2274 | { | |
2275 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2276 | int flag; | |
2277 | ||
2278 | *mntrflags = 0; | |
2279 | ||
2280 | if (!nla) | |
2281 | return -EINVAL; | |
2282 | ||
2283 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2284 | nla, mntr_flags_policy)) | |
2285 | return -EINVAL; | |
2286 | ||
2287 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2288 | if (flags[flag]) | |
2289 | *mntrflags |= (1<<flag); | |
2290 | ||
2291 | return 0; | |
2292 | } | |
2293 | ||
9bc383de | 2294 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2295 | struct net_device *netdev, u8 use_4addr, |
2296 | enum nl80211_iftype iftype) | |
9bc383de | 2297 | { |
ad4bb6f8 | 2298 | if (!use_4addr) { |
f350a0a8 | 2299 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2300 | return -EBUSY; |
9bc383de | 2301 | return 0; |
ad4bb6f8 | 2302 | } |
9bc383de JB |
2303 | |
2304 | switch (iftype) { | |
2305 | case NL80211_IFTYPE_AP_VLAN: | |
2306 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2307 | return 0; | |
2308 | break; | |
2309 | case NL80211_IFTYPE_STATION: | |
2310 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2311 | return 0; | |
2312 | break; | |
2313 | default: | |
2314 | break; | |
2315 | } | |
2316 | ||
2317 | return -EOPNOTSUPP; | |
2318 | } | |
2319 | ||
55682965 JB |
2320 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2321 | { | |
4c476991 | 2322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2323 | struct vif_params params; |
e36d56b6 | 2324 | int err; |
04a773ad | 2325 | enum nl80211_iftype otype, ntype; |
4c476991 | 2326 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2327 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2328 | bool change = false; |
55682965 | 2329 | |
2ec600d6 LCC |
2330 | memset(¶ms, 0, sizeof(params)); |
2331 | ||
04a773ad | 2332 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2333 | |
723b038d | 2334 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2335 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2336 | if (otype != ntype) |
ac7f9cfa | 2337 | change = true; |
4c476991 JB |
2338 | if (ntype > NL80211_IFTYPE_MAX) |
2339 | return -EINVAL; | |
723b038d JB |
2340 | } |
2341 | ||
92ffe055 | 2342 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2343 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2344 | ||
4c476991 JB |
2345 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2346 | return -EINVAL; | |
29cbe68c JB |
2347 | if (netif_running(dev)) |
2348 | return -EBUSY; | |
2349 | ||
2350 | wdev_lock(wdev); | |
2351 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2352 | IEEE80211_MAX_MESH_ID_LEN); | |
2353 | wdev->mesh_id_up_len = | |
2354 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2355 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2356 | wdev->mesh_id_up_len); | |
2357 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2358 | } |
2359 | ||
8b787643 FF |
2360 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2361 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2362 | change = true; | |
ad4bb6f8 | 2363 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2364 | if (err) |
4c476991 | 2365 | return err; |
8b787643 FF |
2366 | } else { |
2367 | params.use_4addr = -1; | |
2368 | } | |
2369 | ||
92ffe055 | 2370 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2371 | if (ntype != NL80211_IFTYPE_MONITOR) |
2372 | return -EINVAL; | |
92ffe055 JB |
2373 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2374 | &_flags); | |
ac7f9cfa | 2375 | if (err) |
4c476991 | 2376 | return err; |
ac7f9cfa JB |
2377 | |
2378 | flags = &_flags; | |
2379 | change = true; | |
92ffe055 | 2380 | } |
3b85875a | 2381 | |
ac7f9cfa | 2382 | if (change) |
3d54d255 | 2383 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2384 | else |
2385 | err = 0; | |
60719ffd | 2386 | |
9bc383de JB |
2387 | if (!err && params.use_4addr != -1) |
2388 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2389 | ||
55682965 JB |
2390 | return err; |
2391 | } | |
2392 | ||
2393 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2394 | { | |
4c476991 | 2395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2396 | struct vif_params params; |
84efbb84 | 2397 | struct wireless_dev *wdev; |
1c90f9d4 | 2398 | struct sk_buff *msg; |
55682965 JB |
2399 | int err; |
2400 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2401 | u32 flags; |
55682965 | 2402 | |
2ec600d6 LCC |
2403 | memset(¶ms, 0, sizeof(params)); |
2404 | ||
55682965 JB |
2405 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2406 | return -EINVAL; | |
2407 | ||
2408 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2409 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2410 | if (type > NL80211_IFTYPE_MAX) | |
2411 | return -EINVAL; | |
2412 | } | |
2413 | ||
79c97e97 | 2414 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2415 | !(rdev->wiphy.interface_modes & (1 << type))) |
2416 | return -EOPNOTSUPP; | |
55682965 | 2417 | |
1c18f145 AS |
2418 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2419 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2420 | ETH_ALEN); | |
2421 | if (!is_valid_ether_addr(params.macaddr)) | |
2422 | return -EADDRNOTAVAIL; | |
2423 | } | |
2424 | ||
9bc383de | 2425 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2426 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2427 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2428 | if (err) |
4c476991 | 2429 | return err; |
9bc383de | 2430 | } |
8b787643 | 2431 | |
1c90f9d4 JB |
2432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2433 | if (!msg) | |
2434 | return -ENOMEM; | |
2435 | ||
66f7ac50 MW |
2436 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2437 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2438 | &flags); | |
e35e4d28 HG |
2439 | wdev = rdev_add_virtual_intf(rdev, |
2440 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2441 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2442 | if (IS_ERR(wdev)) { |
2443 | nlmsg_free(msg); | |
84efbb84 | 2444 | return PTR_ERR(wdev); |
1c90f9d4 | 2445 | } |
2ec600d6 | 2446 | |
98104fde JB |
2447 | switch (type) { |
2448 | case NL80211_IFTYPE_MESH_POINT: | |
2449 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2450 | break; | |
29cbe68c JB |
2451 | wdev_lock(wdev); |
2452 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2453 | IEEE80211_MAX_MESH_ID_LEN); | |
2454 | wdev->mesh_id_up_len = | |
2455 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2456 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2457 | wdev->mesh_id_up_len); | |
2458 | wdev_unlock(wdev); | |
98104fde JB |
2459 | break; |
2460 | case NL80211_IFTYPE_P2P_DEVICE: | |
2461 | /* | |
2462 | * P2P Device doesn't have a netdev, so doesn't go | |
2463 | * through the netdev notifier and must be added here | |
2464 | */ | |
2465 | mutex_init(&wdev->mtx); | |
2466 | INIT_LIST_HEAD(&wdev->event_list); | |
2467 | spin_lock_init(&wdev->event_lock); | |
2468 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2469 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2470 | ||
2471 | mutex_lock(&rdev->devlist_mtx); | |
2472 | wdev->identifier = ++rdev->wdev_id; | |
2473 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2474 | rdev->devlist_generation++; | |
2475 | mutex_unlock(&rdev->devlist_mtx); | |
2476 | break; | |
2477 | default: | |
2478 | break; | |
29cbe68c JB |
2479 | } |
2480 | ||
15e47304 | 2481 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2482 | rdev, wdev) < 0) { |
2483 | nlmsg_free(msg); | |
2484 | return -ENOBUFS; | |
2485 | } | |
2486 | ||
2487 | return genlmsg_reply(msg, info); | |
55682965 JB |
2488 | } |
2489 | ||
2490 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2491 | { | |
4c476991 | 2492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2493 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2494 | |
4c476991 JB |
2495 | if (!rdev->ops->del_virtual_intf) |
2496 | return -EOPNOTSUPP; | |
55682965 | 2497 | |
84efbb84 JB |
2498 | /* |
2499 | * If we remove a wireless device without a netdev then clear | |
2500 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2501 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2502 | * since the wdev has been freed, unlike with a netdev where | |
2503 | * we need the dev_put() for the netdev to really be freed. | |
2504 | */ | |
2505 | if (!wdev->netdev) | |
2506 | info->user_ptr[1] = NULL; | |
2507 | ||
e35e4d28 | 2508 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2509 | } |
2510 | ||
1d9d9213 SW |
2511 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2512 | { | |
2513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2514 | struct net_device *dev = info->user_ptr[1]; | |
2515 | u16 noack_map; | |
2516 | ||
2517 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2518 | return -EINVAL; | |
2519 | ||
2520 | if (!rdev->ops->set_noack_map) | |
2521 | return -EOPNOTSUPP; | |
2522 | ||
2523 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2524 | ||
e35e4d28 | 2525 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2526 | } |
2527 | ||
41ade00f JB |
2528 | struct get_key_cookie { |
2529 | struct sk_buff *msg; | |
2530 | int error; | |
b9454e83 | 2531 | int idx; |
41ade00f JB |
2532 | }; |
2533 | ||
2534 | static void get_key_callback(void *c, struct key_params *params) | |
2535 | { | |
b9454e83 | 2536 | struct nlattr *key; |
41ade00f JB |
2537 | struct get_key_cookie *cookie = c; |
2538 | ||
9360ffd1 DM |
2539 | if ((params->key && |
2540 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2541 | params->key_len, params->key)) || | |
2542 | (params->seq && | |
2543 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2544 | params->seq_len, params->seq)) || | |
2545 | (params->cipher && | |
2546 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2547 | params->cipher))) | |
2548 | goto nla_put_failure; | |
41ade00f | 2549 | |
b9454e83 JB |
2550 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2551 | if (!key) | |
2552 | goto nla_put_failure; | |
2553 | ||
9360ffd1 DM |
2554 | if ((params->key && |
2555 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2556 | params->key_len, params->key)) || | |
2557 | (params->seq && | |
2558 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2559 | params->seq_len, params->seq)) || | |
2560 | (params->cipher && | |
2561 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2562 | params->cipher))) | |
2563 | goto nla_put_failure; | |
b9454e83 | 2564 | |
9360ffd1 DM |
2565 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2566 | goto nla_put_failure; | |
b9454e83 JB |
2567 | |
2568 | nla_nest_end(cookie->msg, key); | |
2569 | ||
41ade00f JB |
2570 | return; |
2571 | nla_put_failure: | |
2572 | cookie->error = 1; | |
2573 | } | |
2574 | ||
2575 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2576 | { | |
4c476991 | 2577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2578 | int err; |
4c476991 | 2579 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2580 | u8 key_idx = 0; |
e31b8213 JB |
2581 | const u8 *mac_addr = NULL; |
2582 | bool pairwise; | |
41ade00f JB |
2583 | struct get_key_cookie cookie = { |
2584 | .error = 0, | |
2585 | }; | |
2586 | void *hdr; | |
2587 | struct sk_buff *msg; | |
2588 | ||
2589 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2590 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2591 | ||
3cfcf6ac | 2592 | if (key_idx > 5) |
41ade00f JB |
2593 | return -EINVAL; |
2594 | ||
2595 | if (info->attrs[NL80211_ATTR_MAC]) | |
2596 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2597 | ||
e31b8213 JB |
2598 | pairwise = !!mac_addr; |
2599 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2600 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2601 | if (kt >= NUM_NL80211_KEYTYPES) | |
2602 | return -EINVAL; | |
2603 | if (kt != NL80211_KEYTYPE_GROUP && | |
2604 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2605 | return -EINVAL; | |
2606 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2607 | } | |
2608 | ||
4c476991 JB |
2609 | if (!rdev->ops->get_key) |
2610 | return -EOPNOTSUPP; | |
41ade00f | 2611 | |
fd2120ca | 2612 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2613 | if (!msg) |
2614 | return -ENOMEM; | |
41ade00f | 2615 | |
15e47304 | 2616 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2617 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2618 | if (IS_ERR(hdr)) |
2619 | return PTR_ERR(hdr); | |
41ade00f JB |
2620 | |
2621 | cookie.msg = msg; | |
b9454e83 | 2622 | cookie.idx = key_idx; |
41ade00f | 2623 | |
9360ffd1 DM |
2624 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2625 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2626 | goto nla_put_failure; | |
2627 | if (mac_addr && | |
2628 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2629 | goto nla_put_failure; | |
41ade00f | 2630 | |
e31b8213 JB |
2631 | if (pairwise && mac_addr && |
2632 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2633 | return -ENOENT; | |
2634 | ||
e35e4d28 HG |
2635 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2636 | get_key_callback); | |
41ade00f JB |
2637 | |
2638 | if (err) | |
6c95e2a2 | 2639 | goto free_msg; |
41ade00f JB |
2640 | |
2641 | if (cookie.error) | |
2642 | goto nla_put_failure; | |
2643 | ||
2644 | genlmsg_end(msg, hdr); | |
4c476991 | 2645 | return genlmsg_reply(msg, info); |
41ade00f JB |
2646 | |
2647 | nla_put_failure: | |
2648 | err = -ENOBUFS; | |
6c95e2a2 | 2649 | free_msg: |
41ade00f | 2650 | nlmsg_free(msg); |
41ade00f JB |
2651 | return err; |
2652 | } | |
2653 | ||
2654 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2655 | { | |
4c476991 | 2656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2657 | struct key_parse key; |
41ade00f | 2658 | int err; |
4c476991 | 2659 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2660 | |
b9454e83 JB |
2661 | err = nl80211_parse_key(info, &key); |
2662 | if (err) | |
2663 | return err; | |
41ade00f | 2664 | |
b9454e83 | 2665 | if (key.idx < 0) |
41ade00f JB |
2666 | return -EINVAL; |
2667 | ||
b9454e83 JB |
2668 | /* only support setting default key */ |
2669 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2670 | return -EINVAL; |
2671 | ||
dbd2fd65 | 2672 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2673 | |
dbd2fd65 JB |
2674 | if (key.def) { |
2675 | if (!rdev->ops->set_default_key) { | |
2676 | err = -EOPNOTSUPP; | |
2677 | goto out; | |
2678 | } | |
41ade00f | 2679 | |
dbd2fd65 JB |
2680 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2681 | if (err) | |
2682 | goto out; | |
2683 | ||
e35e4d28 | 2684 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2685 | key.def_uni, key.def_multi); |
2686 | ||
2687 | if (err) | |
2688 | goto out; | |
fffd0934 | 2689 | |
3d23e349 | 2690 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2691 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2692 | #endif | |
2693 | } else { | |
2694 | if (key.def_uni || !key.def_multi) { | |
2695 | err = -EINVAL; | |
2696 | goto out; | |
2697 | } | |
2698 | ||
2699 | if (!rdev->ops->set_default_mgmt_key) { | |
2700 | err = -EOPNOTSUPP; | |
2701 | goto out; | |
2702 | } | |
2703 | ||
2704 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2705 | if (err) | |
2706 | goto out; | |
2707 | ||
e35e4d28 | 2708 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2709 | if (err) |
2710 | goto out; | |
2711 | ||
2712 | #ifdef CONFIG_CFG80211_WEXT | |
2713 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2714 | #endif |
dbd2fd65 JB |
2715 | } |
2716 | ||
2717 | out: | |
fffd0934 | 2718 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2719 | |
41ade00f JB |
2720 | return err; |
2721 | } | |
2722 | ||
2723 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2724 | { | |
4c476991 | 2725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2726 | int err; |
4c476991 | 2727 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2728 | struct key_parse key; |
e31b8213 | 2729 | const u8 *mac_addr = NULL; |
41ade00f | 2730 | |
b9454e83 JB |
2731 | err = nl80211_parse_key(info, &key); |
2732 | if (err) | |
2733 | return err; | |
41ade00f | 2734 | |
b9454e83 | 2735 | if (!key.p.key) |
41ade00f JB |
2736 | return -EINVAL; |
2737 | ||
41ade00f JB |
2738 | if (info->attrs[NL80211_ATTR_MAC]) |
2739 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2740 | ||
e31b8213 JB |
2741 | if (key.type == -1) { |
2742 | if (mac_addr) | |
2743 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2744 | else | |
2745 | key.type = NL80211_KEYTYPE_GROUP; | |
2746 | } | |
2747 | ||
2748 | /* for now */ | |
2749 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2750 | key.type != NL80211_KEYTYPE_GROUP) | |
2751 | return -EINVAL; | |
2752 | ||
4c476991 JB |
2753 | if (!rdev->ops->add_key) |
2754 | return -EOPNOTSUPP; | |
25e47c18 | 2755 | |
e31b8213 JB |
2756 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2757 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2758 | mac_addr)) | |
4c476991 | 2759 | return -EINVAL; |
41ade00f | 2760 | |
fffd0934 JB |
2761 | wdev_lock(dev->ieee80211_ptr); |
2762 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2763 | if (!err) | |
e35e4d28 HG |
2764 | err = rdev_add_key(rdev, dev, key.idx, |
2765 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2766 | mac_addr, &key.p); | |
fffd0934 | 2767 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2768 | |
41ade00f JB |
2769 | return err; |
2770 | } | |
2771 | ||
2772 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2773 | { | |
4c476991 | 2774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2775 | int err; |
4c476991 | 2776 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2777 | u8 *mac_addr = NULL; |
b9454e83 | 2778 | struct key_parse key; |
41ade00f | 2779 | |
b9454e83 JB |
2780 | err = nl80211_parse_key(info, &key); |
2781 | if (err) | |
2782 | return err; | |
41ade00f JB |
2783 | |
2784 | if (info->attrs[NL80211_ATTR_MAC]) | |
2785 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2786 | ||
e31b8213 JB |
2787 | if (key.type == -1) { |
2788 | if (mac_addr) | |
2789 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2790 | else | |
2791 | key.type = NL80211_KEYTYPE_GROUP; | |
2792 | } | |
2793 | ||
2794 | /* for now */ | |
2795 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2796 | key.type != NL80211_KEYTYPE_GROUP) | |
2797 | return -EINVAL; | |
2798 | ||
4c476991 JB |
2799 | if (!rdev->ops->del_key) |
2800 | return -EOPNOTSUPP; | |
41ade00f | 2801 | |
fffd0934 JB |
2802 | wdev_lock(dev->ieee80211_ptr); |
2803 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2804 | |
2805 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2806 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2807 | err = -ENOENT; | |
2808 | ||
fffd0934 | 2809 | if (!err) |
e35e4d28 HG |
2810 | err = rdev_del_key(rdev, dev, key.idx, |
2811 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2812 | mac_addr); | |
41ade00f | 2813 | |
3d23e349 | 2814 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2815 | if (!err) { |
b9454e83 | 2816 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2817 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2818 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2819 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2820 | } | |
2821 | #endif | |
fffd0934 | 2822 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2823 | |
41ade00f JB |
2824 | return err; |
2825 | } | |
2826 | ||
77765eaf VT |
2827 | /* This function returns an error or the number of nested attributes */ |
2828 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2829 | { | |
2830 | struct nlattr *attr; | |
2831 | int n_entries = 0, tmp; | |
2832 | ||
2833 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2834 | if (nla_len(attr) != ETH_ALEN) | |
2835 | return -EINVAL; | |
2836 | ||
2837 | n_entries++; | |
2838 | } | |
2839 | ||
2840 | return n_entries; | |
2841 | } | |
2842 | ||
2843 | /* | |
2844 | * This function parses ACL information and allocates memory for ACL data. | |
2845 | * On successful return, the calling function is responsible to free the | |
2846 | * ACL buffer returned by this function. | |
2847 | */ | |
2848 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2849 | struct genl_info *info) | |
2850 | { | |
2851 | enum nl80211_acl_policy acl_policy; | |
2852 | struct nlattr *attr; | |
2853 | struct cfg80211_acl_data *acl; | |
2854 | int i = 0, n_entries, tmp; | |
2855 | ||
2856 | if (!wiphy->max_acl_mac_addrs) | |
2857 | return ERR_PTR(-EOPNOTSUPP); | |
2858 | ||
2859 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2860 | return ERR_PTR(-EINVAL); | |
2861 | ||
2862 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2863 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2864 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2865 | return ERR_PTR(-EINVAL); | |
2866 | ||
2867 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2868 | return ERR_PTR(-EINVAL); | |
2869 | ||
2870 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2871 | if (n_entries < 0) | |
2872 | return ERR_PTR(n_entries); | |
2873 | ||
2874 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2875 | return ERR_PTR(-ENOTSUPP); | |
2876 | ||
2877 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2878 | GFP_KERNEL); | |
2879 | if (!acl) | |
2880 | return ERR_PTR(-ENOMEM); | |
2881 | ||
2882 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2883 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2884 | i++; | |
2885 | } | |
2886 | ||
2887 | acl->n_acl_entries = n_entries; | |
2888 | acl->acl_policy = acl_policy; | |
2889 | ||
2890 | return acl; | |
2891 | } | |
2892 | ||
2893 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2894 | { | |
2895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2896 | struct net_device *dev = info->user_ptr[1]; | |
2897 | struct cfg80211_acl_data *acl; | |
2898 | int err; | |
2899 | ||
2900 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2901 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2902 | return -EOPNOTSUPP; | |
2903 | ||
2904 | if (!dev->ieee80211_ptr->beacon_interval) | |
2905 | return -EINVAL; | |
2906 | ||
2907 | acl = parse_acl_data(&rdev->wiphy, info); | |
2908 | if (IS_ERR(acl)) | |
2909 | return PTR_ERR(acl); | |
2910 | ||
2911 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2912 | ||
2913 | kfree(acl); | |
2914 | ||
2915 | return err; | |
2916 | } | |
2917 | ||
8860020e JB |
2918 | static int nl80211_parse_beacon(struct genl_info *info, |
2919 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2920 | { |
8860020e | 2921 | bool haveinfo = false; |
ed1b6cc7 | 2922 | |
9946ecfb JM |
2923 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2924 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2925 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2926 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2927 | return -EINVAL; |
2928 | ||
8860020e | 2929 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2930 | |
ed1b6cc7 | 2931 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2932 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2933 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2934 | if (!bcn->head_len) | |
2935 | return -EINVAL; | |
2936 | haveinfo = true; | |
ed1b6cc7 JB |
2937 | } |
2938 | ||
2939 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2940 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2941 | bcn->tail_len = | |
ed1b6cc7 | 2942 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2943 | haveinfo = true; |
ed1b6cc7 JB |
2944 | } |
2945 | ||
4c476991 JB |
2946 | if (!haveinfo) |
2947 | return -EINVAL; | |
3b85875a | 2948 | |
9946ecfb | 2949 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2950 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2951 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2952 | } |
2953 | ||
2954 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2955 | bcn->proberesp_ies = |
9946ecfb | 2956 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2957 | bcn->proberesp_ies_len = |
9946ecfb JM |
2958 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2959 | } | |
2960 | ||
2961 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2962 | bcn->assocresp_ies = |
9946ecfb | 2963 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2964 | bcn->assocresp_ies_len = |
9946ecfb JM |
2965 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2966 | } | |
2967 | ||
00f740e1 | 2968 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2969 | bcn->probe_resp = |
00f740e1 | 2970 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2971 | bcn->probe_resp_len = |
00f740e1 AN |
2972 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2973 | } | |
2974 | ||
8860020e JB |
2975 | return 0; |
2976 | } | |
2977 | ||
46c1dd0c FF |
2978 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2979 | struct cfg80211_ap_settings *params) | |
2980 | { | |
2981 | struct wireless_dev *wdev; | |
2982 | bool ret = false; | |
2983 | ||
2984 | mutex_lock(&rdev->devlist_mtx); | |
2985 | ||
89a54e48 | 2986 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
2987 | if (wdev->iftype != NL80211_IFTYPE_AP && |
2988 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2989 | continue; | |
2990 | ||
683b6d3b | 2991 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
2992 | continue; |
2993 | ||
683b6d3b | 2994 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
2995 | ret = true; |
2996 | break; | |
2997 | } | |
2998 | ||
2999 | mutex_unlock(&rdev->devlist_mtx); | |
3000 | ||
3001 | return ret; | |
3002 | } | |
3003 | ||
e39e5b5e JM |
3004 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3005 | enum nl80211_auth_type auth_type, | |
3006 | enum nl80211_commands cmd) | |
3007 | { | |
3008 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3009 | return false; | |
3010 | ||
3011 | switch (cmd) { | |
3012 | case NL80211_CMD_AUTHENTICATE: | |
3013 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3014 | auth_type == NL80211_AUTHTYPE_SAE) | |
3015 | return false; | |
3016 | return true; | |
3017 | case NL80211_CMD_CONNECT: | |
3018 | case NL80211_CMD_START_AP: | |
3019 | /* SAE not supported yet */ | |
3020 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3021 | return false; | |
3022 | return true; | |
3023 | default: | |
3024 | return false; | |
3025 | } | |
3026 | } | |
3027 | ||
8860020e JB |
3028 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3029 | { | |
3030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3031 | struct net_device *dev = info->user_ptr[1]; | |
3032 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3033 | struct cfg80211_ap_settings params; | |
3034 | int err; | |
04f39047 | 3035 | u8 radar_detect_width = 0; |
8860020e JB |
3036 | |
3037 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3038 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3039 | return -EOPNOTSUPP; | |
3040 | ||
3041 | if (!rdev->ops->start_ap) | |
3042 | return -EOPNOTSUPP; | |
3043 | ||
3044 | if (wdev->beacon_interval) | |
3045 | return -EALREADY; | |
3046 | ||
3047 | memset(¶ms, 0, sizeof(params)); | |
3048 | ||
3049 | /* these are required for START_AP */ | |
3050 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3051 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3052 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3053 | return -EINVAL; | |
3054 | ||
3055 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
3056 | if (err) | |
3057 | return err; | |
3058 | ||
3059 | params.beacon_interval = | |
3060 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3061 | params.dtim_period = | |
3062 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3063 | ||
3064 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3065 | if (err) | |
3066 | return err; | |
3067 | ||
3068 | /* | |
3069 | * In theory, some of these attributes should be required here | |
3070 | * but since they were not used when the command was originally | |
3071 | * added, keep them optional for old user space programs to let | |
3072 | * them continue to work with drivers that do not need the | |
3073 | * additional information -- drivers must check! | |
3074 | */ | |
3075 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3076 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3077 | params.ssid_len = | |
3078 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3079 | if (params.ssid_len == 0 || | |
3080 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3081 | return -EINVAL; | |
3082 | } | |
3083 | ||
3084 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3085 | params.hidden_ssid = nla_get_u32( | |
3086 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3087 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3088 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3089 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3090 | return -EINVAL; | |
3091 | } | |
3092 | ||
3093 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3094 | ||
3095 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3096 | params.auth_type = nla_get_u32( | |
3097 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3098 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3099 | NL80211_CMD_START_AP)) | |
8860020e JB |
3100 | return -EINVAL; |
3101 | } else | |
3102 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3103 | ||
3104 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3105 | NL80211_MAX_NR_CIPHER_SUITES); | |
3106 | if (err) | |
3107 | return err; | |
3108 | ||
1b658f11 VT |
3109 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3110 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3111 | return -EOPNOTSUPP; | |
3112 | params.inactivity_timeout = nla_get_u16( | |
3113 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3114 | } | |
3115 | ||
53cabad7 JB |
3116 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3117 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3118 | return -EINVAL; | |
3119 | params.p2p_ctwindow = | |
3120 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3121 | if (params.p2p_ctwindow > 127) | |
3122 | return -EINVAL; | |
3123 | if (params.p2p_ctwindow != 0 && | |
3124 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3125 | return -EINVAL; | |
3126 | } | |
3127 | ||
3128 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3129 | u8 tmp; | |
3130 | ||
3131 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3132 | return -EINVAL; | |
3133 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3134 | if (tmp > 1) | |
3135 | return -EINVAL; | |
3136 | params.p2p_opp_ps = tmp; | |
3137 | if (params.p2p_opp_ps != 0 && | |
3138 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3139 | return -EINVAL; | |
3140 | } | |
3141 | ||
aa430da4 | 3142 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3143 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3144 | if (err) | |
3145 | return err; | |
3146 | } else if (wdev->preset_chandef.chan) { | |
3147 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3148 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3149 | return -EINVAL; |
3150 | ||
683b6d3b | 3151 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3152 | return -EINVAL; |
3153 | ||
04f39047 SW |
3154 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3155 | if (err < 0) | |
3156 | return err; | |
3157 | if (err) { | |
3158 | radar_detect_width = BIT(params.chandef.width); | |
3159 | params.radar_required = true; | |
3160 | } | |
3161 | ||
e4e32459 | 3162 | mutex_lock(&rdev->devlist_mtx); |
04f39047 SW |
3163 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3164 | params.chandef.chan, | |
3165 | CHAN_MODE_SHARED, | |
3166 | radar_detect_width); | |
e4e32459 MK |
3167 | mutex_unlock(&rdev->devlist_mtx); |
3168 | ||
3169 | if (err) | |
3170 | return err; | |
3171 | ||
77765eaf VT |
3172 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3173 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3174 | if (IS_ERR(params.acl)) | |
3175 | return PTR_ERR(params.acl); | |
3176 | } | |
3177 | ||
e35e4d28 | 3178 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3179 | if (!err) { |
683b6d3b | 3180 | wdev->preset_chandef = params.chandef; |
8860020e | 3181 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3182 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3183 | wdev->ssid_len = params.ssid_len; |
3184 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3185 | } |
77765eaf VT |
3186 | |
3187 | kfree(params.acl); | |
3188 | ||
56d1893d | 3189 | return err; |
ed1b6cc7 JB |
3190 | } |
3191 | ||
8860020e JB |
3192 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3193 | { | |
3194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3195 | struct net_device *dev = info->user_ptr[1]; | |
3196 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3197 | struct cfg80211_beacon_data params; | |
3198 | int err; | |
3199 | ||
3200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3202 | return -EOPNOTSUPP; | |
3203 | ||
3204 | if (!rdev->ops->change_beacon) | |
3205 | return -EOPNOTSUPP; | |
3206 | ||
3207 | if (!wdev->beacon_interval) | |
3208 | return -EINVAL; | |
3209 | ||
3210 | err = nl80211_parse_beacon(info, ¶ms); | |
3211 | if (err) | |
3212 | return err; | |
3213 | ||
e35e4d28 | 3214 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3215 | } |
3216 | ||
3217 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3218 | { |
4c476991 JB |
3219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3220 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3221 | |
60771780 | 3222 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3223 | } |
3224 | ||
5727ef1b JB |
3225 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3226 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3227 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3228 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3229 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3230 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3231 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3232 | }; |
3233 | ||
eccb8e8f | 3234 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3235 | enum nl80211_iftype iftype, |
eccb8e8f | 3236 | struct station_parameters *params) |
5727ef1b JB |
3237 | { |
3238 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3239 | struct nlattr *nla; |
5727ef1b JB |
3240 | int flag; |
3241 | ||
eccb8e8f JB |
3242 | /* |
3243 | * Try parsing the new attribute first so userspace | |
3244 | * can specify both for older kernels. | |
3245 | */ | |
3246 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3247 | if (nla) { | |
3248 | struct nl80211_sta_flag_update *sta_flags; | |
3249 | ||
3250 | sta_flags = nla_data(nla); | |
3251 | params->sta_flags_mask = sta_flags->mask; | |
3252 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3253 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3254 | if ((params->sta_flags_mask | |
3255 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3256 | return -EINVAL; | |
3257 | return 0; | |
3258 | } | |
3259 | ||
3260 | /* if present, parse the old attribute */ | |
5727ef1b | 3261 | |
eccb8e8f | 3262 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3263 | if (!nla) |
3264 | return 0; | |
3265 | ||
3266 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3267 | nla, sta_flags_policy)) | |
3268 | return -EINVAL; | |
3269 | ||
bdd3ae3d JB |
3270 | /* |
3271 | * Only allow certain flags for interface types so that | |
3272 | * other attributes are silently ignored. Remember that | |
3273 | * this is backward compatibility code with old userspace | |
3274 | * and shouldn't be hit in other cases anyway. | |
3275 | */ | |
3276 | switch (iftype) { | |
3277 | case NL80211_IFTYPE_AP: | |
3278 | case NL80211_IFTYPE_AP_VLAN: | |
3279 | case NL80211_IFTYPE_P2P_GO: | |
3280 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3281 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3282 | BIT(NL80211_STA_FLAG_WME) | | |
3283 | BIT(NL80211_STA_FLAG_MFP); | |
3284 | break; | |
3285 | case NL80211_IFTYPE_P2P_CLIENT: | |
3286 | case NL80211_IFTYPE_STATION: | |
3287 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3288 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3289 | break; | |
3290 | case NL80211_IFTYPE_MESH_POINT: | |
3291 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3292 | BIT(NL80211_STA_FLAG_MFP) | | |
3293 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3294 | default: | |
3295 | return -EINVAL; | |
3296 | } | |
5727ef1b | 3297 | |
3383b5a6 JB |
3298 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3299 | if (flags[flag]) { | |
eccb8e8f | 3300 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3301 | |
3383b5a6 JB |
3302 | /* no longer support new API additions in old API */ |
3303 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3304 | return -EINVAL; | |
3305 | } | |
3306 | } | |
3307 | ||
5727ef1b JB |
3308 | return 0; |
3309 | } | |
3310 | ||
c8dcfd8a FF |
3311 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3312 | int attr) | |
3313 | { | |
3314 | struct nlattr *rate; | |
8eb41c8d VK |
3315 | u32 bitrate; |
3316 | u16 bitrate_compat; | |
c8dcfd8a FF |
3317 | |
3318 | rate = nla_nest_start(msg, attr); | |
3319 | if (!rate) | |
db9c64cf | 3320 | return false; |
c8dcfd8a FF |
3321 | |
3322 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3323 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3324 | /* report 16-bit bitrate only if we can */ |
3325 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3326 | if (bitrate > 0 && |
3327 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3328 | return false; | |
3329 | if (bitrate_compat > 0 && | |
3330 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3331 | return false; | |
3332 | ||
3333 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3334 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3335 | return false; | |
3336 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3337 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3338 | return false; | |
3339 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3340 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3341 | return false; | |
3342 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3343 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3344 | return false; | |
3345 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3346 | return false; | |
3347 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3348 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3349 | return false; | |
3350 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3351 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3352 | return false; | |
3353 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3354 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3355 | return false; | |
3356 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3357 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3358 | return false; | |
3359 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3360 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3361 | return false; | |
3362 | } | |
c8dcfd8a FF |
3363 | |
3364 | nla_nest_end(msg, rate); | |
3365 | return true; | |
c8dcfd8a FF |
3366 | } |
3367 | ||
15e47304 | 3368 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3369 | int flags, |
3370 | struct cfg80211_registered_device *rdev, | |
3371 | struct net_device *dev, | |
98b62183 | 3372 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3373 | { |
3374 | void *hdr; | |
f4263c98 | 3375 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3376 | |
15e47304 | 3377 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3378 | if (!hdr) |
3379 | return -1; | |
3380 | ||
9360ffd1 DM |
3381 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3382 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3383 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3384 | goto nla_put_failure; | |
f5ea9120 | 3385 | |
2ec600d6 LCC |
3386 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3387 | if (!sinfoattr) | |
fd5b74dc | 3388 | goto nla_put_failure; |
9360ffd1 DM |
3389 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3390 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3391 | sinfo->connected_time)) | |
3392 | goto nla_put_failure; | |
3393 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3394 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3395 | sinfo->inactive_time)) | |
3396 | goto nla_put_failure; | |
42745e03 VK |
3397 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3398 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3399 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3400 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3401 | goto nla_put_failure; |
42745e03 VK |
3402 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
3403 | NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3404 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3405 | (u32)sinfo->tx_bytes)) |
3406 | goto nla_put_failure; | |
3407 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3408 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3409 | sinfo->rx_bytes)) | |
3410 | goto nla_put_failure; | |
3411 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3412 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3413 | sinfo->tx_bytes)) |
3414 | goto nla_put_failure; | |
3415 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3416 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3417 | goto nla_put_failure; | |
3418 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3419 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3420 | goto nla_put_failure; | |
3421 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3422 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3423 | sinfo->plink_state)) | |
3424 | goto nla_put_failure; | |
66266b3a JL |
3425 | switch (rdev->wiphy.signal_type) { |
3426 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3427 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3428 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3429 | sinfo->signal)) | |
3430 | goto nla_put_failure; | |
3431 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3432 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3433 | sinfo->signal_avg)) | |
3434 | goto nla_put_failure; | |
66266b3a JL |
3435 | break; |
3436 | default: | |
3437 | break; | |
3438 | } | |
420e7fab | 3439 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3440 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3441 | NL80211_STA_INFO_TX_BITRATE)) | |
3442 | goto nla_put_failure; | |
3443 | } | |
3444 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3445 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3446 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3447 | goto nla_put_failure; |
420e7fab | 3448 | } |
9360ffd1 DM |
3449 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3450 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3451 | sinfo->rx_packets)) | |
3452 | goto nla_put_failure; | |
3453 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3454 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3455 | sinfo->tx_packets)) | |
3456 | goto nla_put_failure; | |
3457 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3458 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3459 | sinfo->tx_retries)) | |
3460 | goto nla_put_failure; | |
3461 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3462 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3463 | sinfo->tx_failed)) | |
3464 | goto nla_put_failure; | |
3465 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3466 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3467 | sinfo->beacon_loss_count)) | |
3468 | goto nla_put_failure; | |
3b1c5a53 MP |
3469 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3470 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3471 | sinfo->local_pm)) | |
3472 | goto nla_put_failure; | |
3473 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3474 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3475 | sinfo->peer_pm)) | |
3476 | goto nla_put_failure; | |
3477 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3478 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3479 | sinfo->nonpeer_pm)) | |
3480 | goto nla_put_failure; | |
f4263c98 PS |
3481 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3482 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3483 | if (!bss_param) | |
3484 | goto nla_put_failure; | |
3485 | ||
9360ffd1 DM |
3486 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3487 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3488 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3489 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3490 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3491 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3492 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3493 | sinfo->bss_param.dtim_period) || | |
3494 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3495 | sinfo->bss_param.beacon_interval)) | |
3496 | goto nla_put_failure; | |
f4263c98 PS |
3497 | |
3498 | nla_nest_end(msg, bss_param); | |
3499 | } | |
9360ffd1 DM |
3500 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3501 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3502 | sizeof(struct nl80211_sta_flag_update), | |
3503 | &sinfo->sta_flags)) | |
3504 | goto nla_put_failure; | |
7eab0f64 JL |
3505 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3506 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3507 | sinfo->t_offset)) | |
3508 | goto nla_put_failure; | |
2ec600d6 | 3509 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3510 | |
9360ffd1 DM |
3511 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3512 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3513 | sinfo->assoc_req_ies)) | |
3514 | goto nla_put_failure; | |
50d3dfb7 | 3515 | |
fd5b74dc JB |
3516 | return genlmsg_end(msg, hdr); |
3517 | ||
3518 | nla_put_failure: | |
bc3ed28c TG |
3519 | genlmsg_cancel(msg, hdr); |
3520 | return -EMSGSIZE; | |
fd5b74dc JB |
3521 | } |
3522 | ||
2ec600d6 | 3523 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3524 | struct netlink_callback *cb) |
2ec600d6 | 3525 | { |
2ec600d6 LCC |
3526 | struct station_info sinfo; |
3527 | struct cfg80211_registered_device *dev; | |
bba95fef | 3528 | struct net_device *netdev; |
2ec600d6 | 3529 | u8 mac_addr[ETH_ALEN]; |
bba95fef | 3530 | int sta_idx = cb->args[1]; |
2ec600d6 | 3531 | int err; |
2ec600d6 | 3532 | |
67748893 JB |
3533 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3534 | if (err) | |
3535 | return err; | |
bba95fef JB |
3536 | |
3537 | if (!dev->ops->dump_station) { | |
eec60b03 | 3538 | err = -EOPNOTSUPP; |
bba95fef JB |
3539 | goto out_err; |
3540 | } | |
3541 | ||
bba95fef | 3542 | while (1) { |
f612cedf | 3543 | memset(&sinfo, 0, sizeof(sinfo)); |
e35e4d28 HG |
3544 | err = rdev_dump_station(dev, netdev, sta_idx, |
3545 | mac_addr, &sinfo); | |
bba95fef JB |
3546 | if (err == -ENOENT) |
3547 | break; | |
3548 | if (err) | |
3b85875a | 3549 | goto out_err; |
bba95fef JB |
3550 | |
3551 | if (nl80211_send_station(skb, | |
15e47304 | 3552 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3553 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
66266b3a | 3554 | dev, netdev, mac_addr, |
bba95fef JB |
3555 | &sinfo) < 0) |
3556 | goto out; | |
3557 | ||
3558 | sta_idx++; | |
3559 | } | |
3560 | ||
3561 | ||
3562 | out: | |
3563 | cb->args[1] = sta_idx; | |
3564 | err = skb->len; | |
bba95fef | 3565 | out_err: |
67748893 | 3566 | nl80211_finish_netdev_dump(dev); |
bba95fef JB |
3567 | |
3568 | return err; | |
2ec600d6 | 3569 | } |
fd5b74dc | 3570 | |
5727ef1b JB |
3571 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3572 | { | |
4c476991 JB |
3573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3574 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3575 | struct station_info sinfo; |
fd5b74dc JB |
3576 | struct sk_buff *msg; |
3577 | u8 *mac_addr = NULL; | |
4c476991 | 3578 | int err; |
fd5b74dc | 3579 | |
2ec600d6 | 3580 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3581 | |
3582 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3583 | return -EINVAL; | |
3584 | ||
3585 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3586 | ||
4c476991 JB |
3587 | if (!rdev->ops->get_station) |
3588 | return -EOPNOTSUPP; | |
3b85875a | 3589 | |
e35e4d28 | 3590 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3591 | if (err) |
4c476991 | 3592 | return err; |
2ec600d6 | 3593 | |
fd2120ca | 3594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3595 | if (!msg) |
4c476991 | 3596 | return -ENOMEM; |
fd5b74dc | 3597 | |
15e47304 | 3598 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3599 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3600 | nlmsg_free(msg); |
3601 | return -ENOBUFS; | |
3602 | } | |
3b85875a | 3603 | |
4c476991 | 3604 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3605 | } |
3606 | ||
77ee7c89 JB |
3607 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3608 | struct station_parameters *params, | |
3609 | enum cfg80211_station_type statype) | |
3610 | { | |
3611 | if (params->listen_interval != -1) | |
3612 | return -EINVAL; | |
3613 | if (params->aid) | |
3614 | return -EINVAL; | |
3615 | ||
3616 | /* When you run into this, adjust the code below for the new flag */ | |
3617 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3618 | ||
3619 | switch (statype) { | |
eef941e6 TP |
3620 | case CFG80211_STA_MESH_PEER_KERNEL: |
3621 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3622 | /* |
3623 | * No ignoring the TDLS flag here -- the userspace mesh | |
3624 | * code doesn't have the bug of including TDLS in the | |
3625 | * mask everywhere. | |
3626 | */ | |
3627 | if (params->sta_flags_mask & | |
3628 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3629 | BIT(NL80211_STA_FLAG_MFP) | | |
3630 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3631 | return -EINVAL; | |
3632 | break; | |
3633 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3634 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3635 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3636 | return -EINVAL; | |
3637 | /* ignore since it can't change */ | |
3638 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3639 | break; | |
3640 | default: | |
3641 | /* disallow mesh-specific things */ | |
3642 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3643 | return -EINVAL; | |
3644 | if (params->local_pm) | |
3645 | return -EINVAL; | |
3646 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3647 | return -EINVAL; | |
3648 | } | |
3649 | ||
3650 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3651 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3652 | /* TDLS can't be set, ... */ | |
3653 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3654 | return -EINVAL; | |
3655 | /* | |
3656 | * ... but don't bother the driver with it. This works around | |
3657 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3658 | * TLDS_PEER flag in the mask even for AP mode. | |
3659 | */ | |
3660 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3661 | } | |
3662 | ||
3663 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3664 | /* reject other things that can't change */ | |
3665 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3666 | return -EINVAL; | |
3667 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3668 | return -EINVAL; | |
3669 | if (params->supported_rates) | |
3670 | return -EINVAL; | |
3671 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3672 | return -EINVAL; | |
3673 | } | |
3674 | ||
3675 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3676 | if (params->vlan) | |
3677 | return -EINVAL; | |
3678 | } | |
3679 | ||
3680 | switch (statype) { | |
3681 | case CFG80211_STA_AP_MLME_CLIENT: | |
3682 | /* Use this only for authorizing/unauthorizing a station */ | |
3683 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3684 | return -EOPNOTSUPP; | |
3685 | break; | |
3686 | case CFG80211_STA_AP_CLIENT: | |
3687 | /* accept only the listed bits */ | |
3688 | if (params->sta_flags_mask & | |
3689 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3690 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3691 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3692 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3693 | BIT(NL80211_STA_FLAG_WME) | | |
3694 | BIT(NL80211_STA_FLAG_MFP))) | |
3695 | return -EINVAL; | |
3696 | ||
3697 | /* but authenticated/associated only if driver handles it */ | |
3698 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3699 | params->sta_flags_mask & | |
3700 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3701 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3702 | return -EINVAL; | |
3703 | break; | |
3704 | case CFG80211_STA_IBSS: | |
3705 | case CFG80211_STA_AP_STA: | |
3706 | /* reject any changes other than AUTHORIZED */ | |
3707 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3708 | return -EINVAL; | |
3709 | break; | |
3710 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3711 | /* reject any changes other than AUTHORIZED or WME */ | |
3712 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3713 | BIT(NL80211_STA_FLAG_WME))) | |
3714 | return -EINVAL; | |
3715 | /* force (at least) rates when authorizing */ | |
3716 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3717 | !params->supported_rates) | |
3718 | return -EINVAL; | |
3719 | break; | |
3720 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3721 | /* reject any changes */ | |
3722 | return -EINVAL; | |
eef941e6 | 3723 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3724 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3725 | return -EINVAL; | |
3726 | break; | |
eef941e6 | 3727 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3728 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3729 | return -EINVAL; | |
3730 | break; | |
3731 | } | |
3732 | ||
3733 | return 0; | |
3734 | } | |
3735 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3736 | ||
5727ef1b | 3737 | /* |
c258d2de | 3738 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3739 | */ |
80b99899 JB |
3740 | static struct net_device *get_vlan(struct genl_info *info, |
3741 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3742 | { |
463d0183 | 3743 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3744 | struct net_device *v; |
3745 | int ret; | |
3746 | ||
3747 | if (!vlanattr) | |
3748 | return NULL; | |
3749 | ||
3750 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3751 | if (!v) | |
3752 | return ERR_PTR(-ENODEV); | |
3753 | ||
3754 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3755 | ret = -EINVAL; | |
3756 | goto error; | |
5727ef1b | 3757 | } |
80b99899 | 3758 | |
77ee7c89 JB |
3759 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3760 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3761 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3762 | ret = -EINVAL; | |
3763 | goto error; | |
3764 | } | |
3765 | ||
80b99899 JB |
3766 | if (!netif_running(v)) { |
3767 | ret = -ENETDOWN; | |
3768 | goto error; | |
3769 | } | |
3770 | ||
3771 | return v; | |
3772 | error: | |
3773 | dev_put(v); | |
3774 | return ERR_PTR(ret); | |
5727ef1b JB |
3775 | } |
3776 | ||
df881293 JM |
3777 | static struct nla_policy |
3778 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3779 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3780 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3781 | }; | |
3782 | ||
ff276691 JB |
3783 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3784 | struct station_parameters *params) | |
df881293 | 3785 | { |
df881293 JM |
3786 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3787 | struct nlattr *nla; | |
3788 | int err; | |
3789 | ||
df881293 JM |
3790 | /* parse WME attributes if present */ |
3791 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3792 | return 0; | |
3793 | ||
3794 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3795 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3796 | nl80211_sta_wme_policy); | |
3797 | if (err) | |
3798 | return err; | |
3799 | ||
3800 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3801 | params->uapsd_queues = nla_get_u8( | |
3802 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3803 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3804 | return -EINVAL; | |
3805 | ||
3806 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3807 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3808 | ||
3809 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3810 | return -EINVAL; | |
3811 | ||
3812 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3813 | ||
3814 | return 0; | |
3815 | } | |
3816 | ||
ff276691 JB |
3817 | static int nl80211_set_station_tdls(struct genl_info *info, |
3818 | struct station_parameters *params) | |
3819 | { | |
3820 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
3821 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | |
3822 | params->ht_capa = | |
3823 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3824 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3825 | params->vht_capa = | |
3826 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3827 | ||
3828 | return nl80211_parse_sta_wme(info, params); | |
3829 | } | |
3830 | ||
5727ef1b JB |
3831 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3832 | { | |
4c476991 | 3833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3834 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3835 | struct station_parameters params; |
77ee7c89 JB |
3836 | u8 *mac_addr; |
3837 | int err; | |
5727ef1b JB |
3838 | |
3839 | memset(¶ms, 0, sizeof(params)); | |
3840 | ||
3841 | params.listen_interval = -1; | |
3842 | ||
77ee7c89 JB |
3843 | if (!rdev->ops->change_station) |
3844 | return -EOPNOTSUPP; | |
3845 | ||
5727ef1b JB |
3846 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3847 | return -EINVAL; | |
3848 | ||
3849 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3850 | return -EINVAL; | |
3851 | ||
3852 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3853 | ||
3854 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3855 | params.supported_rates = | |
3856 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3857 | params.supported_rates_len = | |
3858 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3859 | } | |
3860 | ||
9d62a986 JM |
3861 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3862 | params.capability = | |
3863 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3864 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3865 | } | |
3866 | ||
3867 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3868 | params.ext_capab = | |
3869 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3870 | params.ext_capab_len = | |
3871 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3872 | } | |
3873 | ||
df881293 | 3874 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3875 | return -EINVAL; |
36aedc90 | 3876 | |
bdd3ae3d | 3877 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3878 | return -EINVAL; |
3879 | ||
f8bacc21 | 3880 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3881 | params.plink_action = |
f8bacc21 JB |
3882 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3883 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3884 | return -EINVAL; | |
3885 | } | |
2ec600d6 | 3886 | |
f8bacc21 | 3887 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3888 | params.plink_state = |
f8bacc21 JB |
3889 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3890 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3891 | return -EINVAL; | |
3892 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3893 | } | |
9c3990aa | 3894 | |
3b1c5a53 MP |
3895 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3896 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3897 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3898 | ||
3899 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3900 | pm > NL80211_MESH_POWER_MAX) | |
3901 | return -EINVAL; | |
3902 | ||
3903 | params.local_pm = pm; | |
3904 | } | |
3905 | ||
77ee7c89 JB |
3906 | /* Include parameters for TDLS peer (will check later) */ |
3907 | err = nl80211_set_station_tdls(info, ¶ms); | |
3908 | if (err) | |
3909 | return err; | |
3910 | ||
3911 | params.vlan = get_vlan(info, rdev); | |
3912 | if (IS_ERR(params.vlan)) | |
3913 | return PTR_ERR(params.vlan); | |
3914 | ||
a97f4424 JB |
3915 | switch (dev->ieee80211_ptr->iftype) { |
3916 | case NL80211_IFTYPE_AP: | |
3917 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3918 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3919 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3920 | case NL80211_IFTYPE_STATION: |
267335d6 | 3921 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3922 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3923 | break; |
3924 | default: | |
77ee7c89 JB |
3925 | err = -EOPNOTSUPP; |
3926 | goto out_put_vlan; | |
034d655e JB |
3927 | } |
3928 | ||
77ee7c89 | 3929 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 3930 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3931 | |
77ee7c89 | 3932 | out_put_vlan: |
5727ef1b JB |
3933 | if (params.vlan) |
3934 | dev_put(params.vlan); | |
3b85875a | 3935 | |
5727ef1b JB |
3936 | return err; |
3937 | } | |
3938 | ||
3939 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
3940 | { | |
4c476991 | 3941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3942 | int err; |
4c476991 | 3943 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3944 | struct station_parameters params; |
3945 | u8 *mac_addr = NULL; | |
3946 | ||
3947 | memset(¶ms, 0, sizeof(params)); | |
3948 | ||
984c311b JB |
3949 | if (!rdev->ops->add_station) |
3950 | return -EOPNOTSUPP; | |
3951 | ||
5727ef1b JB |
3952 | if (!info->attrs[NL80211_ATTR_MAC]) |
3953 | return -EINVAL; | |
3954 | ||
5727ef1b JB |
3955 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3956 | return -EINVAL; | |
3957 | ||
3958 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3959 | return -EINVAL; | |
3960 | ||
0e956c13 TLSC |
3961 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
3962 | return -EINVAL; | |
3963 | ||
5727ef1b JB |
3964 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3965 | params.supported_rates = | |
3966 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3967 | params.supported_rates_len = | |
3968 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3969 | params.listen_interval = | |
3970 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3971 | |
0e956c13 TLSC |
3972 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
3973 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
3974 | return -EINVAL; | |
51b50fbe | 3975 | |
9d62a986 JM |
3976 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3977 | params.capability = | |
3978 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3979 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3980 | } | |
3981 | ||
3982 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3983 | params.ext_capab = | |
3984 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3985 | params.ext_capab_len = | |
3986 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3987 | } | |
3988 | ||
36aedc90 JM |
3989 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3990 | params.ht_capa = | |
3991 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 3992 | |
f461be3e MP |
3993 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
3994 | params.vht_capa = | |
3995 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3996 | ||
f8bacc21 | 3997 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 3998 | params.plink_action = |
f8bacc21 JB |
3999 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4000 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4001 | return -EINVAL; | |
4002 | } | |
96b78dff | 4003 | |
ff276691 JB |
4004 | err = nl80211_parse_sta_wme(info, ¶ms); |
4005 | if (err) | |
4006 | return err; | |
bdd90d5e | 4007 | |
bdd3ae3d | 4008 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4009 | return -EINVAL; |
4010 | ||
77ee7c89 JB |
4011 | /* When you run into this, adjust the code below for the new flag */ |
4012 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4013 | ||
bdd90d5e JB |
4014 | switch (dev->ieee80211_ptr->iftype) { |
4015 | case NL80211_IFTYPE_AP: | |
4016 | case NL80211_IFTYPE_AP_VLAN: | |
4017 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4018 | /* ignore WME attributes if iface/sta is not capable */ |
4019 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4020 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4021 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4022 | |
bdd90d5e JB |
4023 | /* TDLS peers cannot be added */ |
4024 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 4025 | return -EINVAL; |
bdd90d5e JB |
4026 | /* but don't bother the driver with it */ |
4027 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4028 | |
d582cffb JB |
4029 | /* allow authenticated/associated only if driver handles it */ |
4030 | if (!(rdev->wiphy.features & | |
4031 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4032 | params.sta_flags_mask & | |
4033 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4034 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4035 | return -EINVAL; | |
4036 | ||
bdd90d5e JB |
4037 | /* must be last in here for error handling */ |
4038 | params.vlan = get_vlan(info, rdev); | |
4039 | if (IS_ERR(params.vlan)) | |
4040 | return PTR_ERR(params.vlan); | |
4041 | break; | |
4042 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4043 | /* ignore uAPSD data */ |
4044 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4045 | ||
d582cffb JB |
4046 | /* associated is disallowed */ |
4047 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4048 | return -EINVAL; | |
bdd90d5e JB |
4049 | /* TDLS peers cannot be added */ |
4050 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4051 | return -EINVAL; | |
4052 | break; | |
4053 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4054 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4055 | /* ignore uAPSD data */ |
4056 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4057 | ||
77ee7c89 JB |
4058 | /* these are disallowed */ |
4059 | if (params.sta_flags_mask & | |
4060 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4061 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4062 | return -EINVAL; |
bdd90d5e JB |
4063 | /* Only TDLS peers can be added */ |
4064 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4065 | return -EINVAL; | |
4066 | /* Can only add if TDLS ... */ | |
4067 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4068 | return -EOPNOTSUPP; | |
4069 | /* ... with external setup is supported */ | |
4070 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4071 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4072 | /* |
4073 | * Older wpa_supplicant versions always mark the TDLS peer | |
4074 | * as authorized, but it shouldn't yet be. | |
4075 | */ | |
4076 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4077 | break; |
4078 | default: | |
4079 | return -EOPNOTSUPP; | |
c75786c9 EP |
4080 | } |
4081 | ||
bdd90d5e | 4082 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4083 | |
e35e4d28 | 4084 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4085 | |
5727ef1b JB |
4086 | if (params.vlan) |
4087 | dev_put(params.vlan); | |
5727ef1b JB |
4088 | return err; |
4089 | } | |
4090 | ||
4091 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4092 | { | |
4c476991 JB |
4093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4094 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4095 | u8 *mac_addr = NULL; |
4096 | ||
4097 | if (info->attrs[NL80211_ATTR_MAC]) | |
4098 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4099 | ||
e80cf853 | 4100 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4103 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4104 | return -EINVAL; | |
5727ef1b | 4105 | |
4c476991 JB |
4106 | if (!rdev->ops->del_station) |
4107 | return -EOPNOTSUPP; | |
3b85875a | 4108 | |
e35e4d28 | 4109 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4110 | } |
4111 | ||
15e47304 | 4112 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4113 | int flags, struct net_device *dev, |
4114 | u8 *dst, u8 *next_hop, | |
4115 | struct mpath_info *pinfo) | |
4116 | { | |
4117 | void *hdr; | |
4118 | struct nlattr *pinfoattr; | |
4119 | ||
15e47304 | 4120 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4121 | if (!hdr) |
4122 | return -1; | |
4123 | ||
9360ffd1 DM |
4124 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4125 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4126 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4127 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4128 | goto nla_put_failure; | |
f5ea9120 | 4129 | |
2ec600d6 LCC |
4130 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4131 | if (!pinfoattr) | |
4132 | goto nla_put_failure; | |
9360ffd1 DM |
4133 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4134 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4135 | pinfo->frame_qlen)) | |
4136 | goto nla_put_failure; | |
4137 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4138 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4139 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4140 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4141 | pinfo->metric)) || | |
4142 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4143 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4144 | pinfo->exptime)) || | |
4145 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4146 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4147 | pinfo->flags)) || | |
4148 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4149 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4150 | pinfo->discovery_timeout)) || | |
4151 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4152 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4153 | pinfo->discovery_retries))) | |
4154 | goto nla_put_failure; | |
2ec600d6 LCC |
4155 | |
4156 | nla_nest_end(msg, pinfoattr); | |
4157 | ||
4158 | return genlmsg_end(msg, hdr); | |
4159 | ||
4160 | nla_put_failure: | |
bc3ed28c TG |
4161 | genlmsg_cancel(msg, hdr); |
4162 | return -EMSGSIZE; | |
2ec600d6 LCC |
4163 | } |
4164 | ||
4165 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4166 | struct netlink_callback *cb) |
2ec600d6 | 4167 | { |
2ec600d6 LCC |
4168 | struct mpath_info pinfo; |
4169 | struct cfg80211_registered_device *dev; | |
bba95fef | 4170 | struct net_device *netdev; |
2ec600d6 LCC |
4171 | u8 dst[ETH_ALEN]; |
4172 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 4173 | int path_idx = cb->args[1]; |
2ec600d6 | 4174 | int err; |
2ec600d6 | 4175 | |
67748893 JB |
4176 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
4177 | if (err) | |
4178 | return err; | |
bba95fef JB |
4179 | |
4180 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4181 | err = -EOPNOTSUPP; |
bba95fef JB |
4182 | goto out_err; |
4183 | } | |
4184 | ||
eec60b03 JM |
4185 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
4186 | err = -EOPNOTSUPP; | |
0448b5fc | 4187 | goto out_err; |
eec60b03 JM |
4188 | } |
4189 | ||
bba95fef | 4190 | while (1) { |
e35e4d28 HG |
4191 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
4192 | &pinfo); | |
bba95fef | 4193 | if (err == -ENOENT) |
2ec600d6 | 4194 | break; |
bba95fef | 4195 | if (err) |
3b85875a | 4196 | goto out_err; |
2ec600d6 | 4197 | |
15e47304 | 4198 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef JB |
4199 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
4200 | netdev, dst, next_hop, | |
4201 | &pinfo) < 0) | |
4202 | goto out; | |
2ec600d6 | 4203 | |
bba95fef | 4204 | path_idx++; |
2ec600d6 | 4205 | } |
2ec600d6 | 4206 | |
2ec600d6 | 4207 | |
bba95fef JB |
4208 | out: |
4209 | cb->args[1] = path_idx; | |
4210 | err = skb->len; | |
bba95fef | 4211 | out_err: |
67748893 | 4212 | nl80211_finish_netdev_dump(dev); |
bba95fef | 4213 | return err; |
2ec600d6 LCC |
4214 | } |
4215 | ||
4216 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4217 | { | |
4c476991 | 4218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4219 | int err; |
4c476991 | 4220 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4221 | struct mpath_info pinfo; |
4222 | struct sk_buff *msg; | |
4223 | u8 *dst = NULL; | |
4224 | u8 next_hop[ETH_ALEN]; | |
4225 | ||
4226 | memset(&pinfo, 0, sizeof(pinfo)); | |
4227 | ||
4228 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4229 | return -EINVAL; | |
4230 | ||
4231 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4232 | ||
4c476991 JB |
4233 | if (!rdev->ops->get_mpath) |
4234 | return -EOPNOTSUPP; | |
2ec600d6 | 4235 | |
4c476991 JB |
4236 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4237 | return -EOPNOTSUPP; | |
eec60b03 | 4238 | |
e35e4d28 | 4239 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4240 | if (err) |
4c476991 | 4241 | return err; |
2ec600d6 | 4242 | |
fd2120ca | 4243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4244 | if (!msg) |
4c476991 | 4245 | return -ENOMEM; |
2ec600d6 | 4246 | |
15e47304 | 4247 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4248 | dev, dst, next_hop, &pinfo) < 0) { |
4249 | nlmsg_free(msg); | |
4250 | return -ENOBUFS; | |
4251 | } | |
3b85875a | 4252 | |
4c476991 | 4253 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4254 | } |
4255 | ||
4256 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4257 | { | |
4c476991 JB |
4258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4259 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4260 | u8 *dst = NULL; |
4261 | u8 *next_hop = NULL; | |
4262 | ||
4263 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4264 | return -EINVAL; | |
4265 | ||
4266 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4267 | return -EINVAL; | |
4268 | ||
4269 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4270 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4271 | ||
4c476991 JB |
4272 | if (!rdev->ops->change_mpath) |
4273 | return -EOPNOTSUPP; | |
35a8efe1 | 4274 | |
4c476991 JB |
4275 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4276 | return -EOPNOTSUPP; | |
2ec600d6 | 4277 | |
e35e4d28 | 4278 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4279 | } |
4c476991 | 4280 | |
2ec600d6 LCC |
4281 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4282 | { | |
4c476991 JB |
4283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4284 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4285 | u8 *dst = NULL; |
4286 | u8 *next_hop = NULL; | |
4287 | ||
4288 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4289 | return -EINVAL; | |
4290 | ||
4291 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4292 | return -EINVAL; | |
4293 | ||
4294 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4295 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4296 | ||
4c476991 JB |
4297 | if (!rdev->ops->add_mpath) |
4298 | return -EOPNOTSUPP; | |
35a8efe1 | 4299 | |
4c476991 JB |
4300 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4301 | return -EOPNOTSUPP; | |
2ec600d6 | 4302 | |
e35e4d28 | 4303 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4304 | } |
4305 | ||
4306 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4307 | { | |
4c476991 JB |
4308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4309 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4310 | u8 *dst = NULL; |
4311 | ||
4312 | if (info->attrs[NL80211_ATTR_MAC]) | |
4313 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4314 | ||
4c476991 JB |
4315 | if (!rdev->ops->del_mpath) |
4316 | return -EOPNOTSUPP; | |
3b85875a | 4317 | |
e35e4d28 | 4318 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4319 | } |
4320 | ||
9f1ba906 JM |
4321 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4322 | { | |
4c476991 JB |
4323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4324 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4325 | struct bss_parameters params; |
4326 | ||
4327 | memset(¶ms, 0, sizeof(params)); | |
4328 | /* default to not changing parameters */ | |
4329 | params.use_cts_prot = -1; | |
4330 | params.use_short_preamble = -1; | |
4331 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4332 | params.ap_isolate = -1; |
50b12f59 | 4333 | params.ht_opmode = -1; |
53cabad7 JB |
4334 | params.p2p_ctwindow = -1; |
4335 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4336 | |
4337 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4338 | params.use_cts_prot = | |
4339 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4340 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4341 | params.use_short_preamble = | |
4342 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4343 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4344 | params.use_short_slot_time = | |
4345 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4346 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4347 | params.basic_rates = | |
4348 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4349 | params.basic_rates_len = | |
4350 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4351 | } | |
fd8aaaf3 FF |
4352 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4353 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4354 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4355 | params.ht_opmode = | |
4356 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4357 | |
53cabad7 JB |
4358 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4359 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4360 | return -EINVAL; | |
4361 | params.p2p_ctwindow = | |
4362 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4363 | if (params.p2p_ctwindow < 0) | |
4364 | return -EINVAL; | |
4365 | if (params.p2p_ctwindow != 0 && | |
4366 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4367 | return -EINVAL; | |
4368 | } | |
4369 | ||
4370 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4371 | u8 tmp; | |
4372 | ||
4373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4374 | return -EINVAL; | |
4375 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4376 | if (tmp > 1) | |
4377 | return -EINVAL; | |
4378 | params.p2p_opp_ps = tmp; | |
4379 | if (params.p2p_opp_ps && | |
4380 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4381 | return -EINVAL; | |
4382 | } | |
4383 | ||
4c476991 JB |
4384 | if (!rdev->ops->change_bss) |
4385 | return -EOPNOTSUPP; | |
9f1ba906 | 4386 | |
074ac8df | 4387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4388 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4389 | return -EOPNOTSUPP; | |
3b85875a | 4390 | |
e35e4d28 | 4391 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4392 | } |
4393 | ||
b54452b0 | 4394 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4395 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4396 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4397 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4398 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4399 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4400 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4401 | }; | |
4402 | ||
4403 | static int parse_reg_rule(struct nlattr *tb[], | |
4404 | struct ieee80211_reg_rule *reg_rule) | |
4405 | { | |
4406 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4407 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4408 | ||
4409 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4410 | return -EINVAL; | |
4411 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4412 | return -EINVAL; | |
4413 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4414 | return -EINVAL; | |
4415 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4416 | return -EINVAL; | |
4417 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4418 | return -EINVAL; | |
4419 | ||
4420 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4421 | ||
4422 | freq_range->start_freq_khz = | |
4423 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4424 | freq_range->end_freq_khz = | |
4425 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4426 | freq_range->max_bandwidth_khz = | |
4427 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4428 | ||
4429 | power_rule->max_eirp = | |
4430 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4431 | ||
4432 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4433 | power_rule->max_antenna_gain = | |
4434 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4435 | ||
4436 | return 0; | |
4437 | } | |
4438 | ||
4439 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4440 | { | |
4441 | int r; | |
4442 | char *data = NULL; | |
57b5ce07 | 4443 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4444 | |
80778f18 LR |
4445 | /* |
4446 | * You should only get this when cfg80211 hasn't yet initialized | |
4447 | * completely when built-in to the kernel right between the time | |
4448 | * window between nl80211_init() and regulatory_init(), if that is | |
4449 | * even possible. | |
4450 | */ | |
458f4f9e | 4451 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4452 | return -EINPROGRESS; |
80778f18 | 4453 | |
fe33eb39 LR |
4454 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4455 | return -EINVAL; | |
b2e1b302 LR |
4456 | |
4457 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4458 | ||
57b5ce07 LR |
4459 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4460 | user_reg_hint_type = | |
4461 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4462 | else | |
4463 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4464 | ||
4465 | switch (user_reg_hint_type) { | |
4466 | case NL80211_USER_REG_HINT_USER: | |
4467 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4468 | break; | |
4469 | default: | |
4470 | return -EINVAL; | |
4471 | } | |
4472 | ||
4473 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4474 | |
b2e1b302 LR |
4475 | return r; |
4476 | } | |
4477 | ||
24bdd9f4 | 4478 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4479 | struct genl_info *info) |
93da9cc1 | 4480 | { |
4c476991 | 4481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4482 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4483 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4484 | struct mesh_config cur_params; | |
4485 | int err = 0; | |
93da9cc1 | 4486 | void *hdr; |
4487 | struct nlattr *pinfoattr; | |
4488 | struct sk_buff *msg; | |
4489 | ||
29cbe68c JB |
4490 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4491 | return -EOPNOTSUPP; | |
4492 | ||
24bdd9f4 | 4493 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4494 | return -EOPNOTSUPP; |
f3f92586 | 4495 | |
29cbe68c JB |
4496 | wdev_lock(wdev); |
4497 | /* If not connected, get default parameters */ | |
4498 | if (!wdev->mesh_id_len) | |
4499 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4500 | else | |
e35e4d28 | 4501 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4502 | wdev_unlock(wdev); |
4503 | ||
93da9cc1 | 4504 | if (err) |
4c476991 | 4505 | return err; |
93da9cc1 | 4506 | |
4507 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4508 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4509 | if (!msg) |
4510 | return -ENOMEM; | |
15e47304 | 4511 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4512 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4513 | if (!hdr) |
efe1cf0c | 4514 | goto out; |
24bdd9f4 | 4515 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4516 | if (!pinfoattr) |
4517 | goto nla_put_failure; | |
9360ffd1 DM |
4518 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4519 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4520 | cur_params.dot11MeshRetryTimeout) || | |
4521 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4522 | cur_params.dot11MeshConfirmTimeout) || | |
4523 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4524 | cur_params.dot11MeshHoldingTimeout) || | |
4525 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4526 | cur_params.dot11MeshMaxPeerLinks) || | |
4527 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4528 | cur_params.dot11MeshMaxRetries) || | |
4529 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4530 | cur_params.dot11MeshTTL) || | |
4531 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4532 | cur_params.element_ttl) || | |
4533 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4534 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4535 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4536 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4537 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4538 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4539 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4540 | cur_params.path_refresh_time) || | |
4541 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4542 | cur_params.min_discovery_timeout) || | |
4543 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4544 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4545 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4546 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4547 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4548 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4549 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4550 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4551 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4552 | cur_params.dot11MeshHWMPRootMode) || | |
4553 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4554 | cur_params.dot11MeshHWMPRannInterval) || | |
4555 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4556 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4557 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4558 | cur_params.dot11MeshForwarding) || | |
4559 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4560 | cur_params.rssi_threshold) || |
4561 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4562 | cur_params.ht_opmode) || |
4563 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4564 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4565 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4566 | cur_params.dot11MeshHWMProotInterval) || |
4567 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4568 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4569 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4570 | cur_params.power_mode) || | |
4571 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
4572 | cur_params.dot11MeshAwakeWindowDuration)) | |
9360ffd1 | 4573 | goto nla_put_failure; |
93da9cc1 | 4574 | nla_nest_end(msg, pinfoattr); |
4575 | genlmsg_end(msg, hdr); | |
4c476991 | 4576 | return genlmsg_reply(msg, info); |
93da9cc1 | 4577 | |
3b85875a | 4578 | nla_put_failure: |
93da9cc1 | 4579 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4580 | out: |
d080e275 | 4581 | nlmsg_free(msg); |
4c476991 | 4582 | return -ENOBUFS; |
93da9cc1 | 4583 | } |
4584 | ||
b54452b0 | 4585 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4586 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4587 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4588 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4589 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4590 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4591 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4592 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4593 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4594 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4595 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4596 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4597 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4598 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4599 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4600 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4601 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4602 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4603 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4604 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4605 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4606 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4607 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4608 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4609 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4610 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4611 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4612 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
93da9cc1 | 4613 | }; |
4614 | ||
c80d545d JC |
4615 | static const struct nla_policy |
4616 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4617 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4618 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4619 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4620 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
bb2798d4 | 4621 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4622 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4623 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4624 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4625 | }; |
4626 | ||
24bdd9f4 | 4627 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4628 | struct mesh_config *cfg, |
4629 | u32 *mask_out) | |
93da9cc1 | 4630 | { |
93da9cc1 | 4631 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4632 | u32 mask = 0; |
93da9cc1 | 4633 | |
ea54fba2 MP |
4634 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4635 | do { \ | |
4636 | if (tb[attr]) { \ | |
4637 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4638 | return -EINVAL; \ | |
4639 | cfg->param = fn(tb[attr]); \ | |
4640 | mask |= (1 << (attr - 1)); \ | |
4641 | } \ | |
4642 | } while (0) | |
bd90fdcc JB |
4643 | |
4644 | ||
24bdd9f4 | 4645 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4646 | return -EINVAL; |
4647 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4648 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4649 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4650 | return -EINVAL; |
4651 | ||
93da9cc1 | 4652 | /* This makes sure that there aren't more than 32 mesh config |
4653 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4654 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4655 | ||
4656 | /* Fill in the params struct */ | |
ea54fba2 | 4657 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4658 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4659 | nla_get_u16); | |
ea54fba2 | 4660 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4661 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4662 | nla_get_u16); | |
ea54fba2 | 4663 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4664 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4665 | nla_get_u16); | |
ea54fba2 | 4666 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4667 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4668 | nla_get_u16); | |
ea54fba2 | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4670 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4671 | nla_get_u8); | |
ea54fba2 | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4673 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4674 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4675 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4676 | nla_get_u8); | |
ea54fba2 | 4677 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4678 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4679 | nla_get_u8); | |
ea54fba2 MP |
4680 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4681 | 1, 255, mask, | |
a4f606ea CYY |
4682 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4683 | nla_get_u32); | |
ea54fba2 | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4685 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4686 | nla_get_u8); | |
ea54fba2 | 4687 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4688 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4689 | nla_get_u32); | |
ea54fba2 | 4690 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4691 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4692 | nla_get_u16); | |
ea54fba2 MP |
4693 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4694 | 1, 65535, mask, | |
a4f606ea CYY |
4695 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4696 | nla_get_u32); | |
93da9cc1 | 4697 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4698 | 1, 65535, mask, |
4699 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4700 | nla_get_u16); |
dca7e943 | 4701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4702 | 1, 65535, mask, |
4703 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4704 | nla_get_u16); |
93da9cc1 | 4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4706 | dot11MeshHWMPnetDiameterTraversalTime, |
4707 | 1, 65535, mask, | |
a4f606ea CYY |
4708 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4709 | nla_get_u16); | |
ea54fba2 MP |
4710 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4711 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4712 | nla_get_u8); | |
4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4714 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4715 | nla_get_u16); |
63c5723b | 4716 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4717 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4718 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4719 | nla_get_u8); |
ea54fba2 | 4720 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4721 | mask, NL80211_MESHCONF_FORWARDING, |
4722 | nla_get_u8); | |
ea54fba2 | 4723 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4724 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4725 | nla_get_u32); | |
ea54fba2 | 4726 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4727 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4728 | nla_get_u16); |
4729 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4730 | 1, 65535, mask, |
ac1073a6 CYY |
4731 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4732 | nla_get_u32); | |
ea54fba2 | 4733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4734 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4735 | nla_get_u16); |
4736 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4737 | dot11MeshHWMPconfirmationInterval, |
4738 | 1, 65535, mask, | |
728b19e5 | 4739 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4740 | nla_get_u16); |
3b1c5a53 MP |
4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4742 | NL80211_MESH_POWER_ACTIVE, | |
4743 | NL80211_MESH_POWER_MAX, | |
4744 | mask, NL80211_MESHCONF_POWER_MODE, | |
4745 | nla_get_u32); | |
4746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4747 | 0, 65535, mask, | |
4748 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
bd90fdcc JB |
4749 | if (mask_out) |
4750 | *mask_out = mask; | |
c80d545d | 4751 | |
bd90fdcc JB |
4752 | return 0; |
4753 | ||
4754 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4755 | } | |
4756 | ||
c80d545d JC |
4757 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4758 | struct mesh_setup *setup) | |
4759 | { | |
bb2798d4 | 4760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4761 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4762 | ||
4763 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4764 | return -EINVAL; | |
4765 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4766 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4767 | nl80211_mesh_setup_params_policy)) | |
4768 | return -EINVAL; | |
4769 | ||
d299a1f2 JC |
4770 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4771 | setup->sync_method = | |
4772 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4773 | IEEE80211_SYNC_METHOD_VENDOR : | |
4774 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4775 | ||
c80d545d JC |
4776 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4777 | setup->path_sel_proto = | |
4778 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4779 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4780 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4781 | ||
4782 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4783 | setup->path_metric = | |
4784 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4785 | IEEE80211_PATH_METRIC_VENDOR : | |
4786 | IEEE80211_PATH_METRIC_AIRTIME; | |
4787 | ||
581a8b0f JC |
4788 | |
4789 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4790 | struct nlattr *ieattr = |
581a8b0f | 4791 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4792 | if (!is_valid_ie_attr(ieattr)) |
4793 | return -EINVAL; | |
581a8b0f JC |
4794 | setup->ie = nla_data(ieattr); |
4795 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4796 | } |
bb2798d4 TP |
4797 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4798 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4799 | return -EINVAL; | |
4800 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4801 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4802 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4803 | if (setup->is_secure) |
4804 | setup->user_mpm = true; | |
c80d545d JC |
4805 | |
4806 | return 0; | |
4807 | } | |
4808 | ||
24bdd9f4 | 4809 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4810 | struct genl_info *info) |
bd90fdcc JB |
4811 | { |
4812 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4813 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4814 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4815 | struct mesh_config cfg; |
4816 | u32 mask; | |
4817 | int err; | |
4818 | ||
29cbe68c JB |
4819 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4820 | return -EOPNOTSUPP; | |
4821 | ||
24bdd9f4 | 4822 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4823 | return -EOPNOTSUPP; |
4824 | ||
24bdd9f4 | 4825 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4826 | if (err) |
4827 | return err; | |
4828 | ||
29cbe68c JB |
4829 | wdev_lock(wdev); |
4830 | if (!wdev->mesh_id_len) | |
4831 | err = -ENOLINK; | |
4832 | ||
4833 | if (!err) | |
e35e4d28 | 4834 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4835 | |
4836 | wdev_unlock(wdev); | |
4837 | ||
4838 | return err; | |
93da9cc1 | 4839 | } |
4840 | ||
f130347c LR |
4841 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4842 | { | |
458f4f9e | 4843 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4844 | struct sk_buff *msg; |
4845 | void *hdr = NULL; | |
4846 | struct nlattr *nl_reg_rules; | |
4847 | unsigned int i; | |
4848 | int err = -EINVAL; | |
4849 | ||
a1794390 | 4850 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
4851 | |
4852 | if (!cfg80211_regdomain) | |
4853 | goto out; | |
4854 | ||
fd2120ca | 4855 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
4856 | if (!msg) { |
4857 | err = -ENOBUFS; | |
4858 | goto out; | |
4859 | } | |
4860 | ||
15e47304 | 4861 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4862 | NL80211_CMD_GET_REG); |
4863 | if (!hdr) | |
efe1cf0c | 4864 | goto put_failure; |
f130347c | 4865 | |
57b5ce07 LR |
4866 | if (reg_last_request_cell_base() && |
4867 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4868 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4869 | goto nla_put_failure; | |
4870 | ||
458f4f9e JB |
4871 | rcu_read_lock(); |
4872 | regdom = rcu_dereference(cfg80211_regdomain); | |
4873 | ||
4874 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4875 | (regdom->dfs_region && | |
4876 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4877 | goto nla_put_failure_rcu; | |
4878 | ||
f130347c LR |
4879 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4880 | if (!nl_reg_rules) | |
458f4f9e | 4881 | goto nla_put_failure_rcu; |
f130347c | 4882 | |
458f4f9e | 4883 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4884 | struct nlattr *nl_reg_rule; |
4885 | const struct ieee80211_reg_rule *reg_rule; | |
4886 | const struct ieee80211_freq_range *freq_range; | |
4887 | const struct ieee80211_power_rule *power_rule; | |
4888 | ||
458f4f9e | 4889 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4890 | freq_range = ®_rule->freq_range; |
4891 | power_rule = ®_rule->power_rule; | |
4892 | ||
4893 | nl_reg_rule = nla_nest_start(msg, i); | |
4894 | if (!nl_reg_rule) | |
458f4f9e | 4895 | goto nla_put_failure_rcu; |
f130347c | 4896 | |
9360ffd1 DM |
4897 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4898 | reg_rule->flags) || | |
4899 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4900 | freq_range->start_freq_khz) || | |
4901 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4902 | freq_range->end_freq_khz) || | |
4903 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4904 | freq_range->max_bandwidth_khz) || | |
4905 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4906 | power_rule->max_antenna_gain) || | |
4907 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4908 | power_rule->max_eirp)) | |
458f4f9e | 4909 | goto nla_put_failure_rcu; |
f130347c LR |
4910 | |
4911 | nla_nest_end(msg, nl_reg_rule); | |
4912 | } | |
458f4f9e | 4913 | rcu_read_unlock(); |
f130347c LR |
4914 | |
4915 | nla_nest_end(msg, nl_reg_rules); | |
4916 | ||
4917 | genlmsg_end(msg, hdr); | |
134e6375 | 4918 | err = genlmsg_reply(msg, info); |
f130347c LR |
4919 | goto out; |
4920 | ||
458f4f9e JB |
4921 | nla_put_failure_rcu: |
4922 | rcu_read_unlock(); | |
f130347c LR |
4923 | nla_put_failure: |
4924 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4925 | put_failure: |
d080e275 | 4926 | nlmsg_free(msg); |
f130347c LR |
4927 | err = -EMSGSIZE; |
4928 | out: | |
a1794390 | 4929 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
4930 | return err; |
4931 | } | |
4932 | ||
b2e1b302 LR |
4933 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
4934 | { | |
4935 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
4936 | struct nlattr *nl_reg_rule; | |
4937 | char *alpha2 = NULL; | |
4938 | int rem_reg_rules = 0, r = 0; | |
4939 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 4940 | u8 dfs_region = 0; |
b2e1b302 LR |
4941 | struct ieee80211_regdomain *rd = NULL; |
4942 | ||
4943 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
4944 | return -EINVAL; | |
4945 | ||
4946 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
4947 | return -EINVAL; | |
4948 | ||
4949 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4950 | ||
8b60b078 LR |
4951 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
4952 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
4953 | ||
b2e1b302 | 4954 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4955 | rem_reg_rules) { |
b2e1b302 LR |
4956 | num_rules++; |
4957 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 4958 | return -EINVAL; |
b2e1b302 LR |
4959 | } |
4960 | ||
b2e1b302 | 4961 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 4962 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
4963 | |
4964 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
4965 | if (!rd) |
4966 | return -ENOMEM; | |
b2e1b302 LR |
4967 | |
4968 | rd->n_reg_rules = num_rules; | |
4969 | rd->alpha2[0] = alpha2[0]; | |
4970 | rd->alpha2[1] = alpha2[1]; | |
4971 | ||
8b60b078 LR |
4972 | /* |
4973 | * Disable DFS master mode if the DFS region was | |
4974 | * not supported or known on this kernel. | |
4975 | */ | |
4976 | if (reg_supported_dfs_region(dfs_region)) | |
4977 | rd->dfs_region = dfs_region; | |
4978 | ||
b2e1b302 | 4979 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4980 | rem_reg_rules) { |
b2e1b302 | 4981 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
4982 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
4983 | reg_rule_policy); | |
b2e1b302 LR |
4984 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
4985 | if (r) | |
4986 | goto bad_reg; | |
4987 | ||
4988 | rule_idx++; | |
4989 | ||
d0e18f83 LR |
4990 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
4991 | r = -EINVAL; | |
b2e1b302 | 4992 | goto bad_reg; |
d0e18f83 | 4993 | } |
b2e1b302 LR |
4994 | } |
4995 | ||
6913b49a JB |
4996 | mutex_lock(&cfg80211_mutex); |
4997 | ||
b2e1b302 | 4998 | r = set_regdom(rd); |
6913b49a | 4999 | /* set_regdom took ownership */ |
1a919318 | 5000 | rd = NULL; |
6913b49a | 5001 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 5002 | |
d2372b31 | 5003 | bad_reg: |
b2e1b302 | 5004 | kfree(rd); |
d0e18f83 | 5005 | return r; |
b2e1b302 LR |
5006 | } |
5007 | ||
83f5e2cf JB |
5008 | static int validate_scan_freqs(struct nlattr *freqs) |
5009 | { | |
5010 | struct nlattr *attr1, *attr2; | |
5011 | int n_channels = 0, tmp1, tmp2; | |
5012 | ||
5013 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5014 | n_channels++; | |
5015 | /* | |
5016 | * Some hardware has a limited channel list for | |
5017 | * scanning, and it is pretty much nonsensical | |
5018 | * to scan for a channel twice, so disallow that | |
5019 | * and don't require drivers to check that the | |
5020 | * channel list they get isn't longer than what | |
5021 | * they can scan, as long as they can scan all | |
5022 | * the channels they registered at once. | |
5023 | */ | |
5024 | nla_for_each_nested(attr2, freqs, tmp2) | |
5025 | if (attr1 != attr2 && | |
5026 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5027 | return 0; | |
5028 | } | |
5029 | ||
5030 | return n_channels; | |
5031 | } | |
5032 | ||
2a519311 JB |
5033 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5034 | { | |
4c476991 | 5035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5036 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5037 | struct cfg80211_scan_request *request; |
2a519311 JB |
5038 | struct nlattr *attr; |
5039 | struct wiphy *wiphy; | |
83f5e2cf | 5040 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5041 | size_t ie_len; |
2a519311 | 5042 | |
f4a11bb0 JB |
5043 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5044 | return -EINVAL; | |
5045 | ||
79c97e97 | 5046 | wiphy = &rdev->wiphy; |
2a519311 | 5047 | |
4c476991 JB |
5048 | if (!rdev->ops->scan) |
5049 | return -EOPNOTSUPP; | |
2a519311 | 5050 | |
4c476991 JB |
5051 | if (rdev->scan_req) |
5052 | return -EBUSY; | |
2a519311 JB |
5053 | |
5054 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5055 | n_channels = validate_scan_freqs( |
5056 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
5057 | if (!n_channels) |
5058 | return -EINVAL; | |
2a519311 | 5059 | } else { |
34850ab2 | 5060 | enum ieee80211_band band; |
83f5e2cf JB |
5061 | n_channels = 0; |
5062 | ||
2a519311 JB |
5063 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5064 | if (wiphy->bands[band]) | |
5065 | n_channels += wiphy->bands[band]->n_channels; | |
5066 | } | |
5067 | ||
5068 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5069 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5070 | n_ssids++; | |
5071 | ||
4c476991 JB |
5072 | if (n_ssids > wiphy->max_scan_ssids) |
5073 | return -EINVAL; | |
2a519311 | 5074 | |
70692ad2 JM |
5075 | if (info->attrs[NL80211_ATTR_IE]) |
5076 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5077 | else | |
5078 | ie_len = 0; | |
5079 | ||
4c476991 JB |
5080 | if (ie_len > wiphy->max_scan_ie_len) |
5081 | return -EINVAL; | |
18a83659 | 5082 | |
2a519311 | 5083 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5084 | + sizeof(*request->ssids) * n_ssids |
5085 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5086 | + ie_len, GFP_KERNEL); |
4c476991 JB |
5087 | if (!request) |
5088 | return -ENOMEM; | |
2a519311 | 5089 | |
2a519311 | 5090 | if (n_ssids) |
5ba63533 | 5091 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5092 | request->n_ssids = n_ssids; |
70692ad2 JM |
5093 | if (ie_len) { |
5094 | if (request->ssids) | |
5095 | request->ie = (void *)(request->ssids + n_ssids); | |
5096 | else | |
5097 | request->ie = (void *)(request->channels + n_channels); | |
5098 | } | |
2a519311 | 5099 | |
584991dc | 5100 | i = 0; |
2a519311 JB |
5101 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5102 | /* user specified, bail out if channel not found */ | |
2a519311 | 5103 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5104 | struct ieee80211_channel *chan; |
5105 | ||
5106 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5107 | ||
5108 | if (!chan) { | |
2a519311 JB |
5109 | err = -EINVAL; |
5110 | goto out_free; | |
5111 | } | |
584991dc JB |
5112 | |
5113 | /* ignore disabled channels */ | |
5114 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5115 | continue; | |
5116 | ||
5117 | request->channels[i] = chan; | |
2a519311 JB |
5118 | i++; |
5119 | } | |
5120 | } else { | |
34850ab2 JB |
5121 | enum ieee80211_band band; |
5122 | ||
2a519311 | 5123 | /* all channels */ |
2a519311 JB |
5124 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5125 | int j; | |
5126 | if (!wiphy->bands[band]) | |
5127 | continue; | |
5128 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5129 | struct ieee80211_channel *chan; |
5130 | ||
5131 | chan = &wiphy->bands[band]->channels[j]; | |
5132 | ||
5133 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5134 | continue; | |
5135 | ||
5136 | request->channels[i] = chan; | |
2a519311 JB |
5137 | i++; |
5138 | } | |
5139 | } | |
5140 | } | |
5141 | ||
584991dc JB |
5142 | if (!i) { |
5143 | err = -EINVAL; | |
5144 | goto out_free; | |
5145 | } | |
5146 | ||
5147 | request->n_channels = i; | |
5148 | ||
2a519311 JB |
5149 | i = 0; |
5150 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5151 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5152 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5153 | err = -EINVAL; |
5154 | goto out_free; | |
5155 | } | |
57a27e1d | 5156 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5157 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5158 | i++; |
5159 | } | |
5160 | } | |
5161 | ||
70692ad2 JM |
5162 | if (info->attrs[NL80211_ATTR_IE]) { |
5163 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5164 | memcpy((void *)request->ie, |
5165 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5166 | request->ie_len); |
5167 | } | |
5168 | ||
34850ab2 | 5169 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5170 | if (wiphy->bands[i]) |
5171 | request->rates[i] = | |
5172 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5173 | |
5174 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5175 | nla_for_each_nested(attr, | |
5176 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5177 | tmp) { | |
5178 | enum ieee80211_band band = nla_type(attr); | |
5179 | ||
84404623 | 5180 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5181 | err = -EINVAL; |
5182 | goto out_free; | |
5183 | } | |
5184 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5185 | nla_data(attr), | |
5186 | nla_len(attr), | |
5187 | &request->rates[band]); | |
5188 | if (err) | |
5189 | goto out_free; | |
5190 | } | |
5191 | } | |
5192 | ||
46856bbf | 5193 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5194 | request->flags = nla_get_u32( |
5195 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5196 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5197 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5198 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5199 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5200 | err = -EOPNOTSUPP; |
5201 | goto out_free; | |
5202 | } | |
5203 | } | |
ed473771 | 5204 | |
e9f935e3 RM |
5205 | request->no_cck = |
5206 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5207 | ||
fd014284 | 5208 | request->wdev = wdev; |
79c97e97 | 5209 | request->wiphy = &rdev->wiphy; |
15d6030b | 5210 | request->scan_start = jiffies; |
2a519311 | 5211 | |
79c97e97 | 5212 | rdev->scan_req = request; |
e35e4d28 | 5213 | err = rdev_scan(rdev, request); |
2a519311 | 5214 | |
463d0183 | 5215 | if (!err) { |
fd014284 JB |
5216 | nl80211_send_scan_start(rdev, wdev); |
5217 | if (wdev->netdev) | |
5218 | dev_hold(wdev->netdev); | |
4c476991 | 5219 | } else { |
2a519311 | 5220 | out_free: |
79c97e97 | 5221 | rdev->scan_req = NULL; |
2a519311 JB |
5222 | kfree(request); |
5223 | } | |
3b85875a | 5224 | |
2a519311 JB |
5225 | return err; |
5226 | } | |
5227 | ||
807f8a8c LC |
5228 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5229 | struct genl_info *info) | |
5230 | { | |
5231 | struct cfg80211_sched_scan_request *request; | |
5232 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5233 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5234 | struct nlattr *attr; |
5235 | struct wiphy *wiphy; | |
a1f1c21c | 5236 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5237 | u32 interval; |
807f8a8c LC |
5238 | enum ieee80211_band band; |
5239 | size_t ie_len; | |
a1f1c21c | 5240 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5241 | |
5242 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5243 | !rdev->ops->sched_scan_start) | |
5244 | return -EOPNOTSUPP; | |
5245 | ||
5246 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5247 | return -EINVAL; | |
5248 | ||
bbe6ad6d LC |
5249 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5250 | return -EINVAL; | |
5251 | ||
5252 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5253 | if (interval == 0) | |
5254 | return -EINVAL; | |
5255 | ||
807f8a8c LC |
5256 | wiphy = &rdev->wiphy; |
5257 | ||
5258 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5259 | n_channels = validate_scan_freqs( | |
5260 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5261 | if (!n_channels) | |
5262 | return -EINVAL; | |
5263 | } else { | |
5264 | n_channels = 0; | |
5265 | ||
5266 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5267 | if (wiphy->bands[band]) | |
5268 | n_channels += wiphy->bands[band]->n_channels; | |
5269 | } | |
5270 | ||
5271 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5272 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5273 | tmp) | |
5274 | n_ssids++; | |
5275 | ||
93b6aa69 | 5276 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5277 | return -EINVAL; |
5278 | ||
a1f1c21c LC |
5279 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5280 | nla_for_each_nested(attr, | |
5281 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5282 | tmp) | |
5283 | n_match_sets++; | |
5284 | ||
5285 | if (n_match_sets > wiphy->max_match_sets) | |
5286 | return -EINVAL; | |
5287 | ||
807f8a8c LC |
5288 | if (info->attrs[NL80211_ATTR_IE]) |
5289 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5290 | else | |
5291 | ie_len = 0; | |
5292 | ||
5a865bad | 5293 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5294 | return -EINVAL; |
5295 | ||
c10841ca LC |
5296 | mutex_lock(&rdev->sched_scan_mtx); |
5297 | ||
5298 | if (rdev->sched_scan_req) { | |
5299 | err = -EINPROGRESS; | |
5300 | goto out; | |
5301 | } | |
5302 | ||
807f8a8c | 5303 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5304 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5305 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5306 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5307 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5308 | if (!request) { |
5309 | err = -ENOMEM; | |
5310 | goto out; | |
5311 | } | |
807f8a8c LC |
5312 | |
5313 | if (n_ssids) | |
5314 | request->ssids = (void *)&request->channels[n_channels]; | |
5315 | request->n_ssids = n_ssids; | |
5316 | if (ie_len) { | |
5317 | if (request->ssids) | |
5318 | request->ie = (void *)(request->ssids + n_ssids); | |
5319 | else | |
5320 | request->ie = (void *)(request->channels + n_channels); | |
5321 | } | |
5322 | ||
a1f1c21c LC |
5323 | if (n_match_sets) { |
5324 | if (request->ie) | |
5325 | request->match_sets = (void *)(request->ie + ie_len); | |
5326 | else if (request->ssids) | |
5327 | request->match_sets = | |
5328 | (void *)(request->ssids + n_ssids); | |
5329 | else | |
5330 | request->match_sets = | |
5331 | (void *)(request->channels + n_channels); | |
5332 | } | |
5333 | request->n_match_sets = n_match_sets; | |
5334 | ||
807f8a8c LC |
5335 | i = 0; |
5336 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5337 | /* user specified, bail out if channel not found */ | |
5338 | nla_for_each_nested(attr, | |
5339 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5340 | tmp) { | |
5341 | struct ieee80211_channel *chan; | |
5342 | ||
5343 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5344 | ||
5345 | if (!chan) { | |
5346 | err = -EINVAL; | |
5347 | goto out_free; | |
5348 | } | |
5349 | ||
5350 | /* ignore disabled channels */ | |
5351 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5352 | continue; | |
5353 | ||
5354 | request->channels[i] = chan; | |
5355 | i++; | |
5356 | } | |
5357 | } else { | |
5358 | /* all channels */ | |
5359 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5360 | int j; | |
5361 | if (!wiphy->bands[band]) | |
5362 | continue; | |
5363 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5364 | struct ieee80211_channel *chan; | |
5365 | ||
5366 | chan = &wiphy->bands[band]->channels[j]; | |
5367 | ||
5368 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5369 | continue; | |
5370 | ||
5371 | request->channels[i] = chan; | |
5372 | i++; | |
5373 | } | |
5374 | } | |
5375 | } | |
5376 | ||
5377 | if (!i) { | |
5378 | err = -EINVAL; | |
5379 | goto out_free; | |
5380 | } | |
5381 | ||
5382 | request->n_channels = i; | |
5383 | ||
5384 | i = 0; | |
5385 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5386 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5387 | tmp) { | |
57a27e1d | 5388 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5389 | err = -EINVAL; |
5390 | goto out_free; | |
5391 | } | |
57a27e1d | 5392 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5393 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5394 | nla_len(attr)); | |
807f8a8c LC |
5395 | i++; |
5396 | } | |
5397 | } | |
5398 | ||
a1f1c21c LC |
5399 | i = 0; |
5400 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5401 | nla_for_each_nested(attr, | |
5402 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5403 | tmp) { | |
88e920b4 | 5404 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5405 | |
5406 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5407 | nla_data(attr), nla_len(attr), | |
5408 | nl80211_match_policy); | |
4a4ab0d7 | 5409 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5410 | if (ssid) { |
5411 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5412 | err = -EINVAL; | |
5413 | goto out_free; | |
5414 | } | |
5415 | memcpy(request->match_sets[i].ssid.ssid, | |
5416 | nla_data(ssid), nla_len(ssid)); | |
5417 | request->match_sets[i].ssid.ssid_len = | |
5418 | nla_len(ssid); | |
5419 | } | |
88e920b4 TP |
5420 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5421 | if (rssi) | |
5422 | request->rssi_thold = nla_get_u32(rssi); | |
5423 | else | |
5424 | request->rssi_thold = | |
5425 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5426 | i++; |
5427 | } | |
5428 | } | |
5429 | ||
807f8a8c LC |
5430 | if (info->attrs[NL80211_ATTR_IE]) { |
5431 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5432 | memcpy((void *)request->ie, | |
5433 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5434 | request->ie_len); | |
5435 | } | |
5436 | ||
46856bbf | 5437 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5438 | request->flags = nla_get_u32( |
5439 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5440 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5441 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5442 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5443 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5444 | err = -EOPNOTSUPP; |
5445 | goto out_free; | |
5446 | } | |
5447 | } | |
ed473771 | 5448 | |
807f8a8c LC |
5449 | request->dev = dev; |
5450 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5451 | request->interval = interval; |
15d6030b | 5452 | request->scan_start = jiffies; |
807f8a8c | 5453 | |
e35e4d28 | 5454 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5455 | if (!err) { |
5456 | rdev->sched_scan_req = request; | |
5457 | nl80211_send_sched_scan(rdev, dev, | |
5458 | NL80211_CMD_START_SCHED_SCAN); | |
5459 | goto out; | |
5460 | } | |
5461 | ||
5462 | out_free: | |
5463 | kfree(request); | |
5464 | out: | |
c10841ca | 5465 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
5466 | return err; |
5467 | } | |
5468 | ||
5469 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5470 | struct genl_info *info) | |
5471 | { | |
5472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 5473 | int err; |
807f8a8c LC |
5474 | |
5475 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5476 | !rdev->ops->sched_scan_stop) | |
5477 | return -EOPNOTSUPP; | |
5478 | ||
c10841ca LC |
5479 | mutex_lock(&rdev->sched_scan_mtx); |
5480 | err = __cfg80211_stop_sched_scan(rdev, false); | |
5481 | mutex_unlock(&rdev->sched_scan_mtx); | |
5482 | ||
5483 | return err; | |
807f8a8c LC |
5484 | } |
5485 | ||
04f39047 SW |
5486 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5487 | struct genl_info *info) | |
5488 | { | |
5489 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5490 | struct net_device *dev = info->user_ptr[1]; | |
5491 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5492 | struct cfg80211_chan_def chandef; | |
5493 | int err; | |
5494 | ||
5495 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5496 | if (err) | |
5497 | return err; | |
5498 | ||
5499 | if (wdev->cac_started) | |
5500 | return -EBUSY; | |
5501 | ||
5502 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5503 | if (err < 0) | |
5504 | return err; | |
5505 | ||
5506 | if (err == 0) | |
5507 | return -EINVAL; | |
5508 | ||
5509 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5510 | return -EINVAL; | |
5511 | ||
5512 | if (!rdev->ops->start_radar_detection) | |
5513 | return -EOPNOTSUPP; | |
5514 | ||
5515 | mutex_lock(&rdev->devlist_mtx); | |
5516 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5517 | chandef.chan, CHAN_MODE_SHARED, | |
5518 | BIT(chandef.width)); | |
5519 | if (err) | |
5520 | goto err_locked; | |
5521 | ||
5522 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5523 | if (!err) { | |
5524 | wdev->channel = chandef.chan; | |
5525 | wdev->cac_started = true; | |
5526 | wdev->cac_start_time = jiffies; | |
5527 | } | |
5528 | err_locked: | |
5529 | mutex_unlock(&rdev->devlist_mtx); | |
5530 | ||
5531 | return err; | |
5532 | } | |
5533 | ||
9720bb3a JB |
5534 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5535 | u32 seq, int flags, | |
2a519311 | 5536 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5537 | struct wireless_dev *wdev, |
5538 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5539 | { |
48ab905d | 5540 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5541 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5542 | void *hdr; |
5543 | struct nlattr *bss; | |
8cef2c9d | 5544 | bool tsf = false; |
48ab905d JB |
5545 | |
5546 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5547 | |
15e47304 | 5548 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5549 | NL80211_CMD_NEW_SCAN_RESULTS); |
5550 | if (!hdr) | |
5551 | return -1; | |
5552 | ||
9720bb3a JB |
5553 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5554 | ||
9360ffd1 DM |
5555 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
5556 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | |
5557 | goto nla_put_failure; | |
2a519311 JB |
5558 | |
5559 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5560 | if (!bss) | |
5561 | goto nla_put_failure; | |
9360ffd1 | 5562 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5563 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5564 | goto nla_put_failure; |
9caf0364 JB |
5565 | |
5566 | rcu_read_lock(); | |
5567 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5568 | if (ies) { |
5569 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5570 | goto fail_unlock_rcu; | |
5571 | tsf = true; | |
5572 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5573 | ies->len, ies->data)) | |
5574 | goto fail_unlock_rcu; | |
9caf0364 JB |
5575 | } |
5576 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5577 | if (ies) { |
5578 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5579 | goto fail_unlock_rcu; | |
5580 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5581 | ies->len, ies->data)) | |
5582 | goto fail_unlock_rcu; | |
9caf0364 JB |
5583 | } |
5584 | rcu_read_unlock(); | |
5585 | ||
9360ffd1 DM |
5586 | if (res->beacon_interval && |
5587 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5588 | goto nla_put_failure; | |
5589 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5590 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5591 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5592 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5593 | goto nla_put_failure; | |
2a519311 | 5594 | |
77965c97 | 5595 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5596 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5597 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5598 | goto nla_put_failure; | |
2a519311 JB |
5599 | break; |
5600 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5601 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5602 | goto nla_put_failure; | |
2a519311 JB |
5603 | break; |
5604 | default: | |
5605 | break; | |
5606 | } | |
5607 | ||
48ab905d | 5608 | switch (wdev->iftype) { |
074ac8df | 5609 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5610 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5611 | if (intbss == wdev->current_bss && |
5612 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5613 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5614 | goto nla_put_failure; | |
48ab905d JB |
5615 | break; |
5616 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5617 | if (intbss == wdev->current_bss && |
5618 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5619 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5620 | goto nla_put_failure; | |
48ab905d JB |
5621 | break; |
5622 | default: | |
5623 | break; | |
5624 | } | |
5625 | ||
2a519311 JB |
5626 | nla_nest_end(msg, bss); |
5627 | ||
5628 | return genlmsg_end(msg, hdr); | |
5629 | ||
8cef2c9d JB |
5630 | fail_unlock_rcu: |
5631 | rcu_read_unlock(); | |
2a519311 JB |
5632 | nla_put_failure: |
5633 | genlmsg_cancel(msg, hdr); | |
5634 | return -EMSGSIZE; | |
5635 | } | |
5636 | ||
5637 | static int nl80211_dump_scan(struct sk_buff *skb, | |
5638 | struct netlink_callback *cb) | |
5639 | { | |
48ab905d JB |
5640 | struct cfg80211_registered_device *rdev; |
5641 | struct net_device *dev; | |
2a519311 | 5642 | struct cfg80211_internal_bss *scan; |
48ab905d | 5643 | struct wireless_dev *wdev; |
2a519311 JB |
5644 | int start = cb->args[1], idx = 0; |
5645 | int err; | |
5646 | ||
67748893 JB |
5647 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
5648 | if (err) | |
5649 | return err; | |
2a519311 | 5650 | |
48ab905d | 5651 | wdev = dev->ieee80211_ptr; |
2a519311 | 5652 | |
48ab905d JB |
5653 | wdev_lock(wdev); |
5654 | spin_lock_bh(&rdev->bss_lock); | |
5655 | cfg80211_bss_expire(rdev); | |
5656 | ||
9720bb3a JB |
5657 | cb->seq = rdev->bss_generation; |
5658 | ||
48ab905d | 5659 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5660 | if (++idx <= start) |
5661 | continue; | |
9720bb3a | 5662 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5663 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5664 | rdev, wdev, scan) < 0) { |
2a519311 | 5665 | idx--; |
67748893 | 5666 | break; |
2a519311 JB |
5667 | } |
5668 | } | |
5669 | ||
48ab905d JB |
5670 | spin_unlock_bh(&rdev->bss_lock); |
5671 | wdev_unlock(wdev); | |
2a519311 JB |
5672 | |
5673 | cb->args[1] = idx; | |
67748893 | 5674 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 5675 | |
67748893 | 5676 | return skb->len; |
2a519311 JB |
5677 | } |
5678 | ||
15e47304 | 5679 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5680 | int flags, struct net_device *dev, |
5681 | struct survey_info *survey) | |
5682 | { | |
5683 | void *hdr; | |
5684 | struct nlattr *infoattr; | |
5685 | ||
15e47304 | 5686 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5687 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5688 | if (!hdr) | |
5689 | return -ENOMEM; | |
5690 | ||
9360ffd1 DM |
5691 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5692 | goto nla_put_failure; | |
61fa713c HS |
5693 | |
5694 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5695 | if (!infoattr) | |
5696 | goto nla_put_failure; | |
5697 | ||
9360ffd1 DM |
5698 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5699 | survey->channel->center_freq)) | |
5700 | goto nla_put_failure; | |
5701 | ||
5702 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5703 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5704 | goto nla_put_failure; | |
5705 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5706 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5707 | goto nla_put_failure; | |
5708 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5709 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5710 | survey->channel_time)) | |
5711 | goto nla_put_failure; | |
5712 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5713 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5714 | survey->channel_time_busy)) | |
5715 | goto nla_put_failure; | |
5716 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5717 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5718 | survey->channel_time_ext_busy)) | |
5719 | goto nla_put_failure; | |
5720 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5721 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5722 | survey->channel_time_rx)) | |
5723 | goto nla_put_failure; | |
5724 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5725 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5726 | survey->channel_time_tx)) | |
5727 | goto nla_put_failure; | |
61fa713c HS |
5728 | |
5729 | nla_nest_end(msg, infoattr); | |
5730 | ||
5731 | return genlmsg_end(msg, hdr); | |
5732 | ||
5733 | nla_put_failure: | |
5734 | genlmsg_cancel(msg, hdr); | |
5735 | return -EMSGSIZE; | |
5736 | } | |
5737 | ||
5738 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5739 | struct netlink_callback *cb) | |
5740 | { | |
5741 | struct survey_info survey; | |
5742 | struct cfg80211_registered_device *dev; | |
5743 | struct net_device *netdev; | |
61fa713c HS |
5744 | int survey_idx = cb->args[1]; |
5745 | int res; | |
5746 | ||
67748893 JB |
5747 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
5748 | if (res) | |
5749 | return res; | |
61fa713c HS |
5750 | |
5751 | if (!dev->ops->dump_survey) { | |
5752 | res = -EOPNOTSUPP; | |
5753 | goto out_err; | |
5754 | } | |
5755 | ||
5756 | while (1) { | |
180cdc79 LR |
5757 | struct ieee80211_channel *chan; |
5758 | ||
e35e4d28 | 5759 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
61fa713c HS |
5760 | if (res == -ENOENT) |
5761 | break; | |
5762 | if (res) | |
5763 | goto out_err; | |
5764 | ||
180cdc79 LR |
5765 | /* Survey without a channel doesn't make sense */ |
5766 | if (!survey.channel) { | |
5767 | res = -EINVAL; | |
5768 | goto out; | |
5769 | } | |
5770 | ||
5771 | chan = ieee80211_get_channel(&dev->wiphy, | |
5772 | survey.channel->center_freq); | |
5773 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5774 | survey_idx++; | |
5775 | continue; | |
5776 | } | |
5777 | ||
61fa713c | 5778 | if (nl80211_send_survey(skb, |
15e47304 | 5779 | NETLINK_CB(cb->skb).portid, |
61fa713c HS |
5780 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
5781 | netdev, | |
5782 | &survey) < 0) | |
5783 | goto out; | |
5784 | survey_idx++; | |
5785 | } | |
5786 | ||
5787 | out: | |
5788 | cb->args[1] = survey_idx; | |
5789 | res = skb->len; | |
5790 | out_err: | |
67748893 | 5791 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
5792 | return res; |
5793 | } | |
5794 | ||
b23aa676 SO |
5795 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5796 | { | |
5797 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5798 | NL80211_WPA_VERSION_2)); | |
5799 | } | |
5800 | ||
636a5d36 JM |
5801 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5802 | { | |
4c476991 JB |
5803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5804 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5805 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5806 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5807 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5808 | enum nl80211_auth_type auth_type; |
fffd0934 | 5809 | struct key_parse key; |
d5cdfacb | 5810 | bool local_state_change; |
636a5d36 | 5811 | |
f4a11bb0 JB |
5812 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5813 | return -EINVAL; | |
5814 | ||
5815 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5816 | return -EINVAL; | |
5817 | ||
1778092e JM |
5818 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5819 | return -EINVAL; | |
5820 | ||
19957bb3 JB |
5821 | if (!info->attrs[NL80211_ATTR_SSID]) |
5822 | return -EINVAL; | |
5823 | ||
5824 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5825 | return -EINVAL; | |
5826 | ||
fffd0934 JB |
5827 | err = nl80211_parse_key(info, &key); |
5828 | if (err) | |
5829 | return err; | |
5830 | ||
5831 | if (key.idx >= 0) { | |
e31b8213 JB |
5832 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5833 | return -EINVAL; | |
fffd0934 JB |
5834 | if (!key.p.key || !key.p.key_len) |
5835 | return -EINVAL; | |
5836 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5837 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5838 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5839 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5840 | return -EINVAL; | |
5841 | if (key.idx > 4) | |
5842 | return -EINVAL; | |
5843 | } else { | |
5844 | key.p.key_len = 0; | |
5845 | key.p.key = NULL; | |
5846 | } | |
5847 | ||
afea0b7a JB |
5848 | if (key.idx >= 0) { |
5849 | int i; | |
5850 | bool ok = false; | |
5851 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5852 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5853 | ok = true; | |
5854 | break; | |
5855 | } | |
5856 | } | |
4c476991 JB |
5857 | if (!ok) |
5858 | return -EINVAL; | |
afea0b7a JB |
5859 | } |
5860 | ||
4c476991 JB |
5861 | if (!rdev->ops->auth) |
5862 | return -EOPNOTSUPP; | |
636a5d36 | 5863 | |
074ac8df | 5864 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5865 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5866 | return -EOPNOTSUPP; | |
eec60b03 | 5867 | |
19957bb3 | 5868 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5869 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5870 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5871 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5872 | return -EINVAL; | |
636a5d36 | 5873 | |
19957bb3 JB |
5874 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5875 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5876 | |
5877 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5878 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5879 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5880 | } |
5881 | ||
19957bb3 | 5882 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5883 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5884 | return -EINVAL; |
636a5d36 | 5885 | |
e39e5b5e JM |
5886 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5887 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5888 | return -EINVAL; | |
5889 | ||
5890 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5891 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5892 | return -EINVAL; | |
5893 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5894 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5895 | /* need to include at least Auth Transaction and Status Code */ | |
5896 | if (sae_data_len < 4) | |
5897 | return -EINVAL; | |
5898 | } | |
5899 | ||
d5cdfacb JM |
5900 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5901 | ||
95de817b JB |
5902 | /* |
5903 | * Since we no longer track auth state, ignore | |
5904 | * requests to only change local state. | |
5905 | */ | |
5906 | if (local_state_change) | |
5907 | return 0; | |
5908 | ||
4c476991 JB |
5909 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
5910 | ssid, ssid_len, ie, ie_len, | |
e39e5b5e JM |
5911 | key.p.key, key.p.key_len, key.idx, |
5912 | sae_data, sae_data_len); | |
636a5d36 JM |
5913 | } |
5914 | ||
c0692b8f JB |
5915 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
5916 | struct genl_info *info, | |
3dc27d25 JB |
5917 | struct cfg80211_crypto_settings *settings, |
5918 | int cipher_limit) | |
b23aa676 | 5919 | { |
c0b2bbd8 JB |
5920 | memset(settings, 0, sizeof(*settings)); |
5921 | ||
b23aa676 SO |
5922 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
5923 | ||
c0692b8f JB |
5924 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
5925 | u16 proto; | |
5926 | proto = nla_get_u16( | |
5927 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
5928 | settings->control_port_ethertype = cpu_to_be16(proto); | |
5929 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
5930 | proto != ETH_P_PAE) | |
5931 | return -EINVAL; | |
5932 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
5933 | settings->control_port_no_encrypt = true; | |
5934 | } else | |
5935 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
5936 | ||
b23aa676 SO |
5937 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
5938 | void *data; | |
5939 | int len, i; | |
5940 | ||
5941 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5942 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5943 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
5944 | ||
5945 | if (len % sizeof(u32)) | |
5946 | return -EINVAL; | |
5947 | ||
3dc27d25 | 5948 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
5949 | return -EINVAL; |
5950 | ||
5951 | memcpy(settings->ciphers_pairwise, data, len); | |
5952 | ||
5953 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
5954 | if (!cfg80211_supported_cipher_suite( |
5955 | &rdev->wiphy, | |
b23aa676 SO |
5956 | settings->ciphers_pairwise[i])) |
5957 | return -EINVAL; | |
5958 | } | |
5959 | ||
5960 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
5961 | settings->cipher_group = | |
5962 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
5963 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
5964 | settings->cipher_group)) | |
b23aa676 SO |
5965 | return -EINVAL; |
5966 | } | |
5967 | ||
5968 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
5969 | settings->wpa_versions = | |
5970 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
5971 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
5972 | return -EINVAL; | |
5973 | } | |
5974 | ||
5975 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
5976 | void *data; | |
6d30240e | 5977 | int len; |
b23aa676 SO |
5978 | |
5979 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5980 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5981 | settings->n_akm_suites = len / sizeof(u32); | |
5982 | ||
5983 | if (len % sizeof(u32)) | |
5984 | return -EINVAL; | |
5985 | ||
1b9ca027 JM |
5986 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
5987 | return -EINVAL; | |
5988 | ||
b23aa676 | 5989 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
5990 | } |
5991 | ||
5992 | return 0; | |
5993 | } | |
5994 | ||
636a5d36 JM |
5995 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
5996 | { | |
4c476991 JB |
5997 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5998 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 5999 | struct ieee80211_channel *chan; |
f62fab73 JB |
6000 | struct cfg80211_assoc_request req = {}; |
6001 | const u8 *bssid, *ssid; | |
6002 | int err, ssid_len = 0; | |
636a5d36 | 6003 | |
f4a11bb0 JB |
6004 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6005 | return -EINVAL; | |
6006 | ||
6007 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6008 | !info->attrs[NL80211_ATTR_SSID] || |
6009 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6010 | return -EINVAL; |
6011 | ||
4c476991 JB |
6012 | if (!rdev->ops->assoc) |
6013 | return -EOPNOTSUPP; | |
636a5d36 | 6014 | |
074ac8df | 6015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6016 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6017 | return -EOPNOTSUPP; | |
eec60b03 | 6018 | |
19957bb3 | 6019 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6020 | |
19957bb3 JB |
6021 | chan = ieee80211_get_channel(&rdev->wiphy, |
6022 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6023 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6024 | return -EINVAL; | |
636a5d36 | 6025 | |
19957bb3 JB |
6026 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6027 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6028 | |
6029 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6030 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6031 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6032 | } |
6033 | ||
dc6382ce | 6034 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6035 | enum nl80211_mfp mfp = |
dc6382ce | 6036 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6037 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6038 | req.use_mfp = true; |
4c476991 JB |
6039 | else if (mfp != NL80211_MFP_NO) |
6040 | return -EINVAL; | |
dc6382ce JM |
6041 | } |
6042 | ||
3e5d7649 | 6043 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6044 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6045 | |
7e7c8926 | 6046 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6047 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6048 | |
6049 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6050 | memcpy(&req.ht_capa_mask, |
6051 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6052 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6053 | |
6054 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6055 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6056 | return -EINVAL; |
f62fab73 JB |
6057 | memcpy(&req.ht_capa, |
6058 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6059 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6060 | } |
6061 | ||
ee2aca34 | 6062 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6063 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6064 | |
6065 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6066 | memcpy(&req.vht_capa_mask, |
6067 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6068 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6069 | |
6070 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6071 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6072 | return -EINVAL; |
f62fab73 JB |
6073 | memcpy(&req.vht_capa, |
6074 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6075 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6076 | } |
6077 | ||
f62fab73 | 6078 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
b23aa676 | 6079 | if (!err) |
f62fab73 JB |
6080 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6081 | ssid, ssid_len, &req); | |
636a5d36 | 6082 | |
636a5d36 JM |
6083 | return err; |
6084 | } | |
6085 | ||
6086 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6087 | { | |
4c476991 JB |
6088 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6089 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6090 | const u8 *ie = NULL, *bssid; |
4c476991 | 6091 | int ie_len = 0; |
19957bb3 | 6092 | u16 reason_code; |
d5cdfacb | 6093 | bool local_state_change; |
636a5d36 | 6094 | |
f4a11bb0 JB |
6095 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6096 | return -EINVAL; | |
6097 | ||
6098 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6099 | return -EINVAL; | |
6100 | ||
6101 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6102 | return -EINVAL; | |
6103 | ||
4c476991 JB |
6104 | if (!rdev->ops->deauth) |
6105 | return -EOPNOTSUPP; | |
636a5d36 | 6106 | |
074ac8df | 6107 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6108 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6109 | return -EOPNOTSUPP; | |
eec60b03 | 6110 | |
19957bb3 | 6111 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6112 | |
19957bb3 JB |
6113 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6114 | if (reason_code == 0) { | |
f4a11bb0 | 6115 | /* Reason Code 0 is reserved */ |
4c476991 | 6116 | return -EINVAL; |
255e737e | 6117 | } |
636a5d36 JM |
6118 | |
6119 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6120 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6121 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6122 | } |
6123 | ||
d5cdfacb JM |
6124 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6125 | ||
4c476991 JB |
6126 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
6127 | local_state_change); | |
636a5d36 JM |
6128 | } |
6129 | ||
6130 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6131 | { | |
4c476991 JB |
6132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6133 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6134 | const u8 *ie = NULL, *bssid; |
4c476991 | 6135 | int ie_len = 0; |
19957bb3 | 6136 | u16 reason_code; |
d5cdfacb | 6137 | bool local_state_change; |
636a5d36 | 6138 | |
f4a11bb0 JB |
6139 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6140 | return -EINVAL; | |
6141 | ||
6142 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6143 | return -EINVAL; | |
6144 | ||
6145 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6146 | return -EINVAL; | |
6147 | ||
4c476991 JB |
6148 | if (!rdev->ops->disassoc) |
6149 | return -EOPNOTSUPP; | |
636a5d36 | 6150 | |
074ac8df | 6151 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6152 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6153 | return -EOPNOTSUPP; | |
eec60b03 | 6154 | |
19957bb3 | 6155 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6156 | |
19957bb3 JB |
6157 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6158 | if (reason_code == 0) { | |
f4a11bb0 | 6159 | /* Reason Code 0 is reserved */ |
4c476991 | 6160 | return -EINVAL; |
255e737e | 6161 | } |
636a5d36 JM |
6162 | |
6163 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6164 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6165 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6166 | } |
6167 | ||
d5cdfacb JM |
6168 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6169 | ||
4c476991 JB |
6170 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
6171 | local_state_change); | |
636a5d36 JM |
6172 | } |
6173 | ||
dd5b4cc7 FF |
6174 | static bool |
6175 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6176 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6177 | int rateval) | |
6178 | { | |
6179 | struct wiphy *wiphy = &rdev->wiphy; | |
6180 | bool found = false; | |
6181 | int band, i; | |
6182 | ||
6183 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6184 | struct ieee80211_supported_band *sband; | |
6185 | ||
6186 | sband = wiphy->bands[band]; | |
6187 | if (!sband) | |
6188 | continue; | |
6189 | ||
6190 | for (i = 0; i < sband->n_bitrates; i++) { | |
6191 | if (sband->bitrates[i].bitrate == rateval) { | |
6192 | mcast_rate[band] = i + 1; | |
6193 | found = true; | |
6194 | break; | |
6195 | } | |
6196 | } | |
6197 | } | |
6198 | ||
6199 | return found; | |
6200 | } | |
6201 | ||
04a773ad JB |
6202 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6203 | { | |
4c476991 JB |
6204 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6205 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6206 | struct cfg80211_ibss_params ibss; |
6207 | struct wiphy *wiphy; | |
fffd0934 | 6208 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6209 | int err; |
6210 | ||
8e30bc55 JB |
6211 | memset(&ibss, 0, sizeof(ibss)); |
6212 | ||
04a773ad JB |
6213 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6214 | return -EINVAL; | |
6215 | ||
683b6d3b | 6216 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6217 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6218 | return -EINVAL; | |
6219 | ||
8e30bc55 JB |
6220 | ibss.beacon_interval = 100; |
6221 | ||
6222 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6223 | ibss.beacon_interval = | |
6224 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6225 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6226 | return -EINVAL; | |
6227 | } | |
6228 | ||
4c476991 JB |
6229 | if (!rdev->ops->join_ibss) |
6230 | return -EOPNOTSUPP; | |
04a773ad | 6231 | |
4c476991 JB |
6232 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6233 | return -EOPNOTSUPP; | |
04a773ad | 6234 | |
79c97e97 | 6235 | wiphy = &rdev->wiphy; |
04a773ad | 6236 | |
39193498 | 6237 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6238 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6239 | |
6240 | if (!is_valid_ether_addr(ibss.bssid)) | |
6241 | return -EINVAL; | |
6242 | } | |
04a773ad JB |
6243 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6244 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6245 | ||
6246 | if (info->attrs[NL80211_ATTR_IE]) { | |
6247 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6248 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6249 | } | |
6250 | ||
683b6d3b JB |
6251 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6252 | if (err) | |
6253 | return err; | |
04a773ad | 6254 | |
683b6d3b | 6255 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6256 | return -EINVAL; |
6257 | ||
db9c64cf JB |
6258 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
6259 | return -EINVAL; | |
6260 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
6261 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
c04d6150 | 6262 | return -EINVAL; |
db9c64cf | 6263 | |
04a773ad | 6264 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6265 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6266 | ||
fbd2c8dc TP |
6267 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6268 | u8 *rates = | |
6269 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6270 | int n_rates = | |
6271 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6272 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6273 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6274 | |
34850ab2 JB |
6275 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6276 | &ibss.basic_rates); | |
6277 | if (err) | |
6278 | return err; | |
fbd2c8dc | 6279 | } |
dd5b4cc7 FF |
6280 | |
6281 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
6282 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6283 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6284 | return -EINVAL; | |
fbd2c8dc | 6285 | |
4c476991 | 6286 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6287 | bool no_ht = false; |
6288 | ||
4c476991 | 6289 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6290 | info->attrs[NL80211_ATTR_KEYS], |
6291 | &no_ht); | |
4c476991 JB |
6292 | if (IS_ERR(connkeys)) |
6293 | return PTR_ERR(connkeys); | |
de7044ee | 6294 | |
3d9d1d66 JB |
6295 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6296 | no_ht) { | |
de7044ee SM |
6297 | kfree(connkeys); |
6298 | return -EINVAL; | |
6299 | } | |
4c476991 | 6300 | } |
04a773ad | 6301 | |
267335d6 AQ |
6302 | ibss.control_port = |
6303 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6304 | ||
4c476991 | 6305 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6306 | if (err) |
6307 | kfree(connkeys); | |
04a773ad JB |
6308 | return err; |
6309 | } | |
6310 | ||
6311 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6312 | { | |
4c476991 JB |
6313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6314 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6315 | |
4c476991 JB |
6316 | if (!rdev->ops->leave_ibss) |
6317 | return -EOPNOTSUPP; | |
04a773ad | 6318 | |
4c476991 JB |
6319 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6320 | return -EOPNOTSUPP; | |
04a773ad | 6321 | |
4c476991 | 6322 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6323 | } |
6324 | ||
f4e583c8 AQ |
6325 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6326 | { | |
6327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6328 | struct net_device *dev = info->user_ptr[1]; | |
6329 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6330 | u32 nla_rate; | |
6331 | int err; | |
6332 | ||
6333 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6334 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6335 | return -EOPNOTSUPP; | |
6336 | ||
6337 | if (!rdev->ops->set_mcast_rate) | |
6338 | return -EOPNOTSUPP; | |
6339 | ||
6340 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6341 | ||
6342 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6343 | return -EINVAL; | |
6344 | ||
6345 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6346 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6347 | return -EINVAL; | |
6348 | ||
6349 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6350 | ||
6351 | return err; | |
6352 | } | |
6353 | ||
6354 | ||
aff89a9b JB |
6355 | #ifdef CONFIG_NL80211_TESTMODE |
6356 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6357 | .name = "testmode", | |
6358 | }; | |
6359 | ||
6360 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6361 | { | |
4c476991 | 6362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6363 | int err; |
6364 | ||
6365 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6366 | return -EINVAL; | |
6367 | ||
aff89a9b JB |
6368 | err = -EOPNOTSUPP; |
6369 | if (rdev->ops->testmode_cmd) { | |
6370 | rdev->testmode_info = info; | |
e35e4d28 | 6371 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6372 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6373 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6374 | rdev->testmode_info = NULL; | |
6375 | } | |
6376 | ||
aff89a9b JB |
6377 | return err; |
6378 | } | |
6379 | ||
71063f0e WYG |
6380 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6381 | struct netlink_callback *cb) | |
6382 | { | |
00918d33 | 6383 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6384 | int err; |
6385 | long phy_idx; | |
6386 | void *data = NULL; | |
6387 | int data_len = 0; | |
6388 | ||
6389 | if (cb->args[0]) { | |
6390 | /* | |
6391 | * 0 is a valid index, but not valid for args[0], | |
6392 | * so we need to offset by 1. | |
6393 | */ | |
6394 | phy_idx = cb->args[0] - 1; | |
6395 | } else { | |
6396 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6397 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6398 | nl80211_policy); | |
6399 | if (err) | |
6400 | return err; | |
00918d33 | 6401 | |
2bd7e35d JB |
6402 | mutex_lock(&cfg80211_mutex); |
6403 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
6404 | nl80211_fam.attrbuf); | |
6405 | if (IS_ERR(rdev)) { | |
6406 | mutex_unlock(&cfg80211_mutex); | |
6407 | return PTR_ERR(rdev); | |
00918d33 | 6408 | } |
2bd7e35d JB |
6409 | phy_idx = rdev->wiphy_idx; |
6410 | rdev = NULL; | |
6411 | mutex_unlock(&cfg80211_mutex); | |
6412 | ||
71063f0e WYG |
6413 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6414 | cb->args[1] = | |
6415 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6416 | } | |
6417 | ||
6418 | if (cb->args[1]) { | |
6419 | data = nla_data((void *)cb->args[1]); | |
6420 | data_len = nla_len((void *)cb->args[1]); | |
6421 | } | |
6422 | ||
6423 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
6424 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6425 | if (!rdev) { | |
71063f0e WYG |
6426 | mutex_unlock(&cfg80211_mutex); |
6427 | return -ENOENT; | |
6428 | } | |
00918d33 | 6429 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
6430 | mutex_unlock(&cfg80211_mutex); |
6431 | ||
00918d33 | 6432 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6433 | err = -EOPNOTSUPP; |
6434 | goto out_err; | |
6435 | } | |
6436 | ||
6437 | while (1) { | |
15e47304 | 6438 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6439 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6440 | NL80211_CMD_TESTMODE); | |
6441 | struct nlattr *tmdata; | |
6442 | ||
9360ffd1 | 6443 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6444 | genlmsg_cancel(skb, hdr); |
6445 | break; | |
6446 | } | |
6447 | ||
6448 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6449 | if (!tmdata) { | |
6450 | genlmsg_cancel(skb, hdr); | |
6451 | break; | |
6452 | } | |
e35e4d28 | 6453 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6454 | nla_nest_end(skb, tmdata); |
6455 | ||
6456 | if (err == -ENOBUFS || err == -ENOENT) { | |
6457 | genlmsg_cancel(skb, hdr); | |
6458 | break; | |
6459 | } else if (err) { | |
6460 | genlmsg_cancel(skb, hdr); | |
6461 | goto out_err; | |
6462 | } | |
6463 | ||
6464 | genlmsg_end(skb, hdr); | |
6465 | } | |
6466 | ||
6467 | err = skb->len; | |
6468 | /* see above */ | |
6469 | cb->args[0] = phy_idx + 1; | |
6470 | out_err: | |
00918d33 | 6471 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
6472 | return err; |
6473 | } | |
6474 | ||
aff89a9b JB |
6475 | static struct sk_buff * |
6476 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6477 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6478 | { |
6479 | struct sk_buff *skb; | |
6480 | void *hdr; | |
6481 | struct nlattr *data; | |
6482 | ||
6483 | skb = nlmsg_new(approxlen + 100, gfp); | |
6484 | if (!skb) | |
6485 | return NULL; | |
6486 | ||
15e47304 | 6487 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6488 | if (!hdr) { |
6489 | kfree_skb(skb); | |
6490 | return NULL; | |
6491 | } | |
6492 | ||
9360ffd1 DM |
6493 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6494 | goto nla_put_failure; | |
aff89a9b JB |
6495 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6496 | ||
6497 | ((void **)skb->cb)[0] = rdev; | |
6498 | ((void **)skb->cb)[1] = hdr; | |
6499 | ((void **)skb->cb)[2] = data; | |
6500 | ||
6501 | return skb; | |
6502 | ||
6503 | nla_put_failure: | |
6504 | kfree_skb(skb); | |
6505 | return NULL; | |
6506 | } | |
6507 | ||
6508 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6509 | int approxlen) | |
6510 | { | |
6511 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6512 | ||
6513 | if (WARN_ON(!rdev->testmode_info)) | |
6514 | return NULL; | |
6515 | ||
6516 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6517 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6518 | rdev->testmode_info->snd_seq, |
6519 | GFP_KERNEL); | |
6520 | } | |
6521 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6522 | ||
6523 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6524 | { | |
6525 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6526 | void *hdr = ((void **)skb->cb)[1]; | |
6527 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6528 | ||
6529 | if (WARN_ON(!rdev->testmode_info)) { | |
6530 | kfree_skb(skb); | |
6531 | return -EINVAL; | |
6532 | } | |
6533 | ||
6534 | nla_nest_end(skb, data); | |
6535 | genlmsg_end(skb, hdr); | |
6536 | return genlmsg_reply(skb, rdev->testmode_info); | |
6537 | } | |
6538 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6539 | ||
6540 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6541 | int approxlen, gfp_t gfp) | |
6542 | { | |
6543 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6544 | ||
6545 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6546 | } | |
6547 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6548 | ||
6549 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6550 | { | |
6551 | void *hdr = ((void **)skb->cb)[1]; | |
6552 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6553 | ||
6554 | nla_nest_end(skb, data); | |
6555 | genlmsg_end(skb, hdr); | |
6556 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6557 | } | |
6558 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6559 | #endif | |
6560 | ||
b23aa676 SO |
6561 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6562 | { | |
4c476991 JB |
6563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6564 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6565 | struct cfg80211_connect_params connect; |
6566 | struct wiphy *wiphy; | |
fffd0934 | 6567 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6568 | int err; |
6569 | ||
6570 | memset(&connect, 0, sizeof(connect)); | |
6571 | ||
6572 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6573 | return -EINVAL; | |
6574 | ||
6575 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6576 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6577 | return -EINVAL; | |
6578 | ||
6579 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6580 | connect.auth_type = | |
6581 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6582 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6583 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6584 | return -EINVAL; |
6585 | } else | |
6586 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6587 | ||
6588 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6589 | ||
c0692b8f | 6590 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6591 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6592 | if (err) |
6593 | return err; | |
b23aa676 | 6594 | |
074ac8df | 6595 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6596 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6597 | return -EOPNOTSUPP; | |
b23aa676 | 6598 | |
79c97e97 | 6599 | wiphy = &rdev->wiphy; |
b23aa676 | 6600 | |
4486ea98 BS |
6601 | connect.bg_scan_period = -1; |
6602 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6603 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6604 | connect.bg_scan_period = | |
6605 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6606 | } | |
6607 | ||
b23aa676 SO |
6608 | if (info->attrs[NL80211_ATTR_MAC]) |
6609 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6610 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6611 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6612 | ||
6613 | if (info->attrs[NL80211_ATTR_IE]) { | |
6614 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6615 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6616 | } | |
6617 | ||
cee00a95 JM |
6618 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6619 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6620 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6621 | connect.mfp != NL80211_MFP_NO) | |
6622 | return -EINVAL; | |
6623 | } else { | |
6624 | connect.mfp = NL80211_MFP_NO; | |
6625 | } | |
6626 | ||
b23aa676 SO |
6627 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6628 | connect.channel = | |
6629 | ieee80211_get_channel(wiphy, | |
6630 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6631 | if (!connect.channel || | |
4c476991 JB |
6632 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6633 | return -EINVAL; | |
b23aa676 SO |
6634 | } |
6635 | ||
fffd0934 JB |
6636 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6637 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6638 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6639 | if (IS_ERR(connkeys)) |
6640 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6641 | } |
6642 | ||
7e7c8926 BG |
6643 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6644 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6645 | ||
6646 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6647 | memcpy(&connect.ht_capa_mask, | |
6648 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6649 | sizeof(connect.ht_capa_mask)); | |
6650 | ||
6651 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6652 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6653 | kfree(connkeys); | |
7e7c8926 | 6654 | return -EINVAL; |
b4e4f47e | 6655 | } |
7e7c8926 BG |
6656 | memcpy(&connect.ht_capa, |
6657 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6658 | sizeof(connect.ht_capa)); | |
6659 | } | |
6660 | ||
ee2aca34 JB |
6661 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6662 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6663 | ||
6664 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6665 | memcpy(&connect.vht_capa_mask, | |
6666 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6667 | sizeof(connect.vht_capa_mask)); | |
6668 | ||
6669 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6670 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6671 | kfree(connkeys); | |
6672 | return -EINVAL; | |
6673 | } | |
6674 | memcpy(&connect.vht_capa, | |
6675 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6676 | sizeof(connect.vht_capa)); | |
6677 | } | |
6678 | ||
fffd0934 | 6679 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
6680 | if (err) |
6681 | kfree(connkeys); | |
b23aa676 SO |
6682 | return err; |
6683 | } | |
6684 | ||
6685 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6686 | { | |
4c476991 JB |
6687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6688 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6689 | u16 reason; |
6690 | ||
6691 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6692 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6693 | else | |
6694 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6695 | ||
6696 | if (reason == 0) | |
6697 | return -EINVAL; | |
6698 | ||
074ac8df | 6699 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6700 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6701 | return -EOPNOTSUPP; | |
b23aa676 | 6702 | |
4c476991 | 6703 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
6704 | } |
6705 | ||
463d0183 JB |
6706 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6707 | { | |
4c476991 | 6708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6709 | struct net *net; |
6710 | int err; | |
6711 | u32 pid; | |
6712 | ||
6713 | if (!info->attrs[NL80211_ATTR_PID]) | |
6714 | return -EINVAL; | |
6715 | ||
6716 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6717 | ||
463d0183 | 6718 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6719 | if (IS_ERR(net)) |
6720 | return PTR_ERR(net); | |
463d0183 JB |
6721 | |
6722 | err = 0; | |
6723 | ||
6724 | /* check if anything to do */ | |
4c476991 JB |
6725 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6726 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6727 | |
463d0183 | 6728 | put_net(net); |
463d0183 JB |
6729 | return err; |
6730 | } | |
6731 | ||
67fbb16b SO |
6732 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6733 | { | |
4c476991 | 6734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6735 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6736 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6737 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6738 | struct cfg80211_pmksa pmksa; |
6739 | ||
6740 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6741 | ||
6742 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6743 | return -EINVAL; | |
6744 | ||
6745 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6746 | return -EINVAL; | |
6747 | ||
67fbb16b SO |
6748 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6749 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6750 | ||
074ac8df | 6751 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6752 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6753 | return -EOPNOTSUPP; | |
67fbb16b SO |
6754 | |
6755 | switch (info->genlhdr->cmd) { | |
6756 | case NL80211_CMD_SET_PMKSA: | |
6757 | rdev_ops = rdev->ops->set_pmksa; | |
6758 | break; | |
6759 | case NL80211_CMD_DEL_PMKSA: | |
6760 | rdev_ops = rdev->ops->del_pmksa; | |
6761 | break; | |
6762 | default: | |
6763 | WARN_ON(1); | |
6764 | break; | |
6765 | } | |
6766 | ||
4c476991 JB |
6767 | if (!rdev_ops) |
6768 | return -EOPNOTSUPP; | |
67fbb16b | 6769 | |
4c476991 | 6770 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6771 | } |
6772 | ||
6773 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6774 | { | |
4c476991 JB |
6775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6776 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6777 | |
074ac8df | 6778 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6779 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6780 | return -EOPNOTSUPP; | |
67fbb16b | 6781 | |
4c476991 JB |
6782 | if (!rdev->ops->flush_pmksa) |
6783 | return -EOPNOTSUPP; | |
67fbb16b | 6784 | |
e35e4d28 | 6785 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6786 | } |
6787 | ||
109086ce AN |
6788 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6789 | { | |
6790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6791 | struct net_device *dev = info->user_ptr[1]; | |
6792 | u8 action_code, dialog_token; | |
6793 | u16 status_code; | |
6794 | u8 *peer; | |
6795 | ||
6796 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6797 | !rdev->ops->tdls_mgmt) | |
6798 | return -EOPNOTSUPP; | |
6799 | ||
6800 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6801 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6802 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6803 | !info->attrs[NL80211_ATTR_IE] || | |
6804 | !info->attrs[NL80211_ATTR_MAC]) | |
6805 | return -EINVAL; | |
6806 | ||
6807 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6808 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6809 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6810 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6811 | ||
e35e4d28 HG |
6812 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6813 | dialog_token, status_code, | |
6814 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6815 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6816 | } |
6817 | ||
6818 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6819 | { | |
6820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6821 | struct net_device *dev = info->user_ptr[1]; | |
6822 | enum nl80211_tdls_operation operation; | |
6823 | u8 *peer; | |
6824 | ||
6825 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6826 | !rdev->ops->tdls_oper) | |
6827 | return -EOPNOTSUPP; | |
6828 | ||
6829 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6830 | !info->attrs[NL80211_ATTR_MAC]) | |
6831 | return -EINVAL; | |
6832 | ||
6833 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6834 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6835 | ||
e35e4d28 | 6836 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6837 | } |
6838 | ||
9588bbd5 JM |
6839 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6840 | struct genl_info *info) | |
6841 | { | |
4c476991 | 6842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6843 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6844 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6845 | struct sk_buff *msg; |
6846 | void *hdr; | |
6847 | u64 cookie; | |
683b6d3b | 6848 | u32 duration; |
9588bbd5 JM |
6849 | int err; |
6850 | ||
6851 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6852 | !info->attrs[NL80211_ATTR_DURATION]) | |
6853 | return -EINVAL; | |
6854 | ||
6855 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6856 | ||
ebf348fc JB |
6857 | if (!rdev->ops->remain_on_channel || |
6858 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6859 | return -EOPNOTSUPP; | |
6860 | ||
9588bbd5 | 6861 | /* |
ebf348fc JB |
6862 | * We should be on that channel for at least a minimum amount of |
6863 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6864 | */ |
ebf348fc | 6865 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6866 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6867 | return -EINVAL; |
6868 | ||
683b6d3b JB |
6869 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6870 | if (err) | |
6871 | return err; | |
9588bbd5 JM |
6872 | |
6873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6874 | if (!msg) |
6875 | return -ENOMEM; | |
9588bbd5 | 6876 | |
15e47304 | 6877 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6878 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6879 | ||
6880 | if (IS_ERR(hdr)) { | |
6881 | err = PTR_ERR(hdr); | |
6882 | goto free_msg; | |
6883 | } | |
6884 | ||
683b6d3b JB |
6885 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6886 | duration, &cookie); | |
9588bbd5 JM |
6887 | |
6888 | if (err) | |
6889 | goto free_msg; | |
6890 | ||
9360ffd1 DM |
6891 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6892 | goto nla_put_failure; | |
9588bbd5 JM |
6893 | |
6894 | genlmsg_end(msg, hdr); | |
4c476991 JB |
6895 | |
6896 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
6897 | |
6898 | nla_put_failure: | |
6899 | err = -ENOBUFS; | |
6900 | free_msg: | |
6901 | nlmsg_free(msg); | |
9588bbd5 JM |
6902 | return err; |
6903 | } | |
6904 | ||
6905 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
6906 | struct genl_info *info) | |
6907 | { | |
4c476991 | 6908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6909 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 6910 | u64 cookie; |
9588bbd5 JM |
6911 | |
6912 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6913 | return -EINVAL; | |
6914 | ||
4c476991 JB |
6915 | if (!rdev->ops->cancel_remain_on_channel) |
6916 | return -EOPNOTSUPP; | |
9588bbd5 | 6917 | |
9588bbd5 JM |
6918 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
6919 | ||
e35e4d28 | 6920 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
6921 | } |
6922 | ||
13ae75b1 JM |
6923 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
6924 | u8 *rates, u8 rates_len) | |
6925 | { | |
6926 | u8 i; | |
6927 | u32 mask = 0; | |
6928 | ||
6929 | for (i = 0; i < rates_len; i++) { | |
6930 | int rate = (rates[i] & 0x7f) * 5; | |
6931 | int ridx; | |
6932 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
6933 | struct ieee80211_rate *srate = | |
6934 | &sband->bitrates[ridx]; | |
6935 | if (rate == srate->bitrate) { | |
6936 | mask |= 1 << ridx; | |
6937 | break; | |
6938 | } | |
6939 | } | |
6940 | if (ridx == sband->n_bitrates) | |
6941 | return 0; /* rate not found */ | |
6942 | } | |
6943 | ||
6944 | return mask; | |
6945 | } | |
6946 | ||
24db78c0 SW |
6947 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
6948 | u8 *rates, u8 rates_len, | |
6949 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
6950 | { | |
6951 | u8 i; | |
6952 | ||
6953 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
6954 | ||
6955 | for (i = 0; i < rates_len; i++) { | |
6956 | int ridx, rbit; | |
6957 | ||
6958 | ridx = rates[i] / 8; | |
6959 | rbit = BIT(rates[i] % 8); | |
6960 | ||
6961 | /* check validity */ | |
910570b5 | 6962 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
6963 | return false; |
6964 | ||
6965 | /* check availability */ | |
6966 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
6967 | mcs[ridx] |= rbit; | |
6968 | else | |
6969 | return false; | |
6970 | } | |
6971 | ||
6972 | return true; | |
6973 | } | |
6974 | ||
b54452b0 | 6975 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
6976 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
6977 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
6978 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
6979 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
6980 | }; |
6981 | ||
6982 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
6983 | struct genl_info *info) | |
6984 | { | |
6985 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 6986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 6987 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
6988 | int rem, i; |
6989 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
6990 | struct nlattr *tx_rates; |
6991 | struct ieee80211_supported_band *sband; | |
6992 | ||
6993 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
6994 | return -EINVAL; | |
6995 | ||
4c476991 JB |
6996 | if (!rdev->ops->set_bitrate_mask) |
6997 | return -EOPNOTSUPP; | |
13ae75b1 JM |
6998 | |
6999 | memset(&mask, 0, sizeof(mask)); | |
7000 | /* Default to all rates enabled */ | |
7001 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7002 | sband = rdev->wiphy.bands[i]; | |
7003 | mask.control[i].legacy = | |
7004 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7005 | if (sband) |
7006 | memcpy(mask.control[i].mcs, | |
7007 | sband->ht_cap.mcs.rx_mask, | |
7008 | sizeof(mask.control[i].mcs)); | |
7009 | else | |
7010 | memset(mask.control[i].mcs, 0, | |
7011 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7012 | } |
7013 | ||
7014 | /* | |
7015 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7016 | * directly to the enum ieee80211_band values used in cfg80211. | |
7017 | */ | |
24db78c0 | 7018 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7019 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7020 | { | |
7021 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7022 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7023 | return -EINVAL; | |
13ae75b1 | 7024 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7025 | if (sband == NULL) |
7026 | return -EINVAL; | |
13ae75b1 JM |
7027 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7028 | nla_len(tx_rates), nl80211_txattr_policy); | |
7029 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7030 | mask.control[band].legacy = rateset_to_mask( | |
7031 | sband, | |
7032 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7033 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7034 | if ((mask.control[band].legacy == 0) && |
7035 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7036 | return -EINVAL; | |
24db78c0 SW |
7037 | } |
7038 | if (tb[NL80211_TXRATE_MCS]) { | |
7039 | if (!ht_rateset_to_mask( | |
7040 | sband, | |
7041 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7042 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7043 | mask.control[band].mcs)) | |
7044 | return -EINVAL; | |
7045 | } | |
7046 | ||
7047 | if (mask.control[band].legacy == 0) { | |
7048 | /* don't allow empty legacy rates if HT | |
7049 | * is not even supported. */ | |
7050 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7051 | return -EINVAL; | |
7052 | ||
7053 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7054 | if (mask.control[band].mcs[i]) | |
7055 | break; | |
7056 | ||
7057 | /* legacy and mcs rates may not be both empty */ | |
7058 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7059 | return -EINVAL; |
13ae75b1 JM |
7060 | } |
7061 | } | |
7062 | ||
e35e4d28 | 7063 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7064 | } |
7065 | ||
2e161f78 | 7066 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7067 | { |
4c476991 | 7068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7069 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7070 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7071 | |
7072 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7073 | return -EINVAL; | |
7074 | ||
2e161f78 JB |
7075 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7076 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7077 | |
71bbc994 JB |
7078 | switch (wdev->iftype) { |
7079 | case NL80211_IFTYPE_STATION: | |
7080 | case NL80211_IFTYPE_ADHOC: | |
7081 | case NL80211_IFTYPE_P2P_CLIENT: | |
7082 | case NL80211_IFTYPE_AP: | |
7083 | case NL80211_IFTYPE_AP_VLAN: | |
7084 | case NL80211_IFTYPE_MESH_POINT: | |
7085 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7086 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7087 | break; |
7088 | default: | |
4c476991 | 7089 | return -EOPNOTSUPP; |
71bbc994 | 7090 | } |
026331c4 JM |
7091 | |
7092 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7093 | if (!rdev->ops->mgmt_tx) |
7094 | return -EOPNOTSUPP; | |
026331c4 | 7095 | |
15e47304 | 7096 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7097 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7098 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7099 | } |
7100 | ||
2e161f78 | 7101 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7102 | { |
4c476991 | 7103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7104 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7105 | struct cfg80211_chan_def chandef; |
026331c4 | 7106 | int err; |
d64d373f | 7107 | void *hdr = NULL; |
026331c4 | 7108 | u64 cookie; |
e247bd90 | 7109 | struct sk_buff *msg = NULL; |
f7ca38df | 7110 | unsigned int wait = 0; |
e247bd90 JB |
7111 | bool offchan, no_cck, dont_wait_for_ack; |
7112 | ||
7113 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7114 | |
683b6d3b | 7115 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7116 | return -EINVAL; |
7117 | ||
4c476991 JB |
7118 | if (!rdev->ops->mgmt_tx) |
7119 | return -EOPNOTSUPP; | |
026331c4 | 7120 | |
71bbc994 JB |
7121 | switch (wdev->iftype) { |
7122 | case NL80211_IFTYPE_STATION: | |
7123 | case NL80211_IFTYPE_ADHOC: | |
7124 | case NL80211_IFTYPE_P2P_CLIENT: | |
7125 | case NL80211_IFTYPE_AP: | |
7126 | case NL80211_IFTYPE_AP_VLAN: | |
7127 | case NL80211_IFTYPE_MESH_POINT: | |
7128 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7129 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7130 | break; |
7131 | default: | |
4c476991 | 7132 | return -EOPNOTSUPP; |
71bbc994 | 7133 | } |
026331c4 | 7134 | |
f7ca38df | 7135 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7136 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7137 | return -EINVAL; |
7138 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7139 | |
7140 | /* | |
7141 | * We should wait on the channel for at least a minimum amount | |
7142 | * of time (10ms) but no longer than the driver supports. | |
7143 | */ | |
7144 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7145 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7146 | return -EINVAL; | |
7147 | ||
f7ca38df JB |
7148 | } |
7149 | ||
f7ca38df JB |
7150 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7151 | ||
7c4ef712 JB |
7152 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7153 | return -EINVAL; | |
7154 | ||
e9f935e3 RM |
7155 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7156 | ||
683b6d3b JB |
7157 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7158 | if (err) | |
7159 | return err; | |
026331c4 | 7160 | |
e247bd90 JB |
7161 | if (!dont_wait_for_ack) { |
7162 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7163 | if (!msg) | |
7164 | return -ENOMEM; | |
026331c4 | 7165 | |
15e47304 | 7166 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7167 | NL80211_CMD_FRAME); |
026331c4 | 7168 | |
e247bd90 JB |
7169 | if (IS_ERR(hdr)) { |
7170 | err = PTR_ERR(hdr); | |
7171 | goto free_msg; | |
7172 | } | |
026331c4 | 7173 | } |
e247bd90 | 7174 | |
683b6d3b | 7175 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7176 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7177 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7178 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7179 | if (err) |
7180 | goto free_msg; | |
7181 | ||
e247bd90 | 7182 | if (msg) { |
9360ffd1 DM |
7183 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7184 | goto nla_put_failure; | |
026331c4 | 7185 | |
e247bd90 JB |
7186 | genlmsg_end(msg, hdr); |
7187 | return genlmsg_reply(msg, info); | |
7188 | } | |
7189 | ||
7190 | return 0; | |
026331c4 JM |
7191 | |
7192 | nla_put_failure: | |
7193 | err = -ENOBUFS; | |
7194 | free_msg: | |
7195 | nlmsg_free(msg); | |
026331c4 JM |
7196 | return err; |
7197 | } | |
7198 | ||
f7ca38df JB |
7199 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7200 | { | |
7201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7202 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7203 | u64 cookie; |
7204 | ||
7205 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7206 | return -EINVAL; | |
7207 | ||
7208 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7209 | return -EOPNOTSUPP; | |
7210 | ||
71bbc994 JB |
7211 | switch (wdev->iftype) { |
7212 | case NL80211_IFTYPE_STATION: | |
7213 | case NL80211_IFTYPE_ADHOC: | |
7214 | case NL80211_IFTYPE_P2P_CLIENT: | |
7215 | case NL80211_IFTYPE_AP: | |
7216 | case NL80211_IFTYPE_AP_VLAN: | |
7217 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7218 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7219 | break; |
7220 | default: | |
f7ca38df | 7221 | return -EOPNOTSUPP; |
71bbc994 | 7222 | } |
f7ca38df JB |
7223 | |
7224 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7225 | ||
e35e4d28 | 7226 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7227 | } |
7228 | ||
ffb9eb3d KV |
7229 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7230 | { | |
4c476991 | 7231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7232 | struct wireless_dev *wdev; |
4c476991 | 7233 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7234 | u8 ps_state; |
7235 | bool state; | |
7236 | int err; | |
7237 | ||
4c476991 JB |
7238 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7239 | return -EINVAL; | |
ffb9eb3d KV |
7240 | |
7241 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7242 | ||
4c476991 JB |
7243 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7244 | return -EINVAL; | |
ffb9eb3d KV |
7245 | |
7246 | wdev = dev->ieee80211_ptr; | |
7247 | ||
4c476991 JB |
7248 | if (!rdev->ops->set_power_mgmt) |
7249 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7250 | |
7251 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7252 | ||
7253 | if (state == wdev->ps) | |
4c476991 | 7254 | return 0; |
ffb9eb3d | 7255 | |
e35e4d28 | 7256 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7257 | if (!err) |
7258 | wdev->ps = state; | |
ffb9eb3d KV |
7259 | return err; |
7260 | } | |
7261 | ||
7262 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7263 | { | |
4c476991 | 7264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7265 | enum nl80211_ps_state ps_state; |
7266 | struct wireless_dev *wdev; | |
4c476991 | 7267 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7268 | struct sk_buff *msg; |
7269 | void *hdr; | |
7270 | int err; | |
7271 | ||
ffb9eb3d KV |
7272 | wdev = dev->ieee80211_ptr; |
7273 | ||
4c476991 JB |
7274 | if (!rdev->ops->set_power_mgmt) |
7275 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7276 | |
7277 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7278 | if (!msg) |
7279 | return -ENOMEM; | |
ffb9eb3d | 7280 | |
15e47304 | 7281 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7282 | NL80211_CMD_GET_POWER_SAVE); |
7283 | if (!hdr) { | |
4c476991 | 7284 | err = -ENOBUFS; |
ffb9eb3d KV |
7285 | goto free_msg; |
7286 | } | |
7287 | ||
7288 | if (wdev->ps) | |
7289 | ps_state = NL80211_PS_ENABLED; | |
7290 | else | |
7291 | ps_state = NL80211_PS_DISABLED; | |
7292 | ||
9360ffd1 DM |
7293 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7294 | goto nla_put_failure; | |
ffb9eb3d KV |
7295 | |
7296 | genlmsg_end(msg, hdr); | |
4c476991 | 7297 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7298 | |
4c476991 | 7299 | nla_put_failure: |
ffb9eb3d | 7300 | err = -ENOBUFS; |
4c476991 | 7301 | free_msg: |
ffb9eb3d | 7302 | nlmsg_free(msg); |
ffb9eb3d KV |
7303 | return err; |
7304 | } | |
7305 | ||
d6dc1a38 JO |
7306 | static struct nla_policy |
7307 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7308 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7309 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7310 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7311 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7312 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7313 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7314 | }; |
7315 | ||
84f10708 | 7316 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7317 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7318 | { |
7319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7320 | struct wireless_dev *wdev; | |
7321 | struct net_device *dev = info->user_ptr[1]; | |
7322 | ||
d9d8b019 | 7323 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7324 | return -EINVAL; |
7325 | ||
7326 | wdev = dev->ieee80211_ptr; | |
7327 | ||
7328 | if (!rdev->ops->set_cqm_txe_config) | |
7329 | return -EOPNOTSUPP; | |
7330 | ||
7331 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7332 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7333 | return -EOPNOTSUPP; | |
7334 | ||
e35e4d28 | 7335 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7336 | } |
7337 | ||
d6dc1a38 JO |
7338 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7339 | s32 threshold, u32 hysteresis) | |
7340 | { | |
4c476991 | 7341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7342 | struct wireless_dev *wdev; |
4c476991 | 7343 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7344 | |
7345 | if (threshold > 0) | |
7346 | return -EINVAL; | |
7347 | ||
d6dc1a38 JO |
7348 | wdev = dev->ieee80211_ptr; |
7349 | ||
4c476991 JB |
7350 | if (!rdev->ops->set_cqm_rssi_config) |
7351 | return -EOPNOTSUPP; | |
d6dc1a38 | 7352 | |
074ac8df | 7353 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7354 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7355 | return -EOPNOTSUPP; | |
d6dc1a38 | 7356 | |
e35e4d28 | 7357 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7358 | } |
7359 | ||
7360 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7361 | { | |
7362 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7363 | struct nlattr *cqm; | |
7364 | int err; | |
7365 | ||
7366 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7367 | if (!cqm) { | |
7368 | err = -EINVAL; | |
7369 | goto out; | |
7370 | } | |
7371 | ||
7372 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7373 | nl80211_attr_cqm_policy); | |
7374 | if (err) | |
7375 | goto out; | |
7376 | ||
7377 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7378 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7379 | s32 threshold; | |
7380 | u32 hysteresis; | |
7381 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7382 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7383 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7384 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7385 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7386 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7387 | u32 rate, pkts, intvl; | |
7388 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7389 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7390 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7391 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7392 | } else |
7393 | err = -EINVAL; | |
7394 | ||
7395 | out: | |
7396 | return err; | |
7397 | } | |
7398 | ||
29cbe68c JB |
7399 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7400 | { | |
7401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7402 | struct net_device *dev = info->user_ptr[1]; | |
7403 | struct mesh_config cfg; | |
c80d545d | 7404 | struct mesh_setup setup; |
29cbe68c JB |
7405 | int err; |
7406 | ||
7407 | /* start with default */ | |
7408 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7409 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7410 | |
24bdd9f4 | 7411 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7412 | /* and parse parameters if given */ |
24bdd9f4 | 7413 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7414 | if (err) |
7415 | return err; | |
7416 | } | |
7417 | ||
7418 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7419 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7420 | return -EINVAL; | |
7421 | ||
c80d545d JC |
7422 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7423 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7424 | ||
4bb62344 CYY |
7425 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7426 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7427 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7428 | return -EINVAL; | |
7429 | ||
9bdbf04d MP |
7430 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7431 | setup.beacon_interval = | |
7432 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7433 | if (setup.beacon_interval < 10 || | |
7434 | setup.beacon_interval > 10000) | |
7435 | return -EINVAL; | |
7436 | } | |
7437 | ||
7438 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7439 | setup.dtim_period = | |
7440 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7441 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7442 | return -EINVAL; | |
7443 | } | |
7444 | ||
c80d545d JC |
7445 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7446 | /* parse additional setup parameters if given */ | |
7447 | err = nl80211_parse_mesh_setup(info, &setup); | |
7448 | if (err) | |
7449 | return err; | |
7450 | } | |
7451 | ||
d37bb18a TP |
7452 | if (setup.user_mpm) |
7453 | cfg.auto_open_plinks = false; | |
7454 | ||
cc1d2806 | 7455 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7456 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7457 | if (err) | |
7458 | return err; | |
cc1d2806 JB |
7459 | } else { |
7460 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7461 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7462 | } |
7463 | ||
c80d545d | 7464 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7465 | } |
7466 | ||
7467 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7468 | { | |
7469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7470 | struct net_device *dev = info->user_ptr[1]; | |
7471 | ||
7472 | return cfg80211_leave_mesh(rdev, dev); | |
7473 | } | |
7474 | ||
dfb89c56 | 7475 | #ifdef CONFIG_PM |
bb92d199 AK |
7476 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7477 | struct cfg80211_registered_device *rdev) | |
7478 | { | |
7479 | struct nlattr *nl_pats, *nl_pat; | |
7480 | int i, pat_len; | |
7481 | ||
7482 | if (!rdev->wowlan->n_patterns) | |
7483 | return 0; | |
7484 | ||
7485 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7486 | if (!nl_pats) | |
7487 | return -ENOBUFS; | |
7488 | ||
7489 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
7490 | nl_pat = nla_nest_start(msg, i + 1); | |
7491 | if (!nl_pat) | |
7492 | return -ENOBUFS; | |
7493 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
7494 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
7495 | DIV_ROUND_UP(pat_len, 8), | |
7496 | rdev->wowlan->patterns[i].mask) || | |
7497 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
7498 | pat_len, rdev->wowlan->patterns[i].pattern) || | |
7499 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, | |
7500 | rdev->wowlan->patterns[i].pkt_offset)) | |
7501 | return -ENOBUFS; | |
7502 | nla_nest_end(msg, nl_pat); | |
7503 | } | |
7504 | nla_nest_end(msg, nl_pats); | |
7505 | ||
7506 | return 0; | |
7507 | } | |
7508 | ||
2a0e047e JB |
7509 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7510 | struct cfg80211_wowlan_tcp *tcp) | |
7511 | { | |
7512 | struct nlattr *nl_tcp; | |
7513 | ||
7514 | if (!tcp) | |
7515 | return 0; | |
7516 | ||
7517 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7518 | if (!nl_tcp) | |
7519 | return -ENOBUFS; | |
7520 | ||
7521 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7522 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7523 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7524 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7525 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7526 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7527 | tcp->payload_len, tcp->payload) || | |
7528 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7529 | tcp->data_interval) || | |
7530 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7531 | tcp->wake_len, tcp->wake_data) || | |
7532 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7533 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7534 | return -ENOBUFS; | |
7535 | ||
7536 | if (tcp->payload_seq.len && | |
7537 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7538 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7539 | return -ENOBUFS; | |
7540 | ||
7541 | if (tcp->payload_tok.len && | |
7542 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7543 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7544 | &tcp->payload_tok)) | |
7545 | return -ENOBUFS; | |
7546 | ||
7547 | return 0; | |
7548 | } | |
7549 | ||
ff1b6e69 JB |
7550 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7551 | { | |
7552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7553 | struct sk_buff *msg; | |
7554 | void *hdr; | |
2a0e047e | 7555 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7556 | |
2a0e047e JB |
7557 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7558 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7559 | return -EOPNOTSUPP; |
7560 | ||
2a0e047e JB |
7561 | if (rdev->wowlan && rdev->wowlan->tcp) { |
7562 | /* adjust size to have room for all the data */ | |
7563 | size += rdev->wowlan->tcp->tokens_size + | |
7564 | rdev->wowlan->tcp->payload_len + | |
7565 | rdev->wowlan->tcp->wake_len + | |
7566 | rdev->wowlan->tcp->wake_len / 8; | |
7567 | } | |
7568 | ||
7569 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7570 | if (!msg) |
7571 | return -ENOMEM; | |
7572 | ||
15e47304 | 7573 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7574 | NL80211_CMD_GET_WOWLAN); |
7575 | if (!hdr) | |
7576 | goto nla_put_failure; | |
7577 | ||
7578 | if (rdev->wowlan) { | |
7579 | struct nlattr *nl_wowlan; | |
7580 | ||
7581 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7582 | if (!nl_wowlan) | |
7583 | goto nla_put_failure; | |
7584 | ||
9360ffd1 DM |
7585 | if ((rdev->wowlan->any && |
7586 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7587 | (rdev->wowlan->disconnect && | |
7588 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7589 | (rdev->wowlan->magic_pkt && | |
7590 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7591 | (rdev->wowlan->gtk_rekey_failure && | |
7592 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7593 | (rdev->wowlan->eap_identity_req && | |
7594 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7595 | (rdev->wowlan->four_way_handshake && | |
7596 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7597 | (rdev->wowlan->rfkill_release && | |
7598 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
7599 | goto nla_put_failure; | |
2a0e047e | 7600 | |
bb92d199 AK |
7601 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7602 | goto nla_put_failure; | |
2a0e047e JB |
7603 | |
7604 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) | |
7605 | goto nla_put_failure; | |
7606 | ||
ff1b6e69 JB |
7607 | nla_nest_end(msg, nl_wowlan); |
7608 | } | |
7609 | ||
7610 | genlmsg_end(msg, hdr); | |
7611 | return genlmsg_reply(msg, info); | |
7612 | ||
7613 | nla_put_failure: | |
7614 | nlmsg_free(msg); | |
7615 | return -ENOBUFS; | |
7616 | } | |
7617 | ||
2a0e047e JB |
7618 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7619 | struct nlattr *attr, | |
7620 | struct cfg80211_wowlan *trig) | |
7621 | { | |
7622 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7623 | struct cfg80211_wowlan_tcp *cfg; | |
7624 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7625 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7626 | u32 size; | |
7627 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7628 | int err, port; | |
7629 | ||
7630 | if (!rdev->wiphy.wowlan.tcp) | |
7631 | return -EINVAL; | |
7632 | ||
7633 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7634 | nla_data(attr), nla_len(attr), | |
7635 | nl80211_wowlan_tcp_policy); | |
7636 | if (err) | |
7637 | return err; | |
7638 | ||
7639 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7640 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7641 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7642 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7643 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7644 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7645 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7646 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7647 | return -EINVAL; | |
7648 | ||
7649 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
7650 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) | |
7651 | return -EINVAL; | |
7652 | ||
7653 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
723d568a JB |
7654 | rdev->wiphy.wowlan.tcp->data_interval_max || |
7655 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) | |
2a0e047e JB |
7656 | return -EINVAL; |
7657 | ||
7658 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
7659 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) | |
7660 | return -EINVAL; | |
7661 | ||
7662 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7663 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7664 | return -EINVAL; | |
7665 | ||
7666 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7667 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7668 | ||
7669 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7670 | tokens_size = tokln - sizeof(*tok); | |
7671 | ||
7672 | if (!tok->len || tokens_size % tok->len) | |
7673 | return -EINVAL; | |
7674 | if (!rdev->wiphy.wowlan.tcp->tok) | |
7675 | return -EINVAL; | |
7676 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) | |
7677 | return -EINVAL; | |
7678 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) | |
7679 | return -EINVAL; | |
7680 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) | |
7681 | return -EINVAL; | |
7682 | if (tok->offset + tok->len > data_size) | |
7683 | return -EINVAL; | |
7684 | } | |
7685 | ||
7686 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7687 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
7688 | if (!rdev->wiphy.wowlan.tcp->seq) | |
7689 | return -EINVAL; | |
7690 | if (seq->len == 0 || seq->len > 4) | |
7691 | return -EINVAL; | |
7692 | if (seq->len + seq->offset > data_size) | |
7693 | return -EINVAL; | |
7694 | } | |
7695 | ||
7696 | size = sizeof(*cfg); | |
7697 | size += data_size; | |
7698 | size += wake_size + wake_mask_size; | |
7699 | size += tokens_size; | |
7700 | ||
7701 | cfg = kzalloc(size, GFP_KERNEL); | |
7702 | if (!cfg) | |
7703 | return -ENOMEM; | |
7704 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7705 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7706 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7707 | ETH_ALEN); | |
7708 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7709 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7710 | else | |
7711 | port = 0; | |
7712 | #ifdef CONFIG_INET | |
7713 | /* allocate a socket and port for it and use it */ | |
7714 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7715 | IPPROTO_TCP, &cfg->sock, 1); | |
7716 | if (err) { | |
7717 | kfree(cfg); | |
7718 | return err; | |
7719 | } | |
7720 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7721 | sock_release(cfg->sock); | |
7722 | kfree(cfg); | |
7723 | return -EADDRINUSE; | |
7724 | } | |
7725 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7726 | #else | |
7727 | if (!port) { | |
7728 | kfree(cfg); | |
7729 | return -EINVAL; | |
7730 | } | |
7731 | cfg->src_port = port; | |
7732 | #endif | |
7733 | ||
7734 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7735 | cfg->payload_len = data_size; | |
7736 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7737 | memcpy((void *)cfg->payload, | |
7738 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7739 | data_size); | |
7740 | if (seq) | |
7741 | cfg->payload_seq = *seq; | |
7742 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7743 | cfg->wake_len = wake_size; | |
7744 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7745 | memcpy((void *)cfg->wake_data, | |
7746 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7747 | wake_size); | |
7748 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7749 | data_size + wake_size; | |
7750 | memcpy((void *)cfg->wake_mask, | |
7751 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7752 | wake_mask_size); | |
7753 | if (tok) { | |
7754 | cfg->tokens_size = tokens_size; | |
7755 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7756 | } | |
7757 | ||
7758 | trig->tcp = cfg; | |
7759 | ||
7760 | return 0; | |
7761 | } | |
7762 | ||
ff1b6e69 JB |
7763 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7764 | { | |
7765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7766 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7767 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7768 | struct cfg80211_wowlan *ntrig; |
ff1b6e69 JB |
7769 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
7770 | int err, i; | |
6d52563f | 7771 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 | 7772 | |
2a0e047e JB |
7773 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7774 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7775 | return -EOPNOTSUPP; |
7776 | ||
ae33bd81 JB |
7777 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7778 | cfg80211_rdev_free_wowlan(rdev); | |
7779 | rdev->wowlan = NULL; | |
7780 | goto set_wakeup; | |
7781 | } | |
ff1b6e69 JB |
7782 | |
7783 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7784 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7785 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7786 | nl80211_wowlan_policy); | |
7787 | if (err) | |
7788 | return err; | |
7789 | ||
7790 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7791 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7792 | return -EINVAL; | |
7793 | new_triggers.any = true; | |
7794 | } | |
7795 | ||
7796 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7797 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7798 | return -EINVAL; | |
7799 | new_triggers.disconnect = true; | |
7800 | } | |
7801 | ||
7802 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7803 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7804 | return -EINVAL; | |
7805 | new_triggers.magic_pkt = true; | |
7806 | } | |
7807 | ||
77dbbb13 JB |
7808 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7809 | return -EINVAL; | |
7810 | ||
7811 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7812 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7813 | return -EINVAL; | |
7814 | new_triggers.gtk_rekey_failure = true; | |
7815 | } | |
7816 | ||
7817 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7818 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7819 | return -EINVAL; | |
7820 | new_triggers.eap_identity_req = true; | |
7821 | } | |
7822 | ||
7823 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7824 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7825 | return -EINVAL; | |
7826 | new_triggers.four_way_handshake = true; | |
7827 | } | |
7828 | ||
7829 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7830 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7831 | return -EINVAL; | |
7832 | new_triggers.rfkill_release = true; | |
7833 | } | |
7834 | ||
ff1b6e69 JB |
7835 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7836 | struct nlattr *pat; | |
7837 | int n_patterns = 0; | |
bb92d199 | 7838 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7839 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7840 | ||
7841 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7842 | rem) | |
7843 | n_patterns++; | |
7844 | if (n_patterns > wowlan->n_patterns) | |
7845 | return -EINVAL; | |
7846 | ||
7847 | new_triggers.patterns = kcalloc(n_patterns, | |
7848 | sizeof(new_triggers.patterns[0]), | |
7849 | GFP_KERNEL); | |
7850 | if (!new_triggers.patterns) | |
7851 | return -ENOMEM; | |
7852 | ||
7853 | new_triggers.n_patterns = n_patterns; | |
7854 | i = 0; | |
7855 | ||
7856 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7857 | rem) { | |
7858 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7859 | nla_data(pat), nla_len(pat), NULL); | |
7860 | err = -EINVAL; | |
7861 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7862 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7863 | goto error; | |
7864 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7865 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7866 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7867 | mask_len) | |
7868 | goto error; | |
7869 | if (pat_len > wowlan->pattern_max_len || | |
7870 | pat_len < wowlan->pattern_min_len) | |
7871 | goto error; | |
7872 | ||
bb92d199 AK |
7873 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7874 | pkt_offset = 0; | |
7875 | else | |
7876 | pkt_offset = nla_get_u32( | |
7877 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7878 | if (pkt_offset > wowlan->max_pkt_offset) | |
7879 | goto error; | |
7880 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7881 | ||
ff1b6e69 JB |
7882 | new_triggers.patterns[i].mask = |
7883 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7884 | if (!new_triggers.patterns[i].mask) { | |
7885 | err = -ENOMEM; | |
7886 | goto error; | |
7887 | } | |
7888 | new_triggers.patterns[i].pattern = | |
7889 | new_triggers.patterns[i].mask + mask_len; | |
7890 | memcpy(new_triggers.patterns[i].mask, | |
7891 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
7892 | mask_len); | |
7893 | new_triggers.patterns[i].pattern_len = pat_len; | |
7894 | memcpy(new_triggers.patterns[i].pattern, | |
7895 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
7896 | pat_len); | |
7897 | i++; | |
7898 | } | |
7899 | } | |
7900 | ||
2a0e047e JB |
7901 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
7902 | err = nl80211_parse_wowlan_tcp( | |
7903 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
7904 | &new_triggers); | |
7905 | if (err) | |
7906 | goto error; | |
7907 | } | |
7908 | ||
ae33bd81 JB |
7909 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
7910 | if (!ntrig) { | |
7911 | err = -ENOMEM; | |
7912 | goto error; | |
ff1b6e69 | 7913 | } |
ae33bd81 JB |
7914 | cfg80211_rdev_free_wowlan(rdev); |
7915 | rdev->wowlan = ntrig; | |
ff1b6e69 | 7916 | |
ae33bd81 | 7917 | set_wakeup: |
6d52563f | 7918 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
e35e4d28 | 7919 | rdev_set_wakeup(rdev, rdev->wowlan); |
6d52563f | 7920 | |
ff1b6e69 JB |
7921 | return 0; |
7922 | error: | |
7923 | for (i = 0; i < new_triggers.n_patterns; i++) | |
7924 | kfree(new_triggers.patterns[i].mask); | |
7925 | kfree(new_triggers.patterns); | |
2a0e047e JB |
7926 | if (new_triggers.tcp && new_triggers.tcp->sock) |
7927 | sock_release(new_triggers.tcp->sock); | |
7928 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
7929 | return err; |
7930 | } | |
dfb89c56 | 7931 | #endif |
ff1b6e69 | 7932 | |
e5497d76 JB |
7933 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
7934 | { | |
7935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7936 | struct net_device *dev = info->user_ptr[1]; | |
7937 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7938 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
7939 | struct cfg80211_gtk_rekey_data rekey_data; | |
7940 | int err; | |
7941 | ||
7942 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
7943 | return -EINVAL; | |
7944 | ||
7945 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
7946 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7947 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7948 | nl80211_rekey_policy); | |
7949 | if (err) | |
7950 | return err; | |
7951 | ||
7952 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
7953 | return -ERANGE; | |
7954 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
7955 | return -ERANGE; | |
7956 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
7957 | return -ERANGE; | |
7958 | ||
7959 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
7960 | NL80211_KEK_LEN); | |
7961 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
7962 | NL80211_KCK_LEN); | |
7963 | memcpy(rekey_data.replay_ctr, | |
7964 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
7965 | NL80211_REPLAY_CTR_LEN); | |
7966 | ||
7967 | wdev_lock(wdev); | |
7968 | if (!wdev->current_bss) { | |
7969 | err = -ENOTCONN; | |
7970 | goto out; | |
7971 | } | |
7972 | ||
7973 | if (!rdev->ops->set_rekey_data) { | |
7974 | err = -EOPNOTSUPP; | |
7975 | goto out; | |
7976 | } | |
7977 | ||
e35e4d28 | 7978 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
7979 | out: |
7980 | wdev_unlock(wdev); | |
7981 | return err; | |
7982 | } | |
7983 | ||
28946da7 JB |
7984 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
7985 | struct genl_info *info) | |
7986 | { | |
7987 | struct net_device *dev = info->user_ptr[1]; | |
7988 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7989 | ||
7990 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
7991 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
7992 | return -EINVAL; | |
7993 | ||
15e47304 | 7994 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
7995 | return -EBUSY; |
7996 | ||
15e47304 | 7997 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
7998 | return 0; |
7999 | } | |
8000 | ||
7f6cf311 JB |
8001 | static int nl80211_probe_client(struct sk_buff *skb, |
8002 | struct genl_info *info) | |
8003 | { | |
8004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8005 | struct net_device *dev = info->user_ptr[1]; | |
8006 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8007 | struct sk_buff *msg; | |
8008 | void *hdr; | |
8009 | const u8 *addr; | |
8010 | u64 cookie; | |
8011 | int err; | |
8012 | ||
8013 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8014 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8015 | return -EOPNOTSUPP; | |
8016 | ||
8017 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8018 | return -EINVAL; | |
8019 | ||
8020 | if (!rdev->ops->probe_client) | |
8021 | return -EOPNOTSUPP; | |
8022 | ||
8023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8024 | if (!msg) | |
8025 | return -ENOMEM; | |
8026 | ||
15e47304 | 8027 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8028 | NL80211_CMD_PROBE_CLIENT); |
8029 | ||
8030 | if (IS_ERR(hdr)) { | |
8031 | err = PTR_ERR(hdr); | |
8032 | goto free_msg; | |
8033 | } | |
8034 | ||
8035 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8036 | ||
e35e4d28 | 8037 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8038 | if (err) |
8039 | goto free_msg; | |
8040 | ||
9360ffd1 DM |
8041 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8042 | goto nla_put_failure; | |
7f6cf311 JB |
8043 | |
8044 | genlmsg_end(msg, hdr); | |
8045 | ||
8046 | return genlmsg_reply(msg, info); | |
8047 | ||
8048 | nla_put_failure: | |
8049 | err = -ENOBUFS; | |
8050 | free_msg: | |
8051 | nlmsg_free(msg); | |
8052 | return err; | |
8053 | } | |
8054 | ||
5e760230 JB |
8055 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8056 | { | |
8057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8058 | struct cfg80211_beacon_registration *reg, *nreg; |
8059 | int rv; | |
5e760230 JB |
8060 | |
8061 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8062 | return -EOPNOTSUPP; | |
8063 | ||
37c73b5f BG |
8064 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8065 | if (!nreg) | |
8066 | return -ENOMEM; | |
8067 | ||
8068 | /* First, check if already registered. */ | |
8069 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8070 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8071 | if (reg->nlportid == info->snd_portid) { | |
8072 | rv = -EALREADY; | |
8073 | goto out_err; | |
8074 | } | |
8075 | } | |
8076 | /* Add it to the list */ | |
8077 | nreg->nlportid = info->snd_portid; | |
8078 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8079 | |
37c73b5f | 8080 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8081 | |
8082 | return 0; | |
37c73b5f BG |
8083 | out_err: |
8084 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8085 | kfree(nreg); | |
8086 | return rv; | |
5e760230 JB |
8087 | } |
8088 | ||
98104fde JB |
8089 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8090 | { | |
8091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8092 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8093 | int err; | |
8094 | ||
8095 | if (!rdev->ops->start_p2p_device) | |
8096 | return -EOPNOTSUPP; | |
8097 | ||
8098 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8099 | return -EOPNOTSUPP; | |
8100 | ||
8101 | if (wdev->p2p_started) | |
8102 | return 0; | |
8103 | ||
8104 | mutex_lock(&rdev->devlist_mtx); | |
8105 | err = cfg80211_can_add_interface(rdev, wdev->iftype); | |
8106 | mutex_unlock(&rdev->devlist_mtx); | |
8107 | if (err) | |
8108 | return err; | |
8109 | ||
eeb126e9 | 8110 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8111 | if (err) |
8112 | return err; | |
8113 | ||
8114 | wdev->p2p_started = true; | |
8115 | mutex_lock(&rdev->devlist_mtx); | |
8116 | rdev->opencount++; | |
8117 | mutex_unlock(&rdev->devlist_mtx); | |
8118 | ||
8119 | return 0; | |
8120 | } | |
8121 | ||
8122 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8123 | { | |
8124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8125 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8126 | ||
8127 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8128 | return -EOPNOTSUPP; | |
8129 | ||
8130 | if (!rdev->ops->stop_p2p_device) | |
8131 | return -EOPNOTSUPP; | |
8132 | ||
8133 | if (!wdev->p2p_started) | |
8134 | return 0; | |
8135 | ||
eeb126e9 | 8136 | rdev_stop_p2p_device(rdev, wdev); |
98104fde JB |
8137 | wdev->p2p_started = false; |
8138 | ||
8139 | mutex_lock(&rdev->devlist_mtx); | |
8140 | rdev->opencount--; | |
8141 | mutex_unlock(&rdev->devlist_mtx); | |
8142 | ||
8143 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { | |
8144 | rdev->scan_req->aborted = true; | |
8145 | ___cfg80211_scan_done(rdev, true); | |
8146 | } | |
8147 | ||
8148 | return 0; | |
8149 | } | |
8150 | ||
3713b4e3 JB |
8151 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8152 | struct genl_info *info) | |
8153 | { | |
8154 | void *hdr; | |
8155 | struct sk_buff *msg; | |
8156 | ||
8157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8158 | if (!msg) | |
8159 | return -ENOMEM; | |
8160 | ||
8161 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8162 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8163 | if (!hdr) | |
8164 | goto nla_put_failure; | |
8165 | ||
8166 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8167 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8168 | goto nla_put_failure; | |
8169 | ||
8170 | genlmsg_end(msg, hdr); | |
8171 | return genlmsg_reply(msg, info); | |
8172 | ||
8173 | nla_put_failure: | |
8174 | kfree_skb(msg); | |
8175 | return -ENOBUFS; | |
8176 | } | |
8177 | ||
355199e0 JM |
8178 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8179 | { | |
8180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8181 | struct cfg80211_update_ft_ies_params ft_params; | |
8182 | struct net_device *dev = info->user_ptr[1]; | |
8183 | ||
8184 | if (!rdev->ops->update_ft_ies) | |
8185 | return -EOPNOTSUPP; | |
8186 | ||
8187 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8188 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8189 | return -EINVAL; | |
8190 | ||
8191 | memset(&ft_params, 0, sizeof(ft_params)); | |
8192 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8193 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8194 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8195 | ||
8196 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8197 | } | |
8198 | ||
4c476991 JB |
8199 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8200 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8201 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8202 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8203 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8204 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8205 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8206 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8207 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8208 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8209 | |
8210 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8211 | struct genl_info *info) | |
8212 | { | |
8213 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8214 | struct wireless_dev *wdev; |
4c476991 | 8215 | struct net_device *dev; |
4c476991 JB |
8216 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8217 | ||
8218 | if (rtnl) | |
8219 | rtnl_lock(); | |
8220 | ||
8221 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8222 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8223 | if (IS_ERR(rdev)) { |
8224 | if (rtnl) | |
8225 | rtnl_unlock(); | |
8226 | return PTR_ERR(rdev); | |
8227 | } | |
8228 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8229 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8230 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
89a54e48 JB |
8231 | mutex_lock(&cfg80211_mutex); |
8232 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | |
8233 | info->attrs); | |
8234 | if (IS_ERR(wdev)) { | |
8235 | mutex_unlock(&cfg80211_mutex); | |
4c476991 JB |
8236 | if (rtnl) |
8237 | rtnl_unlock(); | |
89a54e48 | 8238 | return PTR_ERR(wdev); |
4c476991 | 8239 | } |
89a54e48 | 8240 | |
89a54e48 JB |
8241 | dev = wdev->netdev; |
8242 | rdev = wiphy_to_dev(wdev->wiphy); | |
8243 | ||
1bf614ef JB |
8244 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8245 | if (!dev) { | |
8246 | mutex_unlock(&cfg80211_mutex); | |
8247 | if (rtnl) | |
8248 | rtnl_unlock(); | |
8249 | return -EINVAL; | |
8250 | } | |
8251 | ||
8252 | info->user_ptr[1] = dev; | |
8253 | } else { | |
8254 | info->user_ptr[1] = wdev; | |
41265714 | 8255 | } |
1bf614ef JB |
8256 | |
8257 | if (dev) { | |
8258 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8259 | !netif_running(dev)) { | |
8260 | mutex_unlock(&cfg80211_mutex); | |
8261 | if (rtnl) | |
8262 | rtnl_unlock(); | |
8263 | return -ENETDOWN; | |
8264 | } | |
8265 | ||
8266 | dev_hold(dev); | |
98104fde JB |
8267 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8268 | if (!wdev->p2p_started) { | |
8269 | mutex_unlock(&cfg80211_mutex); | |
8270 | if (rtnl) | |
8271 | rtnl_unlock(); | |
8272 | return -ENETDOWN; | |
8273 | } | |
41265714 | 8274 | } |
89a54e48 | 8275 | |
89a54e48 JB |
8276 | cfg80211_lock_rdev(rdev); |
8277 | ||
8278 | mutex_unlock(&cfg80211_mutex); | |
8279 | ||
4c476991 | 8280 | info->user_ptr[0] = rdev; |
4c476991 JB |
8281 | } |
8282 | ||
8283 | return 0; | |
8284 | } | |
8285 | ||
8286 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8287 | struct genl_info *info) | |
8288 | { | |
8289 | if (info->user_ptr[0]) | |
8290 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
1bf614ef JB |
8291 | if (info->user_ptr[1]) { |
8292 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8293 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8294 | ||
8295 | if (wdev->netdev) | |
8296 | dev_put(wdev->netdev); | |
8297 | } else { | |
8298 | dev_put(info->user_ptr[1]); | |
8299 | } | |
8300 | } | |
4c476991 JB |
8301 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8302 | rtnl_unlock(); | |
8303 | } | |
8304 | ||
55682965 JB |
8305 | static struct genl_ops nl80211_ops[] = { |
8306 | { | |
8307 | .cmd = NL80211_CMD_GET_WIPHY, | |
8308 | .doit = nl80211_get_wiphy, | |
8309 | .dumpit = nl80211_dump_wiphy, | |
8310 | .policy = nl80211_policy, | |
8311 | /* can be retrieved by unprivileged users */ | |
4c476991 | 8312 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
8313 | }, |
8314 | { | |
8315 | .cmd = NL80211_CMD_SET_WIPHY, | |
8316 | .doit = nl80211_set_wiphy, | |
8317 | .policy = nl80211_policy, | |
8318 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8319 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8320 | }, |
8321 | { | |
8322 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8323 | .doit = nl80211_get_interface, | |
8324 | .dumpit = nl80211_dump_interface, | |
8325 | .policy = nl80211_policy, | |
8326 | /* can be retrieved by unprivileged users */ | |
72fb2abc | 8327 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
55682965 JB |
8328 | }, |
8329 | { | |
8330 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8331 | .doit = nl80211_set_interface, | |
8332 | .policy = nl80211_policy, | |
8333 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8334 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8335 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8336 | }, |
8337 | { | |
8338 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8339 | .doit = nl80211_new_interface, | |
8340 | .policy = nl80211_policy, | |
8341 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8342 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8343 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8344 | }, |
8345 | { | |
8346 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8347 | .doit = nl80211_del_interface, | |
8348 | .policy = nl80211_policy, | |
41ade00f | 8349 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8350 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8351 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8352 | }, |
8353 | { | |
8354 | .cmd = NL80211_CMD_GET_KEY, | |
8355 | .doit = nl80211_get_key, | |
8356 | .policy = nl80211_policy, | |
8357 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8358 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8359 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8360 | }, |
8361 | { | |
8362 | .cmd = NL80211_CMD_SET_KEY, | |
8363 | .doit = nl80211_set_key, | |
8364 | .policy = nl80211_policy, | |
8365 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8367 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8368 | }, |
8369 | { | |
8370 | .cmd = NL80211_CMD_NEW_KEY, | |
8371 | .doit = nl80211_new_key, | |
8372 | .policy = nl80211_policy, | |
8373 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8375 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8376 | }, |
8377 | { | |
8378 | .cmd = NL80211_CMD_DEL_KEY, | |
8379 | .doit = nl80211_del_key, | |
8380 | .policy = nl80211_policy, | |
55682965 | 8381 | .flags = GENL_ADMIN_PERM, |
41265714 | 8382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8383 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8384 | }, |
ed1b6cc7 JB |
8385 | { |
8386 | .cmd = NL80211_CMD_SET_BEACON, | |
8387 | .policy = nl80211_policy, | |
8388 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8389 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8391 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8392 | }, |
8393 | { | |
8860020e | 8394 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8395 | .policy = nl80211_policy, |
8396 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8397 | .doit = nl80211_start_ap, |
2b5f8b0b | 8398 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8399 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8400 | }, |
8401 | { | |
8860020e | 8402 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8403 | .policy = nl80211_policy, |
8404 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8405 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8407 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8408 | }, |
5727ef1b JB |
8409 | { |
8410 | .cmd = NL80211_CMD_GET_STATION, | |
8411 | .doit = nl80211_get_station, | |
2ec600d6 | 8412 | .dumpit = nl80211_dump_station, |
5727ef1b | 8413 | .policy = nl80211_policy, |
4c476991 JB |
8414 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8415 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8416 | }, |
8417 | { | |
8418 | .cmd = NL80211_CMD_SET_STATION, | |
8419 | .doit = nl80211_set_station, | |
8420 | .policy = nl80211_policy, | |
8421 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8422 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8423 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8424 | }, |
8425 | { | |
8426 | .cmd = NL80211_CMD_NEW_STATION, | |
8427 | .doit = nl80211_new_station, | |
8428 | .policy = nl80211_policy, | |
8429 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8430 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8431 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8432 | }, |
8433 | { | |
8434 | .cmd = NL80211_CMD_DEL_STATION, | |
8435 | .doit = nl80211_del_station, | |
8436 | .policy = nl80211_policy, | |
2ec600d6 | 8437 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8438 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8439 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8440 | }, |
8441 | { | |
8442 | .cmd = NL80211_CMD_GET_MPATH, | |
8443 | .doit = nl80211_get_mpath, | |
8444 | .dumpit = nl80211_dump_mpath, | |
8445 | .policy = nl80211_policy, | |
8446 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8447 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8448 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8449 | }, |
8450 | { | |
8451 | .cmd = NL80211_CMD_SET_MPATH, | |
8452 | .doit = nl80211_set_mpath, | |
8453 | .policy = nl80211_policy, | |
8454 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8456 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8457 | }, |
8458 | { | |
8459 | .cmd = NL80211_CMD_NEW_MPATH, | |
8460 | .doit = nl80211_new_mpath, | |
8461 | .policy = nl80211_policy, | |
8462 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8463 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8464 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8465 | }, |
8466 | { | |
8467 | .cmd = NL80211_CMD_DEL_MPATH, | |
8468 | .doit = nl80211_del_mpath, | |
8469 | .policy = nl80211_policy, | |
9f1ba906 | 8470 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8472 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8473 | }, |
8474 | { | |
8475 | .cmd = NL80211_CMD_SET_BSS, | |
8476 | .doit = nl80211_set_bss, | |
8477 | .policy = nl80211_policy, | |
b2e1b302 | 8478 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8479 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8480 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8481 | }, |
f130347c LR |
8482 | { |
8483 | .cmd = NL80211_CMD_GET_REG, | |
8484 | .doit = nl80211_get_reg, | |
8485 | .policy = nl80211_policy, | |
8486 | /* can be retrieved by unprivileged users */ | |
8487 | }, | |
b2e1b302 LR |
8488 | { |
8489 | .cmd = NL80211_CMD_SET_REG, | |
8490 | .doit = nl80211_set_reg, | |
8491 | .policy = nl80211_policy, | |
8492 | .flags = GENL_ADMIN_PERM, | |
8493 | }, | |
8494 | { | |
8495 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8496 | .doit = nl80211_req_set_reg, | |
8497 | .policy = nl80211_policy, | |
93da9cc1 | 8498 | .flags = GENL_ADMIN_PERM, |
8499 | }, | |
8500 | { | |
24bdd9f4 JC |
8501 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8502 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8503 | .policy = nl80211_policy, |
8504 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8506 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8507 | }, |
8508 | { | |
24bdd9f4 JC |
8509 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8510 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8511 | .policy = nl80211_policy, |
9aed3cc1 | 8512 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8514 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8515 | }, |
2a519311 JB |
8516 | { |
8517 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8518 | .doit = nl80211_trigger_scan, | |
8519 | .policy = nl80211_policy, | |
8520 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8521 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8522 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8523 | }, |
8524 | { | |
8525 | .cmd = NL80211_CMD_GET_SCAN, | |
8526 | .policy = nl80211_policy, | |
8527 | .dumpit = nl80211_dump_scan, | |
8528 | }, | |
807f8a8c LC |
8529 | { |
8530 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8531 | .doit = nl80211_start_sched_scan, | |
8532 | .policy = nl80211_policy, | |
8533 | .flags = GENL_ADMIN_PERM, | |
8534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8535 | NL80211_FLAG_NEED_RTNL, | |
8536 | }, | |
8537 | { | |
8538 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8539 | .doit = nl80211_stop_sched_scan, | |
8540 | .policy = nl80211_policy, | |
8541 | .flags = GENL_ADMIN_PERM, | |
8542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8543 | NL80211_FLAG_NEED_RTNL, | |
8544 | }, | |
636a5d36 JM |
8545 | { |
8546 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8547 | .doit = nl80211_authenticate, | |
8548 | .policy = nl80211_policy, | |
8549 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8551 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8552 | }, |
8553 | { | |
8554 | .cmd = NL80211_CMD_ASSOCIATE, | |
8555 | .doit = nl80211_associate, | |
8556 | .policy = nl80211_policy, | |
8557 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8558 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8559 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8560 | }, |
8561 | { | |
8562 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8563 | .doit = nl80211_deauthenticate, | |
8564 | .policy = nl80211_policy, | |
8565 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8566 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8567 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8568 | }, |
8569 | { | |
8570 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8571 | .doit = nl80211_disassociate, | |
8572 | .policy = nl80211_policy, | |
8573 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8575 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8576 | }, |
04a773ad JB |
8577 | { |
8578 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8579 | .doit = nl80211_join_ibss, | |
8580 | .policy = nl80211_policy, | |
8581 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8583 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8584 | }, |
8585 | { | |
8586 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8587 | .doit = nl80211_leave_ibss, | |
8588 | .policy = nl80211_policy, | |
8589 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8591 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8592 | }, |
aff89a9b JB |
8593 | #ifdef CONFIG_NL80211_TESTMODE |
8594 | { | |
8595 | .cmd = NL80211_CMD_TESTMODE, | |
8596 | .doit = nl80211_testmode_do, | |
71063f0e | 8597 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8598 | .policy = nl80211_policy, |
8599 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8600 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8601 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8602 | }, |
8603 | #endif | |
b23aa676 SO |
8604 | { |
8605 | .cmd = NL80211_CMD_CONNECT, | |
8606 | .doit = nl80211_connect, | |
8607 | .policy = nl80211_policy, | |
8608 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8609 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8610 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8611 | }, |
8612 | { | |
8613 | .cmd = NL80211_CMD_DISCONNECT, | |
8614 | .doit = nl80211_disconnect, | |
8615 | .policy = nl80211_policy, | |
8616 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8617 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8618 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8619 | }, |
463d0183 JB |
8620 | { |
8621 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8622 | .doit = nl80211_wiphy_netns, | |
8623 | .policy = nl80211_policy, | |
8624 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8625 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8626 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8627 | }, |
61fa713c HS |
8628 | { |
8629 | .cmd = NL80211_CMD_GET_SURVEY, | |
8630 | .policy = nl80211_policy, | |
8631 | .dumpit = nl80211_dump_survey, | |
8632 | }, | |
67fbb16b SO |
8633 | { |
8634 | .cmd = NL80211_CMD_SET_PMKSA, | |
8635 | .doit = nl80211_setdel_pmksa, | |
8636 | .policy = nl80211_policy, | |
8637 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8638 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8639 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8640 | }, |
8641 | { | |
8642 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8643 | .doit = nl80211_setdel_pmksa, | |
8644 | .policy = nl80211_policy, | |
8645 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8646 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8647 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8648 | }, |
8649 | { | |
8650 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8651 | .doit = nl80211_flush_pmksa, | |
8652 | .policy = nl80211_policy, | |
8653 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8654 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8655 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8656 | }, |
9588bbd5 JM |
8657 | { |
8658 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8659 | .doit = nl80211_remain_on_channel, | |
8660 | .policy = nl80211_policy, | |
8661 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8662 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8663 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8664 | }, |
8665 | { | |
8666 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8667 | .doit = nl80211_cancel_remain_on_channel, | |
8668 | .policy = nl80211_policy, | |
8669 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8670 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8671 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8672 | }, |
13ae75b1 JM |
8673 | { |
8674 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8675 | .doit = nl80211_set_tx_bitrate_mask, | |
8676 | .policy = nl80211_policy, | |
8677 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8678 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8679 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8680 | }, |
026331c4 | 8681 | { |
2e161f78 JB |
8682 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8683 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8684 | .policy = nl80211_policy, |
8685 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8686 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8687 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8688 | }, |
8689 | { | |
2e161f78 JB |
8690 | .cmd = NL80211_CMD_FRAME, |
8691 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8692 | .policy = nl80211_policy, |
f7ca38df | 8693 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8694 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8695 | NL80211_FLAG_NEED_RTNL, |
8696 | }, | |
8697 | { | |
8698 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8699 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8700 | .policy = nl80211_policy, | |
026331c4 | 8701 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8702 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8703 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8704 | }, |
ffb9eb3d KV |
8705 | { |
8706 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8707 | .doit = nl80211_set_power_save, | |
8708 | .policy = nl80211_policy, | |
8709 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8710 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8711 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8712 | }, |
8713 | { | |
8714 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8715 | .doit = nl80211_get_power_save, | |
8716 | .policy = nl80211_policy, | |
8717 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8718 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8719 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8720 | }, |
d6dc1a38 JO |
8721 | { |
8722 | .cmd = NL80211_CMD_SET_CQM, | |
8723 | .doit = nl80211_set_cqm, | |
8724 | .policy = nl80211_policy, | |
8725 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8726 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8727 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8728 | }, |
f444de05 JB |
8729 | { |
8730 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8731 | .doit = nl80211_set_channel, | |
8732 | .policy = nl80211_policy, | |
8733 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8734 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8735 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 8736 | }, |
e8347eba BJ |
8737 | { |
8738 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
8739 | .doit = nl80211_set_wds_peer, | |
8740 | .policy = nl80211_policy, | |
8741 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
8742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8743 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 8744 | }, |
29cbe68c JB |
8745 | { |
8746 | .cmd = NL80211_CMD_JOIN_MESH, | |
8747 | .doit = nl80211_join_mesh, | |
8748 | .policy = nl80211_policy, | |
8749 | .flags = GENL_ADMIN_PERM, | |
8750 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8751 | NL80211_FLAG_NEED_RTNL, | |
8752 | }, | |
8753 | { | |
8754 | .cmd = NL80211_CMD_LEAVE_MESH, | |
8755 | .doit = nl80211_leave_mesh, | |
8756 | .policy = nl80211_policy, | |
8757 | .flags = GENL_ADMIN_PERM, | |
8758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8759 | NL80211_FLAG_NEED_RTNL, | |
8760 | }, | |
dfb89c56 | 8761 | #ifdef CONFIG_PM |
ff1b6e69 JB |
8762 | { |
8763 | .cmd = NL80211_CMD_GET_WOWLAN, | |
8764 | .doit = nl80211_get_wowlan, | |
8765 | .policy = nl80211_policy, | |
8766 | /* can be retrieved by unprivileged users */ | |
8767 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8768 | NL80211_FLAG_NEED_RTNL, | |
8769 | }, | |
8770 | { | |
8771 | .cmd = NL80211_CMD_SET_WOWLAN, | |
8772 | .doit = nl80211_set_wowlan, | |
8773 | .policy = nl80211_policy, | |
8774 | .flags = GENL_ADMIN_PERM, | |
8775 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8776 | NL80211_FLAG_NEED_RTNL, | |
8777 | }, | |
dfb89c56 | 8778 | #endif |
e5497d76 JB |
8779 | { |
8780 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
8781 | .doit = nl80211_set_rekey_data, | |
8782 | .policy = nl80211_policy, | |
8783 | .flags = GENL_ADMIN_PERM, | |
8784 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8785 | NL80211_FLAG_NEED_RTNL, | |
8786 | }, | |
109086ce AN |
8787 | { |
8788 | .cmd = NL80211_CMD_TDLS_MGMT, | |
8789 | .doit = nl80211_tdls_mgmt, | |
8790 | .policy = nl80211_policy, | |
8791 | .flags = GENL_ADMIN_PERM, | |
8792 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8793 | NL80211_FLAG_NEED_RTNL, | |
8794 | }, | |
8795 | { | |
8796 | .cmd = NL80211_CMD_TDLS_OPER, | |
8797 | .doit = nl80211_tdls_oper, | |
8798 | .policy = nl80211_policy, | |
8799 | .flags = GENL_ADMIN_PERM, | |
8800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8801 | NL80211_FLAG_NEED_RTNL, | |
8802 | }, | |
28946da7 JB |
8803 | { |
8804 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
8805 | .doit = nl80211_register_unexpected_frame, | |
8806 | .policy = nl80211_policy, | |
8807 | .flags = GENL_ADMIN_PERM, | |
8808 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8809 | NL80211_FLAG_NEED_RTNL, | |
8810 | }, | |
7f6cf311 JB |
8811 | { |
8812 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
8813 | .doit = nl80211_probe_client, | |
8814 | .policy = nl80211_policy, | |
8815 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
8817 | NL80211_FLAG_NEED_RTNL, |
8818 | }, | |
5e760230 JB |
8819 | { |
8820 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
8821 | .doit = nl80211_register_beacons, | |
8822 | .policy = nl80211_policy, | |
8823 | .flags = GENL_ADMIN_PERM, | |
8824 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8825 | NL80211_FLAG_NEED_RTNL, | |
8826 | }, | |
1d9d9213 SW |
8827 | { |
8828 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
8829 | .doit = nl80211_set_noack_map, | |
8830 | .policy = nl80211_policy, | |
8831 | .flags = GENL_ADMIN_PERM, | |
8832 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8833 | NL80211_FLAG_NEED_RTNL, | |
8834 | }, | |
98104fde JB |
8835 | { |
8836 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
8837 | .doit = nl80211_start_p2p_device, | |
8838 | .policy = nl80211_policy, | |
8839 | .flags = GENL_ADMIN_PERM, | |
8840 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
8841 | NL80211_FLAG_NEED_RTNL, | |
8842 | }, | |
8843 | { | |
8844 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
8845 | .doit = nl80211_stop_p2p_device, | |
8846 | .policy = nl80211_policy, | |
8847 | .flags = GENL_ADMIN_PERM, | |
8848 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8849 | NL80211_FLAG_NEED_RTNL, | |
8850 | }, | |
f4e583c8 AQ |
8851 | { |
8852 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
8853 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
8854 | .policy = nl80211_policy, |
8855 | .flags = GENL_ADMIN_PERM, | |
8856 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8857 | NL80211_FLAG_NEED_RTNL, | |
8858 | }, | |
8859 | { | |
8860 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
8861 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
8862 | .policy = nl80211_policy, |
8863 | .flags = GENL_ADMIN_PERM, | |
8864 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8865 | NL80211_FLAG_NEED_RTNL, | |
8866 | }, | |
04f39047 SW |
8867 | { |
8868 | .cmd = NL80211_CMD_RADAR_DETECT, | |
8869 | .doit = nl80211_start_radar_detection, | |
8870 | .policy = nl80211_policy, | |
8871 | .flags = GENL_ADMIN_PERM, | |
8872 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8873 | NL80211_FLAG_NEED_RTNL, | |
8874 | }, | |
3713b4e3 JB |
8875 | { |
8876 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
8877 | .doit = nl80211_get_protocol_features, | |
8878 | .policy = nl80211_policy, | |
8879 | }, | |
355199e0 JM |
8880 | { |
8881 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
8882 | .doit = nl80211_update_ft_ies, | |
8883 | .policy = nl80211_policy, | |
8884 | .flags = GENL_ADMIN_PERM, | |
8885 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8886 | NL80211_FLAG_NEED_RTNL, | |
8887 | }, | |
55682965 | 8888 | }; |
9588bbd5 | 8889 | |
6039f6d2 JM |
8890 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
8891 | .name = "mlme", | |
8892 | }; | |
55682965 JB |
8893 | |
8894 | /* multicast groups */ | |
8895 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
8896 | .name = "config", | |
8897 | }; | |
2a519311 JB |
8898 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
8899 | .name = "scan", | |
8900 | }; | |
73d54c9e LR |
8901 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
8902 | .name = "regulatory", | |
8903 | }; | |
55682965 JB |
8904 | |
8905 | /* notification functions */ | |
8906 | ||
8907 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
8908 | { | |
8909 | struct sk_buff *msg; | |
8910 | ||
fd2120ca | 8911 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
8912 | if (!msg) |
8913 | return; | |
8914 | ||
3713b4e3 JB |
8915 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
8916 | false, NULL, NULL, NULL) < 0) { | |
55682965 JB |
8917 | nlmsg_free(msg); |
8918 | return; | |
8919 | } | |
8920 | ||
463d0183 JB |
8921 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8922 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
8923 | } |
8924 | ||
362a415d JB |
8925 | static int nl80211_add_scan_req(struct sk_buff *msg, |
8926 | struct cfg80211_registered_device *rdev) | |
8927 | { | |
8928 | struct cfg80211_scan_request *req = rdev->scan_req; | |
8929 | struct nlattr *nest; | |
8930 | int i; | |
8931 | ||
667503dd JB |
8932 | ASSERT_RDEV_LOCK(rdev); |
8933 | ||
362a415d JB |
8934 | if (WARN_ON(!req)) |
8935 | return 0; | |
8936 | ||
8937 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
8938 | if (!nest) | |
8939 | goto nla_put_failure; | |
9360ffd1 DM |
8940 | for (i = 0; i < req->n_ssids; i++) { |
8941 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
8942 | goto nla_put_failure; | |
8943 | } | |
362a415d JB |
8944 | nla_nest_end(msg, nest); |
8945 | ||
8946 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8947 | if (!nest) | |
8948 | goto nla_put_failure; | |
9360ffd1 DM |
8949 | for (i = 0; i < req->n_channels; i++) { |
8950 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
8951 | goto nla_put_failure; | |
8952 | } | |
362a415d JB |
8953 | nla_nest_end(msg, nest); |
8954 | ||
9360ffd1 DM |
8955 | if (req->ie && |
8956 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
8957 | goto nla_put_failure; | |
362a415d | 8958 | |
ed473771 SL |
8959 | if (req->flags) |
8960 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
8961 | ||
362a415d JB |
8962 | return 0; |
8963 | nla_put_failure: | |
8964 | return -ENOBUFS; | |
8965 | } | |
8966 | ||
a538e2d5 JB |
8967 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
8968 | struct cfg80211_registered_device *rdev, | |
fd014284 | 8969 | struct wireless_dev *wdev, |
15e47304 | 8970 | u32 portid, u32 seq, int flags, |
a538e2d5 | 8971 | u32 cmd) |
2a519311 JB |
8972 | { |
8973 | void *hdr; | |
8974 | ||
15e47304 | 8975 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
8976 | if (!hdr) |
8977 | return -1; | |
8978 | ||
9360ffd1 | 8979 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
8980 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
8981 | wdev->netdev->ifindex)) || | |
8982 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 8983 | goto nla_put_failure; |
2a519311 | 8984 | |
362a415d JB |
8985 | /* ignore errors and send incomplete event anyway */ |
8986 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
8987 | |
8988 | return genlmsg_end(msg, hdr); | |
8989 | ||
8990 | nla_put_failure: | |
8991 | genlmsg_cancel(msg, hdr); | |
8992 | return -EMSGSIZE; | |
8993 | } | |
8994 | ||
807f8a8c LC |
8995 | static int |
8996 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
8997 | struct cfg80211_registered_device *rdev, | |
8998 | struct net_device *netdev, | |
15e47304 | 8999 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9000 | { |
9001 | void *hdr; | |
9002 | ||
15e47304 | 9003 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9004 | if (!hdr) |
9005 | return -1; | |
9006 | ||
9360ffd1 DM |
9007 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9008 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9009 | goto nla_put_failure; | |
807f8a8c LC |
9010 | |
9011 | return genlmsg_end(msg, hdr); | |
9012 | ||
9013 | nla_put_failure: | |
9014 | genlmsg_cancel(msg, hdr); | |
9015 | return -EMSGSIZE; | |
9016 | } | |
9017 | ||
a538e2d5 | 9018 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9019 | struct wireless_dev *wdev) |
a538e2d5 JB |
9020 | { |
9021 | struct sk_buff *msg; | |
9022 | ||
58050fce | 9023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9024 | if (!msg) |
9025 | return; | |
9026 | ||
fd014284 | 9027 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9028 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9029 | nlmsg_free(msg); | |
9030 | return; | |
9031 | } | |
9032 | ||
463d0183 JB |
9033 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9034 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9035 | } |
9036 | ||
2a519311 | 9037 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9038 | struct wireless_dev *wdev) |
2a519311 JB |
9039 | { |
9040 | struct sk_buff *msg; | |
9041 | ||
fd2120ca | 9042 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9043 | if (!msg) |
9044 | return; | |
9045 | ||
fd014284 | 9046 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9047 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9048 | nlmsg_free(msg); |
9049 | return; | |
9050 | } | |
9051 | ||
463d0183 JB |
9052 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9053 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9054 | } |
9055 | ||
9056 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9057 | struct wireless_dev *wdev) |
2a519311 JB |
9058 | { |
9059 | struct sk_buff *msg; | |
9060 | ||
fd2120ca | 9061 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9062 | if (!msg) |
9063 | return; | |
9064 | ||
fd014284 | 9065 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9066 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9067 | nlmsg_free(msg); |
9068 | return; | |
9069 | } | |
9070 | ||
463d0183 JB |
9071 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9072 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9073 | } |
9074 | ||
807f8a8c LC |
9075 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9076 | struct net_device *netdev) | |
9077 | { | |
9078 | struct sk_buff *msg; | |
9079 | ||
9080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9081 | if (!msg) | |
9082 | return; | |
9083 | ||
9084 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9085 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9086 | nlmsg_free(msg); | |
9087 | return; | |
9088 | } | |
9089 | ||
9090 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9091 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9092 | } | |
9093 | ||
9094 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9095 | struct net_device *netdev, u32 cmd) | |
9096 | { | |
9097 | struct sk_buff *msg; | |
9098 | ||
58050fce | 9099 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9100 | if (!msg) |
9101 | return; | |
9102 | ||
9103 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9104 | nlmsg_free(msg); | |
9105 | return; | |
9106 | } | |
9107 | ||
9108 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9109 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9110 | } | |
9111 | ||
73d54c9e LR |
9112 | /* |
9113 | * This can happen on global regulatory changes or device specific settings | |
9114 | * based on custom world regulatory domains. | |
9115 | */ | |
9116 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9117 | { | |
9118 | struct sk_buff *msg; | |
9119 | void *hdr; | |
9120 | ||
fd2120ca | 9121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9122 | if (!msg) |
9123 | return; | |
9124 | ||
9125 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9126 | if (!hdr) { | |
9127 | nlmsg_free(msg); | |
9128 | return; | |
9129 | } | |
9130 | ||
9131 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9132 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9133 | goto nla_put_failure; | |
9134 | ||
9135 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9136 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9137 | NL80211_REGDOM_TYPE_WORLD)) | |
9138 | goto nla_put_failure; | |
9139 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9140 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9141 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9142 | goto nla_put_failure; | |
9143 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9144 | request->intersect) { | |
9145 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9146 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9147 | goto nla_put_failure; | |
9148 | } else { | |
9149 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9150 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9151 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9152 | request->alpha2)) | |
9153 | goto nla_put_failure; | |
9154 | } | |
9155 | ||
f4173766 | 9156 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9157 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9158 | goto nla_put_failure; | |
73d54c9e | 9159 | |
3b7b72ee | 9160 | genlmsg_end(msg, hdr); |
73d54c9e | 9161 | |
bc43b28c | 9162 | rcu_read_lock(); |
463d0183 | 9163 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9164 | GFP_ATOMIC); |
9165 | rcu_read_unlock(); | |
73d54c9e LR |
9166 | |
9167 | return; | |
9168 | ||
9169 | nla_put_failure: | |
9170 | genlmsg_cancel(msg, hdr); | |
9171 | nlmsg_free(msg); | |
9172 | } | |
9173 | ||
6039f6d2 JM |
9174 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9175 | struct net_device *netdev, | |
9176 | const u8 *buf, size_t len, | |
e6d6e342 | 9177 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9178 | { |
9179 | struct sk_buff *msg; | |
9180 | void *hdr; | |
9181 | ||
e6d6e342 | 9182 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9183 | if (!msg) |
9184 | return; | |
9185 | ||
9186 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9187 | if (!hdr) { | |
9188 | nlmsg_free(msg); | |
9189 | return; | |
9190 | } | |
9191 | ||
9360ffd1 DM |
9192 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9193 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9194 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9195 | goto nla_put_failure; | |
6039f6d2 | 9196 | |
3b7b72ee | 9197 | genlmsg_end(msg, hdr); |
6039f6d2 | 9198 | |
463d0183 JB |
9199 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9200 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9201 | return; |
9202 | ||
9203 | nla_put_failure: | |
9204 | genlmsg_cancel(msg, hdr); | |
9205 | nlmsg_free(msg); | |
9206 | } | |
9207 | ||
9208 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9209 | struct net_device *netdev, const u8 *buf, |
9210 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9211 | { |
9212 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9213 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9214 | } |
9215 | ||
9216 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9217 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9218 | size_t len, gfp_t gfp) |
6039f6d2 | 9219 | { |
e6d6e342 JB |
9220 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9221 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9222 | } |
9223 | ||
53b46b84 | 9224 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9225 | struct net_device *netdev, const u8 *buf, |
9226 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9227 | { |
9228 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9229 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9230 | } |
9231 | ||
53b46b84 JM |
9232 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9233 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9234 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9235 | { |
9236 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9237 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9238 | } |
9239 | ||
947add36 JB |
9240 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
9241 | size_t len) | |
cf4e594e | 9242 | { |
947add36 JB |
9243 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9244 | struct wiphy *wiphy = wdev->wiphy; | |
9245 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9246 | ||
9247 | trace_cfg80211_send_unprot_deauth(dev); | |
9248 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9249 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); | |
cf4e594e | 9250 | } |
947add36 | 9251 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
cf4e594e | 9252 | |
947add36 JB |
9253 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
9254 | size_t len) | |
cf4e594e | 9255 | { |
947add36 JB |
9256 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9257 | struct wiphy *wiphy = wdev->wiphy; | |
9258 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9259 | ||
9260 | trace_cfg80211_send_unprot_disassoc(dev); | |
9261 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9262 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); | |
cf4e594e | 9263 | } |
947add36 | 9264 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
cf4e594e | 9265 | |
1b06bb40 LR |
9266 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9267 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9268 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9269 | { |
9270 | struct sk_buff *msg; | |
9271 | void *hdr; | |
9272 | ||
e6d6e342 | 9273 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9274 | if (!msg) |
9275 | return; | |
9276 | ||
9277 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9278 | if (!hdr) { | |
9279 | nlmsg_free(msg); | |
9280 | return; | |
9281 | } | |
9282 | ||
9360ffd1 DM |
9283 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9284 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9285 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9286 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9287 | goto nla_put_failure; | |
1965c853 | 9288 | |
3b7b72ee | 9289 | genlmsg_end(msg, hdr); |
1965c853 | 9290 | |
463d0183 JB |
9291 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9292 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9293 | return; |
9294 | ||
9295 | nla_put_failure: | |
9296 | genlmsg_cancel(msg, hdr); | |
9297 | nlmsg_free(msg); | |
9298 | } | |
9299 | ||
9300 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9301 | struct net_device *netdev, const u8 *addr, |
9302 | gfp_t gfp) | |
1965c853 JM |
9303 | { |
9304 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9305 | addr, gfp); |
1965c853 JM |
9306 | } |
9307 | ||
9308 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9309 | struct net_device *netdev, const u8 *addr, |
9310 | gfp_t gfp) | |
1965c853 | 9311 | { |
e6d6e342 JB |
9312 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9313 | addr, gfp); | |
1965c853 JM |
9314 | } |
9315 | ||
b23aa676 SO |
9316 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9317 | struct net_device *netdev, const u8 *bssid, | |
9318 | const u8 *req_ie, size_t req_ie_len, | |
9319 | const u8 *resp_ie, size_t resp_ie_len, | |
9320 | u16 status, gfp_t gfp) | |
9321 | { | |
9322 | struct sk_buff *msg; | |
9323 | void *hdr; | |
9324 | ||
58050fce | 9325 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9326 | if (!msg) |
9327 | return; | |
9328 | ||
9329 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9330 | if (!hdr) { | |
9331 | nlmsg_free(msg); | |
9332 | return; | |
9333 | } | |
9334 | ||
9360ffd1 DM |
9335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9336 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9337 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9338 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9339 | (req_ie && | |
9340 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9341 | (resp_ie && | |
9342 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9343 | goto nla_put_failure; | |
b23aa676 | 9344 | |
3b7b72ee | 9345 | genlmsg_end(msg, hdr); |
b23aa676 | 9346 | |
463d0183 JB |
9347 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9348 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9349 | return; |
9350 | ||
9351 | nla_put_failure: | |
9352 | genlmsg_cancel(msg, hdr); | |
9353 | nlmsg_free(msg); | |
9354 | ||
9355 | } | |
9356 | ||
9357 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9358 | struct net_device *netdev, const u8 *bssid, | |
9359 | const u8 *req_ie, size_t req_ie_len, | |
9360 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9361 | { | |
9362 | struct sk_buff *msg; | |
9363 | void *hdr; | |
9364 | ||
58050fce | 9365 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9366 | if (!msg) |
9367 | return; | |
9368 | ||
9369 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9370 | if (!hdr) { | |
9371 | nlmsg_free(msg); | |
9372 | return; | |
9373 | } | |
9374 | ||
9360ffd1 DM |
9375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9376 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9377 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9378 | (req_ie && | |
9379 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9380 | (resp_ie && | |
9381 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9382 | goto nla_put_failure; | |
b23aa676 | 9383 | |
3b7b72ee | 9384 | genlmsg_end(msg, hdr); |
b23aa676 | 9385 | |
463d0183 JB |
9386 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9387 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9388 | return; |
9389 | ||
9390 | nla_put_failure: | |
9391 | genlmsg_cancel(msg, hdr); | |
9392 | nlmsg_free(msg); | |
9393 | ||
9394 | } | |
9395 | ||
9396 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9397 | struct net_device *netdev, u16 reason, | |
667503dd | 9398 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9399 | { |
9400 | struct sk_buff *msg; | |
9401 | void *hdr; | |
9402 | ||
58050fce | 9403 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9404 | if (!msg) |
9405 | return; | |
9406 | ||
9407 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9408 | if (!hdr) { | |
9409 | nlmsg_free(msg); | |
9410 | return; | |
9411 | } | |
9412 | ||
9360ffd1 DM |
9413 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9414 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9415 | (from_ap && reason && | |
9416 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9417 | (from_ap && | |
9418 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9419 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9420 | goto nla_put_failure; | |
b23aa676 | 9421 | |
3b7b72ee | 9422 | genlmsg_end(msg, hdr); |
b23aa676 | 9423 | |
463d0183 JB |
9424 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9425 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9426 | return; |
9427 | ||
9428 | nla_put_failure: | |
9429 | genlmsg_cancel(msg, hdr); | |
9430 | nlmsg_free(msg); | |
9431 | ||
9432 | } | |
9433 | ||
04a773ad JB |
9434 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9435 | struct net_device *netdev, const u8 *bssid, | |
9436 | gfp_t gfp) | |
9437 | { | |
9438 | struct sk_buff *msg; | |
9439 | void *hdr; | |
9440 | ||
fd2120ca | 9441 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9442 | if (!msg) |
9443 | return; | |
9444 | ||
9445 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9446 | if (!hdr) { | |
9447 | nlmsg_free(msg); | |
9448 | return; | |
9449 | } | |
9450 | ||
9360ffd1 DM |
9451 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9452 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9453 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9454 | goto nla_put_failure; | |
04a773ad | 9455 | |
3b7b72ee | 9456 | genlmsg_end(msg, hdr); |
04a773ad | 9457 | |
463d0183 JB |
9458 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9459 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9460 | return; |
9461 | ||
9462 | nla_put_failure: | |
9463 | genlmsg_cancel(msg, hdr); | |
9464 | nlmsg_free(msg); | |
9465 | } | |
9466 | ||
947add36 JB |
9467 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9468 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9469 | { |
947add36 JB |
9470 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9471 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9472 | struct sk_buff *msg; |
9473 | void *hdr; | |
9474 | ||
947add36 JB |
9475 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9476 | return; | |
9477 | ||
9478 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9479 | ||
c93b5e71 JC |
9480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9481 | if (!msg) | |
9482 | return; | |
9483 | ||
9484 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9485 | if (!hdr) { | |
9486 | nlmsg_free(msg); | |
9487 | return; | |
9488 | } | |
9489 | ||
9360ffd1 | 9490 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9492 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9493 | (ie_len && ie && |
9494 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9495 | goto nla_put_failure; | |
c93b5e71 | 9496 | |
3b7b72ee | 9497 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9498 | |
9499 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9500 | nl80211_mlme_mcgrp.id, gfp); | |
9501 | return; | |
9502 | ||
9503 | nla_put_failure: | |
9504 | genlmsg_cancel(msg, hdr); | |
9505 | nlmsg_free(msg); | |
9506 | } | |
947add36 | 9507 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9508 | |
a3b8b056 JM |
9509 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9510 | struct net_device *netdev, const u8 *addr, | |
9511 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9512 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9513 | { |
9514 | struct sk_buff *msg; | |
9515 | void *hdr; | |
9516 | ||
e6d6e342 | 9517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9518 | if (!msg) |
9519 | return; | |
9520 | ||
9521 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9522 | if (!hdr) { | |
9523 | nlmsg_free(msg); | |
9524 | return; | |
9525 | } | |
9526 | ||
9360ffd1 DM |
9527 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9528 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9529 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9530 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9531 | (key_id != -1 && | |
9532 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9533 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9534 | goto nla_put_failure; | |
a3b8b056 | 9535 | |
3b7b72ee | 9536 | genlmsg_end(msg, hdr); |
a3b8b056 | 9537 | |
463d0183 JB |
9538 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9539 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9540 | return; |
9541 | ||
9542 | nla_put_failure: | |
9543 | genlmsg_cancel(msg, hdr); | |
9544 | nlmsg_free(msg); | |
9545 | } | |
9546 | ||
6bad8766 LR |
9547 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9548 | struct ieee80211_channel *channel_before, | |
9549 | struct ieee80211_channel *channel_after) | |
9550 | { | |
9551 | struct sk_buff *msg; | |
9552 | void *hdr; | |
9553 | struct nlattr *nl_freq; | |
9554 | ||
fd2120ca | 9555 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9556 | if (!msg) |
9557 | return; | |
9558 | ||
9559 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9560 | if (!hdr) { | |
9561 | nlmsg_free(msg); | |
9562 | return; | |
9563 | } | |
9564 | ||
9565 | /* | |
9566 | * Since we are applying the beacon hint to a wiphy we know its | |
9567 | * wiphy_idx is valid | |
9568 | */ | |
9360ffd1 DM |
9569 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9570 | goto nla_put_failure; | |
6bad8766 LR |
9571 | |
9572 | /* Before */ | |
9573 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9574 | if (!nl_freq) | |
9575 | goto nla_put_failure; | |
cdc89b97 | 9576 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
9577 | goto nla_put_failure; |
9578 | nla_nest_end(msg, nl_freq); | |
9579 | ||
9580 | /* After */ | |
9581 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9582 | if (!nl_freq) | |
9583 | goto nla_put_failure; | |
cdc89b97 | 9584 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
9585 | goto nla_put_failure; |
9586 | nla_nest_end(msg, nl_freq); | |
9587 | ||
3b7b72ee | 9588 | genlmsg_end(msg, hdr); |
6bad8766 | 9589 | |
463d0183 JB |
9590 | rcu_read_lock(); |
9591 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9592 | GFP_ATOMIC); | |
9593 | rcu_read_unlock(); | |
6bad8766 LR |
9594 | |
9595 | return; | |
9596 | ||
9597 | nla_put_failure: | |
9598 | genlmsg_cancel(msg, hdr); | |
9599 | nlmsg_free(msg); | |
9600 | } | |
9601 | ||
9588bbd5 JM |
9602 | static void nl80211_send_remain_on_chan_event( |
9603 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9604 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9605 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9606 | unsigned int duration, gfp_t gfp) |
9607 | { | |
9608 | struct sk_buff *msg; | |
9609 | void *hdr; | |
9610 | ||
9611 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9612 | if (!msg) | |
9613 | return; | |
9614 | ||
9615 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9616 | if (!hdr) { | |
9617 | nlmsg_free(msg); | |
9618 | return; | |
9619 | } | |
9620 | ||
9360ffd1 | 9621 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9622 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9623 | wdev->netdev->ifindex)) || | |
00f53350 | 9624 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9625 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9626 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9627 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9628 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9629 | goto nla_put_failure; | |
9588bbd5 | 9630 | |
9360ffd1 DM |
9631 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9632 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9633 | goto nla_put_failure; | |
9588bbd5 | 9634 | |
3b7b72ee | 9635 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9636 | |
9637 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9638 | nl80211_mlme_mcgrp.id, gfp); | |
9639 | return; | |
9640 | ||
9641 | nla_put_failure: | |
9642 | genlmsg_cancel(msg, hdr); | |
9643 | nlmsg_free(msg); | |
9644 | } | |
9645 | ||
947add36 JB |
9646 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
9647 | struct ieee80211_channel *chan, | |
9648 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 9649 | { |
947add36 JB |
9650 | struct wiphy *wiphy = wdev->wiphy; |
9651 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9652 | ||
9653 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 9654 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 9655 | rdev, wdev, cookie, chan, |
42d97a59 | 9656 | duration, gfp); |
9588bbd5 | 9657 | } |
947add36 | 9658 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 9659 | |
947add36 JB |
9660 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
9661 | struct ieee80211_channel *chan, | |
9662 | gfp_t gfp) | |
9588bbd5 | 9663 | { |
947add36 JB |
9664 | struct wiphy *wiphy = wdev->wiphy; |
9665 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9666 | ||
9667 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 9668 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 9669 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 9670 | } |
947add36 | 9671 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 9672 | |
947add36 JB |
9673 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
9674 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 9675 | { |
947add36 JB |
9676 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9677 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
9678 | struct sk_buff *msg; |
9679 | ||
947add36 JB |
9680 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
9681 | ||
58050fce | 9682 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9683 | if (!msg) |
9684 | return; | |
9685 | ||
66266b3a JL |
9686 | if (nl80211_send_station(msg, 0, 0, 0, |
9687 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9688 | nlmsg_free(msg); |
9689 | return; | |
9690 | } | |
9691 | ||
9692 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9693 | nl80211_mlme_mcgrp.id, gfp); | |
9694 | } | |
947add36 | 9695 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 9696 | |
947add36 | 9697 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 9698 | { |
947add36 JB |
9699 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9700 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
9701 | struct sk_buff *msg; |
9702 | void *hdr; | |
9703 | ||
947add36 JB |
9704 | trace_cfg80211_del_sta(dev, mac_addr); |
9705 | ||
58050fce | 9706 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9707 | if (!msg) |
9708 | return; | |
9709 | ||
9710 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
9711 | if (!hdr) { | |
9712 | nlmsg_free(msg); | |
9713 | return; | |
9714 | } | |
9715 | ||
9360ffd1 DM |
9716 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9717 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
9718 | goto nla_put_failure; | |
ec15e68b | 9719 | |
3b7b72ee | 9720 | genlmsg_end(msg, hdr); |
ec15e68b JM |
9721 | |
9722 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9723 | nl80211_mlme_mcgrp.id, gfp); | |
9724 | return; | |
9725 | ||
9726 | nla_put_failure: | |
9727 | genlmsg_cancel(msg, hdr); | |
9728 | nlmsg_free(msg); | |
9729 | } | |
947add36 | 9730 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 9731 | |
947add36 JB |
9732 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
9733 | enum nl80211_connect_failed_reason reason, | |
9734 | gfp_t gfp) | |
ed44a951 | 9735 | { |
947add36 JB |
9736 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9737 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
9738 | struct sk_buff *msg; |
9739 | void *hdr; | |
9740 | ||
9741 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9742 | if (!msg) | |
9743 | return; | |
9744 | ||
9745 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
9746 | if (!hdr) { | |
9747 | nlmsg_free(msg); | |
9748 | return; | |
9749 | } | |
9750 | ||
9751 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9752 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
9753 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
9754 | goto nla_put_failure; | |
9755 | ||
9756 | genlmsg_end(msg, hdr); | |
9757 | ||
9758 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9759 | nl80211_mlme_mcgrp.id, gfp); | |
9760 | return; | |
9761 | ||
9762 | nla_put_failure: | |
9763 | genlmsg_cancel(msg, hdr); | |
9764 | nlmsg_free(msg); | |
9765 | } | |
947add36 | 9766 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 9767 | |
b92ab5d8 JB |
9768 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
9769 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
9770 | { |
9771 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9772 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9773 | struct sk_buff *msg; | |
9774 | void *hdr; | |
9775 | int err; | |
15e47304 | 9776 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 9777 | |
15e47304 | 9778 | if (!nlportid) |
28946da7 JB |
9779 | return false; |
9780 | ||
9781 | msg = nlmsg_new(100, gfp); | |
9782 | if (!msg) | |
9783 | return true; | |
9784 | ||
b92ab5d8 | 9785 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
9786 | if (!hdr) { |
9787 | nlmsg_free(msg); | |
9788 | return true; | |
9789 | } | |
9790 | ||
9360ffd1 DM |
9791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9792 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9794 | goto nla_put_failure; | |
28946da7 JB |
9795 | |
9796 | err = genlmsg_end(msg, hdr); | |
9797 | if (err < 0) { | |
9798 | nlmsg_free(msg); | |
9799 | return true; | |
9800 | } | |
9801 | ||
15e47304 | 9802 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
9803 | return true; |
9804 | ||
9805 | nla_put_failure: | |
9806 | genlmsg_cancel(msg, hdr); | |
9807 | nlmsg_free(msg); | |
9808 | return true; | |
9809 | } | |
9810 | ||
947add36 JB |
9811 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
9812 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9813 | { |
947add36 JB |
9814 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9815 | bool ret; | |
9816 | ||
9817 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
9818 | ||
9819 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9820 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
9821 | trace_cfg80211_return_bool(false); | |
9822 | return false; | |
9823 | } | |
9824 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
9825 | addr, gfp); | |
9826 | trace_cfg80211_return_bool(ret); | |
9827 | return ret; | |
b92ab5d8 | 9828 | } |
947add36 | 9829 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 9830 | |
947add36 JB |
9831 | bool cfg80211_rx_unexpected_4addr_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_unexpected_4addr_frame(dev, addr); | |
9838 | ||
9839 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9840 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
9841 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
9842 | trace_cfg80211_return_bool(false); | |
9843 | return false; | |
9844 | } | |
9845 | ret = __nl80211_unexpected_frame(dev, | |
9846 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
9847 | addr, gfp); | |
9848 | trace_cfg80211_return_bool(ret); | |
9849 | return ret; | |
b92ab5d8 | 9850 | } |
947add36 | 9851 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 9852 | |
2e161f78 | 9853 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 9854 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
9855 | int freq, int sig_dbm, |
9856 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 9857 | { |
71bbc994 | 9858 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9859 | struct sk_buff *msg; |
9860 | void *hdr; | |
026331c4 JM |
9861 | |
9862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9863 | if (!msg) | |
9864 | return -ENOMEM; | |
9865 | ||
2e161f78 | 9866 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
9867 | if (!hdr) { |
9868 | nlmsg_free(msg); | |
9869 | return -ENOMEM; | |
9870 | } | |
9871 | ||
9360ffd1 | 9872 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9873 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9874 | netdev->ifindex)) || | |
9360ffd1 DM |
9875 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
9876 | (sig_dbm && | |
9877 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9878 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9879 | goto nla_put_failure; | |
026331c4 | 9880 | |
3b7b72ee | 9881 | genlmsg_end(msg, hdr); |
026331c4 | 9882 | |
15e47304 | 9883 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
9884 | |
9885 | nla_put_failure: | |
9886 | genlmsg_cancel(msg, hdr); | |
9887 | nlmsg_free(msg); | |
9888 | return -ENOBUFS; | |
9889 | } | |
9890 | ||
947add36 JB |
9891 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
9892 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 9893 | { |
947add36 JB |
9894 | struct wiphy *wiphy = wdev->wiphy; |
9895 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 9896 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9897 | struct sk_buff *msg; |
9898 | void *hdr; | |
9899 | ||
947add36 JB |
9900 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
9901 | ||
026331c4 JM |
9902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9903 | if (!msg) | |
9904 | return; | |
9905 | ||
2e161f78 | 9906 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
9907 | if (!hdr) { |
9908 | nlmsg_free(msg); | |
9909 | return; | |
9910 | } | |
9911 | ||
9360ffd1 | 9912 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9913 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9914 | netdev->ifindex)) || | |
9360ffd1 DM |
9915 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
9916 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
9917 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
9918 | goto nla_put_failure; | |
026331c4 | 9919 | |
3b7b72ee | 9920 | genlmsg_end(msg, hdr); |
026331c4 JM |
9921 | |
9922 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
9923 | return; | |
9924 | ||
9925 | nla_put_failure: | |
9926 | genlmsg_cancel(msg, hdr); | |
9927 | nlmsg_free(msg); | |
9928 | } | |
947add36 | 9929 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 9930 | |
947add36 JB |
9931 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
9932 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
9933 | gfp_t gfp) | |
d6dc1a38 | 9934 | { |
947add36 JB |
9935 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9936 | struct wiphy *wiphy = wdev->wiphy; | |
9937 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
9938 | struct sk_buff *msg; |
9939 | struct nlattr *pinfoattr; | |
9940 | void *hdr; | |
9941 | ||
947add36 JB |
9942 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
9943 | ||
58050fce | 9944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
9945 | if (!msg) |
9946 | return; | |
9947 | ||
9948 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9949 | if (!hdr) { | |
9950 | nlmsg_free(msg); | |
9951 | return; | |
9952 | } | |
9953 | ||
9360ffd1 | 9954 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 9955 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 9956 | goto nla_put_failure; |
d6dc1a38 JO |
9957 | |
9958 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
9959 | if (!pinfoattr) | |
9960 | goto nla_put_failure; | |
9961 | ||
9360ffd1 DM |
9962 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
9963 | rssi_event)) | |
9964 | goto nla_put_failure; | |
d6dc1a38 JO |
9965 | |
9966 | nla_nest_end(msg, pinfoattr); | |
9967 | ||
3b7b72ee | 9968 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
9969 | |
9970 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9971 | nl80211_mlme_mcgrp.id, gfp); | |
9972 | return; | |
9973 | ||
9974 | nla_put_failure: | |
9975 | genlmsg_cancel(msg, hdr); | |
9976 | nlmsg_free(msg); | |
9977 | } | |
947add36 | 9978 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 9979 | |
947add36 JB |
9980 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
9981 | struct net_device *netdev, const u8 *bssid, | |
9982 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
9983 | { |
9984 | struct sk_buff *msg; | |
9985 | struct nlattr *rekey_attr; | |
9986 | void *hdr; | |
9987 | ||
58050fce | 9988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
9989 | if (!msg) |
9990 | return; | |
9991 | ||
9992 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
9993 | if (!hdr) { | |
9994 | nlmsg_free(msg); | |
9995 | return; | |
9996 | } | |
9997 | ||
9360ffd1 DM |
9998 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9999 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10000 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10001 | goto nla_put_failure; | |
e5497d76 JB |
10002 | |
10003 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10004 | if (!rekey_attr) | |
10005 | goto nla_put_failure; | |
10006 | ||
9360ffd1 DM |
10007 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10008 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10009 | goto nla_put_failure; | |
e5497d76 JB |
10010 | |
10011 | nla_nest_end(msg, rekey_attr); | |
10012 | ||
3b7b72ee | 10013 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10014 | |
10015 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10016 | nl80211_mlme_mcgrp.id, gfp); | |
10017 | return; | |
10018 | ||
10019 | nla_put_failure: | |
10020 | genlmsg_cancel(msg, hdr); | |
10021 | nlmsg_free(msg); | |
10022 | } | |
10023 | ||
947add36 JB |
10024 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10025 | const u8 *replay_ctr, gfp_t gfp) | |
10026 | { | |
10027 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10028 | struct wiphy *wiphy = wdev->wiphy; | |
10029 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10030 | ||
10031 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10032 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10033 | } | |
10034 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10035 | ||
10036 | static void | |
10037 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10038 | struct net_device *netdev, int index, | |
10039 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10040 | { |
10041 | struct sk_buff *msg; | |
10042 | struct nlattr *attr; | |
10043 | void *hdr; | |
10044 | ||
58050fce | 10045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10046 | if (!msg) |
10047 | return; | |
10048 | ||
10049 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10050 | if (!hdr) { | |
10051 | nlmsg_free(msg); | |
10052 | return; | |
10053 | } | |
10054 | ||
9360ffd1 DM |
10055 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10056 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10057 | goto nla_put_failure; | |
c9df56b4 JM |
10058 | |
10059 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10060 | if (!attr) | |
10061 | goto nla_put_failure; | |
10062 | ||
9360ffd1 DM |
10063 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10064 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10065 | (preauth && | |
10066 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10067 | goto nla_put_failure; | |
c9df56b4 JM |
10068 | |
10069 | nla_nest_end(msg, attr); | |
10070 | ||
3b7b72ee | 10071 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10072 | |
10073 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10074 | nl80211_mlme_mcgrp.id, gfp); | |
10075 | return; | |
10076 | ||
10077 | nla_put_failure: | |
10078 | genlmsg_cancel(msg, hdr); | |
10079 | nlmsg_free(msg); | |
10080 | } | |
10081 | ||
947add36 JB |
10082 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10083 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10084 | { | |
10085 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10086 | struct wiphy *wiphy = wdev->wiphy; | |
10087 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10088 | ||
10089 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10090 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10091 | } | |
10092 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10093 | ||
10094 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10095 | struct net_device *netdev, | |
10096 | struct cfg80211_chan_def *chandef, | |
10097 | gfp_t gfp) | |
5314526b TP |
10098 | { |
10099 | struct sk_buff *msg; | |
10100 | void *hdr; | |
10101 | ||
58050fce | 10102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10103 | if (!msg) |
10104 | return; | |
10105 | ||
10106 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10107 | if (!hdr) { | |
10108 | nlmsg_free(msg); | |
10109 | return; | |
10110 | } | |
10111 | ||
683b6d3b JB |
10112 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10113 | goto nla_put_failure; | |
10114 | ||
10115 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10116 | goto nla_put_failure; |
5314526b TP |
10117 | |
10118 | genlmsg_end(msg, hdr); | |
10119 | ||
10120 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10121 | nl80211_mlme_mcgrp.id, gfp); | |
10122 | return; | |
10123 | ||
10124 | nla_put_failure: | |
10125 | genlmsg_cancel(msg, hdr); | |
10126 | nlmsg_free(msg); | |
10127 | } | |
10128 | ||
947add36 JB |
10129 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10130 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10131 | { |
947add36 JB |
10132 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10133 | struct wiphy *wiphy = wdev->wiphy; | |
10134 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10135 | ||
10136 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10137 | ||
10138 | wdev_lock(wdev); | |
10139 | ||
10140 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10141 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10142 | goto out; | |
10143 | ||
10144 | wdev->channel = chandef->chan; | |
10145 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10146 | out: | |
10147 | wdev_unlock(wdev); | |
10148 | return; | |
10149 | } | |
10150 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10151 | ||
10152 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10153 | const u8 *peer, u32 num_packets, | |
10154 | u32 rate, u32 intvl, gfp_t gfp) | |
10155 | { | |
10156 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10157 | struct wiphy *wiphy = wdev->wiphy; | |
10158 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10159 | struct sk_buff *msg; |
10160 | struct nlattr *pinfoattr; | |
10161 | void *hdr; | |
10162 | ||
10163 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10164 | if (!msg) | |
10165 | return; | |
10166 | ||
10167 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10168 | if (!hdr) { | |
10169 | nlmsg_free(msg); | |
10170 | return; | |
10171 | } | |
10172 | ||
10173 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10174 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10175 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10176 | goto nla_put_failure; | |
10177 | ||
10178 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10179 | if (!pinfoattr) | |
10180 | goto nla_put_failure; | |
10181 | ||
10182 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10183 | goto nla_put_failure; | |
10184 | ||
10185 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10186 | goto nla_put_failure; | |
10187 | ||
10188 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10189 | goto nla_put_failure; | |
10190 | ||
10191 | nla_nest_end(msg, pinfoattr); | |
10192 | ||
10193 | genlmsg_end(msg, hdr); | |
10194 | ||
10195 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10196 | nl80211_mlme_mcgrp.id, gfp); | |
10197 | return; | |
10198 | ||
10199 | nla_put_failure: | |
10200 | genlmsg_cancel(msg, hdr); | |
10201 | nlmsg_free(msg); | |
10202 | } | |
947add36 | 10203 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10204 | |
04f39047 SW |
10205 | void |
10206 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10207 | struct cfg80211_chan_def *chandef, | |
10208 | enum nl80211_radar_event event, | |
10209 | struct net_device *netdev, gfp_t gfp) | |
10210 | { | |
10211 | struct sk_buff *msg; | |
10212 | void *hdr; | |
10213 | ||
10214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10215 | if (!msg) | |
10216 | return; | |
10217 | ||
10218 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10219 | if (!hdr) { | |
10220 | nlmsg_free(msg); | |
10221 | return; | |
10222 | } | |
10223 | ||
10224 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10225 | goto nla_put_failure; | |
10226 | ||
10227 | /* NOP and radar events don't need a netdev parameter */ | |
10228 | if (netdev) { | |
10229 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10230 | ||
10231 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10232 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10233 | goto nla_put_failure; | |
10234 | } | |
10235 | ||
10236 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10237 | goto nla_put_failure; | |
10238 | ||
10239 | if (nl80211_send_chandef(msg, chandef)) | |
10240 | goto nla_put_failure; | |
10241 | ||
10242 | if (genlmsg_end(msg, hdr) < 0) { | |
10243 | nlmsg_free(msg); | |
10244 | return; | |
10245 | } | |
10246 | ||
10247 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10248 | nl80211_mlme_mcgrp.id, gfp); | |
10249 | return; | |
10250 | ||
10251 | nla_put_failure: | |
10252 | genlmsg_cancel(msg, hdr); | |
10253 | nlmsg_free(msg); | |
10254 | } | |
10255 | ||
947add36 JB |
10256 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10257 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10258 | { |
947add36 JB |
10259 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10260 | struct wiphy *wiphy = wdev->wiphy; | |
10261 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10262 | struct sk_buff *msg; |
10263 | struct nlattr *pinfoattr; | |
10264 | void *hdr; | |
10265 | ||
947add36 JB |
10266 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10267 | ||
58050fce | 10268 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10269 | if (!msg) |
10270 | return; | |
10271 | ||
10272 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10273 | if (!hdr) { | |
10274 | nlmsg_free(msg); | |
10275 | return; | |
10276 | } | |
10277 | ||
9360ffd1 | 10278 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10279 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10280 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10281 | goto nla_put_failure; | |
c063dbf5 JB |
10282 | |
10283 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10284 | if (!pinfoattr) | |
10285 | goto nla_put_failure; | |
10286 | ||
9360ffd1 DM |
10287 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10288 | goto nla_put_failure; | |
c063dbf5 JB |
10289 | |
10290 | nla_nest_end(msg, pinfoattr); | |
10291 | ||
3b7b72ee | 10292 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10293 | |
10294 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10295 | nl80211_mlme_mcgrp.id, gfp); | |
10296 | return; | |
10297 | ||
10298 | nla_put_failure: | |
10299 | genlmsg_cancel(msg, hdr); | |
10300 | nlmsg_free(msg); | |
10301 | } | |
947add36 | 10302 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10303 | |
7f6cf311 JB |
10304 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10305 | u64 cookie, bool acked, gfp_t gfp) | |
10306 | { | |
10307 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10308 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10309 | struct sk_buff *msg; | |
10310 | void *hdr; | |
10311 | int err; | |
10312 | ||
4ee3e063 BL |
10313 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10314 | ||
58050fce | 10315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10316 | |
7f6cf311 JB |
10317 | if (!msg) |
10318 | return; | |
10319 | ||
10320 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10321 | if (!hdr) { | |
10322 | nlmsg_free(msg); | |
10323 | return; | |
10324 | } | |
10325 | ||
9360ffd1 DM |
10326 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10327 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10328 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10329 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10330 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10331 | goto nla_put_failure; | |
7f6cf311 JB |
10332 | |
10333 | err = genlmsg_end(msg, hdr); | |
10334 | if (err < 0) { | |
10335 | nlmsg_free(msg); | |
10336 | return; | |
10337 | } | |
10338 | ||
10339 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10340 | nl80211_mlme_mcgrp.id, gfp); | |
10341 | return; | |
10342 | ||
10343 | nla_put_failure: | |
10344 | genlmsg_cancel(msg, hdr); | |
10345 | nlmsg_free(msg); | |
10346 | } | |
10347 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10348 | ||
5e760230 JB |
10349 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10350 | const u8 *frame, size_t len, | |
37c73b5f | 10351 | int freq, int sig_dbm) |
5e760230 JB |
10352 | { |
10353 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10354 | struct sk_buff *msg; | |
10355 | void *hdr; | |
37c73b5f | 10356 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10357 | |
4ee3e063 BL |
10358 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10359 | ||
37c73b5f BG |
10360 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10361 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10362 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10363 | if (!msg) { | |
10364 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10365 | return; | |
10366 | } | |
5e760230 | 10367 | |
37c73b5f BG |
10368 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10369 | if (!hdr) | |
10370 | goto nla_put_failure; | |
5e760230 | 10371 | |
37c73b5f BG |
10372 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10373 | (freq && | |
10374 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10375 | (sig_dbm && | |
10376 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10377 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10378 | goto nla_put_failure; | |
5e760230 | 10379 | |
37c73b5f | 10380 | genlmsg_end(msg, hdr); |
5e760230 | 10381 | |
37c73b5f BG |
10382 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10383 | } | |
10384 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10385 | return; |
10386 | ||
10387 | nla_put_failure: | |
37c73b5f BG |
10388 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10389 | if (hdr) | |
10390 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10391 | nlmsg_free(msg); |
10392 | } | |
10393 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10394 | ||
cd8f7cb4 JB |
10395 | #ifdef CONFIG_PM |
10396 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10397 | struct cfg80211_wowlan_wakeup *wakeup, | |
10398 | gfp_t gfp) | |
10399 | { | |
10400 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10401 | struct sk_buff *msg; | |
10402 | void *hdr; | |
10403 | int err, size = 200; | |
10404 | ||
10405 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10406 | ||
10407 | if (wakeup) | |
10408 | size += wakeup->packet_present_len; | |
10409 | ||
10410 | msg = nlmsg_new(size, gfp); | |
10411 | if (!msg) | |
10412 | return; | |
10413 | ||
10414 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10415 | if (!hdr) | |
10416 | goto free_msg; | |
10417 | ||
10418 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10419 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10420 | goto free_msg; | |
10421 | ||
10422 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10423 | wdev->netdev->ifindex)) | |
10424 | goto free_msg; | |
10425 | ||
10426 | if (wakeup) { | |
10427 | struct nlattr *reasons; | |
10428 | ||
10429 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10430 | ||
10431 | if (wakeup->disconnect && | |
10432 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10433 | goto free_msg; | |
10434 | if (wakeup->magic_pkt && | |
10435 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10436 | goto free_msg; | |
10437 | if (wakeup->gtk_rekey_failure && | |
10438 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10439 | goto free_msg; | |
10440 | if (wakeup->eap_identity_req && | |
10441 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10442 | goto free_msg; | |
10443 | if (wakeup->four_way_handshake && | |
10444 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10445 | goto free_msg; | |
10446 | if (wakeup->rfkill_release && | |
10447 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10448 | goto free_msg; | |
10449 | ||
10450 | if (wakeup->pattern_idx >= 0 && | |
10451 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10452 | wakeup->pattern_idx)) | |
10453 | goto free_msg; | |
10454 | ||
2a0e047e JB |
10455 | if (wakeup->tcp_match) |
10456 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10457 | ||
10458 | if (wakeup->tcp_connlost) | |
10459 | nla_put_flag(msg, | |
10460 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10461 | ||
10462 | if (wakeup->tcp_nomoretokens) | |
10463 | nla_put_flag(msg, | |
10464 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10465 | ||
cd8f7cb4 JB |
10466 | if (wakeup->packet) { |
10467 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10468 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10469 | ||
10470 | if (!wakeup->packet_80211) { | |
10471 | pkt_attr = | |
10472 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10473 | len_attr = | |
10474 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10475 | } | |
10476 | ||
10477 | if (wakeup->packet_len && | |
10478 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10479 | goto free_msg; | |
10480 | ||
10481 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10482 | wakeup->packet)) | |
10483 | goto free_msg; | |
10484 | } | |
10485 | ||
10486 | nla_nest_end(msg, reasons); | |
10487 | } | |
10488 | ||
10489 | err = genlmsg_end(msg, hdr); | |
10490 | if (err < 0) | |
10491 | goto free_msg; | |
10492 | ||
10493 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10494 | nl80211_mlme_mcgrp.id, gfp); | |
10495 | return; | |
10496 | ||
10497 | free_msg: | |
10498 | nlmsg_free(msg); | |
10499 | } | |
10500 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10501 | #endif | |
10502 | ||
3475b094 JM |
10503 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10504 | enum nl80211_tdls_operation oper, | |
10505 | u16 reason_code, gfp_t gfp) | |
10506 | { | |
10507 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10508 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10509 | struct sk_buff *msg; | |
10510 | void *hdr; | |
10511 | int err; | |
10512 | ||
10513 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10514 | reason_code); | |
10515 | ||
10516 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10517 | if (!msg) | |
10518 | return; | |
10519 | ||
10520 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10521 | if (!hdr) { | |
10522 | nlmsg_free(msg); | |
10523 | return; | |
10524 | } | |
10525 | ||
10526 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10527 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10528 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10529 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10530 | (reason_code > 0 && | |
10531 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10532 | goto nla_put_failure; | |
10533 | ||
10534 | err = genlmsg_end(msg, hdr); | |
10535 | if (err < 0) { | |
10536 | nlmsg_free(msg); | |
10537 | return; | |
10538 | } | |
10539 | ||
10540 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10541 | nl80211_mlme_mcgrp.id, gfp); | |
10542 | return; | |
10543 | ||
10544 | nla_put_failure: | |
10545 | genlmsg_cancel(msg, hdr); | |
10546 | nlmsg_free(msg); | |
10547 | } | |
10548 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10549 | ||
026331c4 JM |
10550 | static int nl80211_netlink_notify(struct notifier_block * nb, |
10551 | unsigned long state, | |
10552 | void *_notify) | |
10553 | { | |
10554 | struct netlink_notify *notify = _notify; | |
10555 | struct cfg80211_registered_device *rdev; | |
10556 | struct wireless_dev *wdev; | |
37c73b5f | 10557 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
10558 | |
10559 | if (state != NETLINK_URELEASE) | |
10560 | return NOTIFY_DONE; | |
10561 | ||
10562 | rcu_read_lock(); | |
10563 | ||
5e760230 | 10564 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 10565 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 10566 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
10567 | |
10568 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10569 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
10570 | list) { | |
10571 | if (reg->nlportid == notify->portid) { | |
10572 | list_del(®->list); | |
10573 | kfree(reg); | |
10574 | break; | |
10575 | } | |
10576 | } | |
10577 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 10578 | } |
026331c4 JM |
10579 | |
10580 | rcu_read_unlock(); | |
10581 | ||
10582 | return NOTIFY_DONE; | |
10583 | } | |
10584 | ||
10585 | static struct notifier_block nl80211_netlink_notifier = { | |
10586 | .notifier_call = nl80211_netlink_notify, | |
10587 | }; | |
10588 | ||
355199e0 JM |
10589 | void cfg80211_ft_event(struct net_device *netdev, |
10590 | struct cfg80211_ft_event_params *ft_event) | |
10591 | { | |
10592 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
10593 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10594 | struct sk_buff *msg; | |
10595 | void *hdr; | |
10596 | int err; | |
10597 | ||
10598 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
10599 | ||
10600 | if (!ft_event->target_ap) | |
10601 | return; | |
10602 | ||
10603 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10604 | if (!msg) | |
10605 | return; | |
10606 | ||
10607 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
10608 | if (!hdr) { | |
10609 | nlmsg_free(msg); | |
10610 | return; | |
10611 | } | |
10612 | ||
10613 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
10614 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
10615 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
10616 | if (ft_event->ies) | |
10617 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
10618 | if (ft_event->ric_ies) | |
10619 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
10620 | ft_event->ric_ies); | |
10621 | ||
10622 | err = genlmsg_end(msg, hdr); | |
10623 | if (err < 0) { | |
10624 | nlmsg_free(msg); | |
10625 | return; | |
10626 | } | |
10627 | ||
10628 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10629 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
10630 | } | |
10631 | EXPORT_SYMBOL(cfg80211_ft_event); | |
10632 | ||
55682965 JB |
10633 | /* initialisation/exit functions */ |
10634 | ||
10635 | int nl80211_init(void) | |
10636 | { | |
0d63cbb5 | 10637 | int err; |
55682965 | 10638 | |
0d63cbb5 MM |
10639 | err = genl_register_family_with_ops(&nl80211_fam, |
10640 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10641 | if (err) |
10642 | return err; | |
10643 | ||
55682965 JB |
10644 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10645 | if (err) | |
10646 | goto err_out; | |
10647 | ||
2a519311 JB |
10648 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10649 | if (err) | |
10650 | goto err_out; | |
10651 | ||
73d54c9e LR |
10652 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10653 | if (err) | |
10654 | goto err_out; | |
10655 | ||
6039f6d2 JM |
10656 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10657 | if (err) | |
10658 | goto err_out; | |
10659 | ||
aff89a9b JB |
10660 | #ifdef CONFIG_NL80211_TESTMODE |
10661 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10662 | if (err) | |
10663 | goto err_out; | |
10664 | #endif | |
10665 | ||
026331c4 JM |
10666 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
10667 | if (err) | |
10668 | goto err_out; | |
10669 | ||
55682965 JB |
10670 | return 0; |
10671 | err_out: | |
10672 | genl_unregister_family(&nl80211_fam); | |
10673 | return err; | |
10674 | } | |
10675 | ||
10676 | void nl80211_exit(void) | |
10677 | { | |
026331c4 | 10678 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
10679 | genl_unregister_family(&nl80211_fam); |
10680 | } |