]>
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 | }, | |
55682965 JB |
378 | }; |
379 | ||
e31b8213 | 380 | /* policy for the key attributes */ |
b54452b0 | 381 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 382 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
383 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
384 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 385 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
386 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
387 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 388 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
389 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
390 | }; | |
391 | ||
392 | /* policy for the key default flags */ | |
393 | static const struct nla_policy | |
394 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
395 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
396 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
397 | }; |
398 | ||
ff1b6e69 JB |
399 | /* policy for WoWLAN attributes */ |
400 | static const struct nla_policy | |
401 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
402 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
403 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
404 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
405 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
406 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
407 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
408 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
409 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
410 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
411 | }; | |
412 | ||
413 | static const struct nla_policy | |
414 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
415 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
416 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
417 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
418 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
419 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
420 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
421 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
422 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
423 | }, | |
424 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
425 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
426 | }, | |
427 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
428 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
429 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
430 | }; |
431 | ||
e5497d76 JB |
432 | /* policy for GTK rekey offload attributes */ |
433 | static const struct nla_policy | |
434 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
435 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
436 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
437 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
438 | }; | |
439 | ||
a1f1c21c LC |
440 | static const struct nla_policy |
441 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 442 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 443 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 444 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
445 | }; |
446 | ||
a043897a HS |
447 | /* ifidx get helper */ |
448 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
449 | { | |
450 | int res; | |
451 | ||
452 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
453 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
454 | nl80211_policy); | |
455 | if (res) | |
456 | return res; | |
457 | ||
458 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
459 | return -EINVAL; | |
460 | ||
461 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
462 | if (!res) | |
463 | return -EINVAL; | |
464 | return res; | |
465 | } | |
466 | ||
67748893 JB |
467 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
468 | struct netlink_callback *cb, | |
469 | struct cfg80211_registered_device **rdev, | |
470 | struct net_device **dev) | |
471 | { | |
472 | int ifidx = cb->args[0]; | |
473 | int err; | |
474 | ||
475 | if (!ifidx) | |
476 | ifidx = nl80211_get_ifidx(cb); | |
477 | if (ifidx < 0) | |
478 | return ifidx; | |
479 | ||
480 | cb->args[0] = ifidx; | |
481 | ||
482 | rtnl_lock(); | |
483 | ||
484 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
485 | if (!*dev) { | |
486 | err = -ENODEV; | |
487 | goto out_rtnl; | |
488 | } | |
489 | ||
490 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3cc25e51 FF |
491 | if (IS_ERR(*rdev)) { |
492 | err = PTR_ERR(*rdev); | |
67748893 JB |
493 | goto out_rtnl; |
494 | } | |
495 | ||
496 | return 0; | |
497 | out_rtnl: | |
498 | rtnl_unlock(); | |
499 | return err; | |
500 | } | |
501 | ||
502 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | |
503 | { | |
504 | cfg80211_unlock_rdev(rdev); | |
505 | rtnl_unlock(); | |
506 | } | |
507 | ||
f4a11bb0 JB |
508 | /* IE validation */ |
509 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
510 | { | |
511 | const u8 *pos; | |
512 | int len; | |
513 | ||
514 | if (!attr) | |
515 | return true; | |
516 | ||
517 | pos = nla_data(attr); | |
518 | len = nla_len(attr); | |
519 | ||
520 | while (len) { | |
521 | u8 elemlen; | |
522 | ||
523 | if (len < 2) | |
524 | return false; | |
525 | len -= 2; | |
526 | ||
527 | elemlen = pos[1]; | |
528 | if (elemlen > len) | |
529 | return false; | |
530 | ||
531 | len -= elemlen; | |
532 | pos += 2 + elemlen; | |
533 | } | |
534 | ||
535 | return true; | |
536 | } | |
537 | ||
55682965 | 538 | /* message building helper */ |
15e47304 | 539 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
540 | int flags, u8 cmd) |
541 | { | |
542 | /* since there is no private header just add the generic one */ | |
15e47304 | 543 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
544 | } |
545 | ||
5dab3b8a | 546 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
547 | struct ieee80211_channel *chan, |
548 | bool large) | |
5dab3b8a | 549 | { |
9360ffd1 DM |
550 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
551 | chan->center_freq)) | |
552 | goto nla_put_failure; | |
5dab3b8a | 553 | |
9360ffd1 DM |
554 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
556 | goto nla_put_failure; | |
557 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
559 | goto nla_put_failure; | |
560 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
562 | goto nla_put_failure; | |
cdc89b97 JB |
563 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
564 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
565 | goto nla_put_failure; | |
566 | if (large) { | |
567 | u32 time; | |
568 | ||
569 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
570 | ||
571 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
572 | chan->dfs_state)) | |
573 | goto nla_put_failure; | |
574 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
575 | time)) | |
576 | goto nla_put_failure; | |
577 | } | |
578 | } | |
5dab3b8a | 579 | |
fe1abafd JB |
580 | if (large) { |
581 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
582 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
583 | goto nla_put_failure; | |
584 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
585 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
586 | goto nla_put_failure; | |
587 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
588 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
589 | goto nla_put_failure; | |
590 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
591 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
592 | goto nla_put_failure; | |
593 | } | |
594 | ||
9360ffd1 DM |
595 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
596 | DBM_TO_MBM(chan->max_power))) | |
597 | goto nla_put_failure; | |
5dab3b8a LR |
598 | |
599 | return 0; | |
600 | ||
601 | nla_put_failure: | |
602 | return -ENOBUFS; | |
603 | } | |
604 | ||
55682965 JB |
605 | /* netlink command implementations */ |
606 | ||
b9454e83 JB |
607 | struct key_parse { |
608 | struct key_params p; | |
609 | int idx; | |
e31b8213 | 610 | int type; |
b9454e83 | 611 | bool def, defmgmt; |
dbd2fd65 | 612 | bool def_uni, def_multi; |
b9454e83 JB |
613 | }; |
614 | ||
615 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
616 | { | |
617 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
618 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
619 | nl80211_key_policy); | |
620 | if (err) | |
621 | return err; | |
622 | ||
623 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
624 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
625 | ||
dbd2fd65 JB |
626 | if (k->def) { |
627 | k->def_uni = true; | |
628 | k->def_multi = true; | |
629 | } | |
630 | if (k->defmgmt) | |
631 | k->def_multi = true; | |
632 | ||
b9454e83 JB |
633 | if (tb[NL80211_KEY_IDX]) |
634 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
635 | ||
636 | if (tb[NL80211_KEY_DATA]) { | |
637 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
638 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
639 | } | |
640 | ||
641 | if (tb[NL80211_KEY_SEQ]) { | |
642 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
643 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
644 | } | |
645 | ||
646 | if (tb[NL80211_KEY_CIPHER]) | |
647 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
648 | ||
e31b8213 JB |
649 | if (tb[NL80211_KEY_TYPE]) { |
650 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
651 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
652 | return -EINVAL; | |
653 | } | |
654 | ||
dbd2fd65 JB |
655 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
656 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
657 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
658 | tb[NL80211_KEY_DEFAULT_TYPES], | |
659 | nl80211_key_default_policy); | |
dbd2fd65 JB |
660 | if (err) |
661 | return err; | |
662 | ||
663 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
664 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
665 | } | |
666 | ||
b9454e83 JB |
667 | return 0; |
668 | } | |
669 | ||
670 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
671 | { | |
672 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
673 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
674 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
675 | } | |
676 | ||
677 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
678 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
679 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
680 | } | |
681 | ||
682 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
683 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
684 | ||
685 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
686 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
687 | ||
688 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
689 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
690 | ||
dbd2fd65 JB |
691 | if (k->def) { |
692 | k->def_uni = true; | |
693 | k->def_multi = true; | |
694 | } | |
695 | if (k->defmgmt) | |
696 | k->def_multi = true; | |
697 | ||
e31b8213 JB |
698 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
699 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
700 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
701 | return -EINVAL; | |
702 | } | |
703 | ||
dbd2fd65 JB |
704 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
705 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
706 | int err = nla_parse_nested( | |
707 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
708 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
709 | nl80211_key_default_policy); | |
710 | if (err) | |
711 | return err; | |
712 | ||
713 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
714 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
715 | } | |
716 | ||
b9454e83 JB |
717 | return 0; |
718 | } | |
719 | ||
720 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
721 | { | |
722 | int err; | |
723 | ||
724 | memset(k, 0, sizeof(*k)); | |
725 | k->idx = -1; | |
e31b8213 | 726 | k->type = -1; |
b9454e83 JB |
727 | |
728 | if (info->attrs[NL80211_ATTR_KEY]) | |
729 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
730 | else | |
731 | err = nl80211_parse_key_old(info, k); | |
732 | ||
733 | if (err) | |
734 | return err; | |
735 | ||
736 | if (k->def && k->defmgmt) | |
737 | return -EINVAL; | |
738 | ||
dbd2fd65 JB |
739 | if (k->defmgmt) { |
740 | if (k->def_uni || !k->def_multi) | |
741 | return -EINVAL; | |
742 | } | |
743 | ||
b9454e83 JB |
744 | if (k->idx != -1) { |
745 | if (k->defmgmt) { | |
746 | if (k->idx < 4 || k->idx > 5) | |
747 | return -EINVAL; | |
748 | } else if (k->def) { | |
749 | if (k->idx < 0 || k->idx > 3) | |
750 | return -EINVAL; | |
751 | } else { | |
752 | if (k->idx < 0 || k->idx > 5) | |
753 | return -EINVAL; | |
754 | } | |
755 | } | |
756 | ||
757 | return 0; | |
758 | } | |
759 | ||
fffd0934 JB |
760 | static struct cfg80211_cached_keys * |
761 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 762 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
763 | { |
764 | struct key_parse parse; | |
765 | struct nlattr *key; | |
766 | struct cfg80211_cached_keys *result; | |
767 | int rem, err, def = 0; | |
768 | ||
769 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
770 | if (!result) | |
771 | return ERR_PTR(-ENOMEM); | |
772 | ||
773 | result->def = -1; | |
774 | result->defmgmt = -1; | |
775 | ||
776 | nla_for_each_nested(key, keys, rem) { | |
777 | memset(&parse, 0, sizeof(parse)); | |
778 | parse.idx = -1; | |
779 | ||
780 | err = nl80211_parse_key_new(key, &parse); | |
781 | if (err) | |
782 | goto error; | |
783 | err = -EINVAL; | |
784 | if (!parse.p.key) | |
785 | goto error; | |
786 | if (parse.idx < 0 || parse.idx > 4) | |
787 | goto error; | |
788 | if (parse.def) { | |
789 | if (def) | |
790 | goto error; | |
791 | def = 1; | |
792 | result->def = parse.idx; | |
dbd2fd65 JB |
793 | if (!parse.def_uni || !parse.def_multi) |
794 | goto error; | |
fffd0934 JB |
795 | } else if (parse.defmgmt) |
796 | goto error; | |
797 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 798 | parse.idx, false, NULL); |
fffd0934 JB |
799 | if (err) |
800 | goto error; | |
801 | result->params[parse.idx].cipher = parse.p.cipher; | |
802 | result->params[parse.idx].key_len = parse.p.key_len; | |
803 | result->params[parse.idx].key = result->data[parse.idx]; | |
804 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
805 | |
806 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
807 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
808 | if (no_ht) | |
809 | *no_ht = true; | |
810 | } | |
fffd0934 JB |
811 | } |
812 | ||
813 | return result; | |
814 | error: | |
815 | kfree(result); | |
816 | return ERR_PTR(err); | |
817 | } | |
818 | ||
819 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
820 | { | |
821 | ASSERT_WDEV_LOCK(wdev); | |
822 | ||
fffd0934 JB |
823 | switch (wdev->iftype) { |
824 | case NL80211_IFTYPE_AP: | |
825 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 826 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 827 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
828 | break; |
829 | case NL80211_IFTYPE_ADHOC: | |
830 | if (!wdev->current_bss) | |
831 | return -ENOLINK; | |
832 | break; | |
833 | case NL80211_IFTYPE_STATION: | |
074ac8df | 834 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
835 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
836 | return -ENOLINK; | |
837 | break; | |
838 | default: | |
839 | return -EINVAL; | |
840 | } | |
841 | ||
842 | return 0; | |
843 | } | |
844 | ||
7527a782 JB |
845 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
846 | { | |
847 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
848 | int i; | |
849 | ||
850 | if (!nl_modes) | |
851 | goto nla_put_failure; | |
852 | ||
853 | i = 0; | |
854 | while (ifmodes) { | |
9360ffd1 DM |
855 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
856 | goto nla_put_failure; | |
7527a782 JB |
857 | ifmodes >>= 1; |
858 | i++; | |
859 | } | |
860 | ||
861 | nla_nest_end(msg, nl_modes); | |
862 | return 0; | |
863 | ||
864 | nla_put_failure: | |
865 | return -ENOBUFS; | |
866 | } | |
867 | ||
868 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
869 | struct sk_buff *msg, |
870 | bool large) | |
7527a782 JB |
871 | { |
872 | struct nlattr *nl_combis; | |
873 | int i, j; | |
874 | ||
875 | nl_combis = nla_nest_start(msg, | |
876 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
877 | if (!nl_combis) | |
878 | goto nla_put_failure; | |
879 | ||
880 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
881 | const struct ieee80211_iface_combination *c; | |
882 | struct nlattr *nl_combi, *nl_limits; | |
883 | ||
884 | c = &wiphy->iface_combinations[i]; | |
885 | ||
886 | nl_combi = nla_nest_start(msg, i + 1); | |
887 | if (!nl_combi) | |
888 | goto nla_put_failure; | |
889 | ||
890 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
891 | if (!nl_limits) | |
892 | goto nla_put_failure; | |
893 | ||
894 | for (j = 0; j < c->n_limits; j++) { | |
895 | struct nlattr *nl_limit; | |
896 | ||
897 | nl_limit = nla_nest_start(msg, j + 1); | |
898 | if (!nl_limit) | |
899 | goto nla_put_failure; | |
9360ffd1 DM |
900 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
901 | c->limits[j].max)) | |
902 | goto nla_put_failure; | |
7527a782 JB |
903 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
904 | c->limits[j].types)) | |
905 | goto nla_put_failure; | |
906 | nla_nest_end(msg, nl_limit); | |
907 | } | |
908 | ||
909 | nla_nest_end(msg, nl_limits); | |
910 | ||
9360ffd1 DM |
911 | if (c->beacon_int_infra_match && |
912 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
913 | goto nla_put_failure; | |
914 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
915 | c->num_different_channels) || | |
916 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
917 | c->max_interfaces)) | |
918 | goto nla_put_failure; | |
cdc89b97 JB |
919 | if (large && |
920 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
921 | c->radar_detect_widths)) | |
922 | goto nla_put_failure; | |
7527a782 JB |
923 | |
924 | nla_nest_end(msg, nl_combi); | |
925 | } | |
926 | ||
927 | nla_nest_end(msg, nl_combis); | |
928 | ||
929 | return 0; | |
930 | nla_put_failure: | |
931 | return -ENOBUFS; | |
932 | } | |
933 | ||
3713b4e3 | 934 | #ifdef CONFIG_PM |
b56cf720 JB |
935 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
936 | struct sk_buff *msg) | |
937 | { | |
938 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; | |
939 | struct nlattr *nl_tcp; | |
940 | ||
941 | if (!tcp) | |
942 | return 0; | |
943 | ||
944 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
945 | if (!nl_tcp) | |
946 | return -ENOBUFS; | |
947 | ||
948 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
949 | tcp->data_payload_max)) | |
950 | return -ENOBUFS; | |
951 | ||
952 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
953 | tcp->data_payload_max)) | |
954 | return -ENOBUFS; | |
955 | ||
956 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
957 | return -ENOBUFS; | |
958 | ||
959 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
960 | sizeof(*tcp->tok), tcp->tok)) | |
961 | return -ENOBUFS; | |
962 | ||
963 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
964 | tcp->data_interval_max)) | |
965 | return -ENOBUFS; | |
966 | ||
967 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
968 | tcp->wake_payload_max)) | |
969 | return -ENOBUFS; | |
970 | ||
971 | nla_nest_end(msg, nl_tcp); | |
972 | return 0; | |
973 | } | |
974 | ||
3713b4e3 | 975 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
976 | struct cfg80211_registered_device *dev, |
977 | bool large) | |
55682965 | 978 | { |
3713b4e3 | 979 | struct nlattr *nl_wowlan; |
55682965 | 980 | |
3713b4e3 JB |
981 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
982 | return 0; | |
55682965 | 983 | |
3713b4e3 JB |
984 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
985 | if (!nl_wowlan) | |
986 | return -ENOBUFS; | |
9360ffd1 | 987 | |
3713b4e3 JB |
988 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
989 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
990 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
991 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
992 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
993 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
994 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
995 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
996 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
997 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
998 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
999 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1000 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1001 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1002 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1003 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1004 | return -ENOBUFS; | |
9360ffd1 | 1005 | |
3713b4e3 JB |
1006 | if (dev->wiphy.wowlan.n_patterns) { |
1007 | struct nl80211_wowlan_pattern_support pat = { | |
1008 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1009 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, | |
1010 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, | |
1011 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, | |
1012 | }; | |
9360ffd1 | 1013 | |
3713b4e3 JB |
1014 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1015 | sizeof(pat), &pat)) | |
1016 | return -ENOBUFS; | |
1017 | } | |
9360ffd1 | 1018 | |
b56cf720 JB |
1019 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1020 | return -ENOBUFS; | |
1021 | ||
3713b4e3 | 1022 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1023 | |
3713b4e3 JB |
1024 | return 0; |
1025 | } | |
1026 | #endif | |
9360ffd1 | 1027 | |
3713b4e3 JB |
1028 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1029 | struct ieee80211_supported_band *sband) | |
1030 | { | |
1031 | struct nlattr *nl_rates, *nl_rate; | |
1032 | struct ieee80211_rate *rate; | |
1033 | int i; | |
87bbbe22 | 1034 | |
3713b4e3 JB |
1035 | /* add HT info */ |
1036 | if (sband->ht_cap.ht_supported && | |
1037 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1038 | sizeof(sband->ht_cap.mcs), | |
1039 | &sband->ht_cap.mcs) || | |
1040 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1041 | sband->ht_cap.cap) || | |
1042 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1043 | sband->ht_cap.ampdu_factor) || | |
1044 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1045 | sband->ht_cap.ampdu_density))) | |
1046 | return -ENOBUFS; | |
afe0cbf8 | 1047 | |
3713b4e3 JB |
1048 | /* add VHT info */ |
1049 | if (sband->vht_cap.vht_supported && | |
1050 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1051 | sizeof(sband->vht_cap.vht_mcs), | |
1052 | &sband->vht_cap.vht_mcs) || | |
1053 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1054 | sband->vht_cap.cap))) | |
1055 | return -ENOBUFS; | |
f59ac048 | 1056 | |
3713b4e3 JB |
1057 | /* add bitrates */ |
1058 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1059 | if (!nl_rates) | |
1060 | return -ENOBUFS; | |
ee688b00 | 1061 | |
3713b4e3 JB |
1062 | for (i = 0; i < sband->n_bitrates; i++) { |
1063 | nl_rate = nla_nest_start(msg, i); | |
1064 | if (!nl_rate) | |
1065 | return -ENOBUFS; | |
ee688b00 | 1066 | |
3713b4e3 JB |
1067 | rate = &sband->bitrates[i]; |
1068 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1069 | rate->bitrate)) | |
1070 | return -ENOBUFS; | |
1071 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1072 | nla_put_flag(msg, | |
1073 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1074 | return -ENOBUFS; | |
ee688b00 | 1075 | |
3713b4e3 JB |
1076 | nla_nest_end(msg, nl_rate); |
1077 | } | |
d51626df | 1078 | |
3713b4e3 | 1079 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1080 | |
3713b4e3 JB |
1081 | return 0; |
1082 | } | |
ee688b00 | 1083 | |
3713b4e3 JB |
1084 | static int |
1085 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1086 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1087 | { | |
1088 | u16 stypes; | |
1089 | struct nlattr *nl_ftypes, *nl_ifs; | |
1090 | enum nl80211_iftype ift; | |
1091 | int i; | |
ee688b00 | 1092 | |
3713b4e3 JB |
1093 | if (!mgmt_stypes) |
1094 | return 0; | |
5dab3b8a | 1095 | |
3713b4e3 JB |
1096 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1097 | if (!nl_ifs) | |
1098 | return -ENOBUFS; | |
e2f367f2 | 1099 | |
3713b4e3 JB |
1100 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1101 | nl_ftypes = nla_nest_start(msg, ift); | |
1102 | if (!nl_ftypes) | |
1103 | return -ENOBUFS; | |
1104 | i = 0; | |
1105 | stypes = mgmt_stypes[ift].tx; | |
1106 | while (stypes) { | |
1107 | if ((stypes & 1) && | |
1108 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1109 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1110 | return -ENOBUFS; | |
1111 | stypes >>= 1; | |
1112 | i++; | |
ee688b00 | 1113 | } |
3713b4e3 JB |
1114 | nla_nest_end(msg, nl_ftypes); |
1115 | } | |
ee688b00 | 1116 | |
3713b4e3 | 1117 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1118 | |
3713b4e3 JB |
1119 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1120 | if (!nl_ifs) | |
1121 | return -ENOBUFS; | |
ee688b00 | 1122 | |
3713b4e3 JB |
1123 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1124 | nl_ftypes = nla_nest_start(msg, ift); | |
1125 | if (!nl_ftypes) | |
1126 | return -ENOBUFS; | |
1127 | i = 0; | |
1128 | stypes = mgmt_stypes[ift].rx; | |
1129 | while (stypes) { | |
1130 | if ((stypes & 1) && | |
1131 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1132 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1133 | return -ENOBUFS; | |
1134 | stypes >>= 1; | |
1135 | i++; | |
1136 | } | |
1137 | nla_nest_end(msg, nl_ftypes); | |
1138 | } | |
1139 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1140 | |
3713b4e3 JB |
1141 | return 0; |
1142 | } | |
ee688b00 | 1143 | |
3713b4e3 JB |
1144 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1145 | struct sk_buff *msg, u32 portid, u32 seq, | |
1146 | int flags, bool split, long *split_start, | |
1147 | long *band_start, long *chan_start) | |
1148 | { | |
1149 | void *hdr; | |
1150 | struct nlattr *nl_bands, *nl_band; | |
1151 | struct nlattr *nl_freqs, *nl_freq; | |
1152 | struct nlattr *nl_cmds; | |
1153 | enum ieee80211_band band; | |
1154 | struct ieee80211_channel *chan; | |
1155 | int i; | |
1156 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1157 | dev->wiphy.mgmt_stypes; | |
1158 | long start = 0, start_chan = 0, start_band = 0; | |
fe1abafd | 1159 | u32 features; |
ee688b00 | 1160 | |
3713b4e3 JB |
1161 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1162 | if (!hdr) | |
1163 | return -ENOBUFS; | |
ee688b00 | 1164 | |
3713b4e3 JB |
1165 | /* allow always using the variables */ |
1166 | if (!split) { | |
1167 | split_start = &start; | |
1168 | band_start = &start_band; | |
1169 | chan_start = &start_chan; | |
ee688b00 | 1170 | } |
ee688b00 | 1171 | |
3713b4e3 JB |
1172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1173 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1174 | wiphy_name(&dev->wiphy)) || | |
1175 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1176 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1177 | goto nla_put_failure; |
1178 | ||
3713b4e3 JB |
1179 | switch (*split_start) { |
1180 | case 0: | |
1181 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1182 | dev->wiphy.retry_short) || | |
1183 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1184 | dev->wiphy.retry_long) || | |
1185 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1186 | dev->wiphy.frag_threshold) || | |
1187 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1188 | dev->wiphy.rts_threshold) || | |
1189 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1190 | dev->wiphy.coverage_class) || | |
1191 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1192 | dev->wiphy.max_scan_ssids) || | |
1193 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1194 | dev->wiphy.max_sched_scan_ssids) || | |
1195 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1196 | dev->wiphy.max_scan_ie_len) || | |
1197 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1198 | dev->wiphy.max_sched_scan_ie_len) || | |
1199 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1200 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1201 | goto nla_put_failure; |
3713b4e3 JB |
1202 | |
1203 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1204 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1205 | goto nla_put_failure; |
3713b4e3 JB |
1206 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1207 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1208 | goto nla_put_failure; | |
1209 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1210 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1211 | goto nla_put_failure; | |
1212 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1213 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1214 | goto nla_put_failure; | |
1215 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1216 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1217 | goto nla_put_failure; | |
1218 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1219 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1220 | goto nla_put_failure; |
8fdc621d | 1221 | |
3713b4e3 JB |
1222 | (*split_start)++; |
1223 | if (split) | |
1224 | break; | |
1225 | case 1: | |
1226 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1227 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1228 | dev->wiphy.cipher_suites)) | |
1229 | goto nla_put_failure; | |
4745fc09 | 1230 | |
3713b4e3 JB |
1231 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1232 | dev->wiphy.max_num_pmkids)) | |
1233 | goto nla_put_failure; | |
b23aa676 | 1234 | |
3713b4e3 JB |
1235 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1236 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1237 | goto nla_put_failure; |
b23aa676 | 1238 | |
3713b4e3 JB |
1239 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1240 | dev->wiphy.available_antennas_tx) || | |
1241 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1242 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1243 | goto nla_put_failure; |
b23aa676 | 1244 | |
3713b4e3 JB |
1245 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1246 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1247 | dev->wiphy.probe_resp_offload)) | |
1248 | goto nla_put_failure; | |
8fdc621d | 1249 | |
3713b4e3 JB |
1250 | if ((dev->wiphy.available_antennas_tx || |
1251 | dev->wiphy.available_antennas_rx) && | |
1252 | dev->ops->get_antenna) { | |
1253 | u32 tx_ant = 0, rx_ant = 0; | |
1254 | int res; | |
1255 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1256 | if (!res) { | |
1257 | if (nla_put_u32(msg, | |
1258 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1259 | tx_ant) || | |
1260 | nla_put_u32(msg, | |
1261 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1262 | rx_ant)) | |
1263 | goto nla_put_failure; | |
1264 | } | |
1265 | } | |
a293911d | 1266 | |
3713b4e3 JB |
1267 | (*split_start)++; |
1268 | if (split) | |
1269 | break; | |
1270 | case 2: | |
1271 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1272 | dev->wiphy.interface_modes)) | |
1273 | goto nla_put_failure; | |
1274 | (*split_start)++; | |
1275 | if (split) | |
1276 | break; | |
1277 | case 3: | |
1278 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1279 | if (!nl_bands) | |
1280 | goto nla_put_failure; | |
f7ca38df | 1281 | |
3713b4e3 JB |
1282 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
1283 | struct ieee80211_supported_band *sband; | |
2e161f78 | 1284 | |
3713b4e3 | 1285 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1286 | |
3713b4e3 JB |
1287 | if (!sband) |
1288 | continue; | |
1289 | ||
1290 | nl_band = nla_nest_start(msg, band); | |
1291 | if (!nl_band) | |
2e161f78 | 1292 | goto nla_put_failure; |
3713b4e3 JB |
1293 | |
1294 | switch (*chan_start) { | |
1295 | case 0: | |
1296 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1297 | goto nla_put_failure; |
3713b4e3 JB |
1298 | (*chan_start)++; |
1299 | if (split) | |
1300 | break; | |
1301 | default: | |
1302 | /* add frequencies */ | |
1303 | nl_freqs = nla_nest_start( | |
1304 | msg, NL80211_BAND_ATTR_FREQS); | |
1305 | if (!nl_freqs) | |
1306 | goto nla_put_failure; | |
1307 | ||
1308 | for (i = *chan_start - 1; | |
1309 | i < sband->n_channels; | |
1310 | i++) { | |
1311 | nl_freq = nla_nest_start(msg, i); | |
1312 | if (!nl_freq) | |
1313 | goto nla_put_failure; | |
1314 | ||
1315 | chan = &sband->channels[i]; | |
1316 | ||
cdc89b97 JB |
1317 | if (nl80211_msg_put_channel(msg, chan, |
1318 | split)) | |
3713b4e3 JB |
1319 | goto nla_put_failure; |
1320 | ||
1321 | nla_nest_end(msg, nl_freq); | |
1322 | if (split) | |
1323 | break; | |
1324 | } | |
1325 | if (i < sband->n_channels) | |
1326 | *chan_start = i + 2; | |
1327 | else | |
1328 | *chan_start = 0; | |
1329 | nla_nest_end(msg, nl_freqs); | |
1330 | } | |
1331 | ||
1332 | nla_nest_end(msg, nl_band); | |
1333 | ||
1334 | if (split) { | |
1335 | /* start again here */ | |
1336 | if (*chan_start) | |
1337 | band--; | |
1338 | break; | |
2e161f78 | 1339 | } |
2e161f78 | 1340 | } |
3713b4e3 | 1341 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1342 | |
3713b4e3 JB |
1343 | if (band < IEEE80211_NUM_BANDS) |
1344 | *band_start = band + 1; | |
1345 | else | |
1346 | *band_start = 0; | |
74b70a4e | 1347 | |
3713b4e3 JB |
1348 | /* if bands & channels are done, continue outside */ |
1349 | if (*band_start == 0 && *chan_start == 0) | |
1350 | (*split_start)++; | |
1351 | if (split) | |
1352 | break; | |
1353 | case 4: | |
1354 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1355 | if (!nl_cmds) | |
2e161f78 JB |
1356 | goto nla_put_failure; |
1357 | ||
3713b4e3 JB |
1358 | i = 0; |
1359 | #define CMD(op, n) \ | |
1360 | do { \ | |
1361 | if (dev->ops->op) { \ | |
1362 | i++; \ | |
1363 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1364 | goto nla_put_failure; \ | |
1365 | } \ | |
1366 | } while (0) | |
1367 | ||
1368 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1369 | CMD(change_virtual_intf, SET_INTERFACE); | |
1370 | CMD(add_key, NEW_KEY); | |
1371 | CMD(start_ap, START_AP); | |
1372 | CMD(add_station, NEW_STATION); | |
1373 | CMD(add_mpath, NEW_MPATH); | |
1374 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1375 | CMD(change_bss, SET_BSS); | |
1376 | CMD(auth, AUTHENTICATE); | |
1377 | CMD(assoc, ASSOCIATE); | |
1378 | CMD(deauth, DEAUTHENTICATE); | |
1379 | CMD(disassoc, DISASSOCIATE); | |
1380 | CMD(join_ibss, JOIN_IBSS); | |
1381 | CMD(join_mesh, JOIN_MESH); | |
1382 | CMD(set_pmksa, SET_PMKSA); | |
1383 | CMD(del_pmksa, DEL_PMKSA); | |
1384 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1385 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1386 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1387 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1388 | CMD(mgmt_tx, FRAME); | |
1389 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1390 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1391 | i++; | |
1392 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1393 | goto nla_put_failure; |
2e161f78 | 1394 | } |
3713b4e3 JB |
1395 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1396 | dev->ops->join_mesh) { | |
1397 | i++; | |
1398 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1399 | goto nla_put_failure; | |
1400 | } | |
1401 | CMD(set_wds_peer, SET_WDS_PEER); | |
1402 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1403 | CMD(tdls_mgmt, TDLS_MGMT); | |
1404 | CMD(tdls_oper, TDLS_OPER); | |
1405 | } | |
1406 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1407 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1408 | CMD(probe_client, PROBE_CLIENT); | |
1409 | CMD(set_noack_map, SET_NOACK_MAP); | |
1410 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1411 | i++; | |
1412 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1413 | goto nla_put_failure; | |
1414 | } | |
1415 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1416 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
2e161f78 | 1417 | |
3713b4e3 JB |
1418 | #ifdef CONFIG_NL80211_TESTMODE |
1419 | CMD(testmode_cmd, TESTMODE); | |
1420 | #endif | |
ff1b6e69 | 1421 | |
3713b4e3 | 1422 | #undef CMD |
ff1b6e69 | 1423 | |
3713b4e3 JB |
1424 | if (dev->ops->connect || dev->ops->auth) { |
1425 | i++; | |
1426 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1427 | goto nla_put_failure; |
ff1b6e69 JB |
1428 | } |
1429 | ||
3713b4e3 JB |
1430 | if (dev->ops->disconnect || dev->ops->deauth) { |
1431 | i++; | |
1432 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1433 | goto nla_put_failure; | |
1434 | } | |
1435 | ||
1436 | nla_nest_end(msg, nl_cmds); | |
1437 | (*split_start)++; | |
1438 | if (split) | |
1439 | break; | |
1440 | case 5: | |
1441 | if (dev->ops->remain_on_channel && | |
1442 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1443 | nla_put_u32(msg, | |
1444 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1445 | dev->wiphy.max_remain_on_channel_duration)) | |
1446 | goto nla_put_failure; | |
1447 | ||
1448 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1449 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1450 | goto nla_put_failure; | |
1451 | ||
1452 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1453 | goto nla_put_failure; | |
1454 | (*split_start)++; | |
1455 | if (split) | |
1456 | break; | |
1457 | case 6: | |
1458 | #ifdef CONFIG_PM | |
b56cf720 | 1459 | if (nl80211_send_wowlan(msg, dev, split)) |
3713b4e3 JB |
1460 | goto nla_put_failure; |
1461 | (*split_start)++; | |
1462 | if (split) | |
1463 | break; | |
1464 | #else | |
1465 | (*split_start)++; | |
dfb89c56 | 1466 | #endif |
3713b4e3 JB |
1467 | case 7: |
1468 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1469 | dev->wiphy.software_iftypes)) | |
1470 | goto nla_put_failure; | |
ff1b6e69 | 1471 | |
cdc89b97 | 1472 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
3713b4e3 | 1473 | goto nla_put_failure; |
7527a782 | 1474 | |
3713b4e3 JB |
1475 | (*split_start)++; |
1476 | if (split) | |
1477 | break; | |
1478 | case 8: | |
1479 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1480 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1481 | dev->wiphy.ap_sme_capa)) | |
1482 | goto nla_put_failure; | |
7527a782 | 1483 | |
fe1abafd JB |
1484 | features = dev->wiphy.features; |
1485 | /* | |
1486 | * We can only add the per-channel limit information if the | |
1487 | * dump is split, otherwise it makes it too big. Therefore | |
1488 | * only advertise it in that case. | |
1489 | */ | |
1490 | if (split) | |
1491 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | |
1492 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1493 | goto nla_put_failure; |
562a7480 | 1494 | |
3713b4e3 JB |
1495 | if (dev->wiphy.ht_capa_mod_mask && |
1496 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1497 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1498 | dev->wiphy.ht_capa_mod_mask)) | |
1499 | goto nla_put_failure; | |
1f074bd8 | 1500 | |
3713b4e3 JB |
1501 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1502 | dev->wiphy.max_acl_mac_addrs && | |
1503 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1504 | dev->wiphy.max_acl_mac_addrs)) | |
1505 | goto nla_put_failure; | |
7e7c8926 | 1506 | |
3713b4e3 JB |
1507 | /* |
1508 | * Any information below this point is only available to | |
1509 | * applications that can deal with it being split. This | |
1510 | * helps ensure that newly added capabilities don't break | |
1511 | * older tools by overrunning their buffers. | |
1512 | * | |
1513 | * We still increment split_start so that in the split | |
1514 | * case we'll continue with more data in the next round, | |
1515 | * but break unconditionally so unsplit data stops here. | |
1516 | */ | |
1517 | (*split_start)++; | |
1518 | break; | |
1519 | case 9: | |
fe1abafd JB |
1520 | if (dev->wiphy.extended_capabilities && |
1521 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1522 | dev->wiphy.extended_capabilities_len, | |
1523 | dev->wiphy.extended_capabilities) || | |
1524 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1525 | dev->wiphy.extended_capabilities_len, | |
1526 | dev->wiphy.extended_capabilities_mask))) | |
1527 | goto nla_put_failure; | |
a50df0c4 | 1528 | |
ee2aca34 JB |
1529 | if (dev->wiphy.vht_capa_mod_mask && |
1530 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1531 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1532 | dev->wiphy.vht_capa_mod_mask)) | |
1533 | goto nla_put_failure; | |
1534 | ||
3713b4e3 JB |
1535 | /* done */ |
1536 | *split_start = 0; | |
1537 | break; | |
1538 | } | |
55682965 JB |
1539 | return genlmsg_end(msg, hdr); |
1540 | ||
1541 | nla_put_failure: | |
bc3ed28c TG |
1542 | genlmsg_cancel(msg, hdr); |
1543 | return -EMSGSIZE; | |
55682965 JB |
1544 | } |
1545 | ||
1546 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1547 | { | |
645e77de | 1548 | int idx = 0, ret; |
55682965 JB |
1549 | int start = cb->args[0]; |
1550 | struct cfg80211_registered_device *dev; | |
3713b4e3 JB |
1551 | s64 filter_wiphy = -1; |
1552 | bool split = false; | |
1553 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1554 | int res; | |
55682965 | 1555 | |
a1794390 | 1556 | mutex_lock(&cfg80211_mutex); |
3713b4e3 JB |
1557 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
1558 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1559 | if (res == 0) { | |
1560 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1561 | if (tb[NL80211_ATTR_WIPHY]) | |
1562 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1563 | if (tb[NL80211_ATTR_WDEV]) | |
1564 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1565 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1566 | struct net_device *netdev; | |
1567 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1568 | ||
1569 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1570 | if (!netdev) { | |
1571 | mutex_unlock(&cfg80211_mutex); | |
1572 | return -ENODEV; | |
1573 | } | |
1574 | if (netdev->ieee80211_ptr) { | |
1575 | dev = wiphy_to_dev( | |
1576 | netdev->ieee80211_ptr->wiphy); | |
1577 | filter_wiphy = dev->wiphy_idx; | |
1578 | } | |
1579 | dev_put(netdev); | |
1580 | } | |
1581 | } | |
1582 | ||
79c97e97 | 1583 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1584 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1585 | continue; | |
b4637271 | 1586 | if (++idx <= start) |
55682965 | 1587 | continue; |
3713b4e3 JB |
1588 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
1589 | continue; | |
1590 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1591 | do { | |
1592 | ret = nl80211_send_wiphy(dev, skb, | |
1593 | NETLINK_CB(cb->skb).portid, | |
1594 | cb->nlh->nlmsg_seq, | |
1595 | NLM_F_MULTI, | |
1596 | split, &cb->args[1], | |
1597 | &cb->args[2], | |
1598 | &cb->args[3]); | |
1599 | if (ret < 0) { | |
1600 | /* | |
1601 | * If sending the wiphy data didn't fit (ENOBUFS | |
1602 | * or EMSGSIZE returned), this SKB is still | |
1603 | * empty (so it's not too big because another | |
1604 | * wiphy dataset is already in the skb) and | |
1605 | * we've not tried to adjust the dump allocation | |
1606 | * yet ... then adjust the alloc size to be | |
1607 | * bigger, and return 1 but with the empty skb. | |
1608 | * This results in an empty message being RX'ed | |
1609 | * in userspace, but that is ignored. | |
1610 | * | |
1611 | * We can then retry with the larger buffer. | |
1612 | */ | |
1613 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1614 | !skb->len && | |
1615 | cb->min_dump_alloc < 4096) { | |
1616 | cb->min_dump_alloc = 4096; | |
1617 | mutex_unlock(&cfg80211_mutex); | |
1618 | return 1; | |
1619 | } | |
1620 | idx--; | |
1621 | break; | |
645e77de | 1622 | } |
3713b4e3 JB |
1623 | } while (cb->args[1] > 0); |
1624 | break; | |
55682965 | 1625 | } |
a1794390 | 1626 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1627 | |
1628 | cb->args[0] = idx; | |
1629 | ||
1630 | return skb->len; | |
1631 | } | |
1632 | ||
1633 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1634 | { | |
1635 | struct sk_buff *msg; | |
4c476991 | 1636 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1637 | |
645e77de | 1638 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1639 | if (!msg) |
4c476991 | 1640 | return -ENOMEM; |
55682965 | 1641 | |
3713b4e3 JB |
1642 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
1643 | false, NULL, NULL, NULL) < 0) { | |
4c476991 JB |
1644 | nlmsg_free(msg); |
1645 | return -ENOBUFS; | |
1646 | } | |
55682965 | 1647 | |
134e6375 | 1648 | return genlmsg_reply(msg, info); |
55682965 JB |
1649 | } |
1650 | ||
31888487 JM |
1651 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1652 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1653 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1654 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1655 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1656 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1657 | }; | |
1658 | ||
1659 | static int parse_txq_params(struct nlattr *tb[], | |
1660 | struct ieee80211_txq_params *txq_params) | |
1661 | { | |
a3304b0a | 1662 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1663 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1664 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1665 | return -EINVAL; | |
1666 | ||
a3304b0a | 1667 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1668 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1669 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1670 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1671 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1672 | ||
a3304b0a JB |
1673 | if (txq_params->ac >= NL80211_NUM_ACS) |
1674 | return -EINVAL; | |
1675 | ||
31888487 JM |
1676 | return 0; |
1677 | } | |
1678 | ||
f444de05 JB |
1679 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1680 | { | |
1681 | /* | |
cc1d2806 JB |
1682 | * You can only set the channel explicitly for WDS interfaces, |
1683 | * all others have their channel managed via their respective | |
1684 | * "establish a connection" command (connect, join, ...) | |
1685 | * | |
1686 | * For AP/GO and mesh mode, the channel can be set with the | |
1687 | * channel userspace API, but is only stored and passed to the | |
1688 | * low-level driver when the AP starts or the mesh is joined. | |
1689 | * This is for backward compatibility, userspace can also give | |
1690 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1691 | * |
1692 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1693 | * whatever else is going on, so they have their own special |
1694 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1695 | */ |
1696 | return !wdev || | |
1697 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1698 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1699 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1700 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1701 | } |
1702 | ||
683b6d3b JB |
1703 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1704 | struct genl_info *info, | |
1705 | struct cfg80211_chan_def *chandef) | |
1706 | { | |
dbeca2ea | 1707 | u32 control_freq; |
683b6d3b JB |
1708 | |
1709 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1710 | return -EINVAL; | |
1711 | ||
1712 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1713 | ||
1714 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1715 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1716 | chandef->center_freq1 = control_freq; | |
1717 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1718 | |
1719 | /* Primary channel not allowed */ | |
1720 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1721 | return -EINVAL; | |
1722 | ||
3d9d1d66 JB |
1723 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1724 | enum nl80211_channel_type chantype; | |
1725 | ||
1726 | chantype = nla_get_u32( | |
1727 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1728 | ||
1729 | switch (chantype) { | |
1730 | case NL80211_CHAN_NO_HT: | |
1731 | case NL80211_CHAN_HT20: | |
1732 | case NL80211_CHAN_HT40PLUS: | |
1733 | case NL80211_CHAN_HT40MINUS: | |
1734 | cfg80211_chandef_create(chandef, chandef->chan, | |
1735 | chantype); | |
1736 | break; | |
1737 | default: | |
1738 | return -EINVAL; | |
1739 | } | |
1740 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1741 | chandef->width = | |
1742 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1743 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1744 | chandef->center_freq1 = | |
1745 | nla_get_u32( | |
1746 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1747 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1748 | chandef->center_freq2 = | |
1749 | nla_get_u32( | |
1750 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1751 | } | |
1752 | ||
9f5e8f6e | 1753 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1754 | return -EINVAL; |
1755 | ||
9f5e8f6e JB |
1756 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1757 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1758 | return -EINVAL; |
1759 | ||
683b6d3b JB |
1760 | return 0; |
1761 | } | |
1762 | ||
f444de05 JB |
1763 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1764 | struct wireless_dev *wdev, | |
1765 | struct genl_info *info) | |
1766 | { | |
683b6d3b | 1767 | struct cfg80211_chan_def chandef; |
f444de05 | 1768 | int result; |
e8c9bd5b JB |
1769 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1770 | ||
1771 | if (wdev) | |
1772 | iftype = wdev->iftype; | |
f444de05 | 1773 | |
f444de05 JB |
1774 | if (!nl80211_can_set_dev_channel(wdev)) |
1775 | return -EOPNOTSUPP; | |
1776 | ||
683b6d3b JB |
1777 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1778 | if (result) | |
1779 | return result; | |
f444de05 JB |
1780 | |
1781 | mutex_lock(&rdev->devlist_mtx); | |
e8c9bd5b | 1782 | switch (iftype) { |
aa430da4 JB |
1783 | case NL80211_IFTYPE_AP: |
1784 | case NL80211_IFTYPE_P2P_GO: | |
1785 | if (wdev->beacon_interval) { | |
1786 | result = -EBUSY; | |
1787 | break; | |
1788 | } | |
683b6d3b | 1789 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1790 | result = -EINVAL; |
1791 | break; | |
1792 | } | |
683b6d3b | 1793 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1794 | result = 0; |
1795 | break; | |
cc1d2806 | 1796 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1797 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1798 | break; |
e8c9bd5b | 1799 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1800 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1801 | break; |
aa430da4 | 1802 | default: |
e8c9bd5b | 1803 | result = -EINVAL; |
f444de05 JB |
1804 | } |
1805 | mutex_unlock(&rdev->devlist_mtx); | |
1806 | ||
1807 | return result; | |
1808 | } | |
1809 | ||
1810 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1811 | { | |
4c476991 JB |
1812 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1813 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1814 | |
4c476991 | 1815 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1816 | } |
1817 | ||
e8347eba BJ |
1818 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1819 | { | |
43b19952 JB |
1820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1821 | struct net_device *dev = info->user_ptr[1]; | |
1822 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1823 | const u8 *bssid; |
e8347eba BJ |
1824 | |
1825 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1826 | return -EINVAL; | |
1827 | ||
43b19952 JB |
1828 | if (netif_running(dev)) |
1829 | return -EBUSY; | |
e8347eba | 1830 | |
43b19952 JB |
1831 | if (!rdev->ops->set_wds_peer) |
1832 | return -EOPNOTSUPP; | |
e8347eba | 1833 | |
43b19952 JB |
1834 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1835 | return -EOPNOTSUPP; | |
e8347eba BJ |
1836 | |
1837 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1838 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1839 | } |
1840 | ||
1841 | ||
55682965 JB |
1842 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1843 | { | |
1844 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1845 | struct net_device *netdev = NULL; |
1846 | struct wireless_dev *wdev; | |
a1e567c8 | 1847 | int result = 0, rem_txq_params = 0; |
31888487 | 1848 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1849 | u32 changed; |
1850 | u8 retry_short = 0, retry_long = 0; | |
1851 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1852 | u8 coverage_class = 0; |
55682965 | 1853 | |
f444de05 JB |
1854 | /* |
1855 | * Try to find the wiphy and netdev. Normally this | |
1856 | * function shouldn't need the netdev, but this is | |
1857 | * done for backward compatibility -- previously | |
1858 | * setting the channel was done per wiphy, but now | |
1859 | * it is per netdev. Previous userland like hostapd | |
1860 | * also passed a netdev to set_wiphy, so that it is | |
1861 | * possible to let that go to the right netdev! | |
1862 | */ | |
4bbf4d56 JB |
1863 | mutex_lock(&cfg80211_mutex); |
1864 | ||
f444de05 JB |
1865 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1866 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1867 | ||
1868 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1869 | if (netdev && netdev->ieee80211_ptr) { | |
1870 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1871 | mutex_lock(&rdev->mtx); | |
1872 | } else | |
1873 | netdev = NULL; | |
4bbf4d56 JB |
1874 | } |
1875 | ||
f444de05 | 1876 | if (!netdev) { |
878d9ec7 JB |
1877 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1878 | info->attrs); | |
f444de05 JB |
1879 | if (IS_ERR(rdev)) { |
1880 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1881 | return PTR_ERR(rdev); |
f444de05 JB |
1882 | } |
1883 | wdev = NULL; | |
1884 | netdev = NULL; | |
1885 | result = 0; | |
1886 | ||
1887 | mutex_lock(&rdev->mtx); | |
71fe96bf | 1888 | } else |
f444de05 | 1889 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1890 | |
1891 | /* | |
1892 | * end workaround code, by now the rdev is available | |
1893 | * and locked, and wdev may or may not be NULL. | |
1894 | */ | |
4bbf4d56 JB |
1895 | |
1896 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1897 | result = cfg80211_dev_rename( |
1898 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1899 | |
1900 | mutex_unlock(&cfg80211_mutex); | |
1901 | ||
1902 | if (result) | |
1903 | goto bad_res; | |
31888487 JM |
1904 | |
1905 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1906 | struct ieee80211_txq_params txq_params; | |
1907 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1908 | ||
1909 | if (!rdev->ops->set_txq_params) { | |
1910 | result = -EOPNOTSUPP; | |
1911 | goto bad_res; | |
1912 | } | |
1913 | ||
f70f01c2 EP |
1914 | if (!netdev) { |
1915 | result = -EINVAL; | |
1916 | goto bad_res; | |
1917 | } | |
1918 | ||
133a3ff2 JB |
1919 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1920 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1921 | result = -EINVAL; | |
1922 | goto bad_res; | |
1923 | } | |
1924 | ||
2b5f8b0b JB |
1925 | if (!netif_running(netdev)) { |
1926 | result = -ENETDOWN; | |
1927 | goto bad_res; | |
1928 | } | |
1929 | ||
31888487 JM |
1930 | nla_for_each_nested(nl_txq_params, |
1931 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1932 | rem_txq_params) { | |
1933 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1934 | nla_data(nl_txq_params), | |
1935 | nla_len(nl_txq_params), | |
1936 | txq_params_policy); | |
1937 | result = parse_txq_params(tb, &txq_params); | |
1938 | if (result) | |
1939 | goto bad_res; | |
1940 | ||
e35e4d28 HG |
1941 | result = rdev_set_txq_params(rdev, netdev, |
1942 | &txq_params); | |
31888487 JM |
1943 | if (result) |
1944 | goto bad_res; | |
1945 | } | |
1946 | } | |
55682965 | 1947 | |
72bdcf34 | 1948 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1949 | result = __nl80211_set_channel(rdev, |
1950 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1951 | info); | |
72bdcf34 JM |
1952 | if (result) |
1953 | goto bad_res; | |
1954 | } | |
1955 | ||
98d2ff8b | 1956 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1957 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1958 | enum nl80211_tx_power_setting type; |
1959 | int idx, mbm = 0; | |
1960 | ||
c8442118 JB |
1961 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
1962 | txp_wdev = NULL; | |
1963 | ||
98d2ff8b | 1964 | if (!rdev->ops->set_tx_power) { |
60ea385f | 1965 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1966 | goto bad_res; |
1967 | } | |
1968 | ||
1969 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1970 | type = nla_get_u32(info->attrs[idx]); | |
1971 | ||
1972 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1973 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1974 | result = -EINVAL; | |
1975 | goto bad_res; | |
1976 | } | |
1977 | ||
1978 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1979 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1980 | mbm = nla_get_u32(info->attrs[idx]); | |
1981 | } | |
1982 | ||
c8442118 | 1983 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
1984 | if (result) |
1985 | goto bad_res; | |
1986 | } | |
1987 | ||
afe0cbf8 BR |
1988 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1989 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1990 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1991 | if ((!rdev->wiphy.available_antennas_tx && |
1992 | !rdev->wiphy.available_antennas_rx) || | |
1993 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1994 | result = -EOPNOTSUPP; |
1995 | goto bad_res; | |
1996 | } | |
1997 | ||
1998 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1999 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2000 | ||
a7ffac95 | 2001 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2002 | * available antenna masks, except for the "all" mask */ |
2003 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2004 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2005 | result = -EINVAL; |
2006 | goto bad_res; | |
2007 | } | |
2008 | ||
7f531e03 BR |
2009 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2010 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2011 | |
e35e4d28 | 2012 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2013 | if (result) |
2014 | goto bad_res; | |
2015 | } | |
2016 | ||
b9a5f8ca JM |
2017 | changed = 0; |
2018 | ||
2019 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2020 | retry_short = nla_get_u8( | |
2021 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2022 | if (retry_short == 0) { | |
2023 | result = -EINVAL; | |
2024 | goto bad_res; | |
2025 | } | |
2026 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2027 | } | |
2028 | ||
2029 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2030 | retry_long = nla_get_u8( | |
2031 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2032 | if (retry_long == 0) { | |
2033 | result = -EINVAL; | |
2034 | goto bad_res; | |
2035 | } | |
2036 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2037 | } | |
2038 | ||
2039 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2040 | frag_threshold = nla_get_u32( | |
2041 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2042 | if (frag_threshold < 256) { | |
2043 | result = -EINVAL; | |
2044 | goto bad_res; | |
2045 | } | |
2046 | if (frag_threshold != (u32) -1) { | |
2047 | /* | |
2048 | * Fragments (apart from the last one) are required to | |
2049 | * have even length. Make the fragmentation code | |
2050 | * simpler by stripping LSB should someone try to use | |
2051 | * odd threshold value. | |
2052 | */ | |
2053 | frag_threshold &= ~0x1; | |
2054 | } | |
2055 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2056 | } | |
2057 | ||
2058 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2059 | rts_threshold = nla_get_u32( | |
2060 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2061 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2062 | } | |
2063 | ||
81077e82 LT |
2064 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2065 | coverage_class = nla_get_u8( | |
2066 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2067 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2068 | } | |
2069 | ||
b9a5f8ca JM |
2070 | if (changed) { |
2071 | u8 old_retry_short, old_retry_long; | |
2072 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2073 | u8 old_coverage_class; |
b9a5f8ca JM |
2074 | |
2075 | if (!rdev->ops->set_wiphy_params) { | |
2076 | result = -EOPNOTSUPP; | |
2077 | goto bad_res; | |
2078 | } | |
2079 | ||
2080 | old_retry_short = rdev->wiphy.retry_short; | |
2081 | old_retry_long = rdev->wiphy.retry_long; | |
2082 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2083 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2084 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2085 | |
2086 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2087 | rdev->wiphy.retry_short = retry_short; | |
2088 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2089 | rdev->wiphy.retry_long = retry_long; | |
2090 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2091 | rdev->wiphy.frag_threshold = frag_threshold; | |
2092 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2093 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2094 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2095 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2096 | |
e35e4d28 | 2097 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2098 | if (result) { |
2099 | rdev->wiphy.retry_short = old_retry_short; | |
2100 | rdev->wiphy.retry_long = old_retry_long; | |
2101 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2102 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2103 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2104 | } |
2105 | } | |
72bdcf34 | 2106 | |
306d6112 | 2107 | bad_res: |
4bbf4d56 | 2108 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
2109 | if (netdev) |
2110 | dev_put(netdev); | |
55682965 JB |
2111 | return result; |
2112 | } | |
2113 | ||
71bbc994 JB |
2114 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2115 | { | |
2116 | return (u64)wdev->identifier | | |
2117 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2118 | } | |
55682965 | 2119 | |
683b6d3b JB |
2120 | static int nl80211_send_chandef(struct sk_buff *msg, |
2121 | struct cfg80211_chan_def *chandef) | |
2122 | { | |
9f5e8f6e | 2123 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2124 | |
683b6d3b JB |
2125 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2126 | chandef->chan->center_freq)) | |
2127 | return -ENOBUFS; | |
3d9d1d66 JB |
2128 | switch (chandef->width) { |
2129 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2130 | case NL80211_CHAN_WIDTH_20: | |
2131 | case NL80211_CHAN_WIDTH_40: | |
2132 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2133 | cfg80211_get_chandef_type(chandef))) | |
2134 | return -ENOBUFS; | |
2135 | break; | |
2136 | default: | |
2137 | break; | |
2138 | } | |
2139 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2140 | return -ENOBUFS; | |
2141 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2142 | return -ENOBUFS; | |
2143 | if (chandef->center_freq2 && | |
2144 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2145 | return -ENOBUFS; |
2146 | return 0; | |
2147 | } | |
2148 | ||
15e47304 | 2149 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2150 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2151 | struct wireless_dev *wdev) |
55682965 | 2152 | { |
72fb2abc | 2153 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2154 | void *hdr; |
2155 | ||
15e47304 | 2156 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2157 | if (!hdr) |
2158 | return -1; | |
2159 | ||
72fb2abc JB |
2160 | if (dev && |
2161 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2162 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2163 | goto nla_put_failure; |
2164 | ||
2165 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2166 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2167 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2168 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2169 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2170 | rdev->devlist_generation ^ | |
2171 | (cfg80211_rdev_list_generation << 2))) | |
2172 | goto nla_put_failure; | |
f5ea9120 | 2173 | |
5b7ccaf3 | 2174 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2175 | int ret; |
2176 | struct cfg80211_chan_def chandef; | |
2177 | ||
2178 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2179 | if (ret == 0) { | |
2180 | if (nl80211_send_chandef(msg, &chandef)) | |
2181 | goto nla_put_failure; | |
2182 | } | |
d91df0e3 PF |
2183 | } |
2184 | ||
b84e7a05 AQ |
2185 | if (wdev->ssid_len) { |
2186 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2187 | goto nla_put_failure; | |
2188 | } | |
2189 | ||
55682965 JB |
2190 | return genlmsg_end(msg, hdr); |
2191 | ||
2192 | nla_put_failure: | |
bc3ed28c TG |
2193 | genlmsg_cancel(msg, hdr); |
2194 | return -EMSGSIZE; | |
55682965 JB |
2195 | } |
2196 | ||
2197 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2198 | { | |
2199 | int wp_idx = 0; | |
2200 | int if_idx = 0; | |
2201 | int wp_start = cb->args[0]; | |
2202 | int if_start = cb->args[1]; | |
f5ea9120 | 2203 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2204 | struct wireless_dev *wdev; |
2205 | ||
a1794390 | 2206 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
2207 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2208 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2209 | continue; |
bba95fef JB |
2210 | if (wp_idx < wp_start) { |
2211 | wp_idx++; | |
55682965 | 2212 | continue; |
bba95fef | 2213 | } |
55682965 JB |
2214 | if_idx = 0; |
2215 | ||
f5ea9120 | 2216 | mutex_lock(&rdev->devlist_mtx); |
89a54e48 | 2217 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2218 | if (if_idx < if_start) { |
2219 | if_idx++; | |
55682965 | 2220 | continue; |
bba95fef | 2221 | } |
15e47304 | 2222 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2223 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2224 | rdev, wdev) < 0) { |
f5ea9120 | 2225 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2226 | goto out; |
2227 | } | |
2228 | if_idx++; | |
55682965 | 2229 | } |
f5ea9120 | 2230 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2231 | |
2232 | wp_idx++; | |
55682965 | 2233 | } |
bba95fef | 2234 | out: |
a1794390 | 2235 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
2236 | |
2237 | cb->args[0] = wp_idx; | |
2238 | cb->args[1] = if_idx; | |
2239 | ||
2240 | return skb->len; | |
2241 | } | |
2242 | ||
2243 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2244 | { | |
2245 | struct sk_buff *msg; | |
4c476991 | 2246 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2247 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2248 | |
fd2120ca | 2249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2250 | if (!msg) |
4c476991 | 2251 | return -ENOMEM; |
55682965 | 2252 | |
15e47304 | 2253 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2254 | dev, wdev) < 0) { |
4c476991 JB |
2255 | nlmsg_free(msg); |
2256 | return -ENOBUFS; | |
2257 | } | |
55682965 | 2258 | |
134e6375 | 2259 | return genlmsg_reply(msg, info); |
55682965 JB |
2260 | } |
2261 | ||
66f7ac50 MW |
2262 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2263 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2264 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2265 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2266 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2267 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
2268 | }; | |
2269 | ||
2270 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2271 | { | |
2272 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2273 | int flag; | |
2274 | ||
2275 | *mntrflags = 0; | |
2276 | ||
2277 | if (!nla) | |
2278 | return -EINVAL; | |
2279 | ||
2280 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2281 | nla, mntr_flags_policy)) | |
2282 | return -EINVAL; | |
2283 | ||
2284 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2285 | if (flags[flag]) | |
2286 | *mntrflags |= (1<<flag); | |
2287 | ||
2288 | return 0; | |
2289 | } | |
2290 | ||
9bc383de | 2291 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2292 | struct net_device *netdev, u8 use_4addr, |
2293 | enum nl80211_iftype iftype) | |
9bc383de | 2294 | { |
ad4bb6f8 | 2295 | if (!use_4addr) { |
f350a0a8 | 2296 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2297 | return -EBUSY; |
9bc383de | 2298 | return 0; |
ad4bb6f8 | 2299 | } |
9bc383de JB |
2300 | |
2301 | switch (iftype) { | |
2302 | case NL80211_IFTYPE_AP_VLAN: | |
2303 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2304 | return 0; | |
2305 | break; | |
2306 | case NL80211_IFTYPE_STATION: | |
2307 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2308 | return 0; | |
2309 | break; | |
2310 | default: | |
2311 | break; | |
2312 | } | |
2313 | ||
2314 | return -EOPNOTSUPP; | |
2315 | } | |
2316 | ||
55682965 JB |
2317 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2318 | { | |
4c476991 | 2319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2320 | struct vif_params params; |
e36d56b6 | 2321 | int err; |
04a773ad | 2322 | enum nl80211_iftype otype, ntype; |
4c476991 | 2323 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2324 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2325 | bool change = false; |
55682965 | 2326 | |
2ec600d6 LCC |
2327 | memset(¶ms, 0, sizeof(params)); |
2328 | ||
04a773ad | 2329 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2330 | |
723b038d | 2331 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2332 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2333 | if (otype != ntype) |
ac7f9cfa | 2334 | change = true; |
4c476991 JB |
2335 | if (ntype > NL80211_IFTYPE_MAX) |
2336 | return -EINVAL; | |
723b038d JB |
2337 | } |
2338 | ||
92ffe055 | 2339 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2340 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2341 | ||
4c476991 JB |
2342 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2343 | return -EINVAL; | |
29cbe68c JB |
2344 | if (netif_running(dev)) |
2345 | return -EBUSY; | |
2346 | ||
2347 | wdev_lock(wdev); | |
2348 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2349 | IEEE80211_MAX_MESH_ID_LEN); | |
2350 | wdev->mesh_id_up_len = | |
2351 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2352 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2353 | wdev->mesh_id_up_len); | |
2354 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2355 | } |
2356 | ||
8b787643 FF |
2357 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2358 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2359 | change = true; | |
ad4bb6f8 | 2360 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2361 | if (err) |
4c476991 | 2362 | return err; |
8b787643 FF |
2363 | } else { |
2364 | params.use_4addr = -1; | |
2365 | } | |
2366 | ||
92ffe055 | 2367 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2368 | if (ntype != NL80211_IFTYPE_MONITOR) |
2369 | return -EINVAL; | |
92ffe055 JB |
2370 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2371 | &_flags); | |
ac7f9cfa | 2372 | if (err) |
4c476991 | 2373 | return err; |
ac7f9cfa JB |
2374 | |
2375 | flags = &_flags; | |
2376 | change = true; | |
92ffe055 | 2377 | } |
3b85875a | 2378 | |
ac7f9cfa | 2379 | if (change) |
3d54d255 | 2380 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2381 | else |
2382 | err = 0; | |
60719ffd | 2383 | |
9bc383de JB |
2384 | if (!err && params.use_4addr != -1) |
2385 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2386 | ||
55682965 JB |
2387 | return err; |
2388 | } | |
2389 | ||
2390 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2391 | { | |
4c476991 | 2392 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2393 | struct vif_params params; |
84efbb84 | 2394 | struct wireless_dev *wdev; |
1c90f9d4 | 2395 | struct sk_buff *msg; |
55682965 JB |
2396 | int err; |
2397 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2398 | u32 flags; |
55682965 | 2399 | |
2ec600d6 LCC |
2400 | memset(¶ms, 0, sizeof(params)); |
2401 | ||
55682965 JB |
2402 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2403 | return -EINVAL; | |
2404 | ||
2405 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2406 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2407 | if (type > NL80211_IFTYPE_MAX) | |
2408 | return -EINVAL; | |
2409 | } | |
2410 | ||
79c97e97 | 2411 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2412 | !(rdev->wiphy.interface_modes & (1 << type))) |
2413 | return -EOPNOTSUPP; | |
55682965 | 2414 | |
1c18f145 AS |
2415 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2416 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2417 | ETH_ALEN); | |
2418 | if (!is_valid_ether_addr(params.macaddr)) | |
2419 | return -EADDRNOTAVAIL; | |
2420 | } | |
2421 | ||
9bc383de | 2422 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2423 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2424 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2425 | if (err) |
4c476991 | 2426 | return err; |
9bc383de | 2427 | } |
8b787643 | 2428 | |
1c90f9d4 JB |
2429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2430 | if (!msg) | |
2431 | return -ENOMEM; | |
2432 | ||
66f7ac50 MW |
2433 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2434 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2435 | &flags); | |
e35e4d28 HG |
2436 | wdev = rdev_add_virtual_intf(rdev, |
2437 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2438 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2439 | if (IS_ERR(wdev)) { |
2440 | nlmsg_free(msg); | |
84efbb84 | 2441 | return PTR_ERR(wdev); |
1c90f9d4 | 2442 | } |
2ec600d6 | 2443 | |
98104fde JB |
2444 | switch (type) { |
2445 | case NL80211_IFTYPE_MESH_POINT: | |
2446 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2447 | break; | |
29cbe68c JB |
2448 | wdev_lock(wdev); |
2449 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2450 | IEEE80211_MAX_MESH_ID_LEN); | |
2451 | wdev->mesh_id_up_len = | |
2452 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2453 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2454 | wdev->mesh_id_up_len); | |
2455 | wdev_unlock(wdev); | |
98104fde JB |
2456 | break; |
2457 | case NL80211_IFTYPE_P2P_DEVICE: | |
2458 | /* | |
2459 | * P2P Device doesn't have a netdev, so doesn't go | |
2460 | * through the netdev notifier and must be added here | |
2461 | */ | |
2462 | mutex_init(&wdev->mtx); | |
2463 | INIT_LIST_HEAD(&wdev->event_list); | |
2464 | spin_lock_init(&wdev->event_lock); | |
2465 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2466 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2467 | ||
2468 | mutex_lock(&rdev->devlist_mtx); | |
2469 | wdev->identifier = ++rdev->wdev_id; | |
2470 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2471 | rdev->devlist_generation++; | |
2472 | mutex_unlock(&rdev->devlist_mtx); | |
2473 | break; | |
2474 | default: | |
2475 | break; | |
29cbe68c JB |
2476 | } |
2477 | ||
15e47304 | 2478 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2479 | rdev, wdev) < 0) { |
2480 | nlmsg_free(msg); | |
2481 | return -ENOBUFS; | |
2482 | } | |
2483 | ||
2484 | return genlmsg_reply(msg, info); | |
55682965 JB |
2485 | } |
2486 | ||
2487 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2488 | { | |
4c476991 | 2489 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2490 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2491 | |
4c476991 JB |
2492 | if (!rdev->ops->del_virtual_intf) |
2493 | return -EOPNOTSUPP; | |
55682965 | 2494 | |
84efbb84 JB |
2495 | /* |
2496 | * If we remove a wireless device without a netdev then clear | |
2497 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2498 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2499 | * since the wdev has been freed, unlike with a netdev where | |
2500 | * we need the dev_put() for the netdev to really be freed. | |
2501 | */ | |
2502 | if (!wdev->netdev) | |
2503 | info->user_ptr[1] = NULL; | |
2504 | ||
e35e4d28 | 2505 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2506 | } |
2507 | ||
1d9d9213 SW |
2508 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2509 | { | |
2510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2511 | struct net_device *dev = info->user_ptr[1]; | |
2512 | u16 noack_map; | |
2513 | ||
2514 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2515 | return -EINVAL; | |
2516 | ||
2517 | if (!rdev->ops->set_noack_map) | |
2518 | return -EOPNOTSUPP; | |
2519 | ||
2520 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2521 | ||
e35e4d28 | 2522 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2523 | } |
2524 | ||
41ade00f JB |
2525 | struct get_key_cookie { |
2526 | struct sk_buff *msg; | |
2527 | int error; | |
b9454e83 | 2528 | int idx; |
41ade00f JB |
2529 | }; |
2530 | ||
2531 | static void get_key_callback(void *c, struct key_params *params) | |
2532 | { | |
b9454e83 | 2533 | struct nlattr *key; |
41ade00f JB |
2534 | struct get_key_cookie *cookie = c; |
2535 | ||
9360ffd1 DM |
2536 | if ((params->key && |
2537 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2538 | params->key_len, params->key)) || | |
2539 | (params->seq && | |
2540 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2541 | params->seq_len, params->seq)) || | |
2542 | (params->cipher && | |
2543 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2544 | params->cipher))) | |
2545 | goto nla_put_failure; | |
41ade00f | 2546 | |
b9454e83 JB |
2547 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2548 | if (!key) | |
2549 | goto nla_put_failure; | |
2550 | ||
9360ffd1 DM |
2551 | if ((params->key && |
2552 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2553 | params->key_len, params->key)) || | |
2554 | (params->seq && | |
2555 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2556 | params->seq_len, params->seq)) || | |
2557 | (params->cipher && | |
2558 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2559 | params->cipher))) | |
2560 | goto nla_put_failure; | |
b9454e83 | 2561 | |
9360ffd1 DM |
2562 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2563 | goto nla_put_failure; | |
b9454e83 JB |
2564 | |
2565 | nla_nest_end(cookie->msg, key); | |
2566 | ||
41ade00f JB |
2567 | return; |
2568 | nla_put_failure: | |
2569 | cookie->error = 1; | |
2570 | } | |
2571 | ||
2572 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2573 | { | |
4c476991 | 2574 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2575 | int err; |
4c476991 | 2576 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2577 | u8 key_idx = 0; |
e31b8213 JB |
2578 | const u8 *mac_addr = NULL; |
2579 | bool pairwise; | |
41ade00f JB |
2580 | struct get_key_cookie cookie = { |
2581 | .error = 0, | |
2582 | }; | |
2583 | void *hdr; | |
2584 | struct sk_buff *msg; | |
2585 | ||
2586 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2587 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2588 | ||
3cfcf6ac | 2589 | if (key_idx > 5) |
41ade00f JB |
2590 | return -EINVAL; |
2591 | ||
2592 | if (info->attrs[NL80211_ATTR_MAC]) | |
2593 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2594 | ||
e31b8213 JB |
2595 | pairwise = !!mac_addr; |
2596 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2597 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2598 | if (kt >= NUM_NL80211_KEYTYPES) | |
2599 | return -EINVAL; | |
2600 | if (kt != NL80211_KEYTYPE_GROUP && | |
2601 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2602 | return -EINVAL; | |
2603 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2604 | } | |
2605 | ||
4c476991 JB |
2606 | if (!rdev->ops->get_key) |
2607 | return -EOPNOTSUPP; | |
41ade00f | 2608 | |
fd2120ca | 2609 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2610 | if (!msg) |
2611 | return -ENOMEM; | |
41ade00f | 2612 | |
15e47304 | 2613 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2614 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2615 | if (IS_ERR(hdr)) |
2616 | return PTR_ERR(hdr); | |
41ade00f JB |
2617 | |
2618 | cookie.msg = msg; | |
b9454e83 | 2619 | cookie.idx = key_idx; |
41ade00f | 2620 | |
9360ffd1 DM |
2621 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2622 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2623 | goto nla_put_failure; | |
2624 | if (mac_addr && | |
2625 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2626 | goto nla_put_failure; | |
41ade00f | 2627 | |
e31b8213 JB |
2628 | if (pairwise && mac_addr && |
2629 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2630 | return -ENOENT; | |
2631 | ||
e35e4d28 HG |
2632 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2633 | get_key_callback); | |
41ade00f JB |
2634 | |
2635 | if (err) | |
6c95e2a2 | 2636 | goto free_msg; |
41ade00f JB |
2637 | |
2638 | if (cookie.error) | |
2639 | goto nla_put_failure; | |
2640 | ||
2641 | genlmsg_end(msg, hdr); | |
4c476991 | 2642 | return genlmsg_reply(msg, info); |
41ade00f JB |
2643 | |
2644 | nla_put_failure: | |
2645 | err = -ENOBUFS; | |
6c95e2a2 | 2646 | free_msg: |
41ade00f | 2647 | nlmsg_free(msg); |
41ade00f JB |
2648 | return err; |
2649 | } | |
2650 | ||
2651 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2652 | { | |
4c476991 | 2653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2654 | struct key_parse key; |
41ade00f | 2655 | int err; |
4c476991 | 2656 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2657 | |
b9454e83 JB |
2658 | err = nl80211_parse_key(info, &key); |
2659 | if (err) | |
2660 | return err; | |
41ade00f | 2661 | |
b9454e83 | 2662 | if (key.idx < 0) |
41ade00f JB |
2663 | return -EINVAL; |
2664 | ||
b9454e83 JB |
2665 | /* only support setting default key */ |
2666 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2667 | return -EINVAL; |
2668 | ||
dbd2fd65 | 2669 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2670 | |
dbd2fd65 JB |
2671 | if (key.def) { |
2672 | if (!rdev->ops->set_default_key) { | |
2673 | err = -EOPNOTSUPP; | |
2674 | goto out; | |
2675 | } | |
41ade00f | 2676 | |
dbd2fd65 JB |
2677 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2678 | if (err) | |
2679 | goto out; | |
2680 | ||
e35e4d28 | 2681 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2682 | key.def_uni, key.def_multi); |
2683 | ||
2684 | if (err) | |
2685 | goto out; | |
fffd0934 | 2686 | |
3d23e349 | 2687 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2688 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2689 | #endif | |
2690 | } else { | |
2691 | if (key.def_uni || !key.def_multi) { | |
2692 | err = -EINVAL; | |
2693 | goto out; | |
2694 | } | |
2695 | ||
2696 | if (!rdev->ops->set_default_mgmt_key) { | |
2697 | err = -EOPNOTSUPP; | |
2698 | goto out; | |
2699 | } | |
2700 | ||
2701 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2702 | if (err) | |
2703 | goto out; | |
2704 | ||
e35e4d28 | 2705 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2706 | if (err) |
2707 | goto out; | |
2708 | ||
2709 | #ifdef CONFIG_CFG80211_WEXT | |
2710 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2711 | #endif |
dbd2fd65 JB |
2712 | } |
2713 | ||
2714 | out: | |
fffd0934 | 2715 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2716 | |
41ade00f JB |
2717 | return err; |
2718 | } | |
2719 | ||
2720 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2721 | { | |
4c476991 | 2722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2723 | int err; |
4c476991 | 2724 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2725 | struct key_parse key; |
e31b8213 | 2726 | const u8 *mac_addr = NULL; |
41ade00f | 2727 | |
b9454e83 JB |
2728 | err = nl80211_parse_key(info, &key); |
2729 | if (err) | |
2730 | return err; | |
41ade00f | 2731 | |
b9454e83 | 2732 | if (!key.p.key) |
41ade00f JB |
2733 | return -EINVAL; |
2734 | ||
41ade00f JB |
2735 | if (info->attrs[NL80211_ATTR_MAC]) |
2736 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2737 | ||
e31b8213 JB |
2738 | if (key.type == -1) { |
2739 | if (mac_addr) | |
2740 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2741 | else | |
2742 | key.type = NL80211_KEYTYPE_GROUP; | |
2743 | } | |
2744 | ||
2745 | /* for now */ | |
2746 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2747 | key.type != NL80211_KEYTYPE_GROUP) | |
2748 | return -EINVAL; | |
2749 | ||
4c476991 JB |
2750 | if (!rdev->ops->add_key) |
2751 | return -EOPNOTSUPP; | |
25e47c18 | 2752 | |
e31b8213 JB |
2753 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2754 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2755 | mac_addr)) | |
4c476991 | 2756 | return -EINVAL; |
41ade00f | 2757 | |
fffd0934 JB |
2758 | wdev_lock(dev->ieee80211_ptr); |
2759 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2760 | if (!err) | |
e35e4d28 HG |
2761 | err = rdev_add_key(rdev, dev, key.idx, |
2762 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2763 | mac_addr, &key.p); | |
fffd0934 | 2764 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2765 | |
41ade00f JB |
2766 | return err; |
2767 | } | |
2768 | ||
2769 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2770 | { | |
4c476991 | 2771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2772 | int err; |
4c476991 | 2773 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2774 | u8 *mac_addr = NULL; |
b9454e83 | 2775 | struct key_parse key; |
41ade00f | 2776 | |
b9454e83 JB |
2777 | err = nl80211_parse_key(info, &key); |
2778 | if (err) | |
2779 | return err; | |
41ade00f JB |
2780 | |
2781 | if (info->attrs[NL80211_ATTR_MAC]) | |
2782 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2783 | ||
e31b8213 JB |
2784 | if (key.type == -1) { |
2785 | if (mac_addr) | |
2786 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2787 | else | |
2788 | key.type = NL80211_KEYTYPE_GROUP; | |
2789 | } | |
2790 | ||
2791 | /* for now */ | |
2792 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2793 | key.type != NL80211_KEYTYPE_GROUP) | |
2794 | return -EINVAL; | |
2795 | ||
4c476991 JB |
2796 | if (!rdev->ops->del_key) |
2797 | return -EOPNOTSUPP; | |
41ade00f | 2798 | |
fffd0934 JB |
2799 | wdev_lock(dev->ieee80211_ptr); |
2800 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2801 | |
2802 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2803 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2804 | err = -ENOENT; | |
2805 | ||
fffd0934 | 2806 | if (!err) |
e35e4d28 HG |
2807 | err = rdev_del_key(rdev, dev, key.idx, |
2808 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2809 | mac_addr); | |
41ade00f | 2810 | |
3d23e349 | 2811 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2812 | if (!err) { |
b9454e83 | 2813 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2814 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2815 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2816 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2817 | } | |
2818 | #endif | |
fffd0934 | 2819 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2820 | |
41ade00f JB |
2821 | return err; |
2822 | } | |
2823 | ||
77765eaf VT |
2824 | /* This function returns an error or the number of nested attributes */ |
2825 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2826 | { | |
2827 | struct nlattr *attr; | |
2828 | int n_entries = 0, tmp; | |
2829 | ||
2830 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2831 | if (nla_len(attr) != ETH_ALEN) | |
2832 | return -EINVAL; | |
2833 | ||
2834 | n_entries++; | |
2835 | } | |
2836 | ||
2837 | return n_entries; | |
2838 | } | |
2839 | ||
2840 | /* | |
2841 | * This function parses ACL information and allocates memory for ACL data. | |
2842 | * On successful return, the calling function is responsible to free the | |
2843 | * ACL buffer returned by this function. | |
2844 | */ | |
2845 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2846 | struct genl_info *info) | |
2847 | { | |
2848 | enum nl80211_acl_policy acl_policy; | |
2849 | struct nlattr *attr; | |
2850 | struct cfg80211_acl_data *acl; | |
2851 | int i = 0, n_entries, tmp; | |
2852 | ||
2853 | if (!wiphy->max_acl_mac_addrs) | |
2854 | return ERR_PTR(-EOPNOTSUPP); | |
2855 | ||
2856 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2857 | return ERR_PTR(-EINVAL); | |
2858 | ||
2859 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2860 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2861 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2862 | return ERR_PTR(-EINVAL); | |
2863 | ||
2864 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2865 | return ERR_PTR(-EINVAL); | |
2866 | ||
2867 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2868 | if (n_entries < 0) | |
2869 | return ERR_PTR(n_entries); | |
2870 | ||
2871 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2872 | return ERR_PTR(-ENOTSUPP); | |
2873 | ||
2874 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2875 | GFP_KERNEL); | |
2876 | if (!acl) | |
2877 | return ERR_PTR(-ENOMEM); | |
2878 | ||
2879 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2880 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2881 | i++; | |
2882 | } | |
2883 | ||
2884 | acl->n_acl_entries = n_entries; | |
2885 | acl->acl_policy = acl_policy; | |
2886 | ||
2887 | return acl; | |
2888 | } | |
2889 | ||
2890 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2891 | { | |
2892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2893 | struct net_device *dev = info->user_ptr[1]; | |
2894 | struct cfg80211_acl_data *acl; | |
2895 | int err; | |
2896 | ||
2897 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2898 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2899 | return -EOPNOTSUPP; | |
2900 | ||
2901 | if (!dev->ieee80211_ptr->beacon_interval) | |
2902 | return -EINVAL; | |
2903 | ||
2904 | acl = parse_acl_data(&rdev->wiphy, info); | |
2905 | if (IS_ERR(acl)) | |
2906 | return PTR_ERR(acl); | |
2907 | ||
2908 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2909 | ||
2910 | kfree(acl); | |
2911 | ||
2912 | return err; | |
2913 | } | |
2914 | ||
8860020e JB |
2915 | static int nl80211_parse_beacon(struct genl_info *info, |
2916 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2917 | { |
8860020e | 2918 | bool haveinfo = false; |
ed1b6cc7 | 2919 | |
9946ecfb JM |
2920 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2921 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2922 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2923 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2924 | return -EINVAL; |
2925 | ||
8860020e | 2926 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2927 | |
ed1b6cc7 | 2928 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2929 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2930 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2931 | if (!bcn->head_len) | |
2932 | return -EINVAL; | |
2933 | haveinfo = true; | |
ed1b6cc7 JB |
2934 | } |
2935 | ||
2936 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2937 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2938 | bcn->tail_len = | |
ed1b6cc7 | 2939 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2940 | haveinfo = true; |
ed1b6cc7 JB |
2941 | } |
2942 | ||
4c476991 JB |
2943 | if (!haveinfo) |
2944 | return -EINVAL; | |
3b85875a | 2945 | |
9946ecfb | 2946 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2947 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2948 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2949 | } |
2950 | ||
2951 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2952 | bcn->proberesp_ies = |
9946ecfb | 2953 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2954 | bcn->proberesp_ies_len = |
9946ecfb JM |
2955 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2956 | } | |
2957 | ||
2958 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2959 | bcn->assocresp_ies = |
9946ecfb | 2960 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2961 | bcn->assocresp_ies_len = |
9946ecfb JM |
2962 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2963 | } | |
2964 | ||
00f740e1 | 2965 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2966 | bcn->probe_resp = |
00f740e1 | 2967 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2968 | bcn->probe_resp_len = |
00f740e1 AN |
2969 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2970 | } | |
2971 | ||
8860020e JB |
2972 | return 0; |
2973 | } | |
2974 | ||
46c1dd0c FF |
2975 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2976 | struct cfg80211_ap_settings *params) | |
2977 | { | |
2978 | struct wireless_dev *wdev; | |
2979 | bool ret = false; | |
2980 | ||
2981 | mutex_lock(&rdev->devlist_mtx); | |
2982 | ||
89a54e48 | 2983 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
2984 | if (wdev->iftype != NL80211_IFTYPE_AP && |
2985 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2986 | continue; | |
2987 | ||
683b6d3b | 2988 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
2989 | continue; |
2990 | ||
683b6d3b | 2991 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
2992 | ret = true; |
2993 | break; | |
2994 | } | |
2995 | ||
2996 | mutex_unlock(&rdev->devlist_mtx); | |
2997 | ||
2998 | return ret; | |
2999 | } | |
3000 | ||
e39e5b5e JM |
3001 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3002 | enum nl80211_auth_type auth_type, | |
3003 | enum nl80211_commands cmd) | |
3004 | { | |
3005 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3006 | return false; | |
3007 | ||
3008 | switch (cmd) { | |
3009 | case NL80211_CMD_AUTHENTICATE: | |
3010 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3011 | auth_type == NL80211_AUTHTYPE_SAE) | |
3012 | return false; | |
3013 | return true; | |
3014 | case NL80211_CMD_CONNECT: | |
3015 | case NL80211_CMD_START_AP: | |
3016 | /* SAE not supported yet */ | |
3017 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3018 | return false; | |
3019 | return true; | |
3020 | default: | |
3021 | return false; | |
3022 | } | |
3023 | } | |
3024 | ||
8860020e JB |
3025 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3026 | { | |
3027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3028 | struct net_device *dev = info->user_ptr[1]; | |
3029 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3030 | struct cfg80211_ap_settings params; | |
3031 | int err; | |
04f39047 | 3032 | u8 radar_detect_width = 0; |
8860020e JB |
3033 | |
3034 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3035 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3036 | return -EOPNOTSUPP; | |
3037 | ||
3038 | if (!rdev->ops->start_ap) | |
3039 | return -EOPNOTSUPP; | |
3040 | ||
3041 | if (wdev->beacon_interval) | |
3042 | return -EALREADY; | |
3043 | ||
3044 | memset(¶ms, 0, sizeof(params)); | |
3045 | ||
3046 | /* these are required for START_AP */ | |
3047 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3048 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3049 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3050 | return -EINVAL; | |
3051 | ||
3052 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
3053 | if (err) | |
3054 | return err; | |
3055 | ||
3056 | params.beacon_interval = | |
3057 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3058 | params.dtim_period = | |
3059 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3060 | ||
3061 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3062 | if (err) | |
3063 | return err; | |
3064 | ||
3065 | /* | |
3066 | * In theory, some of these attributes should be required here | |
3067 | * but since they were not used when the command was originally | |
3068 | * added, keep them optional for old user space programs to let | |
3069 | * them continue to work with drivers that do not need the | |
3070 | * additional information -- drivers must check! | |
3071 | */ | |
3072 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3073 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3074 | params.ssid_len = | |
3075 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3076 | if (params.ssid_len == 0 || | |
3077 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3078 | return -EINVAL; | |
3079 | } | |
3080 | ||
3081 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3082 | params.hidden_ssid = nla_get_u32( | |
3083 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3084 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3085 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3086 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3087 | return -EINVAL; | |
3088 | } | |
3089 | ||
3090 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3091 | ||
3092 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3093 | params.auth_type = nla_get_u32( | |
3094 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3095 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3096 | NL80211_CMD_START_AP)) | |
8860020e JB |
3097 | return -EINVAL; |
3098 | } else | |
3099 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3100 | ||
3101 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3102 | NL80211_MAX_NR_CIPHER_SUITES); | |
3103 | if (err) | |
3104 | return err; | |
3105 | ||
1b658f11 VT |
3106 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3107 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3108 | return -EOPNOTSUPP; | |
3109 | params.inactivity_timeout = nla_get_u16( | |
3110 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3111 | } | |
3112 | ||
53cabad7 JB |
3113 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3114 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3115 | return -EINVAL; | |
3116 | params.p2p_ctwindow = | |
3117 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3118 | if (params.p2p_ctwindow > 127) | |
3119 | return -EINVAL; | |
3120 | if (params.p2p_ctwindow != 0 && | |
3121 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3122 | return -EINVAL; | |
3123 | } | |
3124 | ||
3125 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3126 | u8 tmp; | |
3127 | ||
3128 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3129 | return -EINVAL; | |
3130 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3131 | if (tmp > 1) | |
3132 | return -EINVAL; | |
3133 | params.p2p_opp_ps = tmp; | |
3134 | if (params.p2p_opp_ps != 0 && | |
3135 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3136 | return -EINVAL; | |
3137 | } | |
3138 | ||
aa430da4 | 3139 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3140 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3141 | if (err) | |
3142 | return err; | |
3143 | } else if (wdev->preset_chandef.chan) { | |
3144 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3145 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3146 | return -EINVAL; |
3147 | ||
683b6d3b | 3148 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3149 | return -EINVAL; |
3150 | ||
04f39047 SW |
3151 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3152 | if (err < 0) | |
3153 | return err; | |
3154 | if (err) { | |
3155 | radar_detect_width = BIT(params.chandef.width); | |
3156 | params.radar_required = true; | |
3157 | } | |
3158 | ||
e4e32459 | 3159 | mutex_lock(&rdev->devlist_mtx); |
04f39047 SW |
3160 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3161 | params.chandef.chan, | |
3162 | CHAN_MODE_SHARED, | |
3163 | radar_detect_width); | |
e4e32459 MK |
3164 | mutex_unlock(&rdev->devlist_mtx); |
3165 | ||
3166 | if (err) | |
3167 | return err; | |
3168 | ||
77765eaf VT |
3169 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3170 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3171 | if (IS_ERR(params.acl)) | |
3172 | return PTR_ERR(params.acl); | |
3173 | } | |
3174 | ||
e35e4d28 | 3175 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3176 | if (!err) { |
683b6d3b | 3177 | wdev->preset_chandef = params.chandef; |
8860020e | 3178 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3179 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3180 | wdev->ssid_len = params.ssid_len; |
3181 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3182 | } |
77765eaf VT |
3183 | |
3184 | kfree(params.acl); | |
3185 | ||
56d1893d | 3186 | return err; |
ed1b6cc7 JB |
3187 | } |
3188 | ||
8860020e JB |
3189 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3190 | { | |
3191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3192 | struct net_device *dev = info->user_ptr[1]; | |
3193 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3194 | struct cfg80211_beacon_data params; | |
3195 | int err; | |
3196 | ||
3197 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3198 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3199 | return -EOPNOTSUPP; | |
3200 | ||
3201 | if (!rdev->ops->change_beacon) | |
3202 | return -EOPNOTSUPP; | |
3203 | ||
3204 | if (!wdev->beacon_interval) | |
3205 | return -EINVAL; | |
3206 | ||
3207 | err = nl80211_parse_beacon(info, ¶ms); | |
3208 | if (err) | |
3209 | return err; | |
3210 | ||
e35e4d28 | 3211 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3212 | } |
3213 | ||
3214 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3215 | { |
4c476991 JB |
3216 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3217 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3218 | |
60771780 | 3219 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3220 | } |
3221 | ||
5727ef1b JB |
3222 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3223 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3224 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3225 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3226 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3227 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3228 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3229 | }; |
3230 | ||
eccb8e8f | 3231 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3232 | enum nl80211_iftype iftype, |
eccb8e8f | 3233 | struct station_parameters *params) |
5727ef1b JB |
3234 | { |
3235 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3236 | struct nlattr *nla; |
5727ef1b JB |
3237 | int flag; |
3238 | ||
eccb8e8f JB |
3239 | /* |
3240 | * Try parsing the new attribute first so userspace | |
3241 | * can specify both for older kernels. | |
3242 | */ | |
3243 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3244 | if (nla) { | |
3245 | struct nl80211_sta_flag_update *sta_flags; | |
3246 | ||
3247 | sta_flags = nla_data(nla); | |
3248 | params->sta_flags_mask = sta_flags->mask; | |
3249 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3250 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3251 | if ((params->sta_flags_mask | |
3252 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3253 | return -EINVAL; | |
3254 | return 0; | |
3255 | } | |
3256 | ||
3257 | /* if present, parse the old attribute */ | |
5727ef1b | 3258 | |
eccb8e8f | 3259 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3260 | if (!nla) |
3261 | return 0; | |
3262 | ||
3263 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3264 | nla, sta_flags_policy)) | |
3265 | return -EINVAL; | |
3266 | ||
bdd3ae3d JB |
3267 | /* |
3268 | * Only allow certain flags for interface types so that | |
3269 | * other attributes are silently ignored. Remember that | |
3270 | * this is backward compatibility code with old userspace | |
3271 | * and shouldn't be hit in other cases anyway. | |
3272 | */ | |
3273 | switch (iftype) { | |
3274 | case NL80211_IFTYPE_AP: | |
3275 | case NL80211_IFTYPE_AP_VLAN: | |
3276 | case NL80211_IFTYPE_P2P_GO: | |
3277 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3278 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3279 | BIT(NL80211_STA_FLAG_WME) | | |
3280 | BIT(NL80211_STA_FLAG_MFP); | |
3281 | break; | |
3282 | case NL80211_IFTYPE_P2P_CLIENT: | |
3283 | case NL80211_IFTYPE_STATION: | |
3284 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3285 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3286 | break; | |
3287 | case NL80211_IFTYPE_MESH_POINT: | |
3288 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3289 | BIT(NL80211_STA_FLAG_MFP) | | |
3290 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3291 | default: | |
3292 | return -EINVAL; | |
3293 | } | |
5727ef1b | 3294 | |
3383b5a6 JB |
3295 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3296 | if (flags[flag]) { | |
eccb8e8f | 3297 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3298 | |
3383b5a6 JB |
3299 | /* no longer support new API additions in old API */ |
3300 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3301 | return -EINVAL; | |
3302 | } | |
3303 | } | |
3304 | ||
5727ef1b JB |
3305 | return 0; |
3306 | } | |
3307 | ||
c8dcfd8a FF |
3308 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3309 | int attr) | |
3310 | { | |
3311 | struct nlattr *rate; | |
8eb41c8d VK |
3312 | u32 bitrate; |
3313 | u16 bitrate_compat; | |
c8dcfd8a FF |
3314 | |
3315 | rate = nla_nest_start(msg, attr); | |
3316 | if (!rate) | |
db9c64cf | 3317 | return false; |
c8dcfd8a FF |
3318 | |
3319 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3320 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3321 | /* report 16-bit bitrate only if we can */ |
3322 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3323 | if (bitrate > 0 && |
3324 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3325 | return false; | |
3326 | if (bitrate_compat > 0 && | |
3327 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3328 | return false; | |
3329 | ||
3330 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3331 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3332 | return false; | |
3333 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3334 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3335 | return false; | |
3336 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3337 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3338 | return false; | |
3339 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3340 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3341 | return false; | |
3342 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3343 | return false; | |
3344 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3345 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3346 | return false; | |
3347 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3348 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3349 | return false; | |
3350 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3351 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3352 | return false; | |
3353 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3354 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3355 | return false; | |
3356 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3357 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3358 | return false; | |
3359 | } | |
c8dcfd8a FF |
3360 | |
3361 | nla_nest_end(msg, rate); | |
3362 | return true; | |
c8dcfd8a FF |
3363 | } |
3364 | ||
15e47304 | 3365 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3366 | int flags, |
3367 | struct cfg80211_registered_device *rdev, | |
3368 | struct net_device *dev, | |
98b62183 | 3369 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3370 | { |
3371 | void *hdr; | |
f4263c98 | 3372 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3373 | |
15e47304 | 3374 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3375 | if (!hdr) |
3376 | return -1; | |
3377 | ||
9360ffd1 DM |
3378 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3379 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3380 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3381 | goto nla_put_failure; | |
f5ea9120 | 3382 | |
2ec600d6 LCC |
3383 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3384 | if (!sinfoattr) | |
fd5b74dc | 3385 | goto nla_put_failure; |
9360ffd1 DM |
3386 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3387 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3388 | sinfo->connected_time)) | |
3389 | goto nla_put_failure; | |
3390 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3391 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3392 | sinfo->inactive_time)) | |
3393 | goto nla_put_failure; | |
42745e03 VK |
3394 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3395 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3396 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3397 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3398 | goto nla_put_failure; |
42745e03 VK |
3399 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
3400 | NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3401 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3402 | (u32)sinfo->tx_bytes)) |
3403 | goto nla_put_failure; | |
3404 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3405 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3406 | sinfo->rx_bytes)) | |
3407 | goto nla_put_failure; | |
3408 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3409 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3410 | sinfo->tx_bytes)) |
3411 | goto nla_put_failure; | |
3412 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3413 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3414 | goto nla_put_failure; | |
3415 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3416 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3417 | goto nla_put_failure; | |
3418 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3419 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3420 | sinfo->plink_state)) | |
3421 | goto nla_put_failure; | |
66266b3a JL |
3422 | switch (rdev->wiphy.signal_type) { |
3423 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3424 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3425 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3426 | sinfo->signal)) | |
3427 | goto nla_put_failure; | |
3428 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3429 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3430 | sinfo->signal_avg)) | |
3431 | goto nla_put_failure; | |
66266b3a JL |
3432 | break; |
3433 | default: | |
3434 | break; | |
3435 | } | |
420e7fab | 3436 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3437 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3438 | NL80211_STA_INFO_TX_BITRATE)) | |
3439 | goto nla_put_failure; | |
3440 | } | |
3441 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3442 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3443 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3444 | goto nla_put_failure; |
420e7fab | 3445 | } |
9360ffd1 DM |
3446 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3447 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3448 | sinfo->rx_packets)) | |
3449 | goto nla_put_failure; | |
3450 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3451 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3452 | sinfo->tx_packets)) | |
3453 | goto nla_put_failure; | |
3454 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3455 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3456 | sinfo->tx_retries)) | |
3457 | goto nla_put_failure; | |
3458 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3459 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3460 | sinfo->tx_failed)) | |
3461 | goto nla_put_failure; | |
3462 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3463 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3464 | sinfo->beacon_loss_count)) | |
3465 | goto nla_put_failure; | |
3b1c5a53 MP |
3466 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3467 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3468 | sinfo->local_pm)) | |
3469 | goto nla_put_failure; | |
3470 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3471 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3472 | sinfo->peer_pm)) | |
3473 | goto nla_put_failure; | |
3474 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3475 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3476 | sinfo->nonpeer_pm)) | |
3477 | goto nla_put_failure; | |
f4263c98 PS |
3478 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3479 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3480 | if (!bss_param) | |
3481 | goto nla_put_failure; | |
3482 | ||
9360ffd1 DM |
3483 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3484 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3485 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3486 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3487 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3488 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3489 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3490 | sinfo->bss_param.dtim_period) || | |
3491 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3492 | sinfo->bss_param.beacon_interval)) | |
3493 | goto nla_put_failure; | |
f4263c98 PS |
3494 | |
3495 | nla_nest_end(msg, bss_param); | |
3496 | } | |
9360ffd1 DM |
3497 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3498 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3499 | sizeof(struct nl80211_sta_flag_update), | |
3500 | &sinfo->sta_flags)) | |
3501 | goto nla_put_failure; | |
7eab0f64 JL |
3502 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3503 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3504 | sinfo->t_offset)) | |
3505 | goto nla_put_failure; | |
2ec600d6 | 3506 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3507 | |
9360ffd1 DM |
3508 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3509 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3510 | sinfo->assoc_req_ies)) | |
3511 | goto nla_put_failure; | |
50d3dfb7 | 3512 | |
fd5b74dc JB |
3513 | return genlmsg_end(msg, hdr); |
3514 | ||
3515 | nla_put_failure: | |
bc3ed28c TG |
3516 | genlmsg_cancel(msg, hdr); |
3517 | return -EMSGSIZE; | |
fd5b74dc JB |
3518 | } |
3519 | ||
2ec600d6 | 3520 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3521 | struct netlink_callback *cb) |
2ec600d6 | 3522 | { |
2ec600d6 LCC |
3523 | struct station_info sinfo; |
3524 | struct cfg80211_registered_device *dev; | |
bba95fef | 3525 | struct net_device *netdev; |
2ec600d6 | 3526 | u8 mac_addr[ETH_ALEN]; |
bba95fef | 3527 | int sta_idx = cb->args[1]; |
2ec600d6 | 3528 | int err; |
2ec600d6 | 3529 | |
67748893 JB |
3530 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3531 | if (err) | |
3532 | return err; | |
bba95fef JB |
3533 | |
3534 | if (!dev->ops->dump_station) { | |
eec60b03 | 3535 | err = -EOPNOTSUPP; |
bba95fef JB |
3536 | goto out_err; |
3537 | } | |
3538 | ||
bba95fef | 3539 | while (1) { |
f612cedf | 3540 | memset(&sinfo, 0, sizeof(sinfo)); |
e35e4d28 HG |
3541 | err = rdev_dump_station(dev, netdev, sta_idx, |
3542 | mac_addr, &sinfo); | |
bba95fef JB |
3543 | if (err == -ENOENT) |
3544 | break; | |
3545 | if (err) | |
3b85875a | 3546 | goto out_err; |
bba95fef JB |
3547 | |
3548 | if (nl80211_send_station(skb, | |
15e47304 | 3549 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3550 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
66266b3a | 3551 | dev, netdev, mac_addr, |
bba95fef JB |
3552 | &sinfo) < 0) |
3553 | goto out; | |
3554 | ||
3555 | sta_idx++; | |
3556 | } | |
3557 | ||
3558 | ||
3559 | out: | |
3560 | cb->args[1] = sta_idx; | |
3561 | err = skb->len; | |
bba95fef | 3562 | out_err: |
67748893 | 3563 | nl80211_finish_netdev_dump(dev); |
bba95fef JB |
3564 | |
3565 | return err; | |
2ec600d6 | 3566 | } |
fd5b74dc | 3567 | |
5727ef1b JB |
3568 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3569 | { | |
4c476991 JB |
3570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3571 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3572 | struct station_info sinfo; |
fd5b74dc JB |
3573 | struct sk_buff *msg; |
3574 | u8 *mac_addr = NULL; | |
4c476991 | 3575 | int err; |
fd5b74dc | 3576 | |
2ec600d6 | 3577 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3578 | |
3579 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3580 | return -EINVAL; | |
3581 | ||
3582 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3583 | ||
4c476991 JB |
3584 | if (!rdev->ops->get_station) |
3585 | return -EOPNOTSUPP; | |
3b85875a | 3586 | |
e35e4d28 | 3587 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3588 | if (err) |
4c476991 | 3589 | return err; |
2ec600d6 | 3590 | |
fd2120ca | 3591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3592 | if (!msg) |
4c476991 | 3593 | return -ENOMEM; |
fd5b74dc | 3594 | |
15e47304 | 3595 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3596 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3597 | nlmsg_free(msg); |
3598 | return -ENOBUFS; | |
3599 | } | |
3b85875a | 3600 | |
4c476991 | 3601 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3602 | } |
3603 | ||
77ee7c89 JB |
3604 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3605 | struct station_parameters *params, | |
3606 | enum cfg80211_station_type statype) | |
3607 | { | |
3608 | if (params->listen_interval != -1) | |
3609 | return -EINVAL; | |
3610 | if (params->aid) | |
3611 | return -EINVAL; | |
3612 | ||
3613 | /* When you run into this, adjust the code below for the new flag */ | |
3614 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3615 | ||
3616 | switch (statype) { | |
3617 | case CFG80211_STA_MESH_PEER_NONSEC: | |
3618 | case CFG80211_STA_MESH_PEER_SECURE: | |
3619 | /* | |
3620 | * No ignoring the TDLS flag here -- the userspace mesh | |
3621 | * code doesn't have the bug of including TDLS in the | |
3622 | * mask everywhere. | |
3623 | */ | |
3624 | if (params->sta_flags_mask & | |
3625 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3626 | BIT(NL80211_STA_FLAG_MFP) | | |
3627 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3628 | return -EINVAL; | |
3629 | break; | |
3630 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3631 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3632 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3633 | return -EINVAL; | |
3634 | /* ignore since it can't change */ | |
3635 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3636 | break; | |
3637 | default: | |
3638 | /* disallow mesh-specific things */ | |
3639 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3640 | return -EINVAL; | |
3641 | if (params->local_pm) | |
3642 | return -EINVAL; | |
3643 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3644 | return -EINVAL; | |
3645 | } | |
3646 | ||
3647 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3648 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3649 | /* TDLS can't be set, ... */ | |
3650 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3651 | return -EINVAL; | |
3652 | /* | |
3653 | * ... but don't bother the driver with it. This works around | |
3654 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3655 | * TLDS_PEER flag in the mask even for AP mode. | |
3656 | */ | |
3657 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3658 | } | |
3659 | ||
3660 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3661 | /* reject other things that can't change */ | |
3662 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3663 | return -EINVAL; | |
3664 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3665 | return -EINVAL; | |
3666 | if (params->supported_rates) | |
3667 | return -EINVAL; | |
3668 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3669 | return -EINVAL; | |
3670 | } | |
3671 | ||
3672 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3673 | if (params->vlan) | |
3674 | return -EINVAL; | |
3675 | } | |
3676 | ||
3677 | switch (statype) { | |
3678 | case CFG80211_STA_AP_MLME_CLIENT: | |
3679 | /* Use this only for authorizing/unauthorizing a station */ | |
3680 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3681 | return -EOPNOTSUPP; | |
3682 | break; | |
3683 | case CFG80211_STA_AP_CLIENT: | |
3684 | /* accept only the listed bits */ | |
3685 | if (params->sta_flags_mask & | |
3686 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3687 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3688 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3689 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3690 | BIT(NL80211_STA_FLAG_WME) | | |
3691 | BIT(NL80211_STA_FLAG_MFP))) | |
3692 | return -EINVAL; | |
3693 | ||
3694 | /* but authenticated/associated only if driver handles it */ | |
3695 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3696 | params->sta_flags_mask & | |
3697 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3698 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3699 | return -EINVAL; | |
3700 | break; | |
3701 | case CFG80211_STA_IBSS: | |
3702 | case CFG80211_STA_AP_STA: | |
3703 | /* reject any changes other than AUTHORIZED */ | |
3704 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3705 | return -EINVAL; | |
3706 | break; | |
3707 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3708 | /* reject any changes other than AUTHORIZED or WME */ | |
3709 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3710 | BIT(NL80211_STA_FLAG_WME))) | |
3711 | return -EINVAL; | |
3712 | /* force (at least) rates when authorizing */ | |
3713 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3714 | !params->supported_rates) | |
3715 | return -EINVAL; | |
3716 | break; | |
3717 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3718 | /* reject any changes */ | |
3719 | return -EINVAL; | |
3720 | case CFG80211_STA_MESH_PEER_NONSEC: | |
3721 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3722 | return -EINVAL; | |
3723 | break; | |
3724 | case CFG80211_STA_MESH_PEER_SECURE: | |
3725 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3726 | return -EINVAL; | |
3727 | break; | |
3728 | } | |
3729 | ||
3730 | return 0; | |
3731 | } | |
3732 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3733 | ||
5727ef1b | 3734 | /* |
c258d2de | 3735 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3736 | */ |
80b99899 JB |
3737 | static struct net_device *get_vlan(struct genl_info *info, |
3738 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3739 | { |
463d0183 | 3740 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3741 | struct net_device *v; |
3742 | int ret; | |
3743 | ||
3744 | if (!vlanattr) | |
3745 | return NULL; | |
3746 | ||
3747 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3748 | if (!v) | |
3749 | return ERR_PTR(-ENODEV); | |
3750 | ||
3751 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3752 | ret = -EINVAL; | |
3753 | goto error; | |
5727ef1b | 3754 | } |
80b99899 | 3755 | |
77ee7c89 JB |
3756 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3757 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3758 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3759 | ret = -EINVAL; | |
3760 | goto error; | |
3761 | } | |
3762 | ||
80b99899 JB |
3763 | if (!netif_running(v)) { |
3764 | ret = -ENETDOWN; | |
3765 | goto error; | |
3766 | } | |
3767 | ||
3768 | return v; | |
3769 | error: | |
3770 | dev_put(v); | |
3771 | return ERR_PTR(ret); | |
5727ef1b JB |
3772 | } |
3773 | ||
df881293 JM |
3774 | static struct nla_policy |
3775 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3776 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3777 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3778 | }; | |
3779 | ||
ff276691 JB |
3780 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3781 | struct station_parameters *params) | |
df881293 | 3782 | { |
df881293 JM |
3783 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3784 | struct nlattr *nla; | |
3785 | int err; | |
3786 | ||
df881293 JM |
3787 | /* parse WME attributes if present */ |
3788 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3789 | return 0; | |
3790 | ||
3791 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3792 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3793 | nl80211_sta_wme_policy); | |
3794 | if (err) | |
3795 | return err; | |
3796 | ||
3797 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3798 | params->uapsd_queues = nla_get_u8( | |
3799 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3800 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3801 | return -EINVAL; | |
3802 | ||
3803 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3804 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3805 | ||
3806 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3807 | return -EINVAL; | |
3808 | ||
3809 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3810 | ||
3811 | return 0; | |
3812 | } | |
3813 | ||
ff276691 JB |
3814 | static int nl80211_set_station_tdls(struct genl_info *info, |
3815 | struct station_parameters *params) | |
3816 | { | |
3817 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
3818 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | |
3819 | params->ht_capa = | |
3820 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3821 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3822 | params->vht_capa = | |
3823 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3824 | ||
3825 | return nl80211_parse_sta_wme(info, params); | |
3826 | } | |
3827 | ||
5727ef1b JB |
3828 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3829 | { | |
4c476991 | 3830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3831 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3832 | struct station_parameters params; |
77ee7c89 JB |
3833 | u8 *mac_addr; |
3834 | int err; | |
5727ef1b JB |
3835 | |
3836 | memset(¶ms, 0, sizeof(params)); | |
3837 | ||
3838 | params.listen_interval = -1; | |
3839 | ||
77ee7c89 JB |
3840 | if (!rdev->ops->change_station) |
3841 | return -EOPNOTSUPP; | |
3842 | ||
5727ef1b JB |
3843 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3844 | return -EINVAL; | |
3845 | ||
3846 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3847 | return -EINVAL; | |
3848 | ||
3849 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3850 | ||
3851 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3852 | params.supported_rates = | |
3853 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3854 | params.supported_rates_len = | |
3855 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3856 | } | |
3857 | ||
9d62a986 JM |
3858 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3859 | params.capability = | |
3860 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3861 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3862 | } | |
3863 | ||
3864 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3865 | params.ext_capab = | |
3866 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3867 | params.ext_capab_len = | |
3868 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3869 | } | |
3870 | ||
df881293 | 3871 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3872 | return -EINVAL; |
36aedc90 | 3873 | |
bdd3ae3d | 3874 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3875 | return -EINVAL; |
3876 | ||
f8bacc21 | 3877 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3878 | params.plink_action = |
f8bacc21 JB |
3879 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3880 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3881 | return -EINVAL; | |
3882 | } | |
2ec600d6 | 3883 | |
f8bacc21 | 3884 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3885 | params.plink_state = |
f8bacc21 JB |
3886 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3887 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3888 | return -EINVAL; | |
3889 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3890 | } | |
9c3990aa | 3891 | |
3b1c5a53 MP |
3892 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3893 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3894 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3895 | ||
3896 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3897 | pm > NL80211_MESH_POWER_MAX) | |
3898 | return -EINVAL; | |
3899 | ||
3900 | params.local_pm = pm; | |
3901 | } | |
3902 | ||
77ee7c89 JB |
3903 | /* Include parameters for TDLS peer (will check later) */ |
3904 | err = nl80211_set_station_tdls(info, ¶ms); | |
3905 | if (err) | |
3906 | return err; | |
3907 | ||
3908 | params.vlan = get_vlan(info, rdev); | |
3909 | if (IS_ERR(params.vlan)) | |
3910 | return PTR_ERR(params.vlan); | |
3911 | ||
a97f4424 JB |
3912 | switch (dev->ieee80211_ptr->iftype) { |
3913 | case NL80211_IFTYPE_AP: | |
3914 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3915 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3916 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3917 | case NL80211_IFTYPE_STATION: |
267335d6 | 3918 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3919 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3920 | break; |
3921 | default: | |
77ee7c89 JB |
3922 | err = -EOPNOTSUPP; |
3923 | goto out_put_vlan; | |
034d655e JB |
3924 | } |
3925 | ||
77ee7c89 | 3926 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 3927 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3928 | |
77ee7c89 | 3929 | out_put_vlan: |
5727ef1b JB |
3930 | if (params.vlan) |
3931 | dev_put(params.vlan); | |
3b85875a | 3932 | |
5727ef1b JB |
3933 | return err; |
3934 | } | |
3935 | ||
3936 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
3937 | { | |
4c476991 | 3938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3939 | int err; |
4c476991 | 3940 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3941 | struct station_parameters params; |
3942 | u8 *mac_addr = NULL; | |
3943 | ||
3944 | memset(¶ms, 0, sizeof(params)); | |
3945 | ||
984c311b JB |
3946 | if (!rdev->ops->add_station) |
3947 | return -EOPNOTSUPP; | |
3948 | ||
5727ef1b JB |
3949 | if (!info->attrs[NL80211_ATTR_MAC]) |
3950 | return -EINVAL; | |
3951 | ||
5727ef1b JB |
3952 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3953 | return -EINVAL; | |
3954 | ||
3955 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3956 | return -EINVAL; | |
3957 | ||
0e956c13 TLSC |
3958 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
3959 | return -EINVAL; | |
3960 | ||
5727ef1b JB |
3961 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3962 | params.supported_rates = | |
3963 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3964 | params.supported_rates_len = | |
3965 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3966 | params.listen_interval = | |
3967 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3968 | |
0e956c13 TLSC |
3969 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
3970 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
3971 | return -EINVAL; | |
51b50fbe | 3972 | |
9d62a986 JM |
3973 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3974 | params.capability = | |
3975 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3976 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3977 | } | |
3978 | ||
3979 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3980 | params.ext_capab = | |
3981 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3982 | params.ext_capab_len = | |
3983 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3984 | } | |
3985 | ||
36aedc90 JM |
3986 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3987 | params.ht_capa = | |
3988 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 3989 | |
f461be3e MP |
3990 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
3991 | params.vht_capa = | |
3992 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3993 | ||
f8bacc21 | 3994 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 3995 | params.plink_action = |
f8bacc21 JB |
3996 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3997 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3998 | return -EINVAL; | |
3999 | } | |
96b78dff | 4000 | |
ff276691 JB |
4001 | err = nl80211_parse_sta_wme(info, ¶ms); |
4002 | if (err) | |
4003 | return err; | |
bdd90d5e | 4004 | |
bdd3ae3d | 4005 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4006 | return -EINVAL; |
4007 | ||
77ee7c89 JB |
4008 | /* When you run into this, adjust the code below for the new flag */ |
4009 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4010 | ||
bdd90d5e JB |
4011 | switch (dev->ieee80211_ptr->iftype) { |
4012 | case NL80211_IFTYPE_AP: | |
4013 | case NL80211_IFTYPE_AP_VLAN: | |
4014 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4015 | /* ignore WME attributes if iface/sta is not capable */ |
4016 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4017 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4018 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4019 | |
bdd90d5e JB |
4020 | /* TDLS peers cannot be added */ |
4021 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 4022 | return -EINVAL; |
bdd90d5e JB |
4023 | /* but don't bother the driver with it */ |
4024 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4025 | |
d582cffb JB |
4026 | /* allow authenticated/associated only if driver handles it */ |
4027 | if (!(rdev->wiphy.features & | |
4028 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4029 | params.sta_flags_mask & | |
4030 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4031 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4032 | return -EINVAL; | |
4033 | ||
bdd90d5e JB |
4034 | /* must be last in here for error handling */ |
4035 | params.vlan = get_vlan(info, rdev); | |
4036 | if (IS_ERR(params.vlan)) | |
4037 | return PTR_ERR(params.vlan); | |
4038 | break; | |
4039 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4040 | /* ignore uAPSD data */ |
4041 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4042 | ||
d582cffb JB |
4043 | /* associated is disallowed */ |
4044 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4045 | return -EINVAL; | |
bdd90d5e JB |
4046 | /* TDLS peers cannot be added */ |
4047 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4048 | return -EINVAL; | |
4049 | break; | |
4050 | case NL80211_IFTYPE_STATION: | |
984c311b JB |
4051 | /* ignore uAPSD data */ |
4052 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4053 | ||
77ee7c89 JB |
4054 | /* these are disallowed */ |
4055 | if (params.sta_flags_mask & | |
4056 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4057 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4058 | return -EINVAL; |
bdd90d5e JB |
4059 | /* Only TDLS peers can be added */ |
4060 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4061 | return -EINVAL; | |
4062 | /* Can only add if TDLS ... */ | |
4063 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4064 | return -EOPNOTSUPP; | |
4065 | /* ... with external setup is supported */ | |
4066 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4067 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4068 | /* |
4069 | * Older wpa_supplicant versions always mark the TDLS peer | |
4070 | * as authorized, but it shouldn't yet be. | |
4071 | */ | |
4072 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4073 | break; |
4074 | default: | |
4075 | return -EOPNOTSUPP; | |
c75786c9 EP |
4076 | } |
4077 | ||
bdd90d5e | 4078 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4079 | |
e35e4d28 | 4080 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4081 | |
5727ef1b JB |
4082 | if (params.vlan) |
4083 | dev_put(params.vlan); | |
5727ef1b JB |
4084 | return err; |
4085 | } | |
4086 | ||
4087 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4088 | { | |
4c476991 JB |
4089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4090 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4091 | u8 *mac_addr = NULL; |
4092 | ||
4093 | if (info->attrs[NL80211_ATTR_MAC]) | |
4094 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4095 | ||
e80cf853 | 4096 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4097 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4099 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4100 | return -EINVAL; | |
5727ef1b | 4101 | |
4c476991 JB |
4102 | if (!rdev->ops->del_station) |
4103 | return -EOPNOTSUPP; | |
3b85875a | 4104 | |
e35e4d28 | 4105 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4106 | } |
4107 | ||
15e47304 | 4108 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4109 | int flags, struct net_device *dev, |
4110 | u8 *dst, u8 *next_hop, | |
4111 | struct mpath_info *pinfo) | |
4112 | { | |
4113 | void *hdr; | |
4114 | struct nlattr *pinfoattr; | |
4115 | ||
15e47304 | 4116 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4117 | if (!hdr) |
4118 | return -1; | |
4119 | ||
9360ffd1 DM |
4120 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4121 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4122 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4123 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4124 | goto nla_put_failure; | |
f5ea9120 | 4125 | |
2ec600d6 LCC |
4126 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4127 | if (!pinfoattr) | |
4128 | goto nla_put_failure; | |
9360ffd1 DM |
4129 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4130 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4131 | pinfo->frame_qlen)) | |
4132 | goto nla_put_failure; | |
4133 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4134 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4135 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4136 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4137 | pinfo->metric)) || | |
4138 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4139 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4140 | pinfo->exptime)) || | |
4141 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4142 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4143 | pinfo->flags)) || | |
4144 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4145 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4146 | pinfo->discovery_timeout)) || | |
4147 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4148 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4149 | pinfo->discovery_retries))) | |
4150 | goto nla_put_failure; | |
2ec600d6 LCC |
4151 | |
4152 | nla_nest_end(msg, pinfoattr); | |
4153 | ||
4154 | return genlmsg_end(msg, hdr); | |
4155 | ||
4156 | nla_put_failure: | |
bc3ed28c TG |
4157 | genlmsg_cancel(msg, hdr); |
4158 | return -EMSGSIZE; | |
2ec600d6 LCC |
4159 | } |
4160 | ||
4161 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4162 | struct netlink_callback *cb) |
2ec600d6 | 4163 | { |
2ec600d6 LCC |
4164 | struct mpath_info pinfo; |
4165 | struct cfg80211_registered_device *dev; | |
bba95fef | 4166 | struct net_device *netdev; |
2ec600d6 LCC |
4167 | u8 dst[ETH_ALEN]; |
4168 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 4169 | int path_idx = cb->args[1]; |
2ec600d6 | 4170 | int err; |
2ec600d6 | 4171 | |
67748893 JB |
4172 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
4173 | if (err) | |
4174 | return err; | |
bba95fef JB |
4175 | |
4176 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4177 | err = -EOPNOTSUPP; |
bba95fef JB |
4178 | goto out_err; |
4179 | } | |
4180 | ||
eec60b03 JM |
4181 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
4182 | err = -EOPNOTSUPP; | |
0448b5fc | 4183 | goto out_err; |
eec60b03 JM |
4184 | } |
4185 | ||
bba95fef | 4186 | while (1) { |
e35e4d28 HG |
4187 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
4188 | &pinfo); | |
bba95fef | 4189 | if (err == -ENOENT) |
2ec600d6 | 4190 | break; |
bba95fef | 4191 | if (err) |
3b85875a | 4192 | goto out_err; |
2ec600d6 | 4193 | |
15e47304 | 4194 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef JB |
4195 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
4196 | netdev, dst, next_hop, | |
4197 | &pinfo) < 0) | |
4198 | goto out; | |
2ec600d6 | 4199 | |
bba95fef | 4200 | path_idx++; |
2ec600d6 | 4201 | } |
2ec600d6 | 4202 | |
2ec600d6 | 4203 | |
bba95fef JB |
4204 | out: |
4205 | cb->args[1] = path_idx; | |
4206 | err = skb->len; | |
bba95fef | 4207 | out_err: |
67748893 | 4208 | nl80211_finish_netdev_dump(dev); |
bba95fef | 4209 | return err; |
2ec600d6 LCC |
4210 | } |
4211 | ||
4212 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4213 | { | |
4c476991 | 4214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4215 | int err; |
4c476991 | 4216 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4217 | struct mpath_info pinfo; |
4218 | struct sk_buff *msg; | |
4219 | u8 *dst = NULL; | |
4220 | u8 next_hop[ETH_ALEN]; | |
4221 | ||
4222 | memset(&pinfo, 0, sizeof(pinfo)); | |
4223 | ||
4224 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4225 | return -EINVAL; | |
4226 | ||
4227 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4228 | ||
4c476991 JB |
4229 | if (!rdev->ops->get_mpath) |
4230 | return -EOPNOTSUPP; | |
2ec600d6 | 4231 | |
4c476991 JB |
4232 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4233 | return -EOPNOTSUPP; | |
eec60b03 | 4234 | |
e35e4d28 | 4235 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4236 | if (err) |
4c476991 | 4237 | return err; |
2ec600d6 | 4238 | |
fd2120ca | 4239 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4240 | if (!msg) |
4c476991 | 4241 | return -ENOMEM; |
2ec600d6 | 4242 | |
15e47304 | 4243 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4244 | dev, dst, next_hop, &pinfo) < 0) { |
4245 | nlmsg_free(msg); | |
4246 | return -ENOBUFS; | |
4247 | } | |
3b85875a | 4248 | |
4c476991 | 4249 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4250 | } |
4251 | ||
4252 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4253 | { | |
4c476991 JB |
4254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4255 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4256 | u8 *dst = NULL; |
4257 | u8 *next_hop = NULL; | |
4258 | ||
4259 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4260 | return -EINVAL; | |
4261 | ||
4262 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4263 | return -EINVAL; | |
4264 | ||
4265 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4266 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4267 | ||
4c476991 JB |
4268 | if (!rdev->ops->change_mpath) |
4269 | return -EOPNOTSUPP; | |
35a8efe1 | 4270 | |
4c476991 JB |
4271 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4272 | return -EOPNOTSUPP; | |
2ec600d6 | 4273 | |
e35e4d28 | 4274 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4275 | } |
4c476991 | 4276 | |
2ec600d6 LCC |
4277 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4278 | { | |
4c476991 JB |
4279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4280 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4281 | u8 *dst = NULL; |
4282 | u8 *next_hop = NULL; | |
4283 | ||
4284 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4285 | return -EINVAL; | |
4286 | ||
4287 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4288 | return -EINVAL; | |
4289 | ||
4290 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4291 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4292 | ||
4c476991 JB |
4293 | if (!rdev->ops->add_mpath) |
4294 | return -EOPNOTSUPP; | |
35a8efe1 | 4295 | |
4c476991 JB |
4296 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4297 | return -EOPNOTSUPP; | |
2ec600d6 | 4298 | |
e35e4d28 | 4299 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4300 | } |
4301 | ||
4302 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4303 | { | |
4c476991 JB |
4304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4305 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4306 | u8 *dst = NULL; |
4307 | ||
4308 | if (info->attrs[NL80211_ATTR_MAC]) | |
4309 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4310 | ||
4c476991 JB |
4311 | if (!rdev->ops->del_mpath) |
4312 | return -EOPNOTSUPP; | |
3b85875a | 4313 | |
e35e4d28 | 4314 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4315 | } |
4316 | ||
9f1ba906 JM |
4317 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4318 | { | |
4c476991 JB |
4319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4320 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4321 | struct bss_parameters params; |
4322 | ||
4323 | memset(¶ms, 0, sizeof(params)); | |
4324 | /* default to not changing parameters */ | |
4325 | params.use_cts_prot = -1; | |
4326 | params.use_short_preamble = -1; | |
4327 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4328 | params.ap_isolate = -1; |
50b12f59 | 4329 | params.ht_opmode = -1; |
53cabad7 JB |
4330 | params.p2p_ctwindow = -1; |
4331 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4332 | |
4333 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4334 | params.use_cts_prot = | |
4335 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4336 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4337 | params.use_short_preamble = | |
4338 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4339 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4340 | params.use_short_slot_time = | |
4341 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4342 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4343 | params.basic_rates = | |
4344 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4345 | params.basic_rates_len = | |
4346 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4347 | } | |
fd8aaaf3 FF |
4348 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4349 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4350 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4351 | params.ht_opmode = | |
4352 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4353 | |
53cabad7 JB |
4354 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4355 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4356 | return -EINVAL; | |
4357 | params.p2p_ctwindow = | |
4358 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4359 | if (params.p2p_ctwindow < 0) | |
4360 | return -EINVAL; | |
4361 | if (params.p2p_ctwindow != 0 && | |
4362 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4363 | return -EINVAL; | |
4364 | } | |
4365 | ||
4366 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4367 | u8 tmp; | |
4368 | ||
4369 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4370 | return -EINVAL; | |
4371 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4372 | if (tmp > 1) | |
4373 | return -EINVAL; | |
4374 | params.p2p_opp_ps = tmp; | |
4375 | if (params.p2p_opp_ps && | |
4376 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4377 | return -EINVAL; | |
4378 | } | |
4379 | ||
4c476991 JB |
4380 | if (!rdev->ops->change_bss) |
4381 | return -EOPNOTSUPP; | |
9f1ba906 | 4382 | |
074ac8df | 4383 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4384 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4385 | return -EOPNOTSUPP; | |
3b85875a | 4386 | |
e35e4d28 | 4387 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4388 | } |
4389 | ||
b54452b0 | 4390 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4391 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4392 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4393 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4394 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4395 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4396 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4397 | }; | |
4398 | ||
4399 | static int parse_reg_rule(struct nlattr *tb[], | |
4400 | struct ieee80211_reg_rule *reg_rule) | |
4401 | { | |
4402 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4403 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4404 | ||
4405 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4406 | return -EINVAL; | |
4407 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4408 | return -EINVAL; | |
4409 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4410 | return -EINVAL; | |
4411 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4412 | return -EINVAL; | |
4413 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4414 | return -EINVAL; | |
4415 | ||
4416 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4417 | ||
4418 | freq_range->start_freq_khz = | |
4419 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4420 | freq_range->end_freq_khz = | |
4421 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4422 | freq_range->max_bandwidth_khz = | |
4423 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4424 | ||
4425 | power_rule->max_eirp = | |
4426 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4427 | ||
4428 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4429 | power_rule->max_antenna_gain = | |
4430 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4431 | ||
4432 | return 0; | |
4433 | } | |
4434 | ||
4435 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4436 | { | |
4437 | int r; | |
4438 | char *data = NULL; | |
57b5ce07 | 4439 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4440 | |
80778f18 LR |
4441 | /* |
4442 | * You should only get this when cfg80211 hasn't yet initialized | |
4443 | * completely when built-in to the kernel right between the time | |
4444 | * window between nl80211_init() and regulatory_init(), if that is | |
4445 | * even possible. | |
4446 | */ | |
458f4f9e | 4447 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4448 | return -EINPROGRESS; |
80778f18 | 4449 | |
fe33eb39 LR |
4450 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4451 | return -EINVAL; | |
b2e1b302 LR |
4452 | |
4453 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4454 | ||
57b5ce07 LR |
4455 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4456 | user_reg_hint_type = | |
4457 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4458 | else | |
4459 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4460 | ||
4461 | switch (user_reg_hint_type) { | |
4462 | case NL80211_USER_REG_HINT_USER: | |
4463 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4464 | break; | |
4465 | default: | |
4466 | return -EINVAL; | |
4467 | } | |
4468 | ||
4469 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4470 | |
b2e1b302 LR |
4471 | return r; |
4472 | } | |
4473 | ||
24bdd9f4 | 4474 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4475 | struct genl_info *info) |
93da9cc1 | 4476 | { |
4c476991 | 4477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4478 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4479 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4480 | struct mesh_config cur_params; | |
4481 | int err = 0; | |
93da9cc1 | 4482 | void *hdr; |
4483 | struct nlattr *pinfoattr; | |
4484 | struct sk_buff *msg; | |
4485 | ||
29cbe68c JB |
4486 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4487 | return -EOPNOTSUPP; | |
4488 | ||
24bdd9f4 | 4489 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4490 | return -EOPNOTSUPP; |
f3f92586 | 4491 | |
29cbe68c JB |
4492 | wdev_lock(wdev); |
4493 | /* If not connected, get default parameters */ | |
4494 | if (!wdev->mesh_id_len) | |
4495 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4496 | else | |
e35e4d28 | 4497 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4498 | wdev_unlock(wdev); |
4499 | ||
93da9cc1 | 4500 | if (err) |
4c476991 | 4501 | return err; |
93da9cc1 | 4502 | |
4503 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4505 | if (!msg) |
4506 | return -ENOMEM; | |
15e47304 | 4507 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4508 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4509 | if (!hdr) |
efe1cf0c | 4510 | goto out; |
24bdd9f4 | 4511 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4512 | if (!pinfoattr) |
4513 | goto nla_put_failure; | |
9360ffd1 DM |
4514 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4515 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4516 | cur_params.dot11MeshRetryTimeout) || | |
4517 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4518 | cur_params.dot11MeshConfirmTimeout) || | |
4519 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4520 | cur_params.dot11MeshHoldingTimeout) || | |
4521 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4522 | cur_params.dot11MeshMaxPeerLinks) || | |
4523 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4524 | cur_params.dot11MeshMaxRetries) || | |
4525 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4526 | cur_params.dot11MeshTTL) || | |
4527 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4528 | cur_params.element_ttl) || | |
4529 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4530 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4531 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4532 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4533 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4534 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4535 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4536 | cur_params.path_refresh_time) || | |
4537 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4538 | cur_params.min_discovery_timeout) || | |
4539 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4540 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4541 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4542 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4543 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4544 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4545 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4546 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4547 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4548 | cur_params.dot11MeshHWMPRootMode) || | |
4549 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4550 | cur_params.dot11MeshHWMPRannInterval) || | |
4551 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4552 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4553 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4554 | cur_params.dot11MeshForwarding) || | |
4555 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4556 | cur_params.rssi_threshold) || |
4557 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4558 | cur_params.ht_opmode) || |
4559 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4560 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4561 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4562 | cur_params.dot11MeshHWMProotInterval) || |
4563 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4564 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4565 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4566 | cur_params.power_mode) || | |
4567 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
4568 | cur_params.dot11MeshAwakeWindowDuration)) | |
9360ffd1 | 4569 | goto nla_put_failure; |
93da9cc1 | 4570 | nla_nest_end(msg, pinfoattr); |
4571 | genlmsg_end(msg, hdr); | |
4c476991 | 4572 | return genlmsg_reply(msg, info); |
93da9cc1 | 4573 | |
3b85875a | 4574 | nla_put_failure: |
93da9cc1 | 4575 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4576 | out: |
d080e275 | 4577 | nlmsg_free(msg); |
4c476991 | 4578 | return -ENOBUFS; |
93da9cc1 | 4579 | } |
4580 | ||
b54452b0 | 4581 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4582 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4583 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4584 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4585 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4586 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4587 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4588 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4589 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4590 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4591 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4592 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4593 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4594 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4595 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4596 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4597 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4598 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4599 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4600 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4601 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4602 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4603 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4604 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4605 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4606 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4607 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4608 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
93da9cc1 | 4609 | }; |
4610 | ||
c80d545d JC |
4611 | static const struct nla_policy |
4612 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4613 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4614 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4615 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4616 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
581a8b0f | 4617 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4618 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4619 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4620 | }; |
4621 | ||
24bdd9f4 | 4622 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4623 | struct mesh_config *cfg, |
4624 | u32 *mask_out) | |
93da9cc1 | 4625 | { |
93da9cc1 | 4626 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4627 | u32 mask = 0; |
93da9cc1 | 4628 | |
ea54fba2 MP |
4629 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4630 | do { \ | |
4631 | if (tb[attr]) { \ | |
4632 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4633 | return -EINVAL; \ | |
4634 | cfg->param = fn(tb[attr]); \ | |
4635 | mask |= (1 << (attr - 1)); \ | |
4636 | } \ | |
4637 | } while (0) | |
bd90fdcc JB |
4638 | |
4639 | ||
24bdd9f4 | 4640 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4641 | return -EINVAL; |
4642 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4643 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4644 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4645 | return -EINVAL; |
4646 | ||
93da9cc1 | 4647 | /* This makes sure that there aren't more than 32 mesh config |
4648 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4649 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4650 | ||
4651 | /* Fill in the params struct */ | |
ea54fba2 | 4652 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4653 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4654 | nla_get_u16); | |
ea54fba2 | 4655 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4656 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4657 | nla_get_u16); | |
ea54fba2 | 4658 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4659 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4660 | nla_get_u16); | |
ea54fba2 | 4661 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4662 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4663 | nla_get_u16); | |
ea54fba2 | 4664 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4665 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4666 | nla_get_u8); | |
ea54fba2 | 4667 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4668 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4670 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4671 | nla_get_u8); | |
ea54fba2 | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4673 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4674 | nla_get_u8); | |
ea54fba2 MP |
4675 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4676 | 1, 255, mask, | |
a4f606ea CYY |
4677 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4678 | nla_get_u32); | |
ea54fba2 | 4679 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4680 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4681 | nla_get_u8); | |
ea54fba2 | 4682 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4683 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4684 | nla_get_u32); | |
ea54fba2 | 4685 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4686 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4687 | nla_get_u16); | |
ea54fba2 MP |
4688 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4689 | 1, 65535, mask, | |
a4f606ea CYY |
4690 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4691 | nla_get_u32); | |
93da9cc1 | 4692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4693 | 1, 65535, mask, |
4694 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4695 | nla_get_u16); |
dca7e943 | 4696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4697 | 1, 65535, mask, |
4698 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4699 | nla_get_u16); |
93da9cc1 | 4700 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4701 | dot11MeshHWMPnetDiameterTraversalTime, |
4702 | 1, 65535, mask, | |
a4f606ea CYY |
4703 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4704 | nla_get_u16); | |
ea54fba2 MP |
4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4706 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4707 | nla_get_u8); | |
4708 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4709 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4710 | nla_get_u16); |
63c5723b | 4711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4712 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4713 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4714 | nla_get_u8); |
ea54fba2 | 4715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4716 | mask, NL80211_MESHCONF_FORWARDING, |
4717 | nla_get_u8); | |
ea54fba2 | 4718 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4719 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4720 | nla_get_u32); | |
ea54fba2 | 4721 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4722 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4723 | nla_get_u16); |
4724 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4725 | 1, 65535, mask, |
ac1073a6 CYY |
4726 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4727 | nla_get_u32); | |
ea54fba2 | 4728 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4729 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4730 | nla_get_u16); |
4731 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4732 | dot11MeshHWMPconfirmationInterval, |
4733 | 1, 65535, mask, | |
728b19e5 | 4734 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4735 | nla_get_u16); |
3b1c5a53 MP |
4736 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4737 | NL80211_MESH_POWER_ACTIVE, | |
4738 | NL80211_MESH_POWER_MAX, | |
4739 | mask, NL80211_MESHCONF_POWER_MODE, | |
4740 | nla_get_u32); | |
4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4742 | 0, 65535, mask, | |
4743 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
bd90fdcc JB |
4744 | if (mask_out) |
4745 | *mask_out = mask; | |
c80d545d | 4746 | |
bd90fdcc JB |
4747 | return 0; |
4748 | ||
4749 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4750 | } | |
4751 | ||
c80d545d JC |
4752 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4753 | struct mesh_setup *setup) | |
4754 | { | |
4755 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | |
4756 | ||
4757 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4758 | return -EINVAL; | |
4759 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4760 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4761 | nl80211_mesh_setup_params_policy)) | |
4762 | return -EINVAL; | |
4763 | ||
d299a1f2 JC |
4764 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4765 | setup->sync_method = | |
4766 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4767 | IEEE80211_SYNC_METHOD_VENDOR : | |
4768 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4769 | ||
c80d545d JC |
4770 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4771 | setup->path_sel_proto = | |
4772 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4773 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4774 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4775 | ||
4776 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4777 | setup->path_metric = | |
4778 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4779 | IEEE80211_PATH_METRIC_VENDOR : | |
4780 | IEEE80211_PATH_METRIC_AIRTIME; | |
4781 | ||
581a8b0f JC |
4782 | |
4783 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4784 | struct nlattr *ieattr = |
581a8b0f | 4785 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4786 | if (!is_valid_ie_attr(ieattr)) |
4787 | return -EINVAL; | |
581a8b0f JC |
4788 | setup->ie = nla_data(ieattr); |
4789 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4790 | } |
b130e5ce JC |
4791 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4792 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
c80d545d JC |
4793 | |
4794 | return 0; | |
4795 | } | |
4796 | ||
24bdd9f4 | 4797 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4798 | struct genl_info *info) |
bd90fdcc JB |
4799 | { |
4800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4801 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4803 | struct mesh_config cfg; |
4804 | u32 mask; | |
4805 | int err; | |
4806 | ||
29cbe68c JB |
4807 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4808 | return -EOPNOTSUPP; | |
4809 | ||
24bdd9f4 | 4810 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4811 | return -EOPNOTSUPP; |
4812 | ||
24bdd9f4 | 4813 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4814 | if (err) |
4815 | return err; | |
4816 | ||
29cbe68c JB |
4817 | wdev_lock(wdev); |
4818 | if (!wdev->mesh_id_len) | |
4819 | err = -ENOLINK; | |
4820 | ||
4821 | if (!err) | |
e35e4d28 | 4822 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4823 | |
4824 | wdev_unlock(wdev); | |
4825 | ||
4826 | return err; | |
93da9cc1 | 4827 | } |
4828 | ||
f130347c LR |
4829 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4830 | { | |
458f4f9e | 4831 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4832 | struct sk_buff *msg; |
4833 | void *hdr = NULL; | |
4834 | struct nlattr *nl_reg_rules; | |
4835 | unsigned int i; | |
4836 | int err = -EINVAL; | |
4837 | ||
a1794390 | 4838 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
4839 | |
4840 | if (!cfg80211_regdomain) | |
4841 | goto out; | |
4842 | ||
fd2120ca | 4843 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
4844 | if (!msg) { |
4845 | err = -ENOBUFS; | |
4846 | goto out; | |
4847 | } | |
4848 | ||
15e47304 | 4849 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4850 | NL80211_CMD_GET_REG); |
4851 | if (!hdr) | |
efe1cf0c | 4852 | goto put_failure; |
f130347c | 4853 | |
57b5ce07 LR |
4854 | if (reg_last_request_cell_base() && |
4855 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4856 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4857 | goto nla_put_failure; | |
4858 | ||
458f4f9e JB |
4859 | rcu_read_lock(); |
4860 | regdom = rcu_dereference(cfg80211_regdomain); | |
4861 | ||
4862 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4863 | (regdom->dfs_region && | |
4864 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4865 | goto nla_put_failure_rcu; | |
4866 | ||
f130347c LR |
4867 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4868 | if (!nl_reg_rules) | |
458f4f9e | 4869 | goto nla_put_failure_rcu; |
f130347c | 4870 | |
458f4f9e | 4871 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4872 | struct nlattr *nl_reg_rule; |
4873 | const struct ieee80211_reg_rule *reg_rule; | |
4874 | const struct ieee80211_freq_range *freq_range; | |
4875 | const struct ieee80211_power_rule *power_rule; | |
4876 | ||
458f4f9e | 4877 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4878 | freq_range = ®_rule->freq_range; |
4879 | power_rule = ®_rule->power_rule; | |
4880 | ||
4881 | nl_reg_rule = nla_nest_start(msg, i); | |
4882 | if (!nl_reg_rule) | |
458f4f9e | 4883 | goto nla_put_failure_rcu; |
f130347c | 4884 | |
9360ffd1 DM |
4885 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4886 | reg_rule->flags) || | |
4887 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4888 | freq_range->start_freq_khz) || | |
4889 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4890 | freq_range->end_freq_khz) || | |
4891 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4892 | freq_range->max_bandwidth_khz) || | |
4893 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4894 | power_rule->max_antenna_gain) || | |
4895 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4896 | power_rule->max_eirp)) | |
458f4f9e | 4897 | goto nla_put_failure_rcu; |
f130347c LR |
4898 | |
4899 | nla_nest_end(msg, nl_reg_rule); | |
4900 | } | |
458f4f9e | 4901 | rcu_read_unlock(); |
f130347c LR |
4902 | |
4903 | nla_nest_end(msg, nl_reg_rules); | |
4904 | ||
4905 | genlmsg_end(msg, hdr); | |
134e6375 | 4906 | err = genlmsg_reply(msg, info); |
f130347c LR |
4907 | goto out; |
4908 | ||
458f4f9e JB |
4909 | nla_put_failure_rcu: |
4910 | rcu_read_unlock(); | |
f130347c LR |
4911 | nla_put_failure: |
4912 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4913 | put_failure: |
d080e275 | 4914 | nlmsg_free(msg); |
f130347c LR |
4915 | err = -EMSGSIZE; |
4916 | out: | |
a1794390 | 4917 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
4918 | return err; |
4919 | } | |
4920 | ||
b2e1b302 LR |
4921 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
4922 | { | |
4923 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
4924 | struct nlattr *nl_reg_rule; | |
4925 | char *alpha2 = NULL; | |
4926 | int rem_reg_rules = 0, r = 0; | |
4927 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 4928 | u8 dfs_region = 0; |
b2e1b302 LR |
4929 | struct ieee80211_regdomain *rd = NULL; |
4930 | ||
4931 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
4932 | return -EINVAL; | |
4933 | ||
4934 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
4935 | return -EINVAL; | |
4936 | ||
4937 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4938 | ||
8b60b078 LR |
4939 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
4940 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
4941 | ||
b2e1b302 | 4942 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4943 | rem_reg_rules) { |
b2e1b302 LR |
4944 | num_rules++; |
4945 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 4946 | return -EINVAL; |
b2e1b302 LR |
4947 | } |
4948 | ||
b2e1b302 | 4949 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 4950 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
4951 | |
4952 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
4953 | if (!rd) |
4954 | return -ENOMEM; | |
b2e1b302 LR |
4955 | |
4956 | rd->n_reg_rules = num_rules; | |
4957 | rd->alpha2[0] = alpha2[0]; | |
4958 | rd->alpha2[1] = alpha2[1]; | |
4959 | ||
8b60b078 LR |
4960 | /* |
4961 | * Disable DFS master mode if the DFS region was | |
4962 | * not supported or known on this kernel. | |
4963 | */ | |
4964 | if (reg_supported_dfs_region(dfs_region)) | |
4965 | rd->dfs_region = dfs_region; | |
4966 | ||
b2e1b302 | 4967 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4968 | rem_reg_rules) { |
b2e1b302 | 4969 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
4970 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
4971 | reg_rule_policy); | |
b2e1b302 LR |
4972 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
4973 | if (r) | |
4974 | goto bad_reg; | |
4975 | ||
4976 | rule_idx++; | |
4977 | ||
d0e18f83 LR |
4978 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
4979 | r = -EINVAL; | |
b2e1b302 | 4980 | goto bad_reg; |
d0e18f83 | 4981 | } |
b2e1b302 LR |
4982 | } |
4983 | ||
6913b49a JB |
4984 | mutex_lock(&cfg80211_mutex); |
4985 | ||
b2e1b302 | 4986 | r = set_regdom(rd); |
6913b49a | 4987 | /* set_regdom took ownership */ |
1a919318 | 4988 | rd = NULL; |
6913b49a | 4989 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 4990 | |
d2372b31 | 4991 | bad_reg: |
b2e1b302 | 4992 | kfree(rd); |
d0e18f83 | 4993 | return r; |
b2e1b302 LR |
4994 | } |
4995 | ||
83f5e2cf JB |
4996 | static int validate_scan_freqs(struct nlattr *freqs) |
4997 | { | |
4998 | struct nlattr *attr1, *attr2; | |
4999 | int n_channels = 0, tmp1, tmp2; | |
5000 | ||
5001 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5002 | n_channels++; | |
5003 | /* | |
5004 | * Some hardware has a limited channel list for | |
5005 | * scanning, and it is pretty much nonsensical | |
5006 | * to scan for a channel twice, so disallow that | |
5007 | * and don't require drivers to check that the | |
5008 | * channel list they get isn't longer than what | |
5009 | * they can scan, as long as they can scan all | |
5010 | * the channels they registered at once. | |
5011 | */ | |
5012 | nla_for_each_nested(attr2, freqs, tmp2) | |
5013 | if (attr1 != attr2 && | |
5014 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5015 | return 0; | |
5016 | } | |
5017 | ||
5018 | return n_channels; | |
5019 | } | |
5020 | ||
2a519311 JB |
5021 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5022 | { | |
4c476991 | 5023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5024 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5025 | struct cfg80211_scan_request *request; |
2a519311 JB |
5026 | struct nlattr *attr; |
5027 | struct wiphy *wiphy; | |
83f5e2cf | 5028 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5029 | size_t ie_len; |
2a519311 | 5030 | |
f4a11bb0 JB |
5031 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5032 | return -EINVAL; | |
5033 | ||
79c97e97 | 5034 | wiphy = &rdev->wiphy; |
2a519311 | 5035 | |
4c476991 JB |
5036 | if (!rdev->ops->scan) |
5037 | return -EOPNOTSUPP; | |
2a519311 | 5038 | |
4c476991 JB |
5039 | if (rdev->scan_req) |
5040 | return -EBUSY; | |
2a519311 JB |
5041 | |
5042 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5043 | n_channels = validate_scan_freqs( |
5044 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
5045 | if (!n_channels) |
5046 | return -EINVAL; | |
2a519311 | 5047 | } else { |
34850ab2 | 5048 | enum ieee80211_band band; |
83f5e2cf JB |
5049 | n_channels = 0; |
5050 | ||
2a519311 JB |
5051 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5052 | if (wiphy->bands[band]) | |
5053 | n_channels += wiphy->bands[band]->n_channels; | |
5054 | } | |
5055 | ||
5056 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5057 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5058 | n_ssids++; | |
5059 | ||
4c476991 JB |
5060 | if (n_ssids > wiphy->max_scan_ssids) |
5061 | return -EINVAL; | |
2a519311 | 5062 | |
70692ad2 JM |
5063 | if (info->attrs[NL80211_ATTR_IE]) |
5064 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5065 | else | |
5066 | ie_len = 0; | |
5067 | ||
4c476991 JB |
5068 | if (ie_len > wiphy->max_scan_ie_len) |
5069 | return -EINVAL; | |
18a83659 | 5070 | |
2a519311 | 5071 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5072 | + sizeof(*request->ssids) * n_ssids |
5073 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5074 | + ie_len, GFP_KERNEL); |
4c476991 JB |
5075 | if (!request) |
5076 | return -ENOMEM; | |
2a519311 | 5077 | |
2a519311 | 5078 | if (n_ssids) |
5ba63533 | 5079 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5080 | request->n_ssids = n_ssids; |
70692ad2 JM |
5081 | if (ie_len) { |
5082 | if (request->ssids) | |
5083 | request->ie = (void *)(request->ssids + n_ssids); | |
5084 | else | |
5085 | request->ie = (void *)(request->channels + n_channels); | |
5086 | } | |
2a519311 | 5087 | |
584991dc | 5088 | i = 0; |
2a519311 JB |
5089 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5090 | /* user specified, bail out if channel not found */ | |
2a519311 | 5091 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5092 | struct ieee80211_channel *chan; |
5093 | ||
5094 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5095 | ||
5096 | if (!chan) { | |
2a519311 JB |
5097 | err = -EINVAL; |
5098 | goto out_free; | |
5099 | } | |
584991dc JB |
5100 | |
5101 | /* ignore disabled channels */ | |
5102 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5103 | continue; | |
5104 | ||
5105 | request->channels[i] = chan; | |
2a519311 JB |
5106 | i++; |
5107 | } | |
5108 | } else { | |
34850ab2 JB |
5109 | enum ieee80211_band band; |
5110 | ||
2a519311 | 5111 | /* all channels */ |
2a519311 JB |
5112 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5113 | int j; | |
5114 | if (!wiphy->bands[band]) | |
5115 | continue; | |
5116 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5117 | struct ieee80211_channel *chan; |
5118 | ||
5119 | chan = &wiphy->bands[band]->channels[j]; | |
5120 | ||
5121 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5122 | continue; | |
5123 | ||
5124 | request->channels[i] = chan; | |
2a519311 JB |
5125 | i++; |
5126 | } | |
5127 | } | |
5128 | } | |
5129 | ||
584991dc JB |
5130 | if (!i) { |
5131 | err = -EINVAL; | |
5132 | goto out_free; | |
5133 | } | |
5134 | ||
5135 | request->n_channels = i; | |
5136 | ||
2a519311 JB |
5137 | i = 0; |
5138 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5139 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5140 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5141 | err = -EINVAL; |
5142 | goto out_free; | |
5143 | } | |
57a27e1d | 5144 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5145 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5146 | i++; |
5147 | } | |
5148 | } | |
5149 | ||
70692ad2 JM |
5150 | if (info->attrs[NL80211_ATTR_IE]) { |
5151 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5152 | memcpy((void *)request->ie, |
5153 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5154 | request->ie_len); |
5155 | } | |
5156 | ||
34850ab2 | 5157 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5158 | if (wiphy->bands[i]) |
5159 | request->rates[i] = | |
5160 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5161 | |
5162 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5163 | nla_for_each_nested(attr, | |
5164 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5165 | tmp) { | |
5166 | enum ieee80211_band band = nla_type(attr); | |
5167 | ||
84404623 | 5168 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5169 | err = -EINVAL; |
5170 | goto out_free; | |
5171 | } | |
5172 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5173 | nla_data(attr), | |
5174 | nla_len(attr), | |
5175 | &request->rates[band]); | |
5176 | if (err) | |
5177 | goto out_free; | |
5178 | } | |
5179 | } | |
5180 | ||
46856bbf | 5181 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5182 | request->flags = nla_get_u32( |
5183 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5184 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5185 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5186 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5187 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5188 | err = -EOPNOTSUPP; |
5189 | goto out_free; | |
5190 | } | |
5191 | } | |
ed473771 | 5192 | |
e9f935e3 RM |
5193 | request->no_cck = |
5194 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5195 | ||
fd014284 | 5196 | request->wdev = wdev; |
79c97e97 | 5197 | request->wiphy = &rdev->wiphy; |
15d6030b | 5198 | request->scan_start = jiffies; |
2a519311 | 5199 | |
79c97e97 | 5200 | rdev->scan_req = request; |
e35e4d28 | 5201 | err = rdev_scan(rdev, request); |
2a519311 | 5202 | |
463d0183 | 5203 | if (!err) { |
fd014284 JB |
5204 | nl80211_send_scan_start(rdev, wdev); |
5205 | if (wdev->netdev) | |
5206 | dev_hold(wdev->netdev); | |
4c476991 | 5207 | } else { |
2a519311 | 5208 | out_free: |
79c97e97 | 5209 | rdev->scan_req = NULL; |
2a519311 JB |
5210 | kfree(request); |
5211 | } | |
3b85875a | 5212 | |
2a519311 JB |
5213 | return err; |
5214 | } | |
5215 | ||
807f8a8c LC |
5216 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5217 | struct genl_info *info) | |
5218 | { | |
5219 | struct cfg80211_sched_scan_request *request; | |
5220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5221 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5222 | struct nlattr *attr; |
5223 | struct wiphy *wiphy; | |
a1f1c21c | 5224 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5225 | u32 interval; |
807f8a8c LC |
5226 | enum ieee80211_band band; |
5227 | size_t ie_len; | |
a1f1c21c | 5228 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5229 | |
5230 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5231 | !rdev->ops->sched_scan_start) | |
5232 | return -EOPNOTSUPP; | |
5233 | ||
5234 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5235 | return -EINVAL; | |
5236 | ||
bbe6ad6d LC |
5237 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5238 | return -EINVAL; | |
5239 | ||
5240 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5241 | if (interval == 0) | |
5242 | return -EINVAL; | |
5243 | ||
807f8a8c LC |
5244 | wiphy = &rdev->wiphy; |
5245 | ||
5246 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5247 | n_channels = validate_scan_freqs( | |
5248 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5249 | if (!n_channels) | |
5250 | return -EINVAL; | |
5251 | } else { | |
5252 | n_channels = 0; | |
5253 | ||
5254 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5255 | if (wiphy->bands[band]) | |
5256 | n_channels += wiphy->bands[band]->n_channels; | |
5257 | } | |
5258 | ||
5259 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5260 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5261 | tmp) | |
5262 | n_ssids++; | |
5263 | ||
93b6aa69 | 5264 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5265 | return -EINVAL; |
5266 | ||
a1f1c21c LC |
5267 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5268 | nla_for_each_nested(attr, | |
5269 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5270 | tmp) | |
5271 | n_match_sets++; | |
5272 | ||
5273 | if (n_match_sets > wiphy->max_match_sets) | |
5274 | return -EINVAL; | |
5275 | ||
807f8a8c LC |
5276 | if (info->attrs[NL80211_ATTR_IE]) |
5277 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5278 | else | |
5279 | ie_len = 0; | |
5280 | ||
5a865bad | 5281 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5282 | return -EINVAL; |
5283 | ||
c10841ca LC |
5284 | mutex_lock(&rdev->sched_scan_mtx); |
5285 | ||
5286 | if (rdev->sched_scan_req) { | |
5287 | err = -EINPROGRESS; | |
5288 | goto out; | |
5289 | } | |
5290 | ||
807f8a8c | 5291 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5292 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5293 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5294 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5295 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5296 | if (!request) { |
5297 | err = -ENOMEM; | |
5298 | goto out; | |
5299 | } | |
807f8a8c LC |
5300 | |
5301 | if (n_ssids) | |
5302 | request->ssids = (void *)&request->channels[n_channels]; | |
5303 | request->n_ssids = n_ssids; | |
5304 | if (ie_len) { | |
5305 | if (request->ssids) | |
5306 | request->ie = (void *)(request->ssids + n_ssids); | |
5307 | else | |
5308 | request->ie = (void *)(request->channels + n_channels); | |
5309 | } | |
5310 | ||
a1f1c21c LC |
5311 | if (n_match_sets) { |
5312 | if (request->ie) | |
5313 | request->match_sets = (void *)(request->ie + ie_len); | |
5314 | else if (request->ssids) | |
5315 | request->match_sets = | |
5316 | (void *)(request->ssids + n_ssids); | |
5317 | else | |
5318 | request->match_sets = | |
5319 | (void *)(request->channels + n_channels); | |
5320 | } | |
5321 | request->n_match_sets = n_match_sets; | |
5322 | ||
807f8a8c LC |
5323 | i = 0; |
5324 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5325 | /* user specified, bail out if channel not found */ | |
5326 | nla_for_each_nested(attr, | |
5327 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5328 | tmp) { | |
5329 | struct ieee80211_channel *chan; | |
5330 | ||
5331 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5332 | ||
5333 | if (!chan) { | |
5334 | err = -EINVAL; | |
5335 | goto out_free; | |
5336 | } | |
5337 | ||
5338 | /* ignore disabled channels */ | |
5339 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5340 | continue; | |
5341 | ||
5342 | request->channels[i] = chan; | |
5343 | i++; | |
5344 | } | |
5345 | } else { | |
5346 | /* all channels */ | |
5347 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5348 | int j; | |
5349 | if (!wiphy->bands[band]) | |
5350 | continue; | |
5351 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5352 | struct ieee80211_channel *chan; | |
5353 | ||
5354 | chan = &wiphy->bands[band]->channels[j]; | |
5355 | ||
5356 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5357 | continue; | |
5358 | ||
5359 | request->channels[i] = chan; | |
5360 | i++; | |
5361 | } | |
5362 | } | |
5363 | } | |
5364 | ||
5365 | if (!i) { | |
5366 | err = -EINVAL; | |
5367 | goto out_free; | |
5368 | } | |
5369 | ||
5370 | request->n_channels = i; | |
5371 | ||
5372 | i = 0; | |
5373 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5374 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5375 | tmp) { | |
57a27e1d | 5376 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5377 | err = -EINVAL; |
5378 | goto out_free; | |
5379 | } | |
57a27e1d | 5380 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5381 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5382 | nla_len(attr)); | |
807f8a8c LC |
5383 | i++; |
5384 | } | |
5385 | } | |
5386 | ||
a1f1c21c LC |
5387 | i = 0; |
5388 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5389 | nla_for_each_nested(attr, | |
5390 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5391 | tmp) { | |
88e920b4 | 5392 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5393 | |
5394 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5395 | nla_data(attr), nla_len(attr), | |
5396 | nl80211_match_policy); | |
4a4ab0d7 | 5397 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5398 | if (ssid) { |
5399 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5400 | err = -EINVAL; | |
5401 | goto out_free; | |
5402 | } | |
5403 | memcpy(request->match_sets[i].ssid.ssid, | |
5404 | nla_data(ssid), nla_len(ssid)); | |
5405 | request->match_sets[i].ssid.ssid_len = | |
5406 | nla_len(ssid); | |
5407 | } | |
88e920b4 TP |
5408 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5409 | if (rssi) | |
5410 | request->rssi_thold = nla_get_u32(rssi); | |
5411 | else | |
5412 | request->rssi_thold = | |
5413 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5414 | i++; |
5415 | } | |
5416 | } | |
5417 | ||
807f8a8c LC |
5418 | if (info->attrs[NL80211_ATTR_IE]) { |
5419 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5420 | memcpy((void *)request->ie, | |
5421 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5422 | request->ie_len); | |
5423 | } | |
5424 | ||
46856bbf | 5425 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5426 | request->flags = nla_get_u32( |
5427 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5428 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5429 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5430 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5431 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5432 | err = -EOPNOTSUPP; |
5433 | goto out_free; | |
5434 | } | |
5435 | } | |
ed473771 | 5436 | |
807f8a8c LC |
5437 | request->dev = dev; |
5438 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5439 | request->interval = interval; |
15d6030b | 5440 | request->scan_start = jiffies; |
807f8a8c | 5441 | |
e35e4d28 | 5442 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5443 | if (!err) { |
5444 | rdev->sched_scan_req = request; | |
5445 | nl80211_send_sched_scan(rdev, dev, | |
5446 | NL80211_CMD_START_SCHED_SCAN); | |
5447 | goto out; | |
5448 | } | |
5449 | ||
5450 | out_free: | |
5451 | kfree(request); | |
5452 | out: | |
c10841ca | 5453 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
5454 | return err; |
5455 | } | |
5456 | ||
5457 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5458 | struct genl_info *info) | |
5459 | { | |
5460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 5461 | int err; |
807f8a8c LC |
5462 | |
5463 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5464 | !rdev->ops->sched_scan_stop) | |
5465 | return -EOPNOTSUPP; | |
5466 | ||
c10841ca LC |
5467 | mutex_lock(&rdev->sched_scan_mtx); |
5468 | err = __cfg80211_stop_sched_scan(rdev, false); | |
5469 | mutex_unlock(&rdev->sched_scan_mtx); | |
5470 | ||
5471 | return err; | |
807f8a8c LC |
5472 | } |
5473 | ||
04f39047 SW |
5474 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5475 | struct genl_info *info) | |
5476 | { | |
5477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5478 | struct net_device *dev = info->user_ptr[1]; | |
5479 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5480 | struct cfg80211_chan_def chandef; | |
5481 | int err; | |
5482 | ||
5483 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5484 | if (err) | |
5485 | return err; | |
5486 | ||
5487 | if (wdev->cac_started) | |
5488 | return -EBUSY; | |
5489 | ||
5490 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5491 | if (err < 0) | |
5492 | return err; | |
5493 | ||
5494 | if (err == 0) | |
5495 | return -EINVAL; | |
5496 | ||
5497 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5498 | return -EINVAL; | |
5499 | ||
5500 | if (!rdev->ops->start_radar_detection) | |
5501 | return -EOPNOTSUPP; | |
5502 | ||
5503 | mutex_lock(&rdev->devlist_mtx); | |
5504 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5505 | chandef.chan, CHAN_MODE_SHARED, | |
5506 | BIT(chandef.width)); | |
5507 | if (err) | |
5508 | goto err_locked; | |
5509 | ||
5510 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5511 | if (!err) { | |
5512 | wdev->channel = chandef.chan; | |
5513 | wdev->cac_started = true; | |
5514 | wdev->cac_start_time = jiffies; | |
5515 | } | |
5516 | err_locked: | |
5517 | mutex_unlock(&rdev->devlist_mtx); | |
5518 | ||
5519 | return err; | |
5520 | } | |
5521 | ||
9720bb3a JB |
5522 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5523 | u32 seq, int flags, | |
2a519311 | 5524 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5525 | struct wireless_dev *wdev, |
5526 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5527 | { |
48ab905d | 5528 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5529 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5530 | void *hdr; |
5531 | struct nlattr *bss; | |
8cef2c9d | 5532 | bool tsf = false; |
48ab905d JB |
5533 | |
5534 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5535 | |
15e47304 | 5536 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5537 | NL80211_CMD_NEW_SCAN_RESULTS); |
5538 | if (!hdr) | |
5539 | return -1; | |
5540 | ||
9720bb3a JB |
5541 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5542 | ||
9360ffd1 DM |
5543 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
5544 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | |
5545 | goto nla_put_failure; | |
2a519311 JB |
5546 | |
5547 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5548 | if (!bss) | |
5549 | goto nla_put_failure; | |
9360ffd1 | 5550 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5551 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5552 | goto nla_put_failure; |
9caf0364 JB |
5553 | |
5554 | rcu_read_lock(); | |
5555 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5556 | if (ies) { |
5557 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5558 | goto fail_unlock_rcu; | |
5559 | tsf = true; | |
5560 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5561 | ies->len, ies->data)) | |
5562 | goto fail_unlock_rcu; | |
9caf0364 JB |
5563 | } |
5564 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5565 | if (ies) { |
5566 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5567 | goto fail_unlock_rcu; | |
5568 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5569 | ies->len, ies->data)) | |
5570 | goto fail_unlock_rcu; | |
9caf0364 JB |
5571 | } |
5572 | rcu_read_unlock(); | |
5573 | ||
9360ffd1 DM |
5574 | if (res->beacon_interval && |
5575 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5576 | goto nla_put_failure; | |
5577 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5578 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5579 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5580 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5581 | goto nla_put_failure; | |
2a519311 | 5582 | |
77965c97 | 5583 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5584 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5585 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5586 | goto nla_put_failure; | |
2a519311 JB |
5587 | break; |
5588 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5589 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5590 | goto nla_put_failure; | |
2a519311 JB |
5591 | break; |
5592 | default: | |
5593 | break; | |
5594 | } | |
5595 | ||
48ab905d | 5596 | switch (wdev->iftype) { |
074ac8df | 5597 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5598 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5599 | if (intbss == wdev->current_bss && |
5600 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5601 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5602 | goto nla_put_failure; | |
48ab905d JB |
5603 | break; |
5604 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5605 | if (intbss == wdev->current_bss && |
5606 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5607 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5608 | goto nla_put_failure; | |
48ab905d JB |
5609 | break; |
5610 | default: | |
5611 | break; | |
5612 | } | |
5613 | ||
2a519311 JB |
5614 | nla_nest_end(msg, bss); |
5615 | ||
5616 | return genlmsg_end(msg, hdr); | |
5617 | ||
8cef2c9d JB |
5618 | fail_unlock_rcu: |
5619 | rcu_read_unlock(); | |
2a519311 JB |
5620 | nla_put_failure: |
5621 | genlmsg_cancel(msg, hdr); | |
5622 | return -EMSGSIZE; | |
5623 | } | |
5624 | ||
5625 | static int nl80211_dump_scan(struct sk_buff *skb, | |
5626 | struct netlink_callback *cb) | |
5627 | { | |
48ab905d JB |
5628 | struct cfg80211_registered_device *rdev; |
5629 | struct net_device *dev; | |
2a519311 | 5630 | struct cfg80211_internal_bss *scan; |
48ab905d | 5631 | struct wireless_dev *wdev; |
2a519311 JB |
5632 | int start = cb->args[1], idx = 0; |
5633 | int err; | |
5634 | ||
67748893 JB |
5635 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
5636 | if (err) | |
5637 | return err; | |
2a519311 | 5638 | |
48ab905d | 5639 | wdev = dev->ieee80211_ptr; |
2a519311 | 5640 | |
48ab905d JB |
5641 | wdev_lock(wdev); |
5642 | spin_lock_bh(&rdev->bss_lock); | |
5643 | cfg80211_bss_expire(rdev); | |
5644 | ||
9720bb3a JB |
5645 | cb->seq = rdev->bss_generation; |
5646 | ||
48ab905d | 5647 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5648 | if (++idx <= start) |
5649 | continue; | |
9720bb3a | 5650 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5651 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5652 | rdev, wdev, scan) < 0) { |
2a519311 | 5653 | idx--; |
67748893 | 5654 | break; |
2a519311 JB |
5655 | } |
5656 | } | |
5657 | ||
48ab905d JB |
5658 | spin_unlock_bh(&rdev->bss_lock); |
5659 | wdev_unlock(wdev); | |
2a519311 JB |
5660 | |
5661 | cb->args[1] = idx; | |
67748893 | 5662 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 5663 | |
67748893 | 5664 | return skb->len; |
2a519311 JB |
5665 | } |
5666 | ||
15e47304 | 5667 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5668 | int flags, struct net_device *dev, |
5669 | struct survey_info *survey) | |
5670 | { | |
5671 | void *hdr; | |
5672 | struct nlattr *infoattr; | |
5673 | ||
15e47304 | 5674 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5675 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5676 | if (!hdr) | |
5677 | return -ENOMEM; | |
5678 | ||
9360ffd1 DM |
5679 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5680 | goto nla_put_failure; | |
61fa713c HS |
5681 | |
5682 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5683 | if (!infoattr) | |
5684 | goto nla_put_failure; | |
5685 | ||
9360ffd1 DM |
5686 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5687 | survey->channel->center_freq)) | |
5688 | goto nla_put_failure; | |
5689 | ||
5690 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5691 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5692 | goto nla_put_failure; | |
5693 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5694 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5695 | goto nla_put_failure; | |
5696 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5697 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5698 | survey->channel_time)) | |
5699 | goto nla_put_failure; | |
5700 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5701 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5702 | survey->channel_time_busy)) | |
5703 | goto nla_put_failure; | |
5704 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5705 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5706 | survey->channel_time_ext_busy)) | |
5707 | goto nla_put_failure; | |
5708 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5709 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5710 | survey->channel_time_rx)) | |
5711 | goto nla_put_failure; | |
5712 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5713 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5714 | survey->channel_time_tx)) | |
5715 | goto nla_put_failure; | |
61fa713c HS |
5716 | |
5717 | nla_nest_end(msg, infoattr); | |
5718 | ||
5719 | return genlmsg_end(msg, hdr); | |
5720 | ||
5721 | nla_put_failure: | |
5722 | genlmsg_cancel(msg, hdr); | |
5723 | return -EMSGSIZE; | |
5724 | } | |
5725 | ||
5726 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5727 | struct netlink_callback *cb) | |
5728 | { | |
5729 | struct survey_info survey; | |
5730 | struct cfg80211_registered_device *dev; | |
5731 | struct net_device *netdev; | |
61fa713c HS |
5732 | int survey_idx = cb->args[1]; |
5733 | int res; | |
5734 | ||
67748893 JB |
5735 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
5736 | if (res) | |
5737 | return res; | |
61fa713c HS |
5738 | |
5739 | if (!dev->ops->dump_survey) { | |
5740 | res = -EOPNOTSUPP; | |
5741 | goto out_err; | |
5742 | } | |
5743 | ||
5744 | while (1) { | |
180cdc79 LR |
5745 | struct ieee80211_channel *chan; |
5746 | ||
e35e4d28 | 5747 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
61fa713c HS |
5748 | if (res == -ENOENT) |
5749 | break; | |
5750 | if (res) | |
5751 | goto out_err; | |
5752 | ||
180cdc79 LR |
5753 | /* Survey without a channel doesn't make sense */ |
5754 | if (!survey.channel) { | |
5755 | res = -EINVAL; | |
5756 | goto out; | |
5757 | } | |
5758 | ||
5759 | chan = ieee80211_get_channel(&dev->wiphy, | |
5760 | survey.channel->center_freq); | |
5761 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5762 | survey_idx++; | |
5763 | continue; | |
5764 | } | |
5765 | ||
61fa713c | 5766 | if (nl80211_send_survey(skb, |
15e47304 | 5767 | NETLINK_CB(cb->skb).portid, |
61fa713c HS |
5768 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
5769 | netdev, | |
5770 | &survey) < 0) | |
5771 | goto out; | |
5772 | survey_idx++; | |
5773 | } | |
5774 | ||
5775 | out: | |
5776 | cb->args[1] = survey_idx; | |
5777 | res = skb->len; | |
5778 | out_err: | |
67748893 | 5779 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
5780 | return res; |
5781 | } | |
5782 | ||
b23aa676 SO |
5783 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5784 | { | |
5785 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5786 | NL80211_WPA_VERSION_2)); | |
5787 | } | |
5788 | ||
636a5d36 JM |
5789 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5790 | { | |
4c476991 JB |
5791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5792 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5793 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5794 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5795 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5796 | enum nl80211_auth_type auth_type; |
fffd0934 | 5797 | struct key_parse key; |
d5cdfacb | 5798 | bool local_state_change; |
636a5d36 | 5799 | |
f4a11bb0 JB |
5800 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5801 | return -EINVAL; | |
5802 | ||
5803 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5804 | return -EINVAL; | |
5805 | ||
1778092e JM |
5806 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5807 | return -EINVAL; | |
5808 | ||
19957bb3 JB |
5809 | if (!info->attrs[NL80211_ATTR_SSID]) |
5810 | return -EINVAL; | |
5811 | ||
5812 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5813 | return -EINVAL; | |
5814 | ||
fffd0934 JB |
5815 | err = nl80211_parse_key(info, &key); |
5816 | if (err) | |
5817 | return err; | |
5818 | ||
5819 | if (key.idx >= 0) { | |
e31b8213 JB |
5820 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5821 | return -EINVAL; | |
fffd0934 JB |
5822 | if (!key.p.key || !key.p.key_len) |
5823 | return -EINVAL; | |
5824 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5825 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5826 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5827 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5828 | return -EINVAL; | |
5829 | if (key.idx > 4) | |
5830 | return -EINVAL; | |
5831 | } else { | |
5832 | key.p.key_len = 0; | |
5833 | key.p.key = NULL; | |
5834 | } | |
5835 | ||
afea0b7a JB |
5836 | if (key.idx >= 0) { |
5837 | int i; | |
5838 | bool ok = false; | |
5839 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5840 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5841 | ok = true; | |
5842 | break; | |
5843 | } | |
5844 | } | |
4c476991 JB |
5845 | if (!ok) |
5846 | return -EINVAL; | |
afea0b7a JB |
5847 | } |
5848 | ||
4c476991 JB |
5849 | if (!rdev->ops->auth) |
5850 | return -EOPNOTSUPP; | |
636a5d36 | 5851 | |
074ac8df | 5852 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5853 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5854 | return -EOPNOTSUPP; | |
eec60b03 | 5855 | |
19957bb3 | 5856 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5857 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5858 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5859 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5860 | return -EINVAL; | |
636a5d36 | 5861 | |
19957bb3 JB |
5862 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5863 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5864 | |
5865 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5866 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5867 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5868 | } |
5869 | ||
19957bb3 | 5870 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5871 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5872 | return -EINVAL; |
636a5d36 | 5873 | |
e39e5b5e JM |
5874 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5875 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5876 | return -EINVAL; | |
5877 | ||
5878 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5879 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5880 | return -EINVAL; | |
5881 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5882 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5883 | /* need to include at least Auth Transaction and Status Code */ | |
5884 | if (sae_data_len < 4) | |
5885 | return -EINVAL; | |
5886 | } | |
5887 | ||
d5cdfacb JM |
5888 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5889 | ||
95de817b JB |
5890 | /* |
5891 | * Since we no longer track auth state, ignore | |
5892 | * requests to only change local state. | |
5893 | */ | |
5894 | if (local_state_change) | |
5895 | return 0; | |
5896 | ||
4c476991 JB |
5897 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
5898 | ssid, ssid_len, ie, ie_len, | |
e39e5b5e JM |
5899 | key.p.key, key.p.key_len, key.idx, |
5900 | sae_data, sae_data_len); | |
636a5d36 JM |
5901 | } |
5902 | ||
c0692b8f JB |
5903 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
5904 | struct genl_info *info, | |
3dc27d25 JB |
5905 | struct cfg80211_crypto_settings *settings, |
5906 | int cipher_limit) | |
b23aa676 | 5907 | { |
c0b2bbd8 JB |
5908 | memset(settings, 0, sizeof(*settings)); |
5909 | ||
b23aa676 SO |
5910 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
5911 | ||
c0692b8f JB |
5912 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
5913 | u16 proto; | |
5914 | proto = nla_get_u16( | |
5915 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
5916 | settings->control_port_ethertype = cpu_to_be16(proto); | |
5917 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
5918 | proto != ETH_P_PAE) | |
5919 | return -EINVAL; | |
5920 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
5921 | settings->control_port_no_encrypt = true; | |
5922 | } else | |
5923 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
5924 | ||
b23aa676 SO |
5925 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
5926 | void *data; | |
5927 | int len, i; | |
5928 | ||
5929 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5930 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5931 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
5932 | ||
5933 | if (len % sizeof(u32)) | |
5934 | return -EINVAL; | |
5935 | ||
3dc27d25 | 5936 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
5937 | return -EINVAL; |
5938 | ||
5939 | memcpy(settings->ciphers_pairwise, data, len); | |
5940 | ||
5941 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
5942 | if (!cfg80211_supported_cipher_suite( |
5943 | &rdev->wiphy, | |
b23aa676 SO |
5944 | settings->ciphers_pairwise[i])) |
5945 | return -EINVAL; | |
5946 | } | |
5947 | ||
5948 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
5949 | settings->cipher_group = | |
5950 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
5951 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
5952 | settings->cipher_group)) | |
b23aa676 SO |
5953 | return -EINVAL; |
5954 | } | |
5955 | ||
5956 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
5957 | settings->wpa_versions = | |
5958 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
5959 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
5960 | return -EINVAL; | |
5961 | } | |
5962 | ||
5963 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
5964 | void *data; | |
6d30240e | 5965 | int len; |
b23aa676 SO |
5966 | |
5967 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5968 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5969 | settings->n_akm_suites = len / sizeof(u32); | |
5970 | ||
5971 | if (len % sizeof(u32)) | |
5972 | return -EINVAL; | |
5973 | ||
1b9ca027 JM |
5974 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
5975 | return -EINVAL; | |
5976 | ||
b23aa676 | 5977 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
5978 | } |
5979 | ||
5980 | return 0; | |
5981 | } | |
5982 | ||
636a5d36 JM |
5983 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
5984 | { | |
4c476991 JB |
5985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5986 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5987 | struct cfg80211_crypto_settings crypto; |
f444de05 | 5988 | struct ieee80211_channel *chan; |
3e5d7649 | 5989 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
5990 | int err, ssid_len, ie_len = 0; |
5991 | bool use_mfp = false; | |
7e7c8926 BG |
5992 | u32 flags = 0; |
5993 | struct ieee80211_ht_cap *ht_capa = NULL; | |
5994 | struct ieee80211_ht_cap *ht_capa_mask = NULL; | |
ee2aca34 JB |
5995 | struct ieee80211_vht_cap *vht_capa = NULL; |
5996 | struct ieee80211_vht_cap *vht_capa_mask = NULL; | |
636a5d36 | 5997 | |
f4a11bb0 JB |
5998 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5999 | return -EINVAL; | |
6000 | ||
6001 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6002 | !info->attrs[NL80211_ATTR_SSID] || |
6003 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6004 | return -EINVAL; |
6005 | ||
4c476991 JB |
6006 | if (!rdev->ops->assoc) |
6007 | return -EOPNOTSUPP; | |
636a5d36 | 6008 | |
074ac8df | 6009 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6010 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6011 | return -EOPNOTSUPP; | |
eec60b03 | 6012 | |
19957bb3 | 6013 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6014 | |
19957bb3 JB |
6015 | chan = ieee80211_get_channel(&rdev->wiphy, |
6016 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6017 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6018 | return -EINVAL; | |
636a5d36 | 6019 | |
19957bb3 JB |
6020 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6021 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6022 | |
6023 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6024 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6025 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6026 | } |
6027 | ||
dc6382ce | 6028 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6029 | enum nl80211_mfp mfp = |
dc6382ce | 6030 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6031 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 6032 | use_mfp = true; |
4c476991 JB |
6033 | else if (mfp != NL80211_MFP_NO) |
6034 | return -EINVAL; | |
dc6382ce JM |
6035 | } |
6036 | ||
3e5d7649 JB |
6037 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
6038 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
6039 | ||
7e7c8926 BG |
6040 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6041 | flags |= ASSOC_REQ_DISABLE_HT; | |
6042 | ||
6043 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6044 | ht_capa_mask = | |
6045 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); | |
6046 | ||
6047 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6048 | if (!ht_capa_mask) | |
6049 | return -EINVAL; | |
6050 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
6051 | } | |
6052 | ||
ee2aca34 JB |
6053 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6054 | flags |= ASSOC_REQ_DISABLE_VHT; | |
6055 | ||
6056 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6057 | vht_capa_mask = | |
6058 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]); | |
6059 | ||
6060 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6061 | if (!vht_capa_mask) | |
6062 | return -EINVAL; | |
6063 | vht_capa = nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
6064 | } | |
6065 | ||
c0692b8f | 6066 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 6067 | if (!err) |
3e5d7649 JB |
6068 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
6069 | ssid, ssid_len, ie, ie_len, use_mfp, | |
ee2aca34 JB |
6070 | &crypto, flags, ht_capa, ht_capa_mask, |
6071 | vht_capa, vht_capa_mask); | |
636a5d36 | 6072 | |
636a5d36 JM |
6073 | return err; |
6074 | } | |
6075 | ||
6076 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6077 | { | |
4c476991 JB |
6078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6079 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6080 | const u8 *ie = NULL, *bssid; |
4c476991 | 6081 | int ie_len = 0; |
19957bb3 | 6082 | u16 reason_code; |
d5cdfacb | 6083 | bool local_state_change; |
636a5d36 | 6084 | |
f4a11bb0 JB |
6085 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6086 | return -EINVAL; | |
6087 | ||
6088 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6089 | return -EINVAL; | |
6090 | ||
6091 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6092 | return -EINVAL; | |
6093 | ||
4c476991 JB |
6094 | if (!rdev->ops->deauth) |
6095 | return -EOPNOTSUPP; | |
636a5d36 | 6096 | |
074ac8df | 6097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6099 | return -EOPNOTSUPP; | |
eec60b03 | 6100 | |
19957bb3 | 6101 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6102 | |
19957bb3 JB |
6103 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6104 | if (reason_code == 0) { | |
f4a11bb0 | 6105 | /* Reason Code 0 is reserved */ |
4c476991 | 6106 | return -EINVAL; |
255e737e | 6107 | } |
636a5d36 JM |
6108 | |
6109 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6110 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6111 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6112 | } |
6113 | ||
d5cdfacb JM |
6114 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6115 | ||
4c476991 JB |
6116 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
6117 | local_state_change); | |
636a5d36 JM |
6118 | } |
6119 | ||
6120 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6121 | { | |
4c476991 JB |
6122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6123 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6124 | const u8 *ie = NULL, *bssid; |
4c476991 | 6125 | int ie_len = 0; |
19957bb3 | 6126 | u16 reason_code; |
d5cdfacb | 6127 | bool local_state_change; |
636a5d36 | 6128 | |
f4a11bb0 JB |
6129 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6130 | return -EINVAL; | |
6131 | ||
6132 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6133 | return -EINVAL; | |
6134 | ||
6135 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6136 | return -EINVAL; | |
6137 | ||
4c476991 JB |
6138 | if (!rdev->ops->disassoc) |
6139 | return -EOPNOTSUPP; | |
636a5d36 | 6140 | |
074ac8df | 6141 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6142 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6143 | return -EOPNOTSUPP; | |
eec60b03 | 6144 | |
19957bb3 | 6145 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6146 | |
19957bb3 JB |
6147 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6148 | if (reason_code == 0) { | |
f4a11bb0 | 6149 | /* Reason Code 0 is reserved */ |
4c476991 | 6150 | return -EINVAL; |
255e737e | 6151 | } |
636a5d36 JM |
6152 | |
6153 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6154 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6155 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6156 | } |
6157 | ||
d5cdfacb JM |
6158 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6159 | ||
4c476991 JB |
6160 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
6161 | local_state_change); | |
636a5d36 JM |
6162 | } |
6163 | ||
dd5b4cc7 FF |
6164 | static bool |
6165 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6166 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6167 | int rateval) | |
6168 | { | |
6169 | struct wiphy *wiphy = &rdev->wiphy; | |
6170 | bool found = false; | |
6171 | int band, i; | |
6172 | ||
6173 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6174 | struct ieee80211_supported_band *sband; | |
6175 | ||
6176 | sband = wiphy->bands[band]; | |
6177 | if (!sband) | |
6178 | continue; | |
6179 | ||
6180 | for (i = 0; i < sband->n_bitrates; i++) { | |
6181 | if (sband->bitrates[i].bitrate == rateval) { | |
6182 | mcast_rate[band] = i + 1; | |
6183 | found = true; | |
6184 | break; | |
6185 | } | |
6186 | } | |
6187 | } | |
6188 | ||
6189 | return found; | |
6190 | } | |
6191 | ||
04a773ad JB |
6192 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6193 | { | |
4c476991 JB |
6194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6195 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6196 | struct cfg80211_ibss_params ibss; |
6197 | struct wiphy *wiphy; | |
fffd0934 | 6198 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6199 | int err; |
6200 | ||
8e30bc55 JB |
6201 | memset(&ibss, 0, sizeof(ibss)); |
6202 | ||
04a773ad JB |
6203 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6204 | return -EINVAL; | |
6205 | ||
683b6d3b | 6206 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6207 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6208 | return -EINVAL; | |
6209 | ||
8e30bc55 JB |
6210 | ibss.beacon_interval = 100; |
6211 | ||
6212 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6213 | ibss.beacon_interval = | |
6214 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6215 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6216 | return -EINVAL; | |
6217 | } | |
6218 | ||
4c476991 JB |
6219 | if (!rdev->ops->join_ibss) |
6220 | return -EOPNOTSUPP; | |
04a773ad | 6221 | |
4c476991 JB |
6222 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6223 | return -EOPNOTSUPP; | |
04a773ad | 6224 | |
79c97e97 | 6225 | wiphy = &rdev->wiphy; |
04a773ad | 6226 | |
39193498 | 6227 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6228 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6229 | |
6230 | if (!is_valid_ether_addr(ibss.bssid)) | |
6231 | return -EINVAL; | |
6232 | } | |
04a773ad JB |
6233 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6234 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6235 | ||
6236 | if (info->attrs[NL80211_ATTR_IE]) { | |
6237 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6238 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6239 | } | |
6240 | ||
683b6d3b JB |
6241 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6242 | if (err) | |
6243 | return err; | |
04a773ad | 6244 | |
683b6d3b | 6245 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6246 | return -EINVAL; |
6247 | ||
db9c64cf JB |
6248 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
6249 | return -EINVAL; | |
6250 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
6251 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
c04d6150 | 6252 | return -EINVAL; |
db9c64cf | 6253 | |
04a773ad | 6254 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6255 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6256 | ||
fbd2c8dc TP |
6257 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6258 | u8 *rates = | |
6259 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6260 | int n_rates = | |
6261 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6262 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6263 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6264 | |
34850ab2 JB |
6265 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6266 | &ibss.basic_rates); | |
6267 | if (err) | |
6268 | return err; | |
fbd2c8dc | 6269 | } |
dd5b4cc7 FF |
6270 | |
6271 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
6272 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6273 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6274 | return -EINVAL; | |
fbd2c8dc | 6275 | |
4c476991 | 6276 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6277 | bool no_ht = false; |
6278 | ||
4c476991 | 6279 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6280 | info->attrs[NL80211_ATTR_KEYS], |
6281 | &no_ht); | |
4c476991 JB |
6282 | if (IS_ERR(connkeys)) |
6283 | return PTR_ERR(connkeys); | |
de7044ee | 6284 | |
3d9d1d66 JB |
6285 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6286 | no_ht) { | |
de7044ee SM |
6287 | kfree(connkeys); |
6288 | return -EINVAL; | |
6289 | } | |
4c476991 | 6290 | } |
04a773ad | 6291 | |
267335d6 AQ |
6292 | ibss.control_port = |
6293 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6294 | ||
4c476991 | 6295 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6296 | if (err) |
6297 | kfree(connkeys); | |
04a773ad JB |
6298 | return err; |
6299 | } | |
6300 | ||
6301 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6302 | { | |
4c476991 JB |
6303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6304 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6305 | |
4c476991 JB |
6306 | if (!rdev->ops->leave_ibss) |
6307 | return -EOPNOTSUPP; | |
04a773ad | 6308 | |
4c476991 JB |
6309 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6310 | return -EOPNOTSUPP; | |
04a773ad | 6311 | |
4c476991 | 6312 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6313 | } |
6314 | ||
f4e583c8 AQ |
6315 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6316 | { | |
6317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6318 | struct net_device *dev = info->user_ptr[1]; | |
6319 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6320 | u32 nla_rate; | |
6321 | int err; | |
6322 | ||
6323 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6324 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6325 | return -EOPNOTSUPP; | |
6326 | ||
6327 | if (!rdev->ops->set_mcast_rate) | |
6328 | return -EOPNOTSUPP; | |
6329 | ||
6330 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6331 | ||
6332 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6333 | return -EINVAL; | |
6334 | ||
6335 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6336 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6337 | return -EINVAL; | |
6338 | ||
6339 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6340 | ||
6341 | return err; | |
6342 | } | |
6343 | ||
6344 | ||
aff89a9b JB |
6345 | #ifdef CONFIG_NL80211_TESTMODE |
6346 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6347 | .name = "testmode", | |
6348 | }; | |
6349 | ||
6350 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6351 | { | |
4c476991 | 6352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6353 | int err; |
6354 | ||
6355 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6356 | return -EINVAL; | |
6357 | ||
aff89a9b JB |
6358 | err = -EOPNOTSUPP; |
6359 | if (rdev->ops->testmode_cmd) { | |
6360 | rdev->testmode_info = info; | |
e35e4d28 | 6361 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6362 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6363 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6364 | rdev->testmode_info = NULL; | |
6365 | } | |
6366 | ||
aff89a9b JB |
6367 | return err; |
6368 | } | |
6369 | ||
71063f0e WYG |
6370 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6371 | struct netlink_callback *cb) | |
6372 | { | |
00918d33 | 6373 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6374 | int err; |
6375 | long phy_idx; | |
6376 | void *data = NULL; | |
6377 | int data_len = 0; | |
6378 | ||
6379 | if (cb->args[0]) { | |
6380 | /* | |
6381 | * 0 is a valid index, but not valid for args[0], | |
6382 | * so we need to offset by 1. | |
6383 | */ | |
6384 | phy_idx = cb->args[0] - 1; | |
6385 | } else { | |
6386 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6387 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6388 | nl80211_policy); | |
6389 | if (err) | |
6390 | return err; | |
00918d33 | 6391 | |
2bd7e35d JB |
6392 | mutex_lock(&cfg80211_mutex); |
6393 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
6394 | nl80211_fam.attrbuf); | |
6395 | if (IS_ERR(rdev)) { | |
6396 | mutex_unlock(&cfg80211_mutex); | |
6397 | return PTR_ERR(rdev); | |
00918d33 | 6398 | } |
2bd7e35d JB |
6399 | phy_idx = rdev->wiphy_idx; |
6400 | rdev = NULL; | |
6401 | mutex_unlock(&cfg80211_mutex); | |
6402 | ||
71063f0e WYG |
6403 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6404 | cb->args[1] = | |
6405 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6406 | } | |
6407 | ||
6408 | if (cb->args[1]) { | |
6409 | data = nla_data((void *)cb->args[1]); | |
6410 | data_len = nla_len((void *)cb->args[1]); | |
6411 | } | |
6412 | ||
6413 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
6414 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6415 | if (!rdev) { | |
71063f0e WYG |
6416 | mutex_unlock(&cfg80211_mutex); |
6417 | return -ENOENT; | |
6418 | } | |
00918d33 | 6419 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
6420 | mutex_unlock(&cfg80211_mutex); |
6421 | ||
00918d33 | 6422 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6423 | err = -EOPNOTSUPP; |
6424 | goto out_err; | |
6425 | } | |
6426 | ||
6427 | while (1) { | |
15e47304 | 6428 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6429 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6430 | NL80211_CMD_TESTMODE); | |
6431 | struct nlattr *tmdata; | |
6432 | ||
9360ffd1 | 6433 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6434 | genlmsg_cancel(skb, hdr); |
6435 | break; | |
6436 | } | |
6437 | ||
6438 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6439 | if (!tmdata) { | |
6440 | genlmsg_cancel(skb, hdr); | |
6441 | break; | |
6442 | } | |
e35e4d28 | 6443 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6444 | nla_nest_end(skb, tmdata); |
6445 | ||
6446 | if (err == -ENOBUFS || err == -ENOENT) { | |
6447 | genlmsg_cancel(skb, hdr); | |
6448 | break; | |
6449 | } else if (err) { | |
6450 | genlmsg_cancel(skb, hdr); | |
6451 | goto out_err; | |
6452 | } | |
6453 | ||
6454 | genlmsg_end(skb, hdr); | |
6455 | } | |
6456 | ||
6457 | err = skb->len; | |
6458 | /* see above */ | |
6459 | cb->args[0] = phy_idx + 1; | |
6460 | out_err: | |
00918d33 | 6461 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
6462 | return err; |
6463 | } | |
6464 | ||
aff89a9b JB |
6465 | static struct sk_buff * |
6466 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6467 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6468 | { |
6469 | struct sk_buff *skb; | |
6470 | void *hdr; | |
6471 | struct nlattr *data; | |
6472 | ||
6473 | skb = nlmsg_new(approxlen + 100, gfp); | |
6474 | if (!skb) | |
6475 | return NULL; | |
6476 | ||
15e47304 | 6477 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6478 | if (!hdr) { |
6479 | kfree_skb(skb); | |
6480 | return NULL; | |
6481 | } | |
6482 | ||
9360ffd1 DM |
6483 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6484 | goto nla_put_failure; | |
aff89a9b JB |
6485 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6486 | ||
6487 | ((void **)skb->cb)[0] = rdev; | |
6488 | ((void **)skb->cb)[1] = hdr; | |
6489 | ((void **)skb->cb)[2] = data; | |
6490 | ||
6491 | return skb; | |
6492 | ||
6493 | nla_put_failure: | |
6494 | kfree_skb(skb); | |
6495 | return NULL; | |
6496 | } | |
6497 | ||
6498 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6499 | int approxlen) | |
6500 | { | |
6501 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6502 | ||
6503 | if (WARN_ON(!rdev->testmode_info)) | |
6504 | return NULL; | |
6505 | ||
6506 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6507 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6508 | rdev->testmode_info->snd_seq, |
6509 | GFP_KERNEL); | |
6510 | } | |
6511 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6512 | ||
6513 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6514 | { | |
6515 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6516 | void *hdr = ((void **)skb->cb)[1]; | |
6517 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6518 | ||
6519 | if (WARN_ON(!rdev->testmode_info)) { | |
6520 | kfree_skb(skb); | |
6521 | return -EINVAL; | |
6522 | } | |
6523 | ||
6524 | nla_nest_end(skb, data); | |
6525 | genlmsg_end(skb, hdr); | |
6526 | return genlmsg_reply(skb, rdev->testmode_info); | |
6527 | } | |
6528 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6529 | ||
6530 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6531 | int approxlen, gfp_t gfp) | |
6532 | { | |
6533 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6534 | ||
6535 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6536 | } | |
6537 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6538 | ||
6539 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6540 | { | |
6541 | void *hdr = ((void **)skb->cb)[1]; | |
6542 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6543 | ||
6544 | nla_nest_end(skb, data); | |
6545 | genlmsg_end(skb, hdr); | |
6546 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6547 | } | |
6548 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6549 | #endif | |
6550 | ||
b23aa676 SO |
6551 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6552 | { | |
4c476991 JB |
6553 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6554 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6555 | struct cfg80211_connect_params connect; |
6556 | struct wiphy *wiphy; | |
fffd0934 | 6557 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6558 | int err; |
6559 | ||
6560 | memset(&connect, 0, sizeof(connect)); | |
6561 | ||
6562 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6563 | return -EINVAL; | |
6564 | ||
6565 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6566 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6567 | return -EINVAL; | |
6568 | ||
6569 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6570 | connect.auth_type = | |
6571 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6572 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6573 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6574 | return -EINVAL; |
6575 | } else | |
6576 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6577 | ||
6578 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6579 | ||
c0692b8f | 6580 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6581 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6582 | if (err) |
6583 | return err; | |
b23aa676 | 6584 | |
074ac8df | 6585 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6586 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6587 | return -EOPNOTSUPP; | |
b23aa676 | 6588 | |
79c97e97 | 6589 | wiphy = &rdev->wiphy; |
b23aa676 | 6590 | |
4486ea98 BS |
6591 | connect.bg_scan_period = -1; |
6592 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6593 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6594 | connect.bg_scan_period = | |
6595 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6596 | } | |
6597 | ||
b23aa676 SO |
6598 | if (info->attrs[NL80211_ATTR_MAC]) |
6599 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6600 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6601 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6602 | ||
6603 | if (info->attrs[NL80211_ATTR_IE]) { | |
6604 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6605 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6606 | } | |
6607 | ||
cee00a95 JM |
6608 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6609 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6610 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6611 | connect.mfp != NL80211_MFP_NO) | |
6612 | return -EINVAL; | |
6613 | } else { | |
6614 | connect.mfp = NL80211_MFP_NO; | |
6615 | } | |
6616 | ||
b23aa676 SO |
6617 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6618 | connect.channel = | |
6619 | ieee80211_get_channel(wiphy, | |
6620 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6621 | if (!connect.channel || | |
4c476991 JB |
6622 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6623 | return -EINVAL; | |
b23aa676 SO |
6624 | } |
6625 | ||
fffd0934 JB |
6626 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6627 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6628 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6629 | if (IS_ERR(connkeys)) |
6630 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6631 | } |
6632 | ||
7e7c8926 BG |
6633 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6634 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6635 | ||
6636 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6637 | memcpy(&connect.ht_capa_mask, | |
6638 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6639 | sizeof(connect.ht_capa_mask)); | |
6640 | ||
6641 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6642 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6643 | kfree(connkeys); | |
7e7c8926 | 6644 | return -EINVAL; |
b4e4f47e | 6645 | } |
7e7c8926 BG |
6646 | memcpy(&connect.ht_capa, |
6647 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6648 | sizeof(connect.ht_capa)); | |
6649 | } | |
6650 | ||
ee2aca34 JB |
6651 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6652 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6653 | ||
6654 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6655 | memcpy(&connect.vht_capa_mask, | |
6656 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6657 | sizeof(connect.vht_capa_mask)); | |
6658 | ||
6659 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6660 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6661 | kfree(connkeys); | |
6662 | return -EINVAL; | |
6663 | } | |
6664 | memcpy(&connect.vht_capa, | |
6665 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6666 | sizeof(connect.vht_capa)); | |
6667 | } | |
6668 | ||
fffd0934 | 6669 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
6670 | if (err) |
6671 | kfree(connkeys); | |
b23aa676 SO |
6672 | return err; |
6673 | } | |
6674 | ||
6675 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6676 | { | |
4c476991 JB |
6677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6678 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6679 | u16 reason; |
6680 | ||
6681 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6682 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6683 | else | |
6684 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6685 | ||
6686 | if (reason == 0) | |
6687 | return -EINVAL; | |
6688 | ||
074ac8df | 6689 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6690 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6691 | return -EOPNOTSUPP; | |
b23aa676 | 6692 | |
4c476991 | 6693 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
6694 | } |
6695 | ||
463d0183 JB |
6696 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6697 | { | |
4c476991 | 6698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6699 | struct net *net; |
6700 | int err; | |
6701 | u32 pid; | |
6702 | ||
6703 | if (!info->attrs[NL80211_ATTR_PID]) | |
6704 | return -EINVAL; | |
6705 | ||
6706 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6707 | ||
463d0183 | 6708 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6709 | if (IS_ERR(net)) |
6710 | return PTR_ERR(net); | |
463d0183 JB |
6711 | |
6712 | err = 0; | |
6713 | ||
6714 | /* check if anything to do */ | |
4c476991 JB |
6715 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6716 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6717 | |
463d0183 | 6718 | put_net(net); |
463d0183 JB |
6719 | return err; |
6720 | } | |
6721 | ||
67fbb16b SO |
6722 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6723 | { | |
4c476991 | 6724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6725 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6726 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6727 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6728 | struct cfg80211_pmksa pmksa; |
6729 | ||
6730 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6731 | ||
6732 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6733 | return -EINVAL; | |
6734 | ||
6735 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6736 | return -EINVAL; | |
6737 | ||
67fbb16b SO |
6738 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6739 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6740 | ||
074ac8df | 6741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6742 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6743 | return -EOPNOTSUPP; | |
67fbb16b SO |
6744 | |
6745 | switch (info->genlhdr->cmd) { | |
6746 | case NL80211_CMD_SET_PMKSA: | |
6747 | rdev_ops = rdev->ops->set_pmksa; | |
6748 | break; | |
6749 | case NL80211_CMD_DEL_PMKSA: | |
6750 | rdev_ops = rdev->ops->del_pmksa; | |
6751 | break; | |
6752 | default: | |
6753 | WARN_ON(1); | |
6754 | break; | |
6755 | } | |
6756 | ||
4c476991 JB |
6757 | if (!rdev_ops) |
6758 | return -EOPNOTSUPP; | |
67fbb16b | 6759 | |
4c476991 | 6760 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6761 | } |
6762 | ||
6763 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6764 | { | |
4c476991 JB |
6765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6766 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6767 | |
074ac8df | 6768 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6770 | return -EOPNOTSUPP; | |
67fbb16b | 6771 | |
4c476991 JB |
6772 | if (!rdev->ops->flush_pmksa) |
6773 | return -EOPNOTSUPP; | |
67fbb16b | 6774 | |
e35e4d28 | 6775 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6776 | } |
6777 | ||
109086ce AN |
6778 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6779 | { | |
6780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6781 | struct net_device *dev = info->user_ptr[1]; | |
6782 | u8 action_code, dialog_token; | |
6783 | u16 status_code; | |
6784 | u8 *peer; | |
6785 | ||
6786 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6787 | !rdev->ops->tdls_mgmt) | |
6788 | return -EOPNOTSUPP; | |
6789 | ||
6790 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6791 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6792 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6793 | !info->attrs[NL80211_ATTR_IE] || | |
6794 | !info->attrs[NL80211_ATTR_MAC]) | |
6795 | return -EINVAL; | |
6796 | ||
6797 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6798 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6799 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6800 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6801 | ||
e35e4d28 HG |
6802 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6803 | dialog_token, status_code, | |
6804 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6805 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6806 | } |
6807 | ||
6808 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6809 | { | |
6810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6811 | struct net_device *dev = info->user_ptr[1]; | |
6812 | enum nl80211_tdls_operation operation; | |
6813 | u8 *peer; | |
6814 | ||
6815 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6816 | !rdev->ops->tdls_oper) | |
6817 | return -EOPNOTSUPP; | |
6818 | ||
6819 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6820 | !info->attrs[NL80211_ATTR_MAC]) | |
6821 | return -EINVAL; | |
6822 | ||
6823 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6824 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6825 | ||
e35e4d28 | 6826 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6827 | } |
6828 | ||
9588bbd5 JM |
6829 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6830 | struct genl_info *info) | |
6831 | { | |
4c476991 | 6832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6833 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6834 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6835 | struct sk_buff *msg; |
6836 | void *hdr; | |
6837 | u64 cookie; | |
683b6d3b | 6838 | u32 duration; |
9588bbd5 JM |
6839 | int err; |
6840 | ||
6841 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6842 | !info->attrs[NL80211_ATTR_DURATION]) | |
6843 | return -EINVAL; | |
6844 | ||
6845 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6846 | ||
ebf348fc JB |
6847 | if (!rdev->ops->remain_on_channel || |
6848 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6849 | return -EOPNOTSUPP; | |
6850 | ||
9588bbd5 | 6851 | /* |
ebf348fc JB |
6852 | * We should be on that channel for at least a minimum amount of |
6853 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6854 | */ |
ebf348fc | 6855 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6856 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6857 | return -EINVAL; |
6858 | ||
683b6d3b JB |
6859 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6860 | if (err) | |
6861 | return err; | |
9588bbd5 JM |
6862 | |
6863 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6864 | if (!msg) |
6865 | return -ENOMEM; | |
9588bbd5 | 6866 | |
15e47304 | 6867 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6868 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6869 | ||
6870 | if (IS_ERR(hdr)) { | |
6871 | err = PTR_ERR(hdr); | |
6872 | goto free_msg; | |
6873 | } | |
6874 | ||
683b6d3b JB |
6875 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6876 | duration, &cookie); | |
9588bbd5 JM |
6877 | |
6878 | if (err) | |
6879 | goto free_msg; | |
6880 | ||
9360ffd1 DM |
6881 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6882 | goto nla_put_failure; | |
9588bbd5 JM |
6883 | |
6884 | genlmsg_end(msg, hdr); | |
4c476991 JB |
6885 | |
6886 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
6887 | |
6888 | nla_put_failure: | |
6889 | err = -ENOBUFS; | |
6890 | free_msg: | |
6891 | nlmsg_free(msg); | |
9588bbd5 JM |
6892 | return err; |
6893 | } | |
6894 | ||
6895 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
6896 | struct genl_info *info) | |
6897 | { | |
4c476991 | 6898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6899 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 6900 | u64 cookie; |
9588bbd5 JM |
6901 | |
6902 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6903 | return -EINVAL; | |
6904 | ||
4c476991 JB |
6905 | if (!rdev->ops->cancel_remain_on_channel) |
6906 | return -EOPNOTSUPP; | |
9588bbd5 | 6907 | |
9588bbd5 JM |
6908 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
6909 | ||
e35e4d28 | 6910 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
6911 | } |
6912 | ||
13ae75b1 JM |
6913 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
6914 | u8 *rates, u8 rates_len) | |
6915 | { | |
6916 | u8 i; | |
6917 | u32 mask = 0; | |
6918 | ||
6919 | for (i = 0; i < rates_len; i++) { | |
6920 | int rate = (rates[i] & 0x7f) * 5; | |
6921 | int ridx; | |
6922 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
6923 | struct ieee80211_rate *srate = | |
6924 | &sband->bitrates[ridx]; | |
6925 | if (rate == srate->bitrate) { | |
6926 | mask |= 1 << ridx; | |
6927 | break; | |
6928 | } | |
6929 | } | |
6930 | if (ridx == sband->n_bitrates) | |
6931 | return 0; /* rate not found */ | |
6932 | } | |
6933 | ||
6934 | return mask; | |
6935 | } | |
6936 | ||
24db78c0 SW |
6937 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
6938 | u8 *rates, u8 rates_len, | |
6939 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
6940 | { | |
6941 | u8 i; | |
6942 | ||
6943 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
6944 | ||
6945 | for (i = 0; i < rates_len; i++) { | |
6946 | int ridx, rbit; | |
6947 | ||
6948 | ridx = rates[i] / 8; | |
6949 | rbit = BIT(rates[i] % 8); | |
6950 | ||
6951 | /* check validity */ | |
910570b5 | 6952 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
6953 | return false; |
6954 | ||
6955 | /* check availability */ | |
6956 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
6957 | mcs[ridx] |= rbit; | |
6958 | else | |
6959 | return false; | |
6960 | } | |
6961 | ||
6962 | return true; | |
6963 | } | |
6964 | ||
b54452b0 | 6965 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
6966 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
6967 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
6968 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
6969 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
6970 | }; |
6971 | ||
6972 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
6973 | struct genl_info *info) | |
6974 | { | |
6975 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 6976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 6977 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
6978 | int rem, i; |
6979 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
6980 | struct nlattr *tx_rates; |
6981 | struct ieee80211_supported_band *sband; | |
6982 | ||
6983 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
6984 | return -EINVAL; | |
6985 | ||
4c476991 JB |
6986 | if (!rdev->ops->set_bitrate_mask) |
6987 | return -EOPNOTSUPP; | |
13ae75b1 JM |
6988 | |
6989 | memset(&mask, 0, sizeof(mask)); | |
6990 | /* Default to all rates enabled */ | |
6991 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
6992 | sband = rdev->wiphy.bands[i]; | |
6993 | mask.control[i].legacy = | |
6994 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
6995 | if (sband) |
6996 | memcpy(mask.control[i].mcs, | |
6997 | sband->ht_cap.mcs.rx_mask, | |
6998 | sizeof(mask.control[i].mcs)); | |
6999 | else | |
7000 | memset(mask.control[i].mcs, 0, | |
7001 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7002 | } |
7003 | ||
7004 | /* | |
7005 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7006 | * directly to the enum ieee80211_band values used in cfg80211. | |
7007 | */ | |
24db78c0 | 7008 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7009 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7010 | { | |
7011 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7012 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7013 | return -EINVAL; | |
13ae75b1 | 7014 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7015 | if (sband == NULL) |
7016 | return -EINVAL; | |
13ae75b1 JM |
7017 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7018 | nla_len(tx_rates), nl80211_txattr_policy); | |
7019 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7020 | mask.control[band].legacy = rateset_to_mask( | |
7021 | sband, | |
7022 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7023 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7024 | if ((mask.control[band].legacy == 0) && |
7025 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7026 | return -EINVAL; | |
24db78c0 SW |
7027 | } |
7028 | if (tb[NL80211_TXRATE_MCS]) { | |
7029 | if (!ht_rateset_to_mask( | |
7030 | sband, | |
7031 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7032 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7033 | mask.control[band].mcs)) | |
7034 | return -EINVAL; | |
7035 | } | |
7036 | ||
7037 | if (mask.control[band].legacy == 0) { | |
7038 | /* don't allow empty legacy rates if HT | |
7039 | * is not even supported. */ | |
7040 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7041 | return -EINVAL; | |
7042 | ||
7043 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7044 | if (mask.control[band].mcs[i]) | |
7045 | break; | |
7046 | ||
7047 | /* legacy and mcs rates may not be both empty */ | |
7048 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7049 | return -EINVAL; |
13ae75b1 JM |
7050 | } |
7051 | } | |
7052 | ||
e35e4d28 | 7053 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7054 | } |
7055 | ||
2e161f78 | 7056 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7057 | { |
4c476991 | 7058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7059 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7060 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7061 | |
7062 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7063 | return -EINVAL; | |
7064 | ||
2e161f78 JB |
7065 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7066 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7067 | |
71bbc994 JB |
7068 | switch (wdev->iftype) { |
7069 | case NL80211_IFTYPE_STATION: | |
7070 | case NL80211_IFTYPE_ADHOC: | |
7071 | case NL80211_IFTYPE_P2P_CLIENT: | |
7072 | case NL80211_IFTYPE_AP: | |
7073 | case NL80211_IFTYPE_AP_VLAN: | |
7074 | case NL80211_IFTYPE_MESH_POINT: | |
7075 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7076 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7077 | break; |
7078 | default: | |
4c476991 | 7079 | return -EOPNOTSUPP; |
71bbc994 | 7080 | } |
026331c4 JM |
7081 | |
7082 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7083 | if (!rdev->ops->mgmt_tx) |
7084 | return -EOPNOTSUPP; | |
026331c4 | 7085 | |
15e47304 | 7086 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7087 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7088 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7089 | } |
7090 | ||
2e161f78 | 7091 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7092 | { |
4c476991 | 7093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7094 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7095 | struct cfg80211_chan_def chandef; |
026331c4 | 7096 | int err; |
d64d373f | 7097 | void *hdr = NULL; |
026331c4 | 7098 | u64 cookie; |
e247bd90 | 7099 | struct sk_buff *msg = NULL; |
f7ca38df | 7100 | unsigned int wait = 0; |
e247bd90 JB |
7101 | bool offchan, no_cck, dont_wait_for_ack; |
7102 | ||
7103 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7104 | |
683b6d3b | 7105 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7106 | return -EINVAL; |
7107 | ||
4c476991 JB |
7108 | if (!rdev->ops->mgmt_tx) |
7109 | return -EOPNOTSUPP; | |
026331c4 | 7110 | |
71bbc994 JB |
7111 | switch (wdev->iftype) { |
7112 | case NL80211_IFTYPE_STATION: | |
7113 | case NL80211_IFTYPE_ADHOC: | |
7114 | case NL80211_IFTYPE_P2P_CLIENT: | |
7115 | case NL80211_IFTYPE_AP: | |
7116 | case NL80211_IFTYPE_AP_VLAN: | |
7117 | case NL80211_IFTYPE_MESH_POINT: | |
7118 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7119 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7120 | break; |
7121 | default: | |
4c476991 | 7122 | return -EOPNOTSUPP; |
71bbc994 | 7123 | } |
026331c4 | 7124 | |
f7ca38df | 7125 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7126 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7127 | return -EINVAL; |
7128 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7129 | |
7130 | /* | |
7131 | * We should wait on the channel for at least a minimum amount | |
7132 | * of time (10ms) but no longer than the driver supports. | |
7133 | */ | |
7134 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7135 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7136 | return -EINVAL; | |
7137 | ||
f7ca38df JB |
7138 | } |
7139 | ||
f7ca38df JB |
7140 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7141 | ||
7c4ef712 JB |
7142 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7143 | return -EINVAL; | |
7144 | ||
e9f935e3 RM |
7145 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7146 | ||
683b6d3b JB |
7147 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7148 | if (err) | |
7149 | return err; | |
026331c4 | 7150 | |
e247bd90 JB |
7151 | if (!dont_wait_for_ack) { |
7152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7153 | if (!msg) | |
7154 | return -ENOMEM; | |
026331c4 | 7155 | |
15e47304 | 7156 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7157 | NL80211_CMD_FRAME); |
026331c4 | 7158 | |
e247bd90 JB |
7159 | if (IS_ERR(hdr)) { |
7160 | err = PTR_ERR(hdr); | |
7161 | goto free_msg; | |
7162 | } | |
026331c4 | 7163 | } |
e247bd90 | 7164 | |
683b6d3b | 7165 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7166 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7167 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7168 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7169 | if (err) |
7170 | goto free_msg; | |
7171 | ||
e247bd90 | 7172 | if (msg) { |
9360ffd1 DM |
7173 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7174 | goto nla_put_failure; | |
026331c4 | 7175 | |
e247bd90 JB |
7176 | genlmsg_end(msg, hdr); |
7177 | return genlmsg_reply(msg, info); | |
7178 | } | |
7179 | ||
7180 | return 0; | |
026331c4 JM |
7181 | |
7182 | nla_put_failure: | |
7183 | err = -ENOBUFS; | |
7184 | free_msg: | |
7185 | nlmsg_free(msg); | |
026331c4 JM |
7186 | return err; |
7187 | } | |
7188 | ||
f7ca38df JB |
7189 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7190 | { | |
7191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7192 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7193 | u64 cookie; |
7194 | ||
7195 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7196 | return -EINVAL; | |
7197 | ||
7198 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7199 | return -EOPNOTSUPP; | |
7200 | ||
71bbc994 JB |
7201 | switch (wdev->iftype) { |
7202 | case NL80211_IFTYPE_STATION: | |
7203 | case NL80211_IFTYPE_ADHOC: | |
7204 | case NL80211_IFTYPE_P2P_CLIENT: | |
7205 | case NL80211_IFTYPE_AP: | |
7206 | case NL80211_IFTYPE_AP_VLAN: | |
7207 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7208 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7209 | break; |
7210 | default: | |
f7ca38df | 7211 | return -EOPNOTSUPP; |
71bbc994 | 7212 | } |
f7ca38df JB |
7213 | |
7214 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7215 | ||
e35e4d28 | 7216 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7217 | } |
7218 | ||
ffb9eb3d KV |
7219 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7220 | { | |
4c476991 | 7221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7222 | struct wireless_dev *wdev; |
4c476991 | 7223 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7224 | u8 ps_state; |
7225 | bool state; | |
7226 | int err; | |
7227 | ||
4c476991 JB |
7228 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7229 | return -EINVAL; | |
ffb9eb3d KV |
7230 | |
7231 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7232 | ||
4c476991 JB |
7233 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7234 | return -EINVAL; | |
ffb9eb3d KV |
7235 | |
7236 | wdev = dev->ieee80211_ptr; | |
7237 | ||
4c476991 JB |
7238 | if (!rdev->ops->set_power_mgmt) |
7239 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7240 | |
7241 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7242 | ||
7243 | if (state == wdev->ps) | |
4c476991 | 7244 | return 0; |
ffb9eb3d | 7245 | |
e35e4d28 | 7246 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7247 | if (!err) |
7248 | wdev->ps = state; | |
ffb9eb3d KV |
7249 | return err; |
7250 | } | |
7251 | ||
7252 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7253 | { | |
4c476991 | 7254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7255 | enum nl80211_ps_state ps_state; |
7256 | struct wireless_dev *wdev; | |
4c476991 | 7257 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7258 | struct sk_buff *msg; |
7259 | void *hdr; | |
7260 | int err; | |
7261 | ||
ffb9eb3d KV |
7262 | wdev = dev->ieee80211_ptr; |
7263 | ||
4c476991 JB |
7264 | if (!rdev->ops->set_power_mgmt) |
7265 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7266 | |
7267 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7268 | if (!msg) |
7269 | return -ENOMEM; | |
ffb9eb3d | 7270 | |
15e47304 | 7271 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7272 | NL80211_CMD_GET_POWER_SAVE); |
7273 | if (!hdr) { | |
4c476991 | 7274 | err = -ENOBUFS; |
ffb9eb3d KV |
7275 | goto free_msg; |
7276 | } | |
7277 | ||
7278 | if (wdev->ps) | |
7279 | ps_state = NL80211_PS_ENABLED; | |
7280 | else | |
7281 | ps_state = NL80211_PS_DISABLED; | |
7282 | ||
9360ffd1 DM |
7283 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7284 | goto nla_put_failure; | |
ffb9eb3d KV |
7285 | |
7286 | genlmsg_end(msg, hdr); | |
4c476991 | 7287 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7288 | |
4c476991 | 7289 | nla_put_failure: |
ffb9eb3d | 7290 | err = -ENOBUFS; |
4c476991 | 7291 | free_msg: |
ffb9eb3d | 7292 | nlmsg_free(msg); |
ffb9eb3d KV |
7293 | return err; |
7294 | } | |
7295 | ||
d6dc1a38 JO |
7296 | static struct nla_policy |
7297 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7298 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7299 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7300 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7301 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7302 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7303 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7304 | }; |
7305 | ||
84f10708 | 7306 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7307 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7308 | { |
7309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7310 | struct wireless_dev *wdev; | |
7311 | struct net_device *dev = info->user_ptr[1]; | |
7312 | ||
d9d8b019 | 7313 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7314 | return -EINVAL; |
7315 | ||
7316 | wdev = dev->ieee80211_ptr; | |
7317 | ||
7318 | if (!rdev->ops->set_cqm_txe_config) | |
7319 | return -EOPNOTSUPP; | |
7320 | ||
7321 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7322 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7323 | return -EOPNOTSUPP; | |
7324 | ||
e35e4d28 | 7325 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7326 | } |
7327 | ||
d6dc1a38 JO |
7328 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7329 | s32 threshold, u32 hysteresis) | |
7330 | { | |
4c476991 | 7331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7332 | struct wireless_dev *wdev; |
4c476991 | 7333 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7334 | |
7335 | if (threshold > 0) | |
7336 | return -EINVAL; | |
7337 | ||
d6dc1a38 JO |
7338 | wdev = dev->ieee80211_ptr; |
7339 | ||
4c476991 JB |
7340 | if (!rdev->ops->set_cqm_rssi_config) |
7341 | return -EOPNOTSUPP; | |
d6dc1a38 | 7342 | |
074ac8df | 7343 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7344 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7345 | return -EOPNOTSUPP; | |
d6dc1a38 | 7346 | |
e35e4d28 | 7347 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7348 | } |
7349 | ||
7350 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7351 | { | |
7352 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7353 | struct nlattr *cqm; | |
7354 | int err; | |
7355 | ||
7356 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7357 | if (!cqm) { | |
7358 | err = -EINVAL; | |
7359 | goto out; | |
7360 | } | |
7361 | ||
7362 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7363 | nl80211_attr_cqm_policy); | |
7364 | if (err) | |
7365 | goto out; | |
7366 | ||
7367 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7368 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7369 | s32 threshold; | |
7370 | u32 hysteresis; | |
7371 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7372 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7373 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7374 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7375 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7376 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7377 | u32 rate, pkts, intvl; | |
7378 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7379 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7380 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7381 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7382 | } else |
7383 | err = -EINVAL; | |
7384 | ||
7385 | out: | |
7386 | return err; | |
7387 | } | |
7388 | ||
29cbe68c JB |
7389 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7390 | { | |
7391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7392 | struct net_device *dev = info->user_ptr[1]; | |
7393 | struct mesh_config cfg; | |
c80d545d | 7394 | struct mesh_setup setup; |
29cbe68c JB |
7395 | int err; |
7396 | ||
7397 | /* start with default */ | |
7398 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7399 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7400 | |
24bdd9f4 | 7401 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7402 | /* and parse parameters if given */ |
24bdd9f4 | 7403 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7404 | if (err) |
7405 | return err; | |
7406 | } | |
7407 | ||
7408 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7409 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7410 | return -EINVAL; | |
7411 | ||
c80d545d JC |
7412 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7413 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7414 | ||
4bb62344 CYY |
7415 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7416 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7417 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7418 | return -EINVAL; | |
7419 | ||
9bdbf04d MP |
7420 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7421 | setup.beacon_interval = | |
7422 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7423 | if (setup.beacon_interval < 10 || | |
7424 | setup.beacon_interval > 10000) | |
7425 | return -EINVAL; | |
7426 | } | |
7427 | ||
7428 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7429 | setup.dtim_period = | |
7430 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7431 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7432 | return -EINVAL; | |
7433 | } | |
7434 | ||
c80d545d JC |
7435 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7436 | /* parse additional setup parameters if given */ | |
7437 | err = nl80211_parse_mesh_setup(info, &setup); | |
7438 | if (err) | |
7439 | return err; | |
7440 | } | |
7441 | ||
cc1d2806 | 7442 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7443 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7444 | if (err) | |
7445 | return err; | |
cc1d2806 JB |
7446 | } else { |
7447 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7448 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7449 | } |
7450 | ||
c80d545d | 7451 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7452 | } |
7453 | ||
7454 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7455 | { | |
7456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7457 | struct net_device *dev = info->user_ptr[1]; | |
7458 | ||
7459 | return cfg80211_leave_mesh(rdev, dev); | |
7460 | } | |
7461 | ||
dfb89c56 | 7462 | #ifdef CONFIG_PM |
bb92d199 AK |
7463 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7464 | struct cfg80211_registered_device *rdev) | |
7465 | { | |
7466 | struct nlattr *nl_pats, *nl_pat; | |
7467 | int i, pat_len; | |
7468 | ||
7469 | if (!rdev->wowlan->n_patterns) | |
7470 | return 0; | |
7471 | ||
7472 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7473 | if (!nl_pats) | |
7474 | return -ENOBUFS; | |
7475 | ||
7476 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
7477 | nl_pat = nla_nest_start(msg, i + 1); | |
7478 | if (!nl_pat) | |
7479 | return -ENOBUFS; | |
7480 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
7481 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
7482 | DIV_ROUND_UP(pat_len, 8), | |
7483 | rdev->wowlan->patterns[i].mask) || | |
7484 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
7485 | pat_len, rdev->wowlan->patterns[i].pattern) || | |
7486 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, | |
7487 | rdev->wowlan->patterns[i].pkt_offset)) | |
7488 | return -ENOBUFS; | |
7489 | nla_nest_end(msg, nl_pat); | |
7490 | } | |
7491 | nla_nest_end(msg, nl_pats); | |
7492 | ||
7493 | return 0; | |
7494 | } | |
7495 | ||
2a0e047e JB |
7496 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7497 | struct cfg80211_wowlan_tcp *tcp) | |
7498 | { | |
7499 | struct nlattr *nl_tcp; | |
7500 | ||
7501 | if (!tcp) | |
7502 | return 0; | |
7503 | ||
7504 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7505 | if (!nl_tcp) | |
7506 | return -ENOBUFS; | |
7507 | ||
7508 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7509 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7510 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7511 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7512 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7513 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7514 | tcp->payload_len, tcp->payload) || | |
7515 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7516 | tcp->data_interval) || | |
7517 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7518 | tcp->wake_len, tcp->wake_data) || | |
7519 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7520 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7521 | return -ENOBUFS; | |
7522 | ||
7523 | if (tcp->payload_seq.len && | |
7524 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7525 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7526 | return -ENOBUFS; | |
7527 | ||
7528 | if (tcp->payload_tok.len && | |
7529 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7530 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7531 | &tcp->payload_tok)) | |
7532 | return -ENOBUFS; | |
7533 | ||
7534 | return 0; | |
7535 | } | |
7536 | ||
ff1b6e69 JB |
7537 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7538 | { | |
7539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7540 | struct sk_buff *msg; | |
7541 | void *hdr; | |
2a0e047e | 7542 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7543 | |
2a0e047e JB |
7544 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7545 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7546 | return -EOPNOTSUPP; |
7547 | ||
2a0e047e JB |
7548 | if (rdev->wowlan && rdev->wowlan->tcp) { |
7549 | /* adjust size to have room for all the data */ | |
7550 | size += rdev->wowlan->tcp->tokens_size + | |
7551 | rdev->wowlan->tcp->payload_len + | |
7552 | rdev->wowlan->tcp->wake_len + | |
7553 | rdev->wowlan->tcp->wake_len / 8; | |
7554 | } | |
7555 | ||
7556 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7557 | if (!msg) |
7558 | return -ENOMEM; | |
7559 | ||
15e47304 | 7560 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7561 | NL80211_CMD_GET_WOWLAN); |
7562 | if (!hdr) | |
7563 | goto nla_put_failure; | |
7564 | ||
7565 | if (rdev->wowlan) { | |
7566 | struct nlattr *nl_wowlan; | |
7567 | ||
7568 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7569 | if (!nl_wowlan) | |
7570 | goto nla_put_failure; | |
7571 | ||
9360ffd1 DM |
7572 | if ((rdev->wowlan->any && |
7573 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7574 | (rdev->wowlan->disconnect && | |
7575 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7576 | (rdev->wowlan->magic_pkt && | |
7577 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7578 | (rdev->wowlan->gtk_rekey_failure && | |
7579 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7580 | (rdev->wowlan->eap_identity_req && | |
7581 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7582 | (rdev->wowlan->four_way_handshake && | |
7583 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7584 | (rdev->wowlan->rfkill_release && | |
7585 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
7586 | goto nla_put_failure; | |
2a0e047e | 7587 | |
bb92d199 AK |
7588 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7589 | goto nla_put_failure; | |
2a0e047e JB |
7590 | |
7591 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) | |
7592 | goto nla_put_failure; | |
7593 | ||
ff1b6e69 JB |
7594 | nla_nest_end(msg, nl_wowlan); |
7595 | } | |
7596 | ||
7597 | genlmsg_end(msg, hdr); | |
7598 | return genlmsg_reply(msg, info); | |
7599 | ||
7600 | nla_put_failure: | |
7601 | nlmsg_free(msg); | |
7602 | return -ENOBUFS; | |
7603 | } | |
7604 | ||
2a0e047e JB |
7605 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7606 | struct nlattr *attr, | |
7607 | struct cfg80211_wowlan *trig) | |
7608 | { | |
7609 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7610 | struct cfg80211_wowlan_tcp *cfg; | |
7611 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7612 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7613 | u32 size; | |
7614 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7615 | int err, port; | |
7616 | ||
7617 | if (!rdev->wiphy.wowlan.tcp) | |
7618 | return -EINVAL; | |
7619 | ||
7620 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7621 | nla_data(attr), nla_len(attr), | |
7622 | nl80211_wowlan_tcp_policy); | |
7623 | if (err) | |
7624 | return err; | |
7625 | ||
7626 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7627 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7628 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7629 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7630 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7631 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7632 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7633 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7634 | return -EINVAL; | |
7635 | ||
7636 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
7637 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) | |
7638 | return -EINVAL; | |
7639 | ||
7640 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
7641 | rdev->wiphy.wowlan.tcp->data_interval_max) | |
7642 | return -EINVAL; | |
7643 | ||
7644 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
7645 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) | |
7646 | return -EINVAL; | |
7647 | ||
7648 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7649 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7650 | return -EINVAL; | |
7651 | ||
7652 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7653 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7654 | ||
7655 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7656 | tokens_size = tokln - sizeof(*tok); | |
7657 | ||
7658 | if (!tok->len || tokens_size % tok->len) | |
7659 | return -EINVAL; | |
7660 | if (!rdev->wiphy.wowlan.tcp->tok) | |
7661 | return -EINVAL; | |
7662 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) | |
7663 | return -EINVAL; | |
7664 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) | |
7665 | return -EINVAL; | |
7666 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) | |
7667 | return -EINVAL; | |
7668 | if (tok->offset + tok->len > data_size) | |
7669 | return -EINVAL; | |
7670 | } | |
7671 | ||
7672 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7673 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
7674 | if (!rdev->wiphy.wowlan.tcp->seq) | |
7675 | return -EINVAL; | |
7676 | if (seq->len == 0 || seq->len > 4) | |
7677 | return -EINVAL; | |
7678 | if (seq->len + seq->offset > data_size) | |
7679 | return -EINVAL; | |
7680 | } | |
7681 | ||
7682 | size = sizeof(*cfg); | |
7683 | size += data_size; | |
7684 | size += wake_size + wake_mask_size; | |
7685 | size += tokens_size; | |
7686 | ||
7687 | cfg = kzalloc(size, GFP_KERNEL); | |
7688 | if (!cfg) | |
7689 | return -ENOMEM; | |
7690 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7691 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7692 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7693 | ETH_ALEN); | |
7694 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7695 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7696 | else | |
7697 | port = 0; | |
7698 | #ifdef CONFIG_INET | |
7699 | /* allocate a socket and port for it and use it */ | |
7700 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7701 | IPPROTO_TCP, &cfg->sock, 1); | |
7702 | if (err) { | |
7703 | kfree(cfg); | |
7704 | return err; | |
7705 | } | |
7706 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7707 | sock_release(cfg->sock); | |
7708 | kfree(cfg); | |
7709 | return -EADDRINUSE; | |
7710 | } | |
7711 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7712 | #else | |
7713 | if (!port) { | |
7714 | kfree(cfg); | |
7715 | return -EINVAL; | |
7716 | } | |
7717 | cfg->src_port = port; | |
7718 | #endif | |
7719 | ||
7720 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7721 | cfg->payload_len = data_size; | |
7722 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7723 | memcpy((void *)cfg->payload, | |
7724 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7725 | data_size); | |
7726 | if (seq) | |
7727 | cfg->payload_seq = *seq; | |
7728 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7729 | cfg->wake_len = wake_size; | |
7730 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7731 | memcpy((void *)cfg->wake_data, | |
7732 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7733 | wake_size); | |
7734 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7735 | data_size + wake_size; | |
7736 | memcpy((void *)cfg->wake_mask, | |
7737 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7738 | wake_mask_size); | |
7739 | if (tok) { | |
7740 | cfg->tokens_size = tokens_size; | |
7741 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7742 | } | |
7743 | ||
7744 | trig->tcp = cfg; | |
7745 | ||
7746 | return 0; | |
7747 | } | |
7748 | ||
ff1b6e69 JB |
7749 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7750 | { | |
7751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7752 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7753 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7754 | struct cfg80211_wowlan *ntrig; |
ff1b6e69 JB |
7755 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
7756 | int err, i; | |
6d52563f | 7757 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 | 7758 | |
2a0e047e JB |
7759 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7760 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7761 | return -EOPNOTSUPP; |
7762 | ||
ae33bd81 JB |
7763 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7764 | cfg80211_rdev_free_wowlan(rdev); | |
7765 | rdev->wowlan = NULL; | |
7766 | goto set_wakeup; | |
7767 | } | |
ff1b6e69 JB |
7768 | |
7769 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7770 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7771 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7772 | nl80211_wowlan_policy); | |
7773 | if (err) | |
7774 | return err; | |
7775 | ||
7776 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7777 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7778 | return -EINVAL; | |
7779 | new_triggers.any = true; | |
7780 | } | |
7781 | ||
7782 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7783 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7784 | return -EINVAL; | |
7785 | new_triggers.disconnect = true; | |
7786 | } | |
7787 | ||
7788 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7789 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7790 | return -EINVAL; | |
7791 | new_triggers.magic_pkt = true; | |
7792 | } | |
7793 | ||
77dbbb13 JB |
7794 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7795 | return -EINVAL; | |
7796 | ||
7797 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7798 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7799 | return -EINVAL; | |
7800 | new_triggers.gtk_rekey_failure = true; | |
7801 | } | |
7802 | ||
7803 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7804 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7805 | return -EINVAL; | |
7806 | new_triggers.eap_identity_req = true; | |
7807 | } | |
7808 | ||
7809 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7810 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7811 | return -EINVAL; | |
7812 | new_triggers.four_way_handshake = true; | |
7813 | } | |
7814 | ||
7815 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7816 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7817 | return -EINVAL; | |
7818 | new_triggers.rfkill_release = true; | |
7819 | } | |
7820 | ||
ff1b6e69 JB |
7821 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7822 | struct nlattr *pat; | |
7823 | int n_patterns = 0; | |
bb92d199 | 7824 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7825 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7826 | ||
7827 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7828 | rem) | |
7829 | n_patterns++; | |
7830 | if (n_patterns > wowlan->n_patterns) | |
7831 | return -EINVAL; | |
7832 | ||
7833 | new_triggers.patterns = kcalloc(n_patterns, | |
7834 | sizeof(new_triggers.patterns[0]), | |
7835 | GFP_KERNEL); | |
7836 | if (!new_triggers.patterns) | |
7837 | return -ENOMEM; | |
7838 | ||
7839 | new_triggers.n_patterns = n_patterns; | |
7840 | i = 0; | |
7841 | ||
7842 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7843 | rem) { | |
7844 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7845 | nla_data(pat), nla_len(pat), NULL); | |
7846 | err = -EINVAL; | |
7847 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7848 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7849 | goto error; | |
7850 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7851 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7852 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7853 | mask_len) | |
7854 | goto error; | |
7855 | if (pat_len > wowlan->pattern_max_len || | |
7856 | pat_len < wowlan->pattern_min_len) | |
7857 | goto error; | |
7858 | ||
bb92d199 AK |
7859 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7860 | pkt_offset = 0; | |
7861 | else | |
7862 | pkt_offset = nla_get_u32( | |
7863 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7864 | if (pkt_offset > wowlan->max_pkt_offset) | |
7865 | goto error; | |
7866 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7867 | ||
ff1b6e69 JB |
7868 | new_triggers.patterns[i].mask = |
7869 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7870 | if (!new_triggers.patterns[i].mask) { | |
7871 | err = -ENOMEM; | |
7872 | goto error; | |
7873 | } | |
7874 | new_triggers.patterns[i].pattern = | |
7875 | new_triggers.patterns[i].mask + mask_len; | |
7876 | memcpy(new_triggers.patterns[i].mask, | |
7877 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
7878 | mask_len); | |
7879 | new_triggers.patterns[i].pattern_len = pat_len; | |
7880 | memcpy(new_triggers.patterns[i].pattern, | |
7881 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
7882 | pat_len); | |
7883 | i++; | |
7884 | } | |
7885 | } | |
7886 | ||
2a0e047e JB |
7887 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
7888 | err = nl80211_parse_wowlan_tcp( | |
7889 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
7890 | &new_triggers); | |
7891 | if (err) | |
7892 | goto error; | |
7893 | } | |
7894 | ||
ae33bd81 JB |
7895 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
7896 | if (!ntrig) { | |
7897 | err = -ENOMEM; | |
7898 | goto error; | |
ff1b6e69 | 7899 | } |
ae33bd81 JB |
7900 | cfg80211_rdev_free_wowlan(rdev); |
7901 | rdev->wowlan = ntrig; | |
ff1b6e69 | 7902 | |
ae33bd81 | 7903 | set_wakeup: |
6d52563f | 7904 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
e35e4d28 | 7905 | rdev_set_wakeup(rdev, rdev->wowlan); |
6d52563f | 7906 | |
ff1b6e69 JB |
7907 | return 0; |
7908 | error: | |
7909 | for (i = 0; i < new_triggers.n_patterns; i++) | |
7910 | kfree(new_triggers.patterns[i].mask); | |
7911 | kfree(new_triggers.patterns); | |
2a0e047e JB |
7912 | if (new_triggers.tcp && new_triggers.tcp->sock) |
7913 | sock_release(new_triggers.tcp->sock); | |
7914 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
7915 | return err; |
7916 | } | |
dfb89c56 | 7917 | #endif |
ff1b6e69 | 7918 | |
e5497d76 JB |
7919 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
7920 | { | |
7921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7922 | struct net_device *dev = info->user_ptr[1]; | |
7923 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7924 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
7925 | struct cfg80211_gtk_rekey_data rekey_data; | |
7926 | int err; | |
7927 | ||
7928 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
7929 | return -EINVAL; | |
7930 | ||
7931 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
7932 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7933 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7934 | nl80211_rekey_policy); | |
7935 | if (err) | |
7936 | return err; | |
7937 | ||
7938 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
7939 | return -ERANGE; | |
7940 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
7941 | return -ERANGE; | |
7942 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
7943 | return -ERANGE; | |
7944 | ||
7945 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
7946 | NL80211_KEK_LEN); | |
7947 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
7948 | NL80211_KCK_LEN); | |
7949 | memcpy(rekey_data.replay_ctr, | |
7950 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
7951 | NL80211_REPLAY_CTR_LEN); | |
7952 | ||
7953 | wdev_lock(wdev); | |
7954 | if (!wdev->current_bss) { | |
7955 | err = -ENOTCONN; | |
7956 | goto out; | |
7957 | } | |
7958 | ||
7959 | if (!rdev->ops->set_rekey_data) { | |
7960 | err = -EOPNOTSUPP; | |
7961 | goto out; | |
7962 | } | |
7963 | ||
e35e4d28 | 7964 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
7965 | out: |
7966 | wdev_unlock(wdev); | |
7967 | return err; | |
7968 | } | |
7969 | ||
28946da7 JB |
7970 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
7971 | struct genl_info *info) | |
7972 | { | |
7973 | struct net_device *dev = info->user_ptr[1]; | |
7974 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7975 | ||
7976 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
7977 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
7978 | return -EINVAL; | |
7979 | ||
15e47304 | 7980 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
7981 | return -EBUSY; |
7982 | ||
15e47304 | 7983 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
7984 | return 0; |
7985 | } | |
7986 | ||
7f6cf311 JB |
7987 | static int nl80211_probe_client(struct sk_buff *skb, |
7988 | struct genl_info *info) | |
7989 | { | |
7990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7991 | struct net_device *dev = info->user_ptr[1]; | |
7992 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7993 | struct sk_buff *msg; | |
7994 | void *hdr; | |
7995 | const u8 *addr; | |
7996 | u64 cookie; | |
7997 | int err; | |
7998 | ||
7999 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8000 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8001 | return -EOPNOTSUPP; | |
8002 | ||
8003 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8004 | return -EINVAL; | |
8005 | ||
8006 | if (!rdev->ops->probe_client) | |
8007 | return -EOPNOTSUPP; | |
8008 | ||
8009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8010 | if (!msg) | |
8011 | return -ENOMEM; | |
8012 | ||
15e47304 | 8013 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8014 | NL80211_CMD_PROBE_CLIENT); |
8015 | ||
8016 | if (IS_ERR(hdr)) { | |
8017 | err = PTR_ERR(hdr); | |
8018 | goto free_msg; | |
8019 | } | |
8020 | ||
8021 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8022 | ||
e35e4d28 | 8023 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8024 | if (err) |
8025 | goto free_msg; | |
8026 | ||
9360ffd1 DM |
8027 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8028 | goto nla_put_failure; | |
7f6cf311 JB |
8029 | |
8030 | genlmsg_end(msg, hdr); | |
8031 | ||
8032 | return genlmsg_reply(msg, info); | |
8033 | ||
8034 | nla_put_failure: | |
8035 | err = -ENOBUFS; | |
8036 | free_msg: | |
8037 | nlmsg_free(msg); | |
8038 | return err; | |
8039 | } | |
8040 | ||
5e760230 JB |
8041 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8042 | { | |
8043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8044 | struct cfg80211_beacon_registration *reg, *nreg; |
8045 | int rv; | |
5e760230 JB |
8046 | |
8047 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8048 | return -EOPNOTSUPP; | |
8049 | ||
37c73b5f BG |
8050 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8051 | if (!nreg) | |
8052 | return -ENOMEM; | |
8053 | ||
8054 | /* First, check if already registered. */ | |
8055 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8056 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8057 | if (reg->nlportid == info->snd_portid) { | |
8058 | rv = -EALREADY; | |
8059 | goto out_err; | |
8060 | } | |
8061 | } | |
8062 | /* Add it to the list */ | |
8063 | nreg->nlportid = info->snd_portid; | |
8064 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8065 | |
37c73b5f | 8066 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8067 | |
8068 | return 0; | |
37c73b5f BG |
8069 | out_err: |
8070 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8071 | kfree(nreg); | |
8072 | return rv; | |
5e760230 JB |
8073 | } |
8074 | ||
98104fde JB |
8075 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8076 | { | |
8077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8078 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8079 | int err; | |
8080 | ||
8081 | if (!rdev->ops->start_p2p_device) | |
8082 | return -EOPNOTSUPP; | |
8083 | ||
8084 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8085 | return -EOPNOTSUPP; | |
8086 | ||
8087 | if (wdev->p2p_started) | |
8088 | return 0; | |
8089 | ||
8090 | mutex_lock(&rdev->devlist_mtx); | |
8091 | err = cfg80211_can_add_interface(rdev, wdev->iftype); | |
8092 | mutex_unlock(&rdev->devlist_mtx); | |
8093 | if (err) | |
8094 | return err; | |
8095 | ||
eeb126e9 | 8096 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8097 | if (err) |
8098 | return err; | |
8099 | ||
8100 | wdev->p2p_started = true; | |
8101 | mutex_lock(&rdev->devlist_mtx); | |
8102 | rdev->opencount++; | |
8103 | mutex_unlock(&rdev->devlist_mtx); | |
8104 | ||
8105 | return 0; | |
8106 | } | |
8107 | ||
8108 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8109 | { | |
8110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8111 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8112 | ||
8113 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8114 | return -EOPNOTSUPP; | |
8115 | ||
8116 | if (!rdev->ops->stop_p2p_device) | |
8117 | return -EOPNOTSUPP; | |
8118 | ||
8119 | if (!wdev->p2p_started) | |
8120 | return 0; | |
8121 | ||
eeb126e9 | 8122 | rdev_stop_p2p_device(rdev, wdev); |
98104fde JB |
8123 | wdev->p2p_started = false; |
8124 | ||
8125 | mutex_lock(&rdev->devlist_mtx); | |
8126 | rdev->opencount--; | |
8127 | mutex_unlock(&rdev->devlist_mtx); | |
8128 | ||
8129 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { | |
8130 | rdev->scan_req->aborted = true; | |
8131 | ___cfg80211_scan_done(rdev, true); | |
8132 | } | |
8133 | ||
8134 | return 0; | |
8135 | } | |
8136 | ||
3713b4e3 JB |
8137 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8138 | struct genl_info *info) | |
8139 | { | |
8140 | void *hdr; | |
8141 | struct sk_buff *msg; | |
8142 | ||
8143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8144 | if (!msg) | |
8145 | return -ENOMEM; | |
8146 | ||
8147 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8148 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8149 | if (!hdr) | |
8150 | goto nla_put_failure; | |
8151 | ||
8152 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8153 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8154 | goto nla_put_failure; | |
8155 | ||
8156 | genlmsg_end(msg, hdr); | |
8157 | return genlmsg_reply(msg, info); | |
8158 | ||
8159 | nla_put_failure: | |
8160 | kfree_skb(msg); | |
8161 | return -ENOBUFS; | |
8162 | } | |
8163 | ||
4c476991 JB |
8164 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8165 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8166 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8167 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8168 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8169 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8170 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8171 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8172 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8173 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8174 | |
8175 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8176 | struct genl_info *info) | |
8177 | { | |
8178 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8179 | struct wireless_dev *wdev; |
4c476991 | 8180 | struct net_device *dev; |
4c476991 JB |
8181 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8182 | ||
8183 | if (rtnl) | |
8184 | rtnl_lock(); | |
8185 | ||
8186 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8187 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8188 | if (IS_ERR(rdev)) { |
8189 | if (rtnl) | |
8190 | rtnl_unlock(); | |
8191 | return PTR_ERR(rdev); | |
8192 | } | |
8193 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8194 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8195 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
89a54e48 JB |
8196 | mutex_lock(&cfg80211_mutex); |
8197 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | |
8198 | info->attrs); | |
8199 | if (IS_ERR(wdev)) { | |
8200 | mutex_unlock(&cfg80211_mutex); | |
4c476991 JB |
8201 | if (rtnl) |
8202 | rtnl_unlock(); | |
89a54e48 | 8203 | return PTR_ERR(wdev); |
4c476991 | 8204 | } |
89a54e48 | 8205 | |
89a54e48 JB |
8206 | dev = wdev->netdev; |
8207 | rdev = wiphy_to_dev(wdev->wiphy); | |
8208 | ||
1bf614ef JB |
8209 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8210 | if (!dev) { | |
8211 | mutex_unlock(&cfg80211_mutex); | |
8212 | if (rtnl) | |
8213 | rtnl_unlock(); | |
8214 | return -EINVAL; | |
8215 | } | |
8216 | ||
8217 | info->user_ptr[1] = dev; | |
8218 | } else { | |
8219 | info->user_ptr[1] = wdev; | |
41265714 | 8220 | } |
1bf614ef JB |
8221 | |
8222 | if (dev) { | |
8223 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8224 | !netif_running(dev)) { | |
8225 | mutex_unlock(&cfg80211_mutex); | |
8226 | if (rtnl) | |
8227 | rtnl_unlock(); | |
8228 | return -ENETDOWN; | |
8229 | } | |
8230 | ||
8231 | dev_hold(dev); | |
98104fde JB |
8232 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8233 | if (!wdev->p2p_started) { | |
8234 | mutex_unlock(&cfg80211_mutex); | |
8235 | if (rtnl) | |
8236 | rtnl_unlock(); | |
8237 | return -ENETDOWN; | |
8238 | } | |
41265714 | 8239 | } |
89a54e48 | 8240 | |
89a54e48 JB |
8241 | cfg80211_lock_rdev(rdev); |
8242 | ||
8243 | mutex_unlock(&cfg80211_mutex); | |
8244 | ||
4c476991 | 8245 | info->user_ptr[0] = rdev; |
4c476991 JB |
8246 | } |
8247 | ||
8248 | return 0; | |
8249 | } | |
8250 | ||
8251 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8252 | struct genl_info *info) | |
8253 | { | |
8254 | if (info->user_ptr[0]) | |
8255 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
1bf614ef JB |
8256 | if (info->user_ptr[1]) { |
8257 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8258 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8259 | ||
8260 | if (wdev->netdev) | |
8261 | dev_put(wdev->netdev); | |
8262 | } else { | |
8263 | dev_put(info->user_ptr[1]); | |
8264 | } | |
8265 | } | |
4c476991 JB |
8266 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8267 | rtnl_unlock(); | |
8268 | } | |
8269 | ||
55682965 JB |
8270 | static struct genl_ops nl80211_ops[] = { |
8271 | { | |
8272 | .cmd = NL80211_CMD_GET_WIPHY, | |
8273 | .doit = nl80211_get_wiphy, | |
8274 | .dumpit = nl80211_dump_wiphy, | |
8275 | .policy = nl80211_policy, | |
8276 | /* can be retrieved by unprivileged users */ | |
4c476991 | 8277 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
8278 | }, |
8279 | { | |
8280 | .cmd = NL80211_CMD_SET_WIPHY, | |
8281 | .doit = nl80211_set_wiphy, | |
8282 | .policy = nl80211_policy, | |
8283 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8284 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8285 | }, |
8286 | { | |
8287 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8288 | .doit = nl80211_get_interface, | |
8289 | .dumpit = nl80211_dump_interface, | |
8290 | .policy = nl80211_policy, | |
8291 | /* can be retrieved by unprivileged users */ | |
72fb2abc | 8292 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
55682965 JB |
8293 | }, |
8294 | { | |
8295 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8296 | .doit = nl80211_set_interface, | |
8297 | .policy = nl80211_policy, | |
8298 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8299 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8300 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8301 | }, |
8302 | { | |
8303 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8304 | .doit = nl80211_new_interface, | |
8305 | .policy = nl80211_policy, | |
8306 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8307 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8308 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8309 | }, |
8310 | { | |
8311 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8312 | .doit = nl80211_del_interface, | |
8313 | .policy = nl80211_policy, | |
41ade00f | 8314 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8315 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8316 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8317 | }, |
8318 | { | |
8319 | .cmd = NL80211_CMD_GET_KEY, | |
8320 | .doit = nl80211_get_key, | |
8321 | .policy = nl80211_policy, | |
8322 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8323 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8324 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8325 | }, |
8326 | { | |
8327 | .cmd = NL80211_CMD_SET_KEY, | |
8328 | .doit = nl80211_set_key, | |
8329 | .policy = nl80211_policy, | |
8330 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8331 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8332 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8333 | }, |
8334 | { | |
8335 | .cmd = NL80211_CMD_NEW_KEY, | |
8336 | .doit = nl80211_new_key, | |
8337 | .policy = nl80211_policy, | |
8338 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8340 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8341 | }, |
8342 | { | |
8343 | .cmd = NL80211_CMD_DEL_KEY, | |
8344 | .doit = nl80211_del_key, | |
8345 | .policy = nl80211_policy, | |
55682965 | 8346 | .flags = GENL_ADMIN_PERM, |
41265714 | 8347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8348 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8349 | }, |
ed1b6cc7 JB |
8350 | { |
8351 | .cmd = NL80211_CMD_SET_BEACON, | |
8352 | .policy = nl80211_policy, | |
8353 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8354 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8355 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8356 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8357 | }, |
8358 | { | |
8860020e | 8359 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8360 | .policy = nl80211_policy, |
8361 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8362 | .doit = nl80211_start_ap, |
2b5f8b0b | 8363 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8364 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8365 | }, |
8366 | { | |
8860020e | 8367 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8368 | .policy = nl80211_policy, |
8369 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8370 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8372 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8373 | }, |
5727ef1b JB |
8374 | { |
8375 | .cmd = NL80211_CMD_GET_STATION, | |
8376 | .doit = nl80211_get_station, | |
2ec600d6 | 8377 | .dumpit = nl80211_dump_station, |
5727ef1b | 8378 | .policy = nl80211_policy, |
4c476991 JB |
8379 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8380 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8381 | }, |
8382 | { | |
8383 | .cmd = NL80211_CMD_SET_STATION, | |
8384 | .doit = nl80211_set_station, | |
8385 | .policy = nl80211_policy, | |
8386 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8388 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8389 | }, |
8390 | { | |
8391 | .cmd = NL80211_CMD_NEW_STATION, | |
8392 | .doit = nl80211_new_station, | |
8393 | .policy = nl80211_policy, | |
8394 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8396 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8397 | }, |
8398 | { | |
8399 | .cmd = NL80211_CMD_DEL_STATION, | |
8400 | .doit = nl80211_del_station, | |
8401 | .policy = nl80211_policy, | |
2ec600d6 | 8402 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8403 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8404 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8405 | }, |
8406 | { | |
8407 | .cmd = NL80211_CMD_GET_MPATH, | |
8408 | .doit = nl80211_get_mpath, | |
8409 | .dumpit = nl80211_dump_mpath, | |
8410 | .policy = nl80211_policy, | |
8411 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8412 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8413 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8414 | }, |
8415 | { | |
8416 | .cmd = NL80211_CMD_SET_MPATH, | |
8417 | .doit = nl80211_set_mpath, | |
8418 | .policy = nl80211_policy, | |
8419 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8421 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8422 | }, |
8423 | { | |
8424 | .cmd = NL80211_CMD_NEW_MPATH, | |
8425 | .doit = nl80211_new_mpath, | |
8426 | .policy = nl80211_policy, | |
8427 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8428 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8429 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8430 | }, |
8431 | { | |
8432 | .cmd = NL80211_CMD_DEL_MPATH, | |
8433 | .doit = nl80211_del_mpath, | |
8434 | .policy = nl80211_policy, | |
9f1ba906 | 8435 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8437 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8438 | }, |
8439 | { | |
8440 | .cmd = NL80211_CMD_SET_BSS, | |
8441 | .doit = nl80211_set_bss, | |
8442 | .policy = nl80211_policy, | |
b2e1b302 | 8443 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8445 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8446 | }, |
f130347c LR |
8447 | { |
8448 | .cmd = NL80211_CMD_GET_REG, | |
8449 | .doit = nl80211_get_reg, | |
8450 | .policy = nl80211_policy, | |
8451 | /* can be retrieved by unprivileged users */ | |
8452 | }, | |
b2e1b302 LR |
8453 | { |
8454 | .cmd = NL80211_CMD_SET_REG, | |
8455 | .doit = nl80211_set_reg, | |
8456 | .policy = nl80211_policy, | |
8457 | .flags = GENL_ADMIN_PERM, | |
8458 | }, | |
8459 | { | |
8460 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8461 | .doit = nl80211_req_set_reg, | |
8462 | .policy = nl80211_policy, | |
93da9cc1 | 8463 | .flags = GENL_ADMIN_PERM, |
8464 | }, | |
8465 | { | |
24bdd9f4 JC |
8466 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8467 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8468 | .policy = nl80211_policy, |
8469 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8470 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8471 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8472 | }, |
8473 | { | |
24bdd9f4 JC |
8474 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8475 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8476 | .policy = nl80211_policy, |
9aed3cc1 | 8477 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8479 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8480 | }, |
2a519311 JB |
8481 | { |
8482 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8483 | .doit = nl80211_trigger_scan, | |
8484 | .policy = nl80211_policy, | |
8485 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8486 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8487 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8488 | }, |
8489 | { | |
8490 | .cmd = NL80211_CMD_GET_SCAN, | |
8491 | .policy = nl80211_policy, | |
8492 | .dumpit = nl80211_dump_scan, | |
8493 | }, | |
807f8a8c LC |
8494 | { |
8495 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8496 | .doit = nl80211_start_sched_scan, | |
8497 | .policy = nl80211_policy, | |
8498 | .flags = GENL_ADMIN_PERM, | |
8499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8500 | NL80211_FLAG_NEED_RTNL, | |
8501 | }, | |
8502 | { | |
8503 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8504 | .doit = nl80211_stop_sched_scan, | |
8505 | .policy = nl80211_policy, | |
8506 | .flags = GENL_ADMIN_PERM, | |
8507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8508 | NL80211_FLAG_NEED_RTNL, | |
8509 | }, | |
636a5d36 JM |
8510 | { |
8511 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8512 | .doit = nl80211_authenticate, | |
8513 | .policy = nl80211_policy, | |
8514 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8515 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8516 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8517 | }, |
8518 | { | |
8519 | .cmd = NL80211_CMD_ASSOCIATE, | |
8520 | .doit = nl80211_associate, | |
8521 | .policy = nl80211_policy, | |
8522 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8524 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8525 | }, |
8526 | { | |
8527 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8528 | .doit = nl80211_deauthenticate, | |
8529 | .policy = nl80211_policy, | |
8530 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8531 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8532 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8533 | }, |
8534 | { | |
8535 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8536 | .doit = nl80211_disassociate, | |
8537 | .policy = nl80211_policy, | |
8538 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8539 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8540 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8541 | }, |
04a773ad JB |
8542 | { |
8543 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8544 | .doit = nl80211_join_ibss, | |
8545 | .policy = nl80211_policy, | |
8546 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8547 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8548 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8549 | }, |
8550 | { | |
8551 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8552 | .doit = nl80211_leave_ibss, | |
8553 | .policy = nl80211_policy, | |
8554 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8556 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8557 | }, |
aff89a9b JB |
8558 | #ifdef CONFIG_NL80211_TESTMODE |
8559 | { | |
8560 | .cmd = NL80211_CMD_TESTMODE, | |
8561 | .doit = nl80211_testmode_do, | |
71063f0e | 8562 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8563 | .policy = nl80211_policy, |
8564 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8565 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8566 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8567 | }, |
8568 | #endif | |
b23aa676 SO |
8569 | { |
8570 | .cmd = NL80211_CMD_CONNECT, | |
8571 | .doit = nl80211_connect, | |
8572 | .policy = nl80211_policy, | |
8573 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8575 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8576 | }, |
8577 | { | |
8578 | .cmd = NL80211_CMD_DISCONNECT, | |
8579 | .doit = nl80211_disconnect, | |
8580 | .policy = nl80211_policy, | |
8581 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8583 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8584 | }, |
463d0183 JB |
8585 | { |
8586 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8587 | .doit = nl80211_wiphy_netns, | |
8588 | .policy = nl80211_policy, | |
8589 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8590 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8591 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8592 | }, |
61fa713c HS |
8593 | { |
8594 | .cmd = NL80211_CMD_GET_SURVEY, | |
8595 | .policy = nl80211_policy, | |
8596 | .dumpit = nl80211_dump_survey, | |
8597 | }, | |
67fbb16b SO |
8598 | { |
8599 | .cmd = NL80211_CMD_SET_PMKSA, | |
8600 | .doit = nl80211_setdel_pmksa, | |
8601 | .policy = nl80211_policy, | |
8602 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8603 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8604 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8605 | }, |
8606 | { | |
8607 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8608 | .doit = nl80211_setdel_pmksa, | |
8609 | .policy = nl80211_policy, | |
8610 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8611 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8612 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8613 | }, |
8614 | { | |
8615 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8616 | .doit = nl80211_flush_pmksa, | |
8617 | .policy = nl80211_policy, | |
8618 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8620 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8621 | }, |
9588bbd5 JM |
8622 | { |
8623 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8624 | .doit = nl80211_remain_on_channel, | |
8625 | .policy = nl80211_policy, | |
8626 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8627 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8628 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8629 | }, |
8630 | { | |
8631 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8632 | .doit = nl80211_cancel_remain_on_channel, | |
8633 | .policy = nl80211_policy, | |
8634 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8635 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8636 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8637 | }, |
13ae75b1 JM |
8638 | { |
8639 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8640 | .doit = nl80211_set_tx_bitrate_mask, | |
8641 | .policy = nl80211_policy, | |
8642 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8643 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8644 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8645 | }, |
026331c4 | 8646 | { |
2e161f78 JB |
8647 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8648 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8649 | .policy = nl80211_policy, |
8650 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8651 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8652 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8653 | }, |
8654 | { | |
2e161f78 JB |
8655 | .cmd = NL80211_CMD_FRAME, |
8656 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8657 | .policy = nl80211_policy, |
f7ca38df | 8658 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8659 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8660 | NL80211_FLAG_NEED_RTNL, |
8661 | }, | |
8662 | { | |
8663 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8664 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8665 | .policy = nl80211_policy, | |
026331c4 | 8666 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8667 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8668 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8669 | }, |
ffb9eb3d KV |
8670 | { |
8671 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8672 | .doit = nl80211_set_power_save, | |
8673 | .policy = nl80211_policy, | |
8674 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8675 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8676 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8677 | }, |
8678 | { | |
8679 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8680 | .doit = nl80211_get_power_save, | |
8681 | .policy = nl80211_policy, | |
8682 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8683 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8684 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8685 | }, |
d6dc1a38 JO |
8686 | { |
8687 | .cmd = NL80211_CMD_SET_CQM, | |
8688 | .doit = nl80211_set_cqm, | |
8689 | .policy = nl80211_policy, | |
8690 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8691 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8692 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8693 | }, |
f444de05 JB |
8694 | { |
8695 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8696 | .doit = nl80211_set_channel, | |
8697 | .policy = nl80211_policy, | |
8698 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8699 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8700 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 8701 | }, |
e8347eba BJ |
8702 | { |
8703 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
8704 | .doit = nl80211_set_wds_peer, | |
8705 | .policy = nl80211_policy, | |
8706 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
8707 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8708 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 8709 | }, |
29cbe68c JB |
8710 | { |
8711 | .cmd = NL80211_CMD_JOIN_MESH, | |
8712 | .doit = nl80211_join_mesh, | |
8713 | .policy = nl80211_policy, | |
8714 | .flags = GENL_ADMIN_PERM, | |
8715 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8716 | NL80211_FLAG_NEED_RTNL, | |
8717 | }, | |
8718 | { | |
8719 | .cmd = NL80211_CMD_LEAVE_MESH, | |
8720 | .doit = nl80211_leave_mesh, | |
8721 | .policy = nl80211_policy, | |
8722 | .flags = GENL_ADMIN_PERM, | |
8723 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8724 | NL80211_FLAG_NEED_RTNL, | |
8725 | }, | |
dfb89c56 | 8726 | #ifdef CONFIG_PM |
ff1b6e69 JB |
8727 | { |
8728 | .cmd = NL80211_CMD_GET_WOWLAN, | |
8729 | .doit = nl80211_get_wowlan, | |
8730 | .policy = nl80211_policy, | |
8731 | /* can be retrieved by unprivileged users */ | |
8732 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8733 | NL80211_FLAG_NEED_RTNL, | |
8734 | }, | |
8735 | { | |
8736 | .cmd = NL80211_CMD_SET_WOWLAN, | |
8737 | .doit = nl80211_set_wowlan, | |
8738 | .policy = nl80211_policy, | |
8739 | .flags = GENL_ADMIN_PERM, | |
8740 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8741 | NL80211_FLAG_NEED_RTNL, | |
8742 | }, | |
dfb89c56 | 8743 | #endif |
e5497d76 JB |
8744 | { |
8745 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
8746 | .doit = nl80211_set_rekey_data, | |
8747 | .policy = nl80211_policy, | |
8748 | .flags = GENL_ADMIN_PERM, | |
8749 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8750 | NL80211_FLAG_NEED_RTNL, | |
8751 | }, | |
109086ce AN |
8752 | { |
8753 | .cmd = NL80211_CMD_TDLS_MGMT, | |
8754 | .doit = nl80211_tdls_mgmt, | |
8755 | .policy = nl80211_policy, | |
8756 | .flags = GENL_ADMIN_PERM, | |
8757 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8758 | NL80211_FLAG_NEED_RTNL, | |
8759 | }, | |
8760 | { | |
8761 | .cmd = NL80211_CMD_TDLS_OPER, | |
8762 | .doit = nl80211_tdls_oper, | |
8763 | .policy = nl80211_policy, | |
8764 | .flags = GENL_ADMIN_PERM, | |
8765 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8766 | NL80211_FLAG_NEED_RTNL, | |
8767 | }, | |
28946da7 JB |
8768 | { |
8769 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
8770 | .doit = nl80211_register_unexpected_frame, | |
8771 | .policy = nl80211_policy, | |
8772 | .flags = GENL_ADMIN_PERM, | |
8773 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8774 | NL80211_FLAG_NEED_RTNL, | |
8775 | }, | |
7f6cf311 JB |
8776 | { |
8777 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
8778 | .doit = nl80211_probe_client, | |
8779 | .policy = nl80211_policy, | |
8780 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8781 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
8782 | NL80211_FLAG_NEED_RTNL, |
8783 | }, | |
5e760230 JB |
8784 | { |
8785 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
8786 | .doit = nl80211_register_beacons, | |
8787 | .policy = nl80211_policy, | |
8788 | .flags = GENL_ADMIN_PERM, | |
8789 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8790 | NL80211_FLAG_NEED_RTNL, | |
8791 | }, | |
1d9d9213 SW |
8792 | { |
8793 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
8794 | .doit = nl80211_set_noack_map, | |
8795 | .policy = nl80211_policy, | |
8796 | .flags = GENL_ADMIN_PERM, | |
8797 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8798 | NL80211_FLAG_NEED_RTNL, | |
8799 | }, | |
98104fde JB |
8800 | { |
8801 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
8802 | .doit = nl80211_start_p2p_device, | |
8803 | .policy = nl80211_policy, | |
8804 | .flags = GENL_ADMIN_PERM, | |
8805 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
8806 | NL80211_FLAG_NEED_RTNL, | |
8807 | }, | |
8808 | { | |
8809 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
8810 | .doit = nl80211_stop_p2p_device, | |
8811 | .policy = nl80211_policy, | |
8812 | .flags = GENL_ADMIN_PERM, | |
8813 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8814 | NL80211_FLAG_NEED_RTNL, | |
8815 | }, | |
f4e583c8 AQ |
8816 | { |
8817 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
8818 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
8819 | .policy = nl80211_policy, |
8820 | .flags = GENL_ADMIN_PERM, | |
8821 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8822 | NL80211_FLAG_NEED_RTNL, | |
8823 | }, | |
8824 | { | |
8825 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
8826 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
8827 | .policy = nl80211_policy, |
8828 | .flags = GENL_ADMIN_PERM, | |
8829 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8830 | NL80211_FLAG_NEED_RTNL, | |
8831 | }, | |
04f39047 SW |
8832 | { |
8833 | .cmd = NL80211_CMD_RADAR_DETECT, | |
8834 | .doit = nl80211_start_radar_detection, | |
8835 | .policy = nl80211_policy, | |
8836 | .flags = GENL_ADMIN_PERM, | |
8837 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8838 | NL80211_FLAG_NEED_RTNL, | |
8839 | }, | |
3713b4e3 JB |
8840 | { |
8841 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
8842 | .doit = nl80211_get_protocol_features, | |
8843 | .policy = nl80211_policy, | |
8844 | }, | |
55682965 | 8845 | }; |
9588bbd5 | 8846 | |
6039f6d2 JM |
8847 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
8848 | .name = "mlme", | |
8849 | }; | |
55682965 JB |
8850 | |
8851 | /* multicast groups */ | |
8852 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
8853 | .name = "config", | |
8854 | }; | |
2a519311 JB |
8855 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
8856 | .name = "scan", | |
8857 | }; | |
73d54c9e LR |
8858 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
8859 | .name = "regulatory", | |
8860 | }; | |
55682965 JB |
8861 | |
8862 | /* notification functions */ | |
8863 | ||
8864 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
8865 | { | |
8866 | struct sk_buff *msg; | |
8867 | ||
fd2120ca | 8868 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
8869 | if (!msg) |
8870 | return; | |
8871 | ||
3713b4e3 JB |
8872 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
8873 | false, NULL, NULL, NULL) < 0) { | |
55682965 JB |
8874 | nlmsg_free(msg); |
8875 | return; | |
8876 | } | |
8877 | ||
463d0183 JB |
8878 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8879 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
8880 | } |
8881 | ||
362a415d JB |
8882 | static int nl80211_add_scan_req(struct sk_buff *msg, |
8883 | struct cfg80211_registered_device *rdev) | |
8884 | { | |
8885 | struct cfg80211_scan_request *req = rdev->scan_req; | |
8886 | struct nlattr *nest; | |
8887 | int i; | |
8888 | ||
667503dd JB |
8889 | ASSERT_RDEV_LOCK(rdev); |
8890 | ||
362a415d JB |
8891 | if (WARN_ON(!req)) |
8892 | return 0; | |
8893 | ||
8894 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
8895 | if (!nest) | |
8896 | goto nla_put_failure; | |
9360ffd1 DM |
8897 | for (i = 0; i < req->n_ssids; i++) { |
8898 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
8899 | goto nla_put_failure; | |
8900 | } | |
362a415d JB |
8901 | nla_nest_end(msg, nest); |
8902 | ||
8903 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8904 | if (!nest) | |
8905 | goto nla_put_failure; | |
9360ffd1 DM |
8906 | for (i = 0; i < req->n_channels; i++) { |
8907 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
8908 | goto nla_put_failure; | |
8909 | } | |
362a415d JB |
8910 | nla_nest_end(msg, nest); |
8911 | ||
9360ffd1 DM |
8912 | if (req->ie && |
8913 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
8914 | goto nla_put_failure; | |
362a415d | 8915 | |
ed473771 SL |
8916 | if (req->flags) |
8917 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
8918 | ||
362a415d JB |
8919 | return 0; |
8920 | nla_put_failure: | |
8921 | return -ENOBUFS; | |
8922 | } | |
8923 | ||
a538e2d5 JB |
8924 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
8925 | struct cfg80211_registered_device *rdev, | |
fd014284 | 8926 | struct wireless_dev *wdev, |
15e47304 | 8927 | u32 portid, u32 seq, int flags, |
a538e2d5 | 8928 | u32 cmd) |
2a519311 JB |
8929 | { |
8930 | void *hdr; | |
8931 | ||
15e47304 | 8932 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
8933 | if (!hdr) |
8934 | return -1; | |
8935 | ||
9360ffd1 | 8936 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
8937 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
8938 | wdev->netdev->ifindex)) || | |
8939 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 8940 | goto nla_put_failure; |
2a519311 | 8941 | |
362a415d JB |
8942 | /* ignore errors and send incomplete event anyway */ |
8943 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
8944 | |
8945 | return genlmsg_end(msg, hdr); | |
8946 | ||
8947 | nla_put_failure: | |
8948 | genlmsg_cancel(msg, hdr); | |
8949 | return -EMSGSIZE; | |
8950 | } | |
8951 | ||
807f8a8c LC |
8952 | static int |
8953 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
8954 | struct cfg80211_registered_device *rdev, | |
8955 | struct net_device *netdev, | |
15e47304 | 8956 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
8957 | { |
8958 | void *hdr; | |
8959 | ||
15e47304 | 8960 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
8961 | if (!hdr) |
8962 | return -1; | |
8963 | ||
9360ffd1 DM |
8964 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8965 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
8966 | goto nla_put_failure; | |
807f8a8c LC |
8967 | |
8968 | return genlmsg_end(msg, hdr); | |
8969 | ||
8970 | nla_put_failure: | |
8971 | genlmsg_cancel(msg, hdr); | |
8972 | return -EMSGSIZE; | |
8973 | } | |
8974 | ||
a538e2d5 | 8975 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 8976 | struct wireless_dev *wdev) |
a538e2d5 JB |
8977 | { |
8978 | struct sk_buff *msg; | |
8979 | ||
58050fce | 8980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
8981 | if (!msg) |
8982 | return; | |
8983 | ||
fd014284 | 8984 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
8985 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
8986 | nlmsg_free(msg); | |
8987 | return; | |
8988 | } | |
8989 | ||
463d0183 JB |
8990 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8991 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
8992 | } |
8993 | ||
2a519311 | 8994 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 8995 | struct wireless_dev *wdev) |
2a519311 JB |
8996 | { |
8997 | struct sk_buff *msg; | |
8998 | ||
fd2120ca | 8999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9000 | if (!msg) |
9001 | return; | |
9002 | ||
fd014284 | 9003 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9004 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9005 | nlmsg_free(msg); |
9006 | return; | |
9007 | } | |
9008 | ||
463d0183 JB |
9009 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9010 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9011 | } |
9012 | ||
9013 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9014 | struct wireless_dev *wdev) |
2a519311 JB |
9015 | { |
9016 | struct sk_buff *msg; | |
9017 | ||
fd2120ca | 9018 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9019 | if (!msg) |
9020 | return; | |
9021 | ||
fd014284 | 9022 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9023 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9024 | nlmsg_free(msg); |
9025 | return; | |
9026 | } | |
9027 | ||
463d0183 JB |
9028 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9029 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9030 | } |
9031 | ||
807f8a8c LC |
9032 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9033 | struct net_device *netdev) | |
9034 | { | |
9035 | struct sk_buff *msg; | |
9036 | ||
9037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9038 | if (!msg) | |
9039 | return; | |
9040 | ||
9041 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9042 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9043 | nlmsg_free(msg); | |
9044 | return; | |
9045 | } | |
9046 | ||
9047 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9048 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9049 | } | |
9050 | ||
9051 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9052 | struct net_device *netdev, u32 cmd) | |
9053 | { | |
9054 | struct sk_buff *msg; | |
9055 | ||
58050fce | 9056 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9057 | if (!msg) |
9058 | return; | |
9059 | ||
9060 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9061 | nlmsg_free(msg); | |
9062 | return; | |
9063 | } | |
9064 | ||
9065 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9066 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9067 | } | |
9068 | ||
73d54c9e LR |
9069 | /* |
9070 | * This can happen on global regulatory changes or device specific settings | |
9071 | * based on custom world regulatory domains. | |
9072 | */ | |
9073 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9074 | { | |
9075 | struct sk_buff *msg; | |
9076 | void *hdr; | |
9077 | ||
fd2120ca | 9078 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9079 | if (!msg) |
9080 | return; | |
9081 | ||
9082 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9083 | if (!hdr) { | |
9084 | nlmsg_free(msg); | |
9085 | return; | |
9086 | } | |
9087 | ||
9088 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9089 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9090 | goto nla_put_failure; | |
9091 | ||
9092 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9093 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9094 | NL80211_REGDOM_TYPE_WORLD)) | |
9095 | goto nla_put_failure; | |
9096 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9097 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9098 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9099 | goto nla_put_failure; | |
9100 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9101 | request->intersect) { | |
9102 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9103 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9104 | goto nla_put_failure; | |
9105 | } else { | |
9106 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9107 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9108 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9109 | request->alpha2)) | |
9110 | goto nla_put_failure; | |
9111 | } | |
9112 | ||
f4173766 | 9113 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9114 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9115 | goto nla_put_failure; | |
73d54c9e | 9116 | |
3b7b72ee | 9117 | genlmsg_end(msg, hdr); |
73d54c9e | 9118 | |
bc43b28c | 9119 | rcu_read_lock(); |
463d0183 | 9120 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9121 | GFP_ATOMIC); |
9122 | rcu_read_unlock(); | |
73d54c9e LR |
9123 | |
9124 | return; | |
9125 | ||
9126 | nla_put_failure: | |
9127 | genlmsg_cancel(msg, hdr); | |
9128 | nlmsg_free(msg); | |
9129 | } | |
9130 | ||
6039f6d2 JM |
9131 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9132 | struct net_device *netdev, | |
9133 | const u8 *buf, size_t len, | |
e6d6e342 | 9134 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9135 | { |
9136 | struct sk_buff *msg; | |
9137 | void *hdr; | |
9138 | ||
e6d6e342 | 9139 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9140 | if (!msg) |
9141 | return; | |
9142 | ||
9143 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9144 | if (!hdr) { | |
9145 | nlmsg_free(msg); | |
9146 | return; | |
9147 | } | |
9148 | ||
9360ffd1 DM |
9149 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9150 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9151 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9152 | goto nla_put_failure; | |
6039f6d2 | 9153 | |
3b7b72ee | 9154 | genlmsg_end(msg, hdr); |
6039f6d2 | 9155 | |
463d0183 JB |
9156 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9157 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9158 | return; |
9159 | ||
9160 | nla_put_failure: | |
9161 | genlmsg_cancel(msg, hdr); | |
9162 | nlmsg_free(msg); | |
9163 | } | |
9164 | ||
9165 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9166 | struct net_device *netdev, const u8 *buf, |
9167 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9168 | { |
9169 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9170 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9171 | } |
9172 | ||
9173 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9174 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9175 | size_t len, gfp_t gfp) |
6039f6d2 | 9176 | { |
e6d6e342 JB |
9177 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9178 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9179 | } |
9180 | ||
53b46b84 | 9181 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9182 | struct net_device *netdev, const u8 *buf, |
9183 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9184 | { |
9185 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9186 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9187 | } |
9188 | ||
53b46b84 JM |
9189 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9190 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9191 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9192 | { |
9193 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9194 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9195 | } |
9196 | ||
947add36 JB |
9197 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
9198 | size_t len) | |
cf4e594e | 9199 | { |
947add36 JB |
9200 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9201 | struct wiphy *wiphy = wdev->wiphy; | |
9202 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9203 | ||
9204 | trace_cfg80211_send_unprot_deauth(dev); | |
9205 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9206 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); | |
cf4e594e | 9207 | } |
947add36 | 9208 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
cf4e594e | 9209 | |
947add36 JB |
9210 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
9211 | size_t len) | |
cf4e594e | 9212 | { |
947add36 JB |
9213 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9214 | struct wiphy *wiphy = wdev->wiphy; | |
9215 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9216 | ||
9217 | trace_cfg80211_send_unprot_disassoc(dev); | |
9218 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9219 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); | |
cf4e594e | 9220 | } |
947add36 | 9221 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
cf4e594e | 9222 | |
1b06bb40 LR |
9223 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9224 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9225 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9226 | { |
9227 | struct sk_buff *msg; | |
9228 | void *hdr; | |
9229 | ||
e6d6e342 | 9230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9231 | if (!msg) |
9232 | return; | |
9233 | ||
9234 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9235 | if (!hdr) { | |
9236 | nlmsg_free(msg); | |
9237 | return; | |
9238 | } | |
9239 | ||
9360ffd1 DM |
9240 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9241 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9242 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9243 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9244 | goto nla_put_failure; | |
1965c853 | 9245 | |
3b7b72ee | 9246 | genlmsg_end(msg, hdr); |
1965c853 | 9247 | |
463d0183 JB |
9248 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9249 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9250 | return; |
9251 | ||
9252 | nla_put_failure: | |
9253 | genlmsg_cancel(msg, hdr); | |
9254 | nlmsg_free(msg); | |
9255 | } | |
9256 | ||
9257 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9258 | struct net_device *netdev, const u8 *addr, |
9259 | gfp_t gfp) | |
1965c853 JM |
9260 | { |
9261 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9262 | addr, gfp); |
1965c853 JM |
9263 | } |
9264 | ||
9265 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9266 | struct net_device *netdev, const u8 *addr, |
9267 | gfp_t gfp) | |
1965c853 | 9268 | { |
e6d6e342 JB |
9269 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9270 | addr, gfp); | |
1965c853 JM |
9271 | } |
9272 | ||
b23aa676 SO |
9273 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9274 | struct net_device *netdev, const u8 *bssid, | |
9275 | const u8 *req_ie, size_t req_ie_len, | |
9276 | const u8 *resp_ie, size_t resp_ie_len, | |
9277 | u16 status, gfp_t gfp) | |
9278 | { | |
9279 | struct sk_buff *msg; | |
9280 | void *hdr; | |
9281 | ||
58050fce | 9282 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9283 | if (!msg) |
9284 | return; | |
9285 | ||
9286 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9287 | if (!hdr) { | |
9288 | nlmsg_free(msg); | |
9289 | return; | |
9290 | } | |
9291 | ||
9360ffd1 DM |
9292 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9293 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9294 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9295 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9296 | (req_ie && | |
9297 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9298 | (resp_ie && | |
9299 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9300 | goto nla_put_failure; | |
b23aa676 | 9301 | |
3b7b72ee | 9302 | genlmsg_end(msg, hdr); |
b23aa676 | 9303 | |
463d0183 JB |
9304 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9305 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9306 | return; |
9307 | ||
9308 | nla_put_failure: | |
9309 | genlmsg_cancel(msg, hdr); | |
9310 | nlmsg_free(msg); | |
9311 | ||
9312 | } | |
9313 | ||
9314 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9315 | struct net_device *netdev, const u8 *bssid, | |
9316 | const u8 *req_ie, size_t req_ie_len, | |
9317 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9318 | { | |
9319 | struct sk_buff *msg; | |
9320 | void *hdr; | |
9321 | ||
58050fce | 9322 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9323 | if (!msg) |
9324 | return; | |
9325 | ||
9326 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9327 | if (!hdr) { | |
9328 | nlmsg_free(msg); | |
9329 | return; | |
9330 | } | |
9331 | ||
9360ffd1 DM |
9332 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9333 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9334 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9335 | (req_ie && | |
9336 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9337 | (resp_ie && | |
9338 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9339 | goto nla_put_failure; | |
b23aa676 | 9340 | |
3b7b72ee | 9341 | genlmsg_end(msg, hdr); |
b23aa676 | 9342 | |
463d0183 JB |
9343 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9344 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9345 | return; |
9346 | ||
9347 | nla_put_failure: | |
9348 | genlmsg_cancel(msg, hdr); | |
9349 | nlmsg_free(msg); | |
9350 | ||
9351 | } | |
9352 | ||
9353 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9354 | struct net_device *netdev, u16 reason, | |
667503dd | 9355 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9356 | { |
9357 | struct sk_buff *msg; | |
9358 | void *hdr; | |
9359 | ||
58050fce | 9360 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9361 | if (!msg) |
9362 | return; | |
9363 | ||
9364 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9365 | if (!hdr) { | |
9366 | nlmsg_free(msg); | |
9367 | return; | |
9368 | } | |
9369 | ||
9360ffd1 DM |
9370 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9371 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9372 | (from_ap && reason && | |
9373 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9374 | (from_ap && | |
9375 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9376 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9377 | goto nla_put_failure; | |
b23aa676 | 9378 | |
3b7b72ee | 9379 | genlmsg_end(msg, hdr); |
b23aa676 | 9380 | |
463d0183 JB |
9381 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9382 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9383 | return; |
9384 | ||
9385 | nla_put_failure: | |
9386 | genlmsg_cancel(msg, hdr); | |
9387 | nlmsg_free(msg); | |
9388 | ||
9389 | } | |
9390 | ||
04a773ad JB |
9391 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9392 | struct net_device *netdev, const u8 *bssid, | |
9393 | gfp_t gfp) | |
9394 | { | |
9395 | struct sk_buff *msg; | |
9396 | void *hdr; | |
9397 | ||
fd2120ca | 9398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9399 | if (!msg) |
9400 | return; | |
9401 | ||
9402 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9403 | if (!hdr) { | |
9404 | nlmsg_free(msg); | |
9405 | return; | |
9406 | } | |
9407 | ||
9360ffd1 DM |
9408 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9409 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9410 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9411 | goto nla_put_failure; | |
04a773ad | 9412 | |
3b7b72ee | 9413 | genlmsg_end(msg, hdr); |
04a773ad | 9414 | |
463d0183 JB |
9415 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9416 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9417 | return; |
9418 | ||
9419 | nla_put_failure: | |
9420 | genlmsg_cancel(msg, hdr); | |
9421 | nlmsg_free(msg); | |
9422 | } | |
9423 | ||
947add36 JB |
9424 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9425 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9426 | { |
947add36 JB |
9427 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9428 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9429 | struct sk_buff *msg; |
9430 | void *hdr; | |
9431 | ||
947add36 JB |
9432 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9433 | return; | |
9434 | ||
9435 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9436 | ||
c93b5e71 JC |
9437 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9438 | if (!msg) | |
9439 | return; | |
9440 | ||
9441 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9442 | if (!hdr) { | |
9443 | nlmsg_free(msg); | |
9444 | return; | |
9445 | } | |
9446 | ||
9360ffd1 | 9447 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9448 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9449 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9450 | (ie_len && ie && |
9451 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9452 | goto nla_put_failure; | |
c93b5e71 | 9453 | |
3b7b72ee | 9454 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9455 | |
9456 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9457 | nl80211_mlme_mcgrp.id, gfp); | |
9458 | return; | |
9459 | ||
9460 | nla_put_failure: | |
9461 | genlmsg_cancel(msg, hdr); | |
9462 | nlmsg_free(msg); | |
9463 | } | |
947add36 | 9464 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9465 | |
a3b8b056 JM |
9466 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9467 | struct net_device *netdev, const u8 *addr, | |
9468 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9469 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9470 | { |
9471 | struct sk_buff *msg; | |
9472 | void *hdr; | |
9473 | ||
e6d6e342 | 9474 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9475 | if (!msg) |
9476 | return; | |
9477 | ||
9478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9479 | if (!hdr) { | |
9480 | nlmsg_free(msg); | |
9481 | return; | |
9482 | } | |
9483 | ||
9360ffd1 DM |
9484 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9485 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9486 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9487 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9488 | (key_id != -1 && | |
9489 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9490 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9491 | goto nla_put_failure; | |
a3b8b056 | 9492 | |
3b7b72ee | 9493 | genlmsg_end(msg, hdr); |
a3b8b056 | 9494 | |
463d0183 JB |
9495 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9496 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9497 | return; |
9498 | ||
9499 | nla_put_failure: | |
9500 | genlmsg_cancel(msg, hdr); | |
9501 | nlmsg_free(msg); | |
9502 | } | |
9503 | ||
6bad8766 LR |
9504 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9505 | struct ieee80211_channel *channel_before, | |
9506 | struct ieee80211_channel *channel_after) | |
9507 | { | |
9508 | struct sk_buff *msg; | |
9509 | void *hdr; | |
9510 | struct nlattr *nl_freq; | |
9511 | ||
fd2120ca | 9512 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9513 | if (!msg) |
9514 | return; | |
9515 | ||
9516 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9517 | if (!hdr) { | |
9518 | nlmsg_free(msg); | |
9519 | return; | |
9520 | } | |
9521 | ||
9522 | /* | |
9523 | * Since we are applying the beacon hint to a wiphy we know its | |
9524 | * wiphy_idx is valid | |
9525 | */ | |
9360ffd1 DM |
9526 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9527 | goto nla_put_failure; | |
6bad8766 LR |
9528 | |
9529 | /* Before */ | |
9530 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9531 | if (!nl_freq) | |
9532 | goto nla_put_failure; | |
cdc89b97 | 9533 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
9534 | goto nla_put_failure; |
9535 | nla_nest_end(msg, nl_freq); | |
9536 | ||
9537 | /* After */ | |
9538 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9539 | if (!nl_freq) | |
9540 | goto nla_put_failure; | |
cdc89b97 | 9541 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
9542 | goto nla_put_failure; |
9543 | nla_nest_end(msg, nl_freq); | |
9544 | ||
3b7b72ee | 9545 | genlmsg_end(msg, hdr); |
6bad8766 | 9546 | |
463d0183 JB |
9547 | rcu_read_lock(); |
9548 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9549 | GFP_ATOMIC); | |
9550 | rcu_read_unlock(); | |
6bad8766 LR |
9551 | |
9552 | return; | |
9553 | ||
9554 | nla_put_failure: | |
9555 | genlmsg_cancel(msg, hdr); | |
9556 | nlmsg_free(msg); | |
9557 | } | |
9558 | ||
9588bbd5 JM |
9559 | static void nl80211_send_remain_on_chan_event( |
9560 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9561 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9562 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9563 | unsigned int duration, gfp_t gfp) |
9564 | { | |
9565 | struct sk_buff *msg; | |
9566 | void *hdr; | |
9567 | ||
9568 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9569 | if (!msg) | |
9570 | return; | |
9571 | ||
9572 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9573 | if (!hdr) { | |
9574 | nlmsg_free(msg); | |
9575 | return; | |
9576 | } | |
9577 | ||
9360ffd1 | 9578 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9579 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9580 | wdev->netdev->ifindex)) || | |
00f53350 | 9581 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9582 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9583 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9584 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9585 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9586 | goto nla_put_failure; | |
9588bbd5 | 9587 | |
9360ffd1 DM |
9588 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9589 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9590 | goto nla_put_failure; | |
9588bbd5 | 9591 | |
3b7b72ee | 9592 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9593 | |
9594 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9595 | nl80211_mlme_mcgrp.id, gfp); | |
9596 | return; | |
9597 | ||
9598 | nla_put_failure: | |
9599 | genlmsg_cancel(msg, hdr); | |
9600 | nlmsg_free(msg); | |
9601 | } | |
9602 | ||
947add36 JB |
9603 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
9604 | struct ieee80211_channel *chan, | |
9605 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 9606 | { |
947add36 JB |
9607 | struct wiphy *wiphy = wdev->wiphy; |
9608 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9609 | ||
9610 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 9611 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 9612 | rdev, wdev, cookie, chan, |
42d97a59 | 9613 | duration, gfp); |
9588bbd5 | 9614 | } |
947add36 | 9615 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 9616 | |
947add36 JB |
9617 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
9618 | struct ieee80211_channel *chan, | |
9619 | gfp_t gfp) | |
9588bbd5 | 9620 | { |
947add36 JB |
9621 | struct wiphy *wiphy = wdev->wiphy; |
9622 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9623 | ||
9624 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 9625 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 9626 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 9627 | } |
947add36 | 9628 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 9629 | |
947add36 JB |
9630 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
9631 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 9632 | { |
947add36 JB |
9633 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9634 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
9635 | struct sk_buff *msg; |
9636 | ||
947add36 JB |
9637 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
9638 | ||
58050fce | 9639 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9640 | if (!msg) |
9641 | return; | |
9642 | ||
66266b3a JL |
9643 | if (nl80211_send_station(msg, 0, 0, 0, |
9644 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9645 | nlmsg_free(msg); |
9646 | return; | |
9647 | } | |
9648 | ||
9649 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9650 | nl80211_mlme_mcgrp.id, gfp); | |
9651 | } | |
947add36 | 9652 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 9653 | |
947add36 | 9654 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 9655 | { |
947add36 JB |
9656 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9657 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
9658 | struct sk_buff *msg; |
9659 | void *hdr; | |
9660 | ||
947add36 JB |
9661 | trace_cfg80211_del_sta(dev, mac_addr); |
9662 | ||
58050fce | 9663 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9664 | if (!msg) |
9665 | return; | |
9666 | ||
9667 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
9668 | if (!hdr) { | |
9669 | nlmsg_free(msg); | |
9670 | return; | |
9671 | } | |
9672 | ||
9360ffd1 DM |
9673 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9674 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
9675 | goto nla_put_failure; | |
ec15e68b | 9676 | |
3b7b72ee | 9677 | genlmsg_end(msg, hdr); |
ec15e68b JM |
9678 | |
9679 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9680 | nl80211_mlme_mcgrp.id, gfp); | |
9681 | return; | |
9682 | ||
9683 | nla_put_failure: | |
9684 | genlmsg_cancel(msg, hdr); | |
9685 | nlmsg_free(msg); | |
9686 | } | |
947add36 | 9687 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 9688 | |
947add36 JB |
9689 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
9690 | enum nl80211_connect_failed_reason reason, | |
9691 | gfp_t gfp) | |
ed44a951 | 9692 | { |
947add36 JB |
9693 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9694 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
9695 | struct sk_buff *msg; |
9696 | void *hdr; | |
9697 | ||
9698 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9699 | if (!msg) | |
9700 | return; | |
9701 | ||
9702 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
9703 | if (!hdr) { | |
9704 | nlmsg_free(msg); | |
9705 | return; | |
9706 | } | |
9707 | ||
9708 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9709 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
9710 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
9711 | goto nla_put_failure; | |
9712 | ||
9713 | genlmsg_end(msg, hdr); | |
9714 | ||
9715 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9716 | nl80211_mlme_mcgrp.id, gfp); | |
9717 | return; | |
9718 | ||
9719 | nla_put_failure: | |
9720 | genlmsg_cancel(msg, hdr); | |
9721 | nlmsg_free(msg); | |
9722 | } | |
947add36 | 9723 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 9724 | |
b92ab5d8 JB |
9725 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
9726 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
9727 | { |
9728 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9729 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9730 | struct sk_buff *msg; | |
9731 | void *hdr; | |
9732 | int err; | |
15e47304 | 9733 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 9734 | |
15e47304 | 9735 | if (!nlportid) |
28946da7 JB |
9736 | return false; |
9737 | ||
9738 | msg = nlmsg_new(100, gfp); | |
9739 | if (!msg) | |
9740 | return true; | |
9741 | ||
b92ab5d8 | 9742 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
9743 | if (!hdr) { |
9744 | nlmsg_free(msg); | |
9745 | return true; | |
9746 | } | |
9747 | ||
9360ffd1 DM |
9748 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9749 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9750 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9751 | goto nla_put_failure; | |
28946da7 JB |
9752 | |
9753 | err = genlmsg_end(msg, hdr); | |
9754 | if (err < 0) { | |
9755 | nlmsg_free(msg); | |
9756 | return true; | |
9757 | } | |
9758 | ||
15e47304 | 9759 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
9760 | return true; |
9761 | ||
9762 | nla_put_failure: | |
9763 | genlmsg_cancel(msg, hdr); | |
9764 | nlmsg_free(msg); | |
9765 | return true; | |
9766 | } | |
9767 | ||
947add36 JB |
9768 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
9769 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9770 | { |
947add36 JB |
9771 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9772 | bool ret; | |
9773 | ||
9774 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
9775 | ||
9776 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9777 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
9778 | trace_cfg80211_return_bool(false); | |
9779 | return false; | |
9780 | } | |
9781 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
9782 | addr, gfp); | |
9783 | trace_cfg80211_return_bool(ret); | |
9784 | return ret; | |
b92ab5d8 | 9785 | } |
947add36 | 9786 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 9787 | |
947add36 JB |
9788 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
9789 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9790 | { |
947add36 JB |
9791 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9792 | bool ret; | |
9793 | ||
9794 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
9795 | ||
9796 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9797 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
9798 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
9799 | trace_cfg80211_return_bool(false); | |
9800 | return false; | |
9801 | } | |
9802 | ret = __nl80211_unexpected_frame(dev, | |
9803 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
9804 | addr, gfp); | |
9805 | trace_cfg80211_return_bool(ret); | |
9806 | return ret; | |
b92ab5d8 | 9807 | } |
947add36 | 9808 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 9809 | |
2e161f78 | 9810 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 9811 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
9812 | int freq, int sig_dbm, |
9813 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 9814 | { |
71bbc994 | 9815 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9816 | struct sk_buff *msg; |
9817 | void *hdr; | |
026331c4 JM |
9818 | |
9819 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9820 | if (!msg) | |
9821 | return -ENOMEM; | |
9822 | ||
2e161f78 | 9823 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
9824 | if (!hdr) { |
9825 | nlmsg_free(msg); | |
9826 | return -ENOMEM; | |
9827 | } | |
9828 | ||
9360ffd1 | 9829 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9830 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9831 | netdev->ifindex)) || | |
9360ffd1 DM |
9832 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
9833 | (sig_dbm && | |
9834 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9835 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9836 | goto nla_put_failure; | |
026331c4 | 9837 | |
3b7b72ee | 9838 | genlmsg_end(msg, hdr); |
026331c4 | 9839 | |
15e47304 | 9840 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
9841 | |
9842 | nla_put_failure: | |
9843 | genlmsg_cancel(msg, hdr); | |
9844 | nlmsg_free(msg); | |
9845 | return -ENOBUFS; | |
9846 | } | |
9847 | ||
947add36 JB |
9848 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
9849 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 9850 | { |
947add36 JB |
9851 | struct wiphy *wiphy = wdev->wiphy; |
9852 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 9853 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9854 | struct sk_buff *msg; |
9855 | void *hdr; | |
9856 | ||
947add36 JB |
9857 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
9858 | ||
026331c4 JM |
9859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9860 | if (!msg) | |
9861 | return; | |
9862 | ||
2e161f78 | 9863 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
9864 | if (!hdr) { |
9865 | nlmsg_free(msg); | |
9866 | return; | |
9867 | } | |
9868 | ||
9360ffd1 | 9869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9870 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9871 | netdev->ifindex)) || | |
9360ffd1 DM |
9872 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
9873 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
9874 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
9875 | goto nla_put_failure; | |
026331c4 | 9876 | |
3b7b72ee | 9877 | genlmsg_end(msg, hdr); |
026331c4 JM |
9878 | |
9879 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
9880 | return; | |
9881 | ||
9882 | nla_put_failure: | |
9883 | genlmsg_cancel(msg, hdr); | |
9884 | nlmsg_free(msg); | |
9885 | } | |
947add36 | 9886 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 9887 | |
947add36 JB |
9888 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
9889 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
9890 | gfp_t gfp) | |
d6dc1a38 | 9891 | { |
947add36 JB |
9892 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9893 | struct wiphy *wiphy = wdev->wiphy; | |
9894 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
9895 | struct sk_buff *msg; |
9896 | struct nlattr *pinfoattr; | |
9897 | void *hdr; | |
9898 | ||
947add36 JB |
9899 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
9900 | ||
58050fce | 9901 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
9902 | if (!msg) |
9903 | return; | |
9904 | ||
9905 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9906 | if (!hdr) { | |
9907 | nlmsg_free(msg); | |
9908 | return; | |
9909 | } | |
9910 | ||
9360ffd1 | 9911 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 9912 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 9913 | goto nla_put_failure; |
d6dc1a38 JO |
9914 | |
9915 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
9916 | if (!pinfoattr) | |
9917 | goto nla_put_failure; | |
9918 | ||
9360ffd1 DM |
9919 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
9920 | rssi_event)) | |
9921 | goto nla_put_failure; | |
d6dc1a38 JO |
9922 | |
9923 | nla_nest_end(msg, pinfoattr); | |
9924 | ||
3b7b72ee | 9925 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
9926 | |
9927 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9928 | nl80211_mlme_mcgrp.id, gfp); | |
9929 | return; | |
9930 | ||
9931 | nla_put_failure: | |
9932 | genlmsg_cancel(msg, hdr); | |
9933 | nlmsg_free(msg); | |
9934 | } | |
947add36 | 9935 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 9936 | |
947add36 JB |
9937 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
9938 | struct net_device *netdev, const u8 *bssid, | |
9939 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
9940 | { |
9941 | struct sk_buff *msg; | |
9942 | struct nlattr *rekey_attr; | |
9943 | void *hdr; | |
9944 | ||
58050fce | 9945 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
9946 | if (!msg) |
9947 | return; | |
9948 | ||
9949 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
9950 | if (!hdr) { | |
9951 | nlmsg_free(msg); | |
9952 | return; | |
9953 | } | |
9954 | ||
9360ffd1 DM |
9955 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9956 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9957 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9958 | goto nla_put_failure; | |
e5497d76 JB |
9959 | |
9960 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
9961 | if (!rekey_attr) | |
9962 | goto nla_put_failure; | |
9963 | ||
9360ffd1 DM |
9964 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
9965 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
9966 | goto nla_put_failure; | |
e5497d76 JB |
9967 | |
9968 | nla_nest_end(msg, rekey_attr); | |
9969 | ||
3b7b72ee | 9970 | genlmsg_end(msg, hdr); |
e5497d76 JB |
9971 | |
9972 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9973 | nl80211_mlme_mcgrp.id, gfp); | |
9974 | return; | |
9975 | ||
9976 | nla_put_failure: | |
9977 | genlmsg_cancel(msg, hdr); | |
9978 | nlmsg_free(msg); | |
9979 | } | |
9980 | ||
947add36 JB |
9981 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
9982 | const u8 *replay_ctr, gfp_t gfp) | |
9983 | { | |
9984 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9985 | struct wiphy *wiphy = wdev->wiphy; | |
9986 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9987 | ||
9988 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
9989 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
9990 | } | |
9991 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
9992 | ||
9993 | static void | |
9994 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
9995 | struct net_device *netdev, int index, | |
9996 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
9997 | { |
9998 | struct sk_buff *msg; | |
9999 | struct nlattr *attr; | |
10000 | void *hdr; | |
10001 | ||
58050fce | 10002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10003 | if (!msg) |
10004 | return; | |
10005 | ||
10006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10007 | if (!hdr) { | |
10008 | nlmsg_free(msg); | |
10009 | return; | |
10010 | } | |
10011 | ||
9360ffd1 DM |
10012 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10013 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10014 | goto nla_put_failure; | |
c9df56b4 JM |
10015 | |
10016 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10017 | if (!attr) | |
10018 | goto nla_put_failure; | |
10019 | ||
9360ffd1 DM |
10020 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10021 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10022 | (preauth && | |
10023 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10024 | goto nla_put_failure; | |
c9df56b4 JM |
10025 | |
10026 | nla_nest_end(msg, attr); | |
10027 | ||
3b7b72ee | 10028 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10029 | |
10030 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10031 | nl80211_mlme_mcgrp.id, gfp); | |
10032 | return; | |
10033 | ||
10034 | nla_put_failure: | |
10035 | genlmsg_cancel(msg, hdr); | |
10036 | nlmsg_free(msg); | |
10037 | } | |
10038 | ||
947add36 JB |
10039 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10040 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10041 | { | |
10042 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10043 | struct wiphy *wiphy = wdev->wiphy; | |
10044 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10045 | ||
10046 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10047 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10048 | } | |
10049 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10050 | ||
10051 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10052 | struct net_device *netdev, | |
10053 | struct cfg80211_chan_def *chandef, | |
10054 | gfp_t gfp) | |
5314526b TP |
10055 | { |
10056 | struct sk_buff *msg; | |
10057 | void *hdr; | |
10058 | ||
58050fce | 10059 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10060 | if (!msg) |
10061 | return; | |
10062 | ||
10063 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10064 | if (!hdr) { | |
10065 | nlmsg_free(msg); | |
10066 | return; | |
10067 | } | |
10068 | ||
683b6d3b JB |
10069 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10070 | goto nla_put_failure; | |
10071 | ||
10072 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10073 | goto nla_put_failure; |
5314526b TP |
10074 | |
10075 | genlmsg_end(msg, hdr); | |
10076 | ||
10077 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10078 | nl80211_mlme_mcgrp.id, gfp); | |
10079 | return; | |
10080 | ||
10081 | nla_put_failure: | |
10082 | genlmsg_cancel(msg, hdr); | |
10083 | nlmsg_free(msg); | |
10084 | } | |
10085 | ||
947add36 JB |
10086 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10087 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10088 | { |
947add36 JB |
10089 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10090 | struct wiphy *wiphy = wdev->wiphy; | |
10091 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10092 | ||
10093 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10094 | ||
10095 | wdev_lock(wdev); | |
10096 | ||
10097 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10098 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10099 | goto out; | |
10100 | ||
10101 | wdev->channel = chandef->chan; | |
10102 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10103 | out: | |
10104 | wdev_unlock(wdev); | |
10105 | return; | |
10106 | } | |
10107 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10108 | ||
10109 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10110 | const u8 *peer, u32 num_packets, | |
10111 | u32 rate, u32 intvl, gfp_t gfp) | |
10112 | { | |
10113 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10114 | struct wiphy *wiphy = wdev->wiphy; | |
10115 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10116 | struct sk_buff *msg; |
10117 | struct nlattr *pinfoattr; | |
10118 | void *hdr; | |
10119 | ||
10120 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10121 | if (!msg) | |
10122 | return; | |
10123 | ||
10124 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10125 | if (!hdr) { | |
10126 | nlmsg_free(msg); | |
10127 | return; | |
10128 | } | |
10129 | ||
10130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10131 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10132 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10133 | goto nla_put_failure; | |
10134 | ||
10135 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10136 | if (!pinfoattr) | |
10137 | goto nla_put_failure; | |
10138 | ||
10139 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10140 | goto nla_put_failure; | |
10141 | ||
10142 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10143 | goto nla_put_failure; | |
10144 | ||
10145 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10146 | goto nla_put_failure; | |
10147 | ||
10148 | nla_nest_end(msg, pinfoattr); | |
10149 | ||
10150 | genlmsg_end(msg, hdr); | |
10151 | ||
10152 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10153 | nl80211_mlme_mcgrp.id, gfp); | |
10154 | return; | |
10155 | ||
10156 | nla_put_failure: | |
10157 | genlmsg_cancel(msg, hdr); | |
10158 | nlmsg_free(msg); | |
10159 | } | |
947add36 | 10160 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10161 | |
04f39047 SW |
10162 | void |
10163 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10164 | struct cfg80211_chan_def *chandef, | |
10165 | enum nl80211_radar_event event, | |
10166 | struct net_device *netdev, gfp_t gfp) | |
10167 | { | |
10168 | struct sk_buff *msg; | |
10169 | void *hdr; | |
10170 | ||
10171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10172 | if (!msg) | |
10173 | return; | |
10174 | ||
10175 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10176 | if (!hdr) { | |
10177 | nlmsg_free(msg); | |
10178 | return; | |
10179 | } | |
10180 | ||
10181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10182 | goto nla_put_failure; | |
10183 | ||
10184 | /* NOP and radar events don't need a netdev parameter */ | |
10185 | if (netdev) { | |
10186 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10187 | ||
10188 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10189 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10190 | goto nla_put_failure; | |
10191 | } | |
10192 | ||
10193 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10194 | goto nla_put_failure; | |
10195 | ||
10196 | if (nl80211_send_chandef(msg, chandef)) | |
10197 | goto nla_put_failure; | |
10198 | ||
10199 | if (genlmsg_end(msg, hdr) < 0) { | |
10200 | nlmsg_free(msg); | |
10201 | return; | |
10202 | } | |
10203 | ||
10204 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10205 | nl80211_mlme_mcgrp.id, gfp); | |
10206 | return; | |
10207 | ||
10208 | nla_put_failure: | |
10209 | genlmsg_cancel(msg, hdr); | |
10210 | nlmsg_free(msg); | |
10211 | } | |
10212 | ||
947add36 JB |
10213 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10214 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10215 | { |
947add36 JB |
10216 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10217 | struct wiphy *wiphy = wdev->wiphy; | |
10218 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10219 | struct sk_buff *msg; |
10220 | struct nlattr *pinfoattr; | |
10221 | void *hdr; | |
10222 | ||
947add36 JB |
10223 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10224 | ||
58050fce | 10225 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10226 | if (!msg) |
10227 | return; | |
10228 | ||
10229 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10230 | if (!hdr) { | |
10231 | nlmsg_free(msg); | |
10232 | return; | |
10233 | } | |
10234 | ||
9360ffd1 | 10235 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10236 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10237 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10238 | goto nla_put_failure; | |
c063dbf5 JB |
10239 | |
10240 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10241 | if (!pinfoattr) | |
10242 | goto nla_put_failure; | |
10243 | ||
9360ffd1 DM |
10244 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10245 | goto nla_put_failure; | |
c063dbf5 JB |
10246 | |
10247 | nla_nest_end(msg, pinfoattr); | |
10248 | ||
3b7b72ee | 10249 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10250 | |
10251 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10252 | nl80211_mlme_mcgrp.id, gfp); | |
10253 | return; | |
10254 | ||
10255 | nla_put_failure: | |
10256 | genlmsg_cancel(msg, hdr); | |
10257 | nlmsg_free(msg); | |
10258 | } | |
947add36 | 10259 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10260 | |
7f6cf311 JB |
10261 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10262 | u64 cookie, bool acked, gfp_t gfp) | |
10263 | { | |
10264 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10265 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10266 | struct sk_buff *msg; | |
10267 | void *hdr; | |
10268 | int err; | |
10269 | ||
4ee3e063 BL |
10270 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10271 | ||
58050fce | 10272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10273 | |
7f6cf311 JB |
10274 | if (!msg) |
10275 | return; | |
10276 | ||
10277 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10278 | if (!hdr) { | |
10279 | nlmsg_free(msg); | |
10280 | return; | |
10281 | } | |
10282 | ||
9360ffd1 DM |
10283 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10284 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10285 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10286 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10287 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10288 | goto nla_put_failure; | |
7f6cf311 JB |
10289 | |
10290 | err = genlmsg_end(msg, hdr); | |
10291 | if (err < 0) { | |
10292 | nlmsg_free(msg); | |
10293 | return; | |
10294 | } | |
10295 | ||
10296 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10297 | nl80211_mlme_mcgrp.id, gfp); | |
10298 | return; | |
10299 | ||
10300 | nla_put_failure: | |
10301 | genlmsg_cancel(msg, hdr); | |
10302 | nlmsg_free(msg); | |
10303 | } | |
10304 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10305 | ||
5e760230 JB |
10306 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10307 | const u8 *frame, size_t len, | |
37c73b5f | 10308 | int freq, int sig_dbm) |
5e760230 JB |
10309 | { |
10310 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10311 | struct sk_buff *msg; | |
10312 | void *hdr; | |
37c73b5f | 10313 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10314 | |
4ee3e063 BL |
10315 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10316 | ||
37c73b5f BG |
10317 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10318 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10319 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10320 | if (!msg) { | |
10321 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10322 | return; | |
10323 | } | |
5e760230 | 10324 | |
37c73b5f BG |
10325 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10326 | if (!hdr) | |
10327 | goto nla_put_failure; | |
5e760230 | 10328 | |
37c73b5f BG |
10329 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10330 | (freq && | |
10331 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10332 | (sig_dbm && | |
10333 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10334 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10335 | goto nla_put_failure; | |
5e760230 | 10336 | |
37c73b5f | 10337 | genlmsg_end(msg, hdr); |
5e760230 | 10338 | |
37c73b5f BG |
10339 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10340 | } | |
10341 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10342 | return; |
10343 | ||
10344 | nla_put_failure: | |
37c73b5f BG |
10345 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10346 | if (hdr) | |
10347 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10348 | nlmsg_free(msg); |
10349 | } | |
10350 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10351 | ||
cd8f7cb4 JB |
10352 | #ifdef CONFIG_PM |
10353 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10354 | struct cfg80211_wowlan_wakeup *wakeup, | |
10355 | gfp_t gfp) | |
10356 | { | |
10357 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10358 | struct sk_buff *msg; | |
10359 | void *hdr; | |
10360 | int err, size = 200; | |
10361 | ||
10362 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10363 | ||
10364 | if (wakeup) | |
10365 | size += wakeup->packet_present_len; | |
10366 | ||
10367 | msg = nlmsg_new(size, gfp); | |
10368 | if (!msg) | |
10369 | return; | |
10370 | ||
10371 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10372 | if (!hdr) | |
10373 | goto free_msg; | |
10374 | ||
10375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10376 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10377 | goto free_msg; | |
10378 | ||
10379 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10380 | wdev->netdev->ifindex)) | |
10381 | goto free_msg; | |
10382 | ||
10383 | if (wakeup) { | |
10384 | struct nlattr *reasons; | |
10385 | ||
10386 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10387 | ||
10388 | if (wakeup->disconnect && | |
10389 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10390 | goto free_msg; | |
10391 | if (wakeup->magic_pkt && | |
10392 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10393 | goto free_msg; | |
10394 | if (wakeup->gtk_rekey_failure && | |
10395 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10396 | goto free_msg; | |
10397 | if (wakeup->eap_identity_req && | |
10398 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10399 | goto free_msg; | |
10400 | if (wakeup->four_way_handshake && | |
10401 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10402 | goto free_msg; | |
10403 | if (wakeup->rfkill_release && | |
10404 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10405 | goto free_msg; | |
10406 | ||
10407 | if (wakeup->pattern_idx >= 0 && | |
10408 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10409 | wakeup->pattern_idx)) | |
10410 | goto free_msg; | |
10411 | ||
2a0e047e JB |
10412 | if (wakeup->tcp_match) |
10413 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10414 | ||
10415 | if (wakeup->tcp_connlost) | |
10416 | nla_put_flag(msg, | |
10417 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10418 | ||
10419 | if (wakeup->tcp_nomoretokens) | |
10420 | nla_put_flag(msg, | |
10421 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10422 | ||
cd8f7cb4 JB |
10423 | if (wakeup->packet) { |
10424 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10425 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10426 | ||
10427 | if (!wakeup->packet_80211) { | |
10428 | pkt_attr = | |
10429 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10430 | len_attr = | |
10431 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10432 | } | |
10433 | ||
10434 | if (wakeup->packet_len && | |
10435 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10436 | goto free_msg; | |
10437 | ||
10438 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10439 | wakeup->packet)) | |
10440 | goto free_msg; | |
10441 | } | |
10442 | ||
10443 | nla_nest_end(msg, reasons); | |
10444 | } | |
10445 | ||
10446 | err = genlmsg_end(msg, hdr); | |
10447 | if (err < 0) | |
10448 | goto free_msg; | |
10449 | ||
10450 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10451 | nl80211_mlme_mcgrp.id, gfp); | |
10452 | return; | |
10453 | ||
10454 | free_msg: | |
10455 | nlmsg_free(msg); | |
10456 | } | |
10457 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10458 | #endif | |
10459 | ||
3475b094 JM |
10460 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10461 | enum nl80211_tdls_operation oper, | |
10462 | u16 reason_code, gfp_t gfp) | |
10463 | { | |
10464 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10465 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10466 | struct sk_buff *msg; | |
10467 | void *hdr; | |
10468 | int err; | |
10469 | ||
10470 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10471 | reason_code); | |
10472 | ||
10473 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10474 | if (!msg) | |
10475 | return; | |
10476 | ||
10477 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10478 | if (!hdr) { | |
10479 | nlmsg_free(msg); | |
10480 | return; | |
10481 | } | |
10482 | ||
10483 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10484 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10485 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10486 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10487 | (reason_code > 0 && | |
10488 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10489 | goto nla_put_failure; | |
10490 | ||
10491 | err = genlmsg_end(msg, hdr); | |
10492 | if (err < 0) { | |
10493 | nlmsg_free(msg); | |
10494 | return; | |
10495 | } | |
10496 | ||
10497 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10498 | nl80211_mlme_mcgrp.id, gfp); | |
10499 | return; | |
10500 | ||
10501 | nla_put_failure: | |
10502 | genlmsg_cancel(msg, hdr); | |
10503 | nlmsg_free(msg); | |
10504 | } | |
10505 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10506 | ||
026331c4 JM |
10507 | static int nl80211_netlink_notify(struct notifier_block * nb, |
10508 | unsigned long state, | |
10509 | void *_notify) | |
10510 | { | |
10511 | struct netlink_notify *notify = _notify; | |
10512 | struct cfg80211_registered_device *rdev; | |
10513 | struct wireless_dev *wdev; | |
37c73b5f | 10514 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
10515 | |
10516 | if (state != NETLINK_URELEASE) | |
10517 | return NOTIFY_DONE; | |
10518 | ||
10519 | rcu_read_lock(); | |
10520 | ||
5e760230 | 10521 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 10522 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 10523 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
10524 | |
10525 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10526 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
10527 | list) { | |
10528 | if (reg->nlportid == notify->portid) { | |
10529 | list_del(®->list); | |
10530 | kfree(reg); | |
10531 | break; | |
10532 | } | |
10533 | } | |
10534 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 10535 | } |
026331c4 JM |
10536 | |
10537 | rcu_read_unlock(); | |
10538 | ||
10539 | return NOTIFY_DONE; | |
10540 | } | |
10541 | ||
10542 | static struct notifier_block nl80211_netlink_notifier = { | |
10543 | .notifier_call = nl80211_netlink_notify, | |
10544 | }; | |
10545 | ||
55682965 JB |
10546 | /* initialisation/exit functions */ |
10547 | ||
10548 | int nl80211_init(void) | |
10549 | { | |
0d63cbb5 | 10550 | int err; |
55682965 | 10551 | |
0d63cbb5 MM |
10552 | err = genl_register_family_with_ops(&nl80211_fam, |
10553 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10554 | if (err) |
10555 | return err; | |
10556 | ||
55682965 JB |
10557 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10558 | if (err) | |
10559 | goto err_out; | |
10560 | ||
2a519311 JB |
10561 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10562 | if (err) | |
10563 | goto err_out; | |
10564 | ||
73d54c9e LR |
10565 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10566 | if (err) | |
10567 | goto err_out; | |
10568 | ||
6039f6d2 JM |
10569 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10570 | if (err) | |
10571 | goto err_out; | |
10572 | ||
aff89a9b JB |
10573 | #ifdef CONFIG_NL80211_TESTMODE |
10574 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10575 | if (err) | |
10576 | goto err_out; | |
10577 | #endif | |
10578 | ||
026331c4 JM |
10579 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
10580 | if (err) | |
10581 | goto err_out; | |
10582 | ||
55682965 JB |
10583 | return 0; |
10584 | err_out: | |
10585 | genl_unregister_family(&nl80211_fam); | |
10586 | return err; | |
10587 | } | |
10588 | ||
10589 | void nl80211_exit(void) | |
10590 | { | |
026331c4 | 10591 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
10592 | genl_unregister_family(&nl80211_fam); |
10593 | } |