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, }, | |
55682965 JB |
373 | }; |
374 | ||
e31b8213 | 375 | /* policy for the key attributes */ |
b54452b0 | 376 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 377 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
378 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
379 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 380 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
381 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
382 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 383 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
384 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
385 | }; | |
386 | ||
387 | /* policy for the key default flags */ | |
388 | static const struct nla_policy | |
389 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
390 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
391 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
392 | }; |
393 | ||
ff1b6e69 JB |
394 | /* policy for WoWLAN attributes */ |
395 | static const struct nla_policy | |
396 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
397 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
398 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
399 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
400 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
401 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
402 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
403 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
404 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
405 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
406 | }; | |
407 | ||
408 | static const struct nla_policy | |
409 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
410 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
411 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
412 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
413 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
414 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
415 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
416 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
417 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
418 | }, | |
419 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
420 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
421 | }, | |
422 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
423 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
424 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
425 | }; |
426 | ||
e5497d76 JB |
427 | /* policy for GTK rekey offload attributes */ |
428 | static const struct nla_policy | |
429 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
430 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
431 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
432 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
433 | }; | |
434 | ||
a1f1c21c LC |
435 | static const struct nla_policy |
436 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 437 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 438 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 439 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
440 | }; |
441 | ||
a043897a HS |
442 | /* ifidx get helper */ |
443 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
444 | { | |
445 | int res; | |
446 | ||
447 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
448 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
449 | nl80211_policy); | |
450 | if (res) | |
451 | return res; | |
452 | ||
453 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
454 | return -EINVAL; | |
455 | ||
456 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
457 | if (!res) | |
458 | return -EINVAL; | |
459 | return res; | |
460 | } | |
461 | ||
67748893 JB |
462 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
463 | struct netlink_callback *cb, | |
464 | struct cfg80211_registered_device **rdev, | |
465 | struct net_device **dev) | |
466 | { | |
467 | int ifidx = cb->args[0]; | |
468 | int err; | |
469 | ||
470 | if (!ifidx) | |
471 | ifidx = nl80211_get_ifidx(cb); | |
472 | if (ifidx < 0) | |
473 | return ifidx; | |
474 | ||
475 | cb->args[0] = ifidx; | |
476 | ||
477 | rtnl_lock(); | |
478 | ||
479 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
480 | if (!*dev) { | |
481 | err = -ENODEV; | |
482 | goto out_rtnl; | |
483 | } | |
484 | ||
485 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3cc25e51 FF |
486 | if (IS_ERR(*rdev)) { |
487 | err = PTR_ERR(*rdev); | |
67748893 JB |
488 | goto out_rtnl; |
489 | } | |
490 | ||
491 | return 0; | |
492 | out_rtnl: | |
493 | rtnl_unlock(); | |
494 | return err; | |
495 | } | |
496 | ||
497 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | |
498 | { | |
499 | cfg80211_unlock_rdev(rdev); | |
500 | rtnl_unlock(); | |
501 | } | |
502 | ||
f4a11bb0 JB |
503 | /* IE validation */ |
504 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
505 | { | |
506 | const u8 *pos; | |
507 | int len; | |
508 | ||
509 | if (!attr) | |
510 | return true; | |
511 | ||
512 | pos = nla_data(attr); | |
513 | len = nla_len(attr); | |
514 | ||
515 | while (len) { | |
516 | u8 elemlen; | |
517 | ||
518 | if (len < 2) | |
519 | return false; | |
520 | len -= 2; | |
521 | ||
522 | elemlen = pos[1]; | |
523 | if (elemlen > len) | |
524 | return false; | |
525 | ||
526 | len -= elemlen; | |
527 | pos += 2 + elemlen; | |
528 | } | |
529 | ||
530 | return true; | |
531 | } | |
532 | ||
55682965 | 533 | /* message building helper */ |
15e47304 | 534 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
535 | int flags, u8 cmd) |
536 | { | |
537 | /* since there is no private header just add the generic one */ | |
15e47304 | 538 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
539 | } |
540 | ||
5dab3b8a LR |
541 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
542 | struct ieee80211_channel *chan) | |
543 | { | |
9360ffd1 DM |
544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
545 | chan->center_freq)) | |
546 | goto nla_put_failure; | |
5dab3b8a | 547 | |
9360ffd1 DM |
548 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
549 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
550 | goto nla_put_failure; | |
551 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
552 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
553 | goto nla_put_failure; | |
554 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
556 | goto nla_put_failure; | |
1c33a059 JB |
557 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
559 | goto nla_put_failure; | |
5dab3b8a | 560 | |
9360ffd1 DM |
561 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
562 | DBM_TO_MBM(chan->max_power))) | |
563 | goto nla_put_failure; | |
5dab3b8a LR |
564 | |
565 | return 0; | |
566 | ||
567 | nla_put_failure: | |
568 | return -ENOBUFS; | |
569 | } | |
570 | ||
55682965 JB |
571 | /* netlink command implementations */ |
572 | ||
b9454e83 JB |
573 | struct key_parse { |
574 | struct key_params p; | |
575 | int idx; | |
e31b8213 | 576 | int type; |
b9454e83 | 577 | bool def, defmgmt; |
dbd2fd65 | 578 | bool def_uni, def_multi; |
b9454e83 JB |
579 | }; |
580 | ||
581 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
582 | { | |
583 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
584 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
585 | nl80211_key_policy); | |
586 | if (err) | |
587 | return err; | |
588 | ||
589 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
590 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
591 | ||
dbd2fd65 JB |
592 | if (k->def) { |
593 | k->def_uni = true; | |
594 | k->def_multi = true; | |
595 | } | |
596 | if (k->defmgmt) | |
597 | k->def_multi = true; | |
598 | ||
b9454e83 JB |
599 | if (tb[NL80211_KEY_IDX]) |
600 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
601 | ||
602 | if (tb[NL80211_KEY_DATA]) { | |
603 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
604 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
605 | } | |
606 | ||
607 | if (tb[NL80211_KEY_SEQ]) { | |
608 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
609 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
610 | } | |
611 | ||
612 | if (tb[NL80211_KEY_CIPHER]) | |
613 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
614 | ||
e31b8213 JB |
615 | if (tb[NL80211_KEY_TYPE]) { |
616 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
617 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
618 | return -EINVAL; | |
619 | } | |
620 | ||
dbd2fd65 JB |
621 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
622 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
623 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
624 | tb[NL80211_KEY_DEFAULT_TYPES], | |
625 | nl80211_key_default_policy); | |
dbd2fd65 JB |
626 | if (err) |
627 | return err; | |
628 | ||
629 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
630 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
631 | } | |
632 | ||
b9454e83 JB |
633 | return 0; |
634 | } | |
635 | ||
636 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
637 | { | |
638 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
639 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
640 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
641 | } | |
642 | ||
643 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
644 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
645 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
646 | } | |
647 | ||
648 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
649 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
650 | ||
651 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
652 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
653 | ||
654 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
655 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
656 | ||
dbd2fd65 JB |
657 | if (k->def) { |
658 | k->def_uni = true; | |
659 | k->def_multi = true; | |
660 | } | |
661 | if (k->defmgmt) | |
662 | k->def_multi = true; | |
663 | ||
e31b8213 JB |
664 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
665 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
666 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
667 | return -EINVAL; | |
668 | } | |
669 | ||
dbd2fd65 JB |
670 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
671 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
672 | int err = nla_parse_nested( | |
673 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
674 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
675 | nl80211_key_default_policy); | |
676 | if (err) | |
677 | return err; | |
678 | ||
679 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
680 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
681 | } | |
682 | ||
b9454e83 JB |
683 | return 0; |
684 | } | |
685 | ||
686 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
687 | { | |
688 | int err; | |
689 | ||
690 | memset(k, 0, sizeof(*k)); | |
691 | k->idx = -1; | |
e31b8213 | 692 | k->type = -1; |
b9454e83 JB |
693 | |
694 | if (info->attrs[NL80211_ATTR_KEY]) | |
695 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
696 | else | |
697 | err = nl80211_parse_key_old(info, k); | |
698 | ||
699 | if (err) | |
700 | return err; | |
701 | ||
702 | if (k->def && k->defmgmt) | |
703 | return -EINVAL; | |
704 | ||
dbd2fd65 JB |
705 | if (k->defmgmt) { |
706 | if (k->def_uni || !k->def_multi) | |
707 | return -EINVAL; | |
708 | } | |
709 | ||
b9454e83 JB |
710 | if (k->idx != -1) { |
711 | if (k->defmgmt) { | |
712 | if (k->idx < 4 || k->idx > 5) | |
713 | return -EINVAL; | |
714 | } else if (k->def) { | |
715 | if (k->idx < 0 || k->idx > 3) | |
716 | return -EINVAL; | |
717 | } else { | |
718 | if (k->idx < 0 || k->idx > 5) | |
719 | return -EINVAL; | |
720 | } | |
721 | } | |
722 | ||
723 | return 0; | |
724 | } | |
725 | ||
fffd0934 JB |
726 | static struct cfg80211_cached_keys * |
727 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 728 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
729 | { |
730 | struct key_parse parse; | |
731 | struct nlattr *key; | |
732 | struct cfg80211_cached_keys *result; | |
733 | int rem, err, def = 0; | |
734 | ||
735 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
736 | if (!result) | |
737 | return ERR_PTR(-ENOMEM); | |
738 | ||
739 | result->def = -1; | |
740 | result->defmgmt = -1; | |
741 | ||
742 | nla_for_each_nested(key, keys, rem) { | |
743 | memset(&parse, 0, sizeof(parse)); | |
744 | parse.idx = -1; | |
745 | ||
746 | err = nl80211_parse_key_new(key, &parse); | |
747 | if (err) | |
748 | goto error; | |
749 | err = -EINVAL; | |
750 | if (!parse.p.key) | |
751 | goto error; | |
752 | if (parse.idx < 0 || parse.idx > 4) | |
753 | goto error; | |
754 | if (parse.def) { | |
755 | if (def) | |
756 | goto error; | |
757 | def = 1; | |
758 | result->def = parse.idx; | |
dbd2fd65 JB |
759 | if (!parse.def_uni || !parse.def_multi) |
760 | goto error; | |
fffd0934 JB |
761 | } else if (parse.defmgmt) |
762 | goto error; | |
763 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 764 | parse.idx, false, NULL); |
fffd0934 JB |
765 | if (err) |
766 | goto error; | |
767 | result->params[parse.idx].cipher = parse.p.cipher; | |
768 | result->params[parse.idx].key_len = parse.p.key_len; | |
769 | result->params[parse.idx].key = result->data[parse.idx]; | |
770 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
771 | |
772 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
773 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
774 | if (no_ht) | |
775 | *no_ht = true; | |
776 | } | |
fffd0934 JB |
777 | } |
778 | ||
779 | return result; | |
780 | error: | |
781 | kfree(result); | |
782 | return ERR_PTR(err); | |
783 | } | |
784 | ||
785 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
786 | { | |
787 | ASSERT_WDEV_LOCK(wdev); | |
788 | ||
fffd0934 JB |
789 | switch (wdev->iftype) { |
790 | case NL80211_IFTYPE_AP: | |
791 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 792 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 793 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
794 | break; |
795 | case NL80211_IFTYPE_ADHOC: | |
796 | if (!wdev->current_bss) | |
797 | return -ENOLINK; | |
798 | break; | |
799 | case NL80211_IFTYPE_STATION: | |
074ac8df | 800 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
801 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
802 | return -ENOLINK; | |
803 | break; | |
804 | default: | |
805 | return -EINVAL; | |
806 | } | |
807 | ||
808 | return 0; | |
809 | } | |
810 | ||
7527a782 JB |
811 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
812 | { | |
813 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
814 | int i; | |
815 | ||
816 | if (!nl_modes) | |
817 | goto nla_put_failure; | |
818 | ||
819 | i = 0; | |
820 | while (ifmodes) { | |
9360ffd1 DM |
821 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
822 | goto nla_put_failure; | |
7527a782 JB |
823 | ifmodes >>= 1; |
824 | i++; | |
825 | } | |
826 | ||
827 | nla_nest_end(msg, nl_modes); | |
828 | return 0; | |
829 | ||
830 | nla_put_failure: | |
831 | return -ENOBUFS; | |
832 | } | |
833 | ||
834 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
835 | struct sk_buff *msg) | |
836 | { | |
837 | struct nlattr *nl_combis; | |
838 | int i, j; | |
839 | ||
840 | nl_combis = nla_nest_start(msg, | |
841 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
842 | if (!nl_combis) | |
843 | goto nla_put_failure; | |
844 | ||
845 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
846 | const struct ieee80211_iface_combination *c; | |
847 | struct nlattr *nl_combi, *nl_limits; | |
848 | ||
849 | c = &wiphy->iface_combinations[i]; | |
850 | ||
851 | nl_combi = nla_nest_start(msg, i + 1); | |
852 | if (!nl_combi) | |
853 | goto nla_put_failure; | |
854 | ||
855 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
856 | if (!nl_limits) | |
857 | goto nla_put_failure; | |
858 | ||
859 | for (j = 0; j < c->n_limits; j++) { | |
860 | struct nlattr *nl_limit; | |
861 | ||
862 | nl_limit = nla_nest_start(msg, j + 1); | |
863 | if (!nl_limit) | |
864 | goto nla_put_failure; | |
9360ffd1 DM |
865 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
866 | c->limits[j].max)) | |
867 | goto nla_put_failure; | |
7527a782 JB |
868 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
869 | c->limits[j].types)) | |
870 | goto nla_put_failure; | |
871 | nla_nest_end(msg, nl_limit); | |
872 | } | |
873 | ||
874 | nla_nest_end(msg, nl_limits); | |
875 | ||
9360ffd1 DM |
876 | if (c->beacon_int_infra_match && |
877 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
878 | goto nla_put_failure; | |
879 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
880 | c->num_different_channels) || | |
881 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
882 | c->max_interfaces)) | |
883 | goto nla_put_failure; | |
7527a782 JB |
884 | |
885 | nla_nest_end(msg, nl_combi); | |
886 | } | |
887 | ||
888 | nla_nest_end(msg, nl_combis); | |
889 | ||
890 | return 0; | |
891 | nla_put_failure: | |
892 | return -ENOBUFS; | |
893 | } | |
894 | ||
15e47304 | 895 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
55682965 JB |
896 | struct cfg80211_registered_device *dev) |
897 | { | |
898 | void *hdr; | |
ee688b00 JB |
899 | struct nlattr *nl_bands, *nl_band; |
900 | struct nlattr *nl_freqs, *nl_freq; | |
901 | struct nlattr *nl_rates, *nl_rate; | |
8fdc621d | 902 | struct nlattr *nl_cmds; |
ee688b00 JB |
903 | enum ieee80211_band band; |
904 | struct ieee80211_channel *chan; | |
905 | struct ieee80211_rate *rate; | |
906 | int i; | |
2e161f78 JB |
907 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
908 | dev->wiphy.mgmt_stypes; | |
55682965 | 909 | |
15e47304 | 910 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
55682965 JB |
911 | if (!hdr) |
912 | return -1; | |
913 | ||
9360ffd1 DM |
914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
915 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || | |
916 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
917 | cfg80211_rdev_list_generation) || | |
918 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
919 | dev->wiphy.retry_short) || | |
920 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
921 | dev->wiphy.retry_long) || | |
922 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
923 | dev->wiphy.frag_threshold) || | |
924 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
925 | dev->wiphy.rts_threshold) || | |
926 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
927 | dev->wiphy.coverage_class) || | |
928 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
929 | dev->wiphy.max_scan_ssids) || | |
930 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
931 | dev->wiphy.max_sched_scan_ssids) || | |
932 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
933 | dev->wiphy.max_scan_ie_len) || | |
934 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
935 | dev->wiphy.max_sched_scan_ie_len) || | |
936 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
937 | dev->wiphy.max_match_sets)) | |
938 | goto nla_put_failure; | |
939 | ||
940 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
941 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
942 | goto nla_put_failure; | |
943 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && | |
944 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
945 | goto nla_put_failure; | |
946 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
947 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
948 | goto nla_put_failure; | |
949 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
950 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
951 | goto nla_put_failure; | |
952 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
953 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
954 | goto nla_put_failure; | |
955 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
956 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
957 | goto nla_put_failure; | |
958 | ||
959 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
960 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
961 | dev->wiphy.cipher_suites)) | |
962 | goto nla_put_failure; | |
963 | ||
964 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, | |
965 | dev->wiphy.max_num_pmkids)) | |
966 | goto nla_put_failure; | |
967 | ||
968 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
969 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
970 | goto nla_put_failure; | |
971 | ||
972 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, | |
973 | dev->wiphy.available_antennas_tx) || | |
974 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
975 | dev->wiphy.available_antennas_rx)) | |
976 | goto nla_put_failure; | |
977 | ||
978 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && | |
979 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
980 | dev->wiphy.probe_resp_offload)) | |
981 | goto nla_put_failure; | |
87bbbe22 | 982 | |
7f531e03 BR |
983 | if ((dev->wiphy.available_antennas_tx || |
984 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { | |
afe0cbf8 BR |
985 | u32 tx_ant = 0, rx_ant = 0; |
986 | int res; | |
e35e4d28 | 987 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
afe0cbf8 | 988 | if (!res) { |
9360ffd1 DM |
989 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
990 | tx_ant) || | |
991 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, | |
992 | rx_ant)) | |
993 | goto nla_put_failure; | |
afe0cbf8 BR |
994 | } |
995 | } | |
996 | ||
7527a782 JB |
997 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
998 | dev->wiphy.interface_modes)) | |
f59ac048 LR |
999 | goto nla_put_failure; |
1000 | ||
ee688b00 JB |
1001 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
1002 | if (!nl_bands) | |
1003 | goto nla_put_failure; | |
1004 | ||
1005 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
1006 | if (!dev->wiphy.bands[band]) | |
1007 | continue; | |
1008 | ||
1009 | nl_band = nla_nest_start(msg, band); | |
1010 | if (!nl_band) | |
1011 | goto nla_put_failure; | |
1012 | ||
d51626df | 1013 | /* add HT info */ |
9360ffd1 DM |
1014 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
1015 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1016 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
1017 | &dev->wiphy.bands[band]->ht_cap.mcs) || | |
1018 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1019 | dev->wiphy.bands[band]->ht_cap.cap) || | |
1020 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1021 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || | |
1022 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1023 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) | |
1024 | goto nla_put_failure; | |
d51626df | 1025 | |
bf0c111e MP |
1026 | /* add VHT info */ |
1027 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && | |
1028 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1029 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), | |
1030 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || | |
1031 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1032 | dev->wiphy.bands[band]->vht_cap.cap))) | |
1033 | goto nla_put_failure; | |
1034 | ||
ee688b00 JB |
1035 | /* add frequencies */ |
1036 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
1037 | if (!nl_freqs) | |
1038 | goto nla_put_failure; | |
1039 | ||
1040 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
1041 | nl_freq = nla_nest_start(msg, i); | |
1042 | if (!nl_freq) | |
1043 | goto nla_put_failure; | |
1044 | ||
1045 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
1046 | |
1047 | if (nl80211_msg_put_channel(msg, chan)) | |
1048 | goto nla_put_failure; | |
e2f367f2 | 1049 | |
ee688b00 JB |
1050 | nla_nest_end(msg, nl_freq); |
1051 | } | |
1052 | ||
1053 | nla_nest_end(msg, nl_freqs); | |
1054 | ||
1055 | /* add bitrates */ | |
1056 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1057 | if (!nl_rates) | |
1058 | goto nla_put_failure; | |
1059 | ||
1060 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
1061 | nl_rate = nla_nest_start(msg, i); | |
1062 | if (!nl_rate) | |
1063 | goto nla_put_failure; | |
1064 | ||
1065 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
9360ffd1 DM |
1066 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
1067 | rate->bitrate)) | |
1068 | goto nla_put_failure; | |
1069 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1070 | nla_put_flag(msg, | |
1071 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1072 | goto nla_put_failure; | |
ee688b00 JB |
1073 | |
1074 | nla_nest_end(msg, nl_rate); | |
1075 | } | |
1076 | ||
1077 | nla_nest_end(msg, nl_rates); | |
1078 | ||
1079 | nla_nest_end(msg, nl_band); | |
1080 | } | |
1081 | nla_nest_end(msg, nl_bands); | |
1082 | ||
8fdc621d JB |
1083 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
1084 | if (!nl_cmds) | |
1085 | goto nla_put_failure; | |
1086 | ||
1087 | i = 0; | |
1088 | #define CMD(op, n) \ | |
1089 | do { \ | |
1090 | if (dev->ops->op) { \ | |
1091 | i++; \ | |
9360ffd1 DM |
1092 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
1093 | goto nla_put_failure; \ | |
8fdc621d JB |
1094 | } \ |
1095 | } while (0) | |
1096 | ||
1097 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1098 | CMD(change_virtual_intf, SET_INTERFACE); | |
1099 | CMD(add_key, NEW_KEY); | |
8860020e | 1100 | CMD(start_ap, START_AP); |
8fdc621d JB |
1101 | CMD(add_station, NEW_STATION); |
1102 | CMD(add_mpath, NEW_MPATH); | |
24bdd9f4 | 1103 | CMD(update_mesh_config, SET_MESH_CONFIG); |
8fdc621d | 1104 | CMD(change_bss, SET_BSS); |
636a5d36 JM |
1105 | CMD(auth, AUTHENTICATE); |
1106 | CMD(assoc, ASSOCIATE); | |
1107 | CMD(deauth, DEAUTHENTICATE); | |
1108 | CMD(disassoc, DISASSOCIATE); | |
04a773ad | 1109 | CMD(join_ibss, JOIN_IBSS); |
29cbe68c | 1110 | CMD(join_mesh, JOIN_MESH); |
67fbb16b SO |
1111 | CMD(set_pmksa, SET_PMKSA); |
1112 | CMD(del_pmksa, DEL_PMKSA); | |
1113 | CMD(flush_pmksa, FLUSH_PMKSA); | |
7c4ef712 JB |
1114 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
1115 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
13ae75b1 | 1116 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
2e161f78 | 1117 | CMD(mgmt_tx, FRAME); |
f7ca38df | 1118 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
5be83de5 | 1119 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
463d0183 | 1120 | i++; |
9360ffd1 DM |
1121 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
1122 | goto nla_put_failure; | |
463d0183 | 1123 | } |
e8c9bd5b | 1124 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
cc1d2806 | 1125 | dev->ops->join_mesh) { |
aa430da4 JB |
1126 | i++; |
1127 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1128 | goto nla_put_failure; | |
1129 | } | |
e8347eba | 1130 | CMD(set_wds_peer, SET_WDS_PEER); |
109086ce AN |
1131 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
1132 | CMD(tdls_mgmt, TDLS_MGMT); | |
1133 | CMD(tdls_oper, TDLS_OPER); | |
1134 | } | |
807f8a8c LC |
1135 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
1136 | CMD(sched_scan_start, START_SCHED_SCAN); | |
7f6cf311 | 1137 | CMD(probe_client, PROBE_CLIENT); |
1d9d9213 | 1138 | CMD(set_noack_map, SET_NOACK_MAP); |
5e760230 JB |
1139 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
1140 | i++; | |
9360ffd1 DM |
1141 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
1142 | goto nla_put_failure; | |
5e760230 | 1143 | } |
98104fde | 1144 | CMD(start_p2p_device, START_P2P_DEVICE); |
f4e583c8 | 1145 | CMD(set_mcast_rate, SET_MCAST_RATE); |
8fdc621d | 1146 | |
4745fc09 KV |
1147 | #ifdef CONFIG_NL80211_TESTMODE |
1148 | CMD(testmode_cmd, TESTMODE); | |
1149 | #endif | |
1150 | ||
8fdc621d | 1151 | #undef CMD |
b23aa676 | 1152 | |
6829c878 | 1153 | if (dev->ops->connect || dev->ops->auth) { |
b23aa676 | 1154 | i++; |
9360ffd1 DM |
1155 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
1156 | goto nla_put_failure; | |
b23aa676 SO |
1157 | } |
1158 | ||
6829c878 | 1159 | if (dev->ops->disconnect || dev->ops->deauth) { |
b23aa676 | 1160 | i++; |
9360ffd1 DM |
1161 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
1162 | goto nla_put_failure; | |
b23aa676 SO |
1163 | } |
1164 | ||
8fdc621d JB |
1165 | nla_nest_end(msg, nl_cmds); |
1166 | ||
7c4ef712 | 1167 | if (dev->ops->remain_on_channel && |
9360ffd1 DM |
1168 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
1169 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1170 | dev->wiphy.max_remain_on_channel_duration)) | |
1171 | goto nla_put_failure; | |
a293911d | 1172 | |
9360ffd1 DM |
1173 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
1174 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1175 | goto nla_put_failure; | |
f7ca38df | 1176 | |
2e161f78 JB |
1177 | if (mgmt_stypes) { |
1178 | u16 stypes; | |
1179 | struct nlattr *nl_ftypes, *nl_ifs; | |
1180 | enum nl80211_iftype ift; | |
1181 | ||
1182 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | |
1183 | if (!nl_ifs) | |
1184 | goto nla_put_failure; | |
1185 | ||
1186 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
1187 | nl_ftypes = nla_nest_start(msg, ift); | |
1188 | if (!nl_ftypes) | |
1189 | goto nla_put_failure; | |
1190 | i = 0; | |
1191 | stypes = mgmt_stypes[ift].tx; | |
1192 | while (stypes) { | |
9360ffd1 DM |
1193 | if ((stypes & 1) && |
1194 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1195 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1196 | goto nla_put_failure; | |
2e161f78 JB |
1197 | stypes >>= 1; |
1198 | i++; | |
1199 | } | |
1200 | nla_nest_end(msg, nl_ftypes); | |
1201 | } | |
1202 | ||
74b70a4e JB |
1203 | nla_nest_end(msg, nl_ifs); |
1204 | ||
2e161f78 JB |
1205 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1206 | if (!nl_ifs) | |
1207 | goto nla_put_failure; | |
1208 | ||
1209 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
1210 | nl_ftypes = nla_nest_start(msg, ift); | |
1211 | if (!nl_ftypes) | |
1212 | goto nla_put_failure; | |
1213 | i = 0; | |
1214 | stypes = mgmt_stypes[ift].rx; | |
1215 | while (stypes) { | |
9360ffd1 DM |
1216 | if ((stypes & 1) && |
1217 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1218 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1219 | goto nla_put_failure; | |
2e161f78 JB |
1220 | stypes >>= 1; |
1221 | i++; | |
1222 | } | |
1223 | nla_nest_end(msg, nl_ftypes); | |
1224 | } | |
1225 | nla_nest_end(msg, nl_ifs); | |
1226 | } | |
1227 | ||
dfb89c56 | 1228 | #ifdef CONFIG_PM |
ff1b6e69 JB |
1229 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
1230 | struct nlattr *nl_wowlan; | |
1231 | ||
1232 | nl_wowlan = nla_nest_start(msg, | |
1233 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | |
1234 | if (!nl_wowlan) | |
1235 | goto nla_put_failure; | |
1236 | ||
9360ffd1 DM |
1237 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
1238 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
1239 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
1240 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
1241 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
1242 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
1243 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
1244 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
1245 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
1246 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
1247 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
1248 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1249 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1250 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1251 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1252 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1253 | goto nla_put_failure; | |
ff1b6e69 JB |
1254 | if (dev->wiphy.wowlan.n_patterns) { |
1255 | struct nl80211_wowlan_pattern_support pat = { | |
1256 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1257 | .min_pattern_len = | |
1258 | dev->wiphy.wowlan.pattern_min_len, | |
1259 | .max_pattern_len = | |
1260 | dev->wiphy.wowlan.pattern_max_len, | |
bb92d199 AK |
1261 | .max_pkt_offset = |
1262 | dev->wiphy.wowlan.max_pkt_offset, | |
ff1b6e69 | 1263 | }; |
9360ffd1 DM |
1264 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1265 | sizeof(pat), &pat)) | |
1266 | goto nla_put_failure; | |
ff1b6e69 JB |
1267 | } |
1268 | ||
1269 | nla_nest_end(msg, nl_wowlan); | |
1270 | } | |
dfb89c56 | 1271 | #endif |
ff1b6e69 | 1272 | |
7527a782 JB |
1273 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
1274 | dev->wiphy.software_iftypes)) | |
1275 | goto nla_put_failure; | |
1276 | ||
1277 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) | |
1278 | goto nla_put_failure; | |
1279 | ||
9360ffd1 DM |
1280 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
1281 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1282 | dev->wiphy.ap_sme_capa)) | |
1283 | goto nla_put_failure; | |
562a7480 | 1284 | |
9360ffd1 DM |
1285 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
1286 | dev->wiphy.features)) | |
1287 | goto nla_put_failure; | |
1f074bd8 | 1288 | |
9360ffd1 DM |
1289 | if (dev->wiphy.ht_capa_mod_mask && |
1290 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1291 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1292 | dev->wiphy.ht_capa_mod_mask)) | |
1293 | goto nla_put_failure; | |
7e7c8926 | 1294 | |
77765eaf VT |
1295 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1296 | dev->wiphy.max_acl_mac_addrs && | |
1297 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1298 | dev->wiphy.max_acl_mac_addrs)) | |
1299 | goto nla_put_failure; | |
a50df0c4 | 1300 | |
55682965 JB |
1301 | return genlmsg_end(msg, hdr); |
1302 | ||
1303 | nla_put_failure: | |
bc3ed28c TG |
1304 | genlmsg_cancel(msg, hdr); |
1305 | return -EMSGSIZE; | |
55682965 JB |
1306 | } |
1307 | ||
1308 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1309 | { | |
1310 | int idx = 0; | |
1311 | int start = cb->args[0]; | |
1312 | struct cfg80211_registered_device *dev; | |
1313 | ||
a1794390 | 1314 | mutex_lock(&cfg80211_mutex); |
79c97e97 | 1315 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1316 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1317 | continue; | |
b4637271 | 1318 | if (++idx <= start) |
55682965 | 1319 | continue; |
15e47304 | 1320 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 1321 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
b4637271 JV |
1322 | dev) < 0) { |
1323 | idx--; | |
55682965 | 1324 | break; |
b4637271 | 1325 | } |
55682965 | 1326 | } |
a1794390 | 1327 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1328 | |
1329 | cb->args[0] = idx; | |
1330 | ||
1331 | return skb->len; | |
1332 | } | |
1333 | ||
1334 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1335 | { | |
1336 | struct sk_buff *msg; | |
4c476991 | 1337 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1338 | |
fd2120ca | 1339 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1340 | if (!msg) |
4c476991 | 1341 | return -ENOMEM; |
55682965 | 1342 | |
15e47304 | 1343 | if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) { |
4c476991 JB |
1344 | nlmsg_free(msg); |
1345 | return -ENOBUFS; | |
1346 | } | |
55682965 | 1347 | |
134e6375 | 1348 | return genlmsg_reply(msg, info); |
55682965 JB |
1349 | } |
1350 | ||
31888487 JM |
1351 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1352 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1353 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1354 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1355 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1356 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1357 | }; | |
1358 | ||
1359 | static int parse_txq_params(struct nlattr *tb[], | |
1360 | struct ieee80211_txq_params *txq_params) | |
1361 | { | |
a3304b0a | 1362 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1363 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1364 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1365 | return -EINVAL; | |
1366 | ||
a3304b0a | 1367 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1368 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1369 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1370 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1371 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1372 | ||
a3304b0a JB |
1373 | if (txq_params->ac >= NL80211_NUM_ACS) |
1374 | return -EINVAL; | |
1375 | ||
31888487 JM |
1376 | return 0; |
1377 | } | |
1378 | ||
f444de05 JB |
1379 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1380 | { | |
1381 | /* | |
cc1d2806 JB |
1382 | * You can only set the channel explicitly for WDS interfaces, |
1383 | * all others have their channel managed via their respective | |
1384 | * "establish a connection" command (connect, join, ...) | |
1385 | * | |
1386 | * For AP/GO and mesh mode, the channel can be set with the | |
1387 | * channel userspace API, but is only stored and passed to the | |
1388 | * low-level driver when the AP starts or the mesh is joined. | |
1389 | * This is for backward compatibility, userspace can also give | |
1390 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1391 | * |
1392 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1393 | * whatever else is going on, so they have their own special |
1394 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1395 | */ |
1396 | return !wdev || | |
1397 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1398 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1399 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1400 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1401 | } |
1402 | ||
683b6d3b JB |
1403 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1404 | struct genl_info *info, | |
1405 | struct cfg80211_chan_def *chandef) | |
1406 | { | |
dbeca2ea | 1407 | u32 control_freq; |
683b6d3b JB |
1408 | |
1409 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1410 | return -EINVAL; | |
1411 | ||
1412 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1413 | ||
1414 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1415 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1416 | chandef->center_freq1 = control_freq; | |
1417 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1418 | |
1419 | /* Primary channel not allowed */ | |
1420 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1421 | return -EINVAL; | |
1422 | ||
3d9d1d66 JB |
1423 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1424 | enum nl80211_channel_type chantype; | |
1425 | ||
1426 | chantype = nla_get_u32( | |
1427 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1428 | ||
1429 | switch (chantype) { | |
1430 | case NL80211_CHAN_NO_HT: | |
1431 | case NL80211_CHAN_HT20: | |
1432 | case NL80211_CHAN_HT40PLUS: | |
1433 | case NL80211_CHAN_HT40MINUS: | |
1434 | cfg80211_chandef_create(chandef, chandef->chan, | |
1435 | chantype); | |
1436 | break; | |
1437 | default: | |
1438 | return -EINVAL; | |
1439 | } | |
1440 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1441 | chandef->width = | |
1442 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1443 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1444 | chandef->center_freq1 = | |
1445 | nla_get_u32( | |
1446 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1447 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1448 | chandef->center_freq2 = | |
1449 | nla_get_u32( | |
1450 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1451 | } | |
1452 | ||
9f5e8f6e | 1453 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1454 | return -EINVAL; |
1455 | ||
9f5e8f6e JB |
1456 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1457 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1458 | return -EINVAL; |
1459 | ||
683b6d3b JB |
1460 | return 0; |
1461 | } | |
1462 | ||
f444de05 JB |
1463 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1464 | struct wireless_dev *wdev, | |
1465 | struct genl_info *info) | |
1466 | { | |
683b6d3b | 1467 | struct cfg80211_chan_def chandef; |
f444de05 | 1468 | int result; |
e8c9bd5b JB |
1469 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1470 | ||
1471 | if (wdev) | |
1472 | iftype = wdev->iftype; | |
f444de05 | 1473 | |
f444de05 JB |
1474 | if (!nl80211_can_set_dev_channel(wdev)) |
1475 | return -EOPNOTSUPP; | |
1476 | ||
683b6d3b JB |
1477 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1478 | if (result) | |
1479 | return result; | |
f444de05 JB |
1480 | |
1481 | mutex_lock(&rdev->devlist_mtx); | |
e8c9bd5b | 1482 | switch (iftype) { |
aa430da4 JB |
1483 | case NL80211_IFTYPE_AP: |
1484 | case NL80211_IFTYPE_P2P_GO: | |
1485 | if (wdev->beacon_interval) { | |
1486 | result = -EBUSY; | |
1487 | break; | |
1488 | } | |
683b6d3b | 1489 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1490 | result = -EINVAL; |
1491 | break; | |
1492 | } | |
683b6d3b | 1493 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1494 | result = 0; |
1495 | break; | |
cc1d2806 | 1496 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1497 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1498 | break; |
e8c9bd5b | 1499 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1500 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1501 | break; |
aa430da4 | 1502 | default: |
e8c9bd5b | 1503 | result = -EINVAL; |
f444de05 JB |
1504 | } |
1505 | mutex_unlock(&rdev->devlist_mtx); | |
1506 | ||
1507 | return result; | |
1508 | } | |
1509 | ||
1510 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1511 | { | |
4c476991 JB |
1512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1513 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1514 | |
4c476991 | 1515 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1516 | } |
1517 | ||
e8347eba BJ |
1518 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1519 | { | |
43b19952 JB |
1520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1521 | struct net_device *dev = info->user_ptr[1]; | |
1522 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1523 | const u8 *bssid; |
e8347eba BJ |
1524 | |
1525 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1526 | return -EINVAL; | |
1527 | ||
43b19952 JB |
1528 | if (netif_running(dev)) |
1529 | return -EBUSY; | |
e8347eba | 1530 | |
43b19952 JB |
1531 | if (!rdev->ops->set_wds_peer) |
1532 | return -EOPNOTSUPP; | |
e8347eba | 1533 | |
43b19952 JB |
1534 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1535 | return -EOPNOTSUPP; | |
e8347eba BJ |
1536 | |
1537 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1538 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1539 | } |
1540 | ||
1541 | ||
55682965 JB |
1542 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1543 | { | |
1544 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1545 | struct net_device *netdev = NULL; |
1546 | struct wireless_dev *wdev; | |
a1e567c8 | 1547 | int result = 0, rem_txq_params = 0; |
31888487 | 1548 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1549 | u32 changed; |
1550 | u8 retry_short = 0, retry_long = 0; | |
1551 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1552 | u8 coverage_class = 0; |
55682965 | 1553 | |
f444de05 JB |
1554 | /* |
1555 | * Try to find the wiphy and netdev. Normally this | |
1556 | * function shouldn't need the netdev, but this is | |
1557 | * done for backward compatibility -- previously | |
1558 | * setting the channel was done per wiphy, but now | |
1559 | * it is per netdev. Previous userland like hostapd | |
1560 | * also passed a netdev to set_wiphy, so that it is | |
1561 | * possible to let that go to the right netdev! | |
1562 | */ | |
4bbf4d56 JB |
1563 | mutex_lock(&cfg80211_mutex); |
1564 | ||
f444de05 JB |
1565 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1566 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1567 | ||
1568 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1569 | if (netdev && netdev->ieee80211_ptr) { | |
1570 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1571 | mutex_lock(&rdev->mtx); | |
1572 | } else | |
1573 | netdev = NULL; | |
4bbf4d56 JB |
1574 | } |
1575 | ||
f444de05 | 1576 | if (!netdev) { |
878d9ec7 JB |
1577 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1578 | info->attrs); | |
f444de05 JB |
1579 | if (IS_ERR(rdev)) { |
1580 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1581 | return PTR_ERR(rdev); |
f444de05 JB |
1582 | } |
1583 | wdev = NULL; | |
1584 | netdev = NULL; | |
1585 | result = 0; | |
1586 | ||
1587 | mutex_lock(&rdev->mtx); | |
71fe96bf | 1588 | } else |
f444de05 | 1589 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1590 | |
1591 | /* | |
1592 | * end workaround code, by now the rdev is available | |
1593 | * and locked, and wdev may or may not be NULL. | |
1594 | */ | |
4bbf4d56 JB |
1595 | |
1596 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1597 | result = cfg80211_dev_rename( |
1598 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1599 | |
1600 | mutex_unlock(&cfg80211_mutex); | |
1601 | ||
1602 | if (result) | |
1603 | goto bad_res; | |
31888487 JM |
1604 | |
1605 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1606 | struct ieee80211_txq_params txq_params; | |
1607 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1608 | ||
1609 | if (!rdev->ops->set_txq_params) { | |
1610 | result = -EOPNOTSUPP; | |
1611 | goto bad_res; | |
1612 | } | |
1613 | ||
f70f01c2 EP |
1614 | if (!netdev) { |
1615 | result = -EINVAL; | |
1616 | goto bad_res; | |
1617 | } | |
1618 | ||
133a3ff2 JB |
1619 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1620 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1621 | result = -EINVAL; | |
1622 | goto bad_res; | |
1623 | } | |
1624 | ||
2b5f8b0b JB |
1625 | if (!netif_running(netdev)) { |
1626 | result = -ENETDOWN; | |
1627 | goto bad_res; | |
1628 | } | |
1629 | ||
31888487 JM |
1630 | nla_for_each_nested(nl_txq_params, |
1631 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1632 | rem_txq_params) { | |
1633 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1634 | nla_data(nl_txq_params), | |
1635 | nla_len(nl_txq_params), | |
1636 | txq_params_policy); | |
1637 | result = parse_txq_params(tb, &txq_params); | |
1638 | if (result) | |
1639 | goto bad_res; | |
1640 | ||
e35e4d28 HG |
1641 | result = rdev_set_txq_params(rdev, netdev, |
1642 | &txq_params); | |
31888487 JM |
1643 | if (result) |
1644 | goto bad_res; | |
1645 | } | |
1646 | } | |
55682965 | 1647 | |
72bdcf34 | 1648 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1649 | result = __nl80211_set_channel(rdev, |
1650 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1651 | info); | |
72bdcf34 JM |
1652 | if (result) |
1653 | goto bad_res; | |
1654 | } | |
1655 | ||
98d2ff8b | 1656 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1657 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1658 | enum nl80211_tx_power_setting type; |
1659 | int idx, mbm = 0; | |
1660 | ||
c8442118 JB |
1661 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
1662 | txp_wdev = NULL; | |
1663 | ||
98d2ff8b | 1664 | if (!rdev->ops->set_tx_power) { |
60ea385f | 1665 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1666 | goto bad_res; |
1667 | } | |
1668 | ||
1669 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1670 | type = nla_get_u32(info->attrs[idx]); | |
1671 | ||
1672 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1673 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1674 | result = -EINVAL; | |
1675 | goto bad_res; | |
1676 | } | |
1677 | ||
1678 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1679 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1680 | mbm = nla_get_u32(info->attrs[idx]); | |
1681 | } | |
1682 | ||
c8442118 | 1683 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
1684 | if (result) |
1685 | goto bad_res; | |
1686 | } | |
1687 | ||
afe0cbf8 BR |
1688 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1689 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1690 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1691 | if ((!rdev->wiphy.available_antennas_tx && |
1692 | !rdev->wiphy.available_antennas_rx) || | |
1693 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1694 | result = -EOPNOTSUPP; |
1695 | goto bad_res; | |
1696 | } | |
1697 | ||
1698 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1699 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
1700 | ||
a7ffac95 | 1701 | /* reject antenna configurations which don't match the |
7f531e03 BR |
1702 | * available antenna masks, except for the "all" mask */ |
1703 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
1704 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
1705 | result = -EINVAL; |
1706 | goto bad_res; | |
1707 | } | |
1708 | ||
7f531e03 BR |
1709 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
1710 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 1711 | |
e35e4d28 | 1712 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
1713 | if (result) |
1714 | goto bad_res; | |
1715 | } | |
1716 | ||
b9a5f8ca JM |
1717 | changed = 0; |
1718 | ||
1719 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
1720 | retry_short = nla_get_u8( | |
1721 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
1722 | if (retry_short == 0) { | |
1723 | result = -EINVAL; | |
1724 | goto bad_res; | |
1725 | } | |
1726 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
1727 | } | |
1728 | ||
1729 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
1730 | retry_long = nla_get_u8( | |
1731 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
1732 | if (retry_long == 0) { | |
1733 | result = -EINVAL; | |
1734 | goto bad_res; | |
1735 | } | |
1736 | changed |= WIPHY_PARAM_RETRY_LONG; | |
1737 | } | |
1738 | ||
1739 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
1740 | frag_threshold = nla_get_u32( | |
1741 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
1742 | if (frag_threshold < 256) { | |
1743 | result = -EINVAL; | |
1744 | goto bad_res; | |
1745 | } | |
1746 | if (frag_threshold != (u32) -1) { | |
1747 | /* | |
1748 | * Fragments (apart from the last one) are required to | |
1749 | * have even length. Make the fragmentation code | |
1750 | * simpler by stripping LSB should someone try to use | |
1751 | * odd threshold value. | |
1752 | */ | |
1753 | frag_threshold &= ~0x1; | |
1754 | } | |
1755 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
1756 | } | |
1757 | ||
1758 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
1759 | rts_threshold = nla_get_u32( | |
1760 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
1761 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
1762 | } | |
1763 | ||
81077e82 LT |
1764 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
1765 | coverage_class = nla_get_u8( | |
1766 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
1767 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
1768 | } | |
1769 | ||
b9a5f8ca JM |
1770 | if (changed) { |
1771 | u8 old_retry_short, old_retry_long; | |
1772 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 1773 | u8 old_coverage_class; |
b9a5f8ca JM |
1774 | |
1775 | if (!rdev->ops->set_wiphy_params) { | |
1776 | result = -EOPNOTSUPP; | |
1777 | goto bad_res; | |
1778 | } | |
1779 | ||
1780 | old_retry_short = rdev->wiphy.retry_short; | |
1781 | old_retry_long = rdev->wiphy.retry_long; | |
1782 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
1783 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 1784 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
1785 | |
1786 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1787 | rdev->wiphy.retry_short = retry_short; | |
1788 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1789 | rdev->wiphy.retry_long = retry_long; | |
1790 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
1791 | rdev->wiphy.frag_threshold = frag_threshold; | |
1792 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
1793 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
1794 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
1795 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 1796 | |
e35e4d28 | 1797 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
1798 | if (result) { |
1799 | rdev->wiphy.retry_short = old_retry_short; | |
1800 | rdev->wiphy.retry_long = old_retry_long; | |
1801 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
1802 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 1803 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
1804 | } |
1805 | } | |
72bdcf34 | 1806 | |
306d6112 | 1807 | bad_res: |
4bbf4d56 | 1808 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
1809 | if (netdev) |
1810 | dev_put(netdev); | |
55682965 JB |
1811 | return result; |
1812 | } | |
1813 | ||
71bbc994 JB |
1814 | static inline u64 wdev_id(struct wireless_dev *wdev) |
1815 | { | |
1816 | return (u64)wdev->identifier | | |
1817 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
1818 | } | |
55682965 | 1819 | |
683b6d3b JB |
1820 | static int nl80211_send_chandef(struct sk_buff *msg, |
1821 | struct cfg80211_chan_def *chandef) | |
1822 | { | |
9f5e8f6e | 1823 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 1824 | |
683b6d3b JB |
1825 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
1826 | chandef->chan->center_freq)) | |
1827 | return -ENOBUFS; | |
3d9d1d66 JB |
1828 | switch (chandef->width) { |
1829 | case NL80211_CHAN_WIDTH_20_NOHT: | |
1830 | case NL80211_CHAN_WIDTH_20: | |
1831 | case NL80211_CHAN_WIDTH_40: | |
1832 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
1833 | cfg80211_get_chandef_type(chandef))) | |
1834 | return -ENOBUFS; | |
1835 | break; | |
1836 | default: | |
1837 | break; | |
1838 | } | |
1839 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
1840 | return -ENOBUFS; | |
1841 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
1842 | return -ENOBUFS; | |
1843 | if (chandef->center_freq2 && | |
1844 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
1845 | return -ENOBUFS; |
1846 | return 0; | |
1847 | } | |
1848 | ||
15e47304 | 1849 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 1850 | struct cfg80211_registered_device *rdev, |
72fb2abc | 1851 | struct wireless_dev *wdev) |
55682965 | 1852 | { |
72fb2abc | 1853 | struct net_device *dev = wdev->netdev; |
55682965 JB |
1854 | void *hdr; |
1855 | ||
15e47304 | 1856 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
1857 | if (!hdr) |
1858 | return -1; | |
1859 | ||
72fb2abc JB |
1860 | if (dev && |
1861 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 1862 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
1863 | goto nla_put_failure; |
1864 | ||
1865 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
1866 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 1867 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 1868 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
1869 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1870 | rdev->devlist_generation ^ | |
1871 | (cfg80211_rdev_list_generation << 2))) | |
1872 | goto nla_put_failure; | |
f5ea9120 | 1873 | |
5b7ccaf3 | 1874 | if (rdev->ops->get_channel) { |
683b6d3b JB |
1875 | int ret; |
1876 | struct cfg80211_chan_def chandef; | |
1877 | ||
1878 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
1879 | if (ret == 0) { | |
1880 | if (nl80211_send_chandef(msg, &chandef)) | |
1881 | goto nla_put_failure; | |
1882 | } | |
d91df0e3 PF |
1883 | } |
1884 | ||
b84e7a05 AQ |
1885 | if (wdev->ssid_len) { |
1886 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
1887 | goto nla_put_failure; | |
1888 | } | |
1889 | ||
55682965 JB |
1890 | return genlmsg_end(msg, hdr); |
1891 | ||
1892 | nla_put_failure: | |
bc3ed28c TG |
1893 | genlmsg_cancel(msg, hdr); |
1894 | return -EMSGSIZE; | |
55682965 JB |
1895 | } |
1896 | ||
1897 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
1898 | { | |
1899 | int wp_idx = 0; | |
1900 | int if_idx = 0; | |
1901 | int wp_start = cb->args[0]; | |
1902 | int if_start = cb->args[1]; | |
f5ea9120 | 1903 | struct cfg80211_registered_device *rdev; |
55682965 JB |
1904 | struct wireless_dev *wdev; |
1905 | ||
a1794390 | 1906 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
1907 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1908 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1909 | continue; |
bba95fef JB |
1910 | if (wp_idx < wp_start) { |
1911 | wp_idx++; | |
55682965 | 1912 | continue; |
bba95fef | 1913 | } |
55682965 JB |
1914 | if_idx = 0; |
1915 | ||
f5ea9120 | 1916 | mutex_lock(&rdev->devlist_mtx); |
89a54e48 | 1917 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
1918 | if (if_idx < if_start) { |
1919 | if_idx++; | |
55682965 | 1920 | continue; |
bba95fef | 1921 | } |
15e47304 | 1922 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 1923 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 1924 | rdev, wdev) < 0) { |
f5ea9120 | 1925 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
1926 | goto out; |
1927 | } | |
1928 | if_idx++; | |
55682965 | 1929 | } |
f5ea9120 | 1930 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
1931 | |
1932 | wp_idx++; | |
55682965 | 1933 | } |
bba95fef | 1934 | out: |
a1794390 | 1935 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1936 | |
1937 | cb->args[0] = wp_idx; | |
1938 | cb->args[1] = if_idx; | |
1939 | ||
1940 | return skb->len; | |
1941 | } | |
1942 | ||
1943 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
1944 | { | |
1945 | struct sk_buff *msg; | |
4c476991 | 1946 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 1947 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 1948 | |
fd2120ca | 1949 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1950 | if (!msg) |
4c476991 | 1951 | return -ENOMEM; |
55682965 | 1952 | |
15e47304 | 1953 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 1954 | dev, wdev) < 0) { |
4c476991 JB |
1955 | nlmsg_free(msg); |
1956 | return -ENOBUFS; | |
1957 | } | |
55682965 | 1958 | |
134e6375 | 1959 | return genlmsg_reply(msg, info); |
55682965 JB |
1960 | } |
1961 | ||
66f7ac50 MW |
1962 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
1963 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
1964 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
1965 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
1966 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
1967 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
1968 | }; | |
1969 | ||
1970 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
1971 | { | |
1972 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
1973 | int flag; | |
1974 | ||
1975 | *mntrflags = 0; | |
1976 | ||
1977 | if (!nla) | |
1978 | return -EINVAL; | |
1979 | ||
1980 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
1981 | nla, mntr_flags_policy)) | |
1982 | return -EINVAL; | |
1983 | ||
1984 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
1985 | if (flags[flag]) | |
1986 | *mntrflags |= (1<<flag); | |
1987 | ||
1988 | return 0; | |
1989 | } | |
1990 | ||
9bc383de | 1991 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
1992 | struct net_device *netdev, u8 use_4addr, |
1993 | enum nl80211_iftype iftype) | |
9bc383de | 1994 | { |
ad4bb6f8 | 1995 | if (!use_4addr) { |
f350a0a8 | 1996 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 1997 | return -EBUSY; |
9bc383de | 1998 | return 0; |
ad4bb6f8 | 1999 | } |
9bc383de JB |
2000 | |
2001 | switch (iftype) { | |
2002 | case NL80211_IFTYPE_AP_VLAN: | |
2003 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2004 | return 0; | |
2005 | break; | |
2006 | case NL80211_IFTYPE_STATION: | |
2007 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2008 | return 0; | |
2009 | break; | |
2010 | default: | |
2011 | break; | |
2012 | } | |
2013 | ||
2014 | return -EOPNOTSUPP; | |
2015 | } | |
2016 | ||
55682965 JB |
2017 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2018 | { | |
4c476991 | 2019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2020 | struct vif_params params; |
e36d56b6 | 2021 | int err; |
04a773ad | 2022 | enum nl80211_iftype otype, ntype; |
4c476991 | 2023 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2024 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2025 | bool change = false; |
55682965 | 2026 | |
2ec600d6 LCC |
2027 | memset(¶ms, 0, sizeof(params)); |
2028 | ||
04a773ad | 2029 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2030 | |
723b038d | 2031 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2032 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2033 | if (otype != ntype) |
ac7f9cfa | 2034 | change = true; |
4c476991 JB |
2035 | if (ntype > NL80211_IFTYPE_MAX) |
2036 | return -EINVAL; | |
723b038d JB |
2037 | } |
2038 | ||
92ffe055 | 2039 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2040 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2041 | ||
4c476991 JB |
2042 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2043 | return -EINVAL; | |
29cbe68c JB |
2044 | if (netif_running(dev)) |
2045 | return -EBUSY; | |
2046 | ||
2047 | wdev_lock(wdev); | |
2048 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2049 | IEEE80211_MAX_MESH_ID_LEN); | |
2050 | wdev->mesh_id_up_len = | |
2051 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2052 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2053 | wdev->mesh_id_up_len); | |
2054 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2055 | } |
2056 | ||
8b787643 FF |
2057 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2058 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2059 | change = true; | |
ad4bb6f8 | 2060 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2061 | if (err) |
4c476991 | 2062 | return err; |
8b787643 FF |
2063 | } else { |
2064 | params.use_4addr = -1; | |
2065 | } | |
2066 | ||
92ffe055 | 2067 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2068 | if (ntype != NL80211_IFTYPE_MONITOR) |
2069 | return -EINVAL; | |
92ffe055 JB |
2070 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2071 | &_flags); | |
ac7f9cfa | 2072 | if (err) |
4c476991 | 2073 | return err; |
ac7f9cfa JB |
2074 | |
2075 | flags = &_flags; | |
2076 | change = true; | |
92ffe055 | 2077 | } |
3b85875a | 2078 | |
ac7f9cfa | 2079 | if (change) |
3d54d255 | 2080 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2081 | else |
2082 | err = 0; | |
60719ffd | 2083 | |
9bc383de JB |
2084 | if (!err && params.use_4addr != -1) |
2085 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2086 | ||
55682965 JB |
2087 | return err; |
2088 | } | |
2089 | ||
2090 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2091 | { | |
4c476991 | 2092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2093 | struct vif_params params; |
84efbb84 | 2094 | struct wireless_dev *wdev; |
1c90f9d4 | 2095 | struct sk_buff *msg; |
55682965 JB |
2096 | int err; |
2097 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2098 | u32 flags; |
55682965 | 2099 | |
2ec600d6 LCC |
2100 | memset(¶ms, 0, sizeof(params)); |
2101 | ||
55682965 JB |
2102 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2103 | return -EINVAL; | |
2104 | ||
2105 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2106 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2107 | if (type > NL80211_IFTYPE_MAX) | |
2108 | return -EINVAL; | |
2109 | } | |
2110 | ||
79c97e97 | 2111 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2112 | !(rdev->wiphy.interface_modes & (1 << type))) |
2113 | return -EOPNOTSUPP; | |
55682965 | 2114 | |
1c18f145 AS |
2115 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2116 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2117 | ETH_ALEN); | |
2118 | if (!is_valid_ether_addr(params.macaddr)) | |
2119 | return -EADDRNOTAVAIL; | |
2120 | } | |
2121 | ||
9bc383de | 2122 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2123 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2124 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2125 | if (err) |
4c476991 | 2126 | return err; |
9bc383de | 2127 | } |
8b787643 | 2128 | |
1c90f9d4 JB |
2129 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2130 | if (!msg) | |
2131 | return -ENOMEM; | |
2132 | ||
66f7ac50 MW |
2133 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2134 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2135 | &flags); | |
e35e4d28 HG |
2136 | wdev = rdev_add_virtual_intf(rdev, |
2137 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2138 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2139 | if (IS_ERR(wdev)) { |
2140 | nlmsg_free(msg); | |
84efbb84 | 2141 | return PTR_ERR(wdev); |
1c90f9d4 | 2142 | } |
2ec600d6 | 2143 | |
98104fde JB |
2144 | switch (type) { |
2145 | case NL80211_IFTYPE_MESH_POINT: | |
2146 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2147 | break; | |
29cbe68c JB |
2148 | wdev_lock(wdev); |
2149 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2150 | IEEE80211_MAX_MESH_ID_LEN); | |
2151 | wdev->mesh_id_up_len = | |
2152 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2153 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2154 | wdev->mesh_id_up_len); | |
2155 | wdev_unlock(wdev); | |
98104fde JB |
2156 | break; |
2157 | case NL80211_IFTYPE_P2P_DEVICE: | |
2158 | /* | |
2159 | * P2P Device doesn't have a netdev, so doesn't go | |
2160 | * through the netdev notifier and must be added here | |
2161 | */ | |
2162 | mutex_init(&wdev->mtx); | |
2163 | INIT_LIST_HEAD(&wdev->event_list); | |
2164 | spin_lock_init(&wdev->event_lock); | |
2165 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2166 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2167 | ||
2168 | mutex_lock(&rdev->devlist_mtx); | |
2169 | wdev->identifier = ++rdev->wdev_id; | |
2170 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2171 | rdev->devlist_generation++; | |
2172 | mutex_unlock(&rdev->devlist_mtx); | |
2173 | break; | |
2174 | default: | |
2175 | break; | |
29cbe68c JB |
2176 | } |
2177 | ||
15e47304 | 2178 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2179 | rdev, wdev) < 0) { |
2180 | nlmsg_free(msg); | |
2181 | return -ENOBUFS; | |
2182 | } | |
2183 | ||
2184 | return genlmsg_reply(msg, info); | |
55682965 JB |
2185 | } |
2186 | ||
2187 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2188 | { | |
4c476991 | 2189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2190 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2191 | |
4c476991 JB |
2192 | if (!rdev->ops->del_virtual_intf) |
2193 | return -EOPNOTSUPP; | |
55682965 | 2194 | |
84efbb84 JB |
2195 | /* |
2196 | * If we remove a wireless device without a netdev then clear | |
2197 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2198 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2199 | * since the wdev has been freed, unlike with a netdev where | |
2200 | * we need the dev_put() for the netdev to really be freed. | |
2201 | */ | |
2202 | if (!wdev->netdev) | |
2203 | info->user_ptr[1] = NULL; | |
2204 | ||
e35e4d28 | 2205 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2206 | } |
2207 | ||
1d9d9213 SW |
2208 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2209 | { | |
2210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2211 | struct net_device *dev = info->user_ptr[1]; | |
2212 | u16 noack_map; | |
2213 | ||
2214 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2215 | return -EINVAL; | |
2216 | ||
2217 | if (!rdev->ops->set_noack_map) | |
2218 | return -EOPNOTSUPP; | |
2219 | ||
2220 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2221 | ||
e35e4d28 | 2222 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2223 | } |
2224 | ||
41ade00f JB |
2225 | struct get_key_cookie { |
2226 | struct sk_buff *msg; | |
2227 | int error; | |
b9454e83 | 2228 | int idx; |
41ade00f JB |
2229 | }; |
2230 | ||
2231 | static void get_key_callback(void *c, struct key_params *params) | |
2232 | { | |
b9454e83 | 2233 | struct nlattr *key; |
41ade00f JB |
2234 | struct get_key_cookie *cookie = c; |
2235 | ||
9360ffd1 DM |
2236 | if ((params->key && |
2237 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2238 | params->key_len, params->key)) || | |
2239 | (params->seq && | |
2240 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2241 | params->seq_len, params->seq)) || | |
2242 | (params->cipher && | |
2243 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2244 | params->cipher))) | |
2245 | goto nla_put_failure; | |
41ade00f | 2246 | |
b9454e83 JB |
2247 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2248 | if (!key) | |
2249 | goto nla_put_failure; | |
2250 | ||
9360ffd1 DM |
2251 | if ((params->key && |
2252 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2253 | params->key_len, params->key)) || | |
2254 | (params->seq && | |
2255 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2256 | params->seq_len, params->seq)) || | |
2257 | (params->cipher && | |
2258 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2259 | params->cipher))) | |
2260 | goto nla_put_failure; | |
b9454e83 | 2261 | |
9360ffd1 DM |
2262 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2263 | goto nla_put_failure; | |
b9454e83 JB |
2264 | |
2265 | nla_nest_end(cookie->msg, key); | |
2266 | ||
41ade00f JB |
2267 | return; |
2268 | nla_put_failure: | |
2269 | cookie->error = 1; | |
2270 | } | |
2271 | ||
2272 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2273 | { | |
4c476991 | 2274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2275 | int err; |
4c476991 | 2276 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2277 | u8 key_idx = 0; |
e31b8213 JB |
2278 | const u8 *mac_addr = NULL; |
2279 | bool pairwise; | |
41ade00f JB |
2280 | struct get_key_cookie cookie = { |
2281 | .error = 0, | |
2282 | }; | |
2283 | void *hdr; | |
2284 | struct sk_buff *msg; | |
2285 | ||
2286 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2287 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2288 | ||
3cfcf6ac | 2289 | if (key_idx > 5) |
41ade00f JB |
2290 | return -EINVAL; |
2291 | ||
2292 | if (info->attrs[NL80211_ATTR_MAC]) | |
2293 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2294 | ||
e31b8213 JB |
2295 | pairwise = !!mac_addr; |
2296 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2297 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2298 | if (kt >= NUM_NL80211_KEYTYPES) | |
2299 | return -EINVAL; | |
2300 | if (kt != NL80211_KEYTYPE_GROUP && | |
2301 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2302 | return -EINVAL; | |
2303 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2304 | } | |
2305 | ||
4c476991 JB |
2306 | if (!rdev->ops->get_key) |
2307 | return -EOPNOTSUPP; | |
41ade00f | 2308 | |
fd2120ca | 2309 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2310 | if (!msg) |
2311 | return -ENOMEM; | |
41ade00f | 2312 | |
15e47304 | 2313 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2314 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2315 | if (IS_ERR(hdr)) |
2316 | return PTR_ERR(hdr); | |
41ade00f JB |
2317 | |
2318 | cookie.msg = msg; | |
b9454e83 | 2319 | cookie.idx = key_idx; |
41ade00f | 2320 | |
9360ffd1 DM |
2321 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2322 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2323 | goto nla_put_failure; | |
2324 | if (mac_addr && | |
2325 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2326 | goto nla_put_failure; | |
41ade00f | 2327 | |
e31b8213 JB |
2328 | if (pairwise && mac_addr && |
2329 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2330 | return -ENOENT; | |
2331 | ||
e35e4d28 HG |
2332 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2333 | get_key_callback); | |
41ade00f JB |
2334 | |
2335 | if (err) | |
6c95e2a2 | 2336 | goto free_msg; |
41ade00f JB |
2337 | |
2338 | if (cookie.error) | |
2339 | goto nla_put_failure; | |
2340 | ||
2341 | genlmsg_end(msg, hdr); | |
4c476991 | 2342 | return genlmsg_reply(msg, info); |
41ade00f JB |
2343 | |
2344 | nla_put_failure: | |
2345 | err = -ENOBUFS; | |
6c95e2a2 | 2346 | free_msg: |
41ade00f | 2347 | nlmsg_free(msg); |
41ade00f JB |
2348 | return err; |
2349 | } | |
2350 | ||
2351 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2352 | { | |
4c476991 | 2353 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2354 | struct key_parse key; |
41ade00f | 2355 | int err; |
4c476991 | 2356 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2357 | |
b9454e83 JB |
2358 | err = nl80211_parse_key(info, &key); |
2359 | if (err) | |
2360 | return err; | |
41ade00f | 2361 | |
b9454e83 | 2362 | if (key.idx < 0) |
41ade00f JB |
2363 | return -EINVAL; |
2364 | ||
b9454e83 JB |
2365 | /* only support setting default key */ |
2366 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2367 | return -EINVAL; |
2368 | ||
dbd2fd65 | 2369 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2370 | |
dbd2fd65 JB |
2371 | if (key.def) { |
2372 | if (!rdev->ops->set_default_key) { | |
2373 | err = -EOPNOTSUPP; | |
2374 | goto out; | |
2375 | } | |
41ade00f | 2376 | |
dbd2fd65 JB |
2377 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2378 | if (err) | |
2379 | goto out; | |
2380 | ||
e35e4d28 | 2381 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2382 | key.def_uni, key.def_multi); |
2383 | ||
2384 | if (err) | |
2385 | goto out; | |
fffd0934 | 2386 | |
3d23e349 | 2387 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2388 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2389 | #endif | |
2390 | } else { | |
2391 | if (key.def_uni || !key.def_multi) { | |
2392 | err = -EINVAL; | |
2393 | goto out; | |
2394 | } | |
2395 | ||
2396 | if (!rdev->ops->set_default_mgmt_key) { | |
2397 | err = -EOPNOTSUPP; | |
2398 | goto out; | |
2399 | } | |
2400 | ||
2401 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2402 | if (err) | |
2403 | goto out; | |
2404 | ||
e35e4d28 | 2405 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2406 | if (err) |
2407 | goto out; | |
2408 | ||
2409 | #ifdef CONFIG_CFG80211_WEXT | |
2410 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2411 | #endif |
dbd2fd65 JB |
2412 | } |
2413 | ||
2414 | out: | |
fffd0934 | 2415 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2416 | |
41ade00f JB |
2417 | return err; |
2418 | } | |
2419 | ||
2420 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2421 | { | |
4c476991 | 2422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2423 | int err; |
4c476991 | 2424 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2425 | struct key_parse key; |
e31b8213 | 2426 | const u8 *mac_addr = NULL; |
41ade00f | 2427 | |
b9454e83 JB |
2428 | err = nl80211_parse_key(info, &key); |
2429 | if (err) | |
2430 | return err; | |
41ade00f | 2431 | |
b9454e83 | 2432 | if (!key.p.key) |
41ade00f JB |
2433 | return -EINVAL; |
2434 | ||
41ade00f JB |
2435 | if (info->attrs[NL80211_ATTR_MAC]) |
2436 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2437 | ||
e31b8213 JB |
2438 | if (key.type == -1) { |
2439 | if (mac_addr) | |
2440 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2441 | else | |
2442 | key.type = NL80211_KEYTYPE_GROUP; | |
2443 | } | |
2444 | ||
2445 | /* for now */ | |
2446 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2447 | key.type != NL80211_KEYTYPE_GROUP) | |
2448 | return -EINVAL; | |
2449 | ||
4c476991 JB |
2450 | if (!rdev->ops->add_key) |
2451 | return -EOPNOTSUPP; | |
25e47c18 | 2452 | |
e31b8213 JB |
2453 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2454 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2455 | mac_addr)) | |
4c476991 | 2456 | return -EINVAL; |
41ade00f | 2457 | |
fffd0934 JB |
2458 | wdev_lock(dev->ieee80211_ptr); |
2459 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2460 | if (!err) | |
e35e4d28 HG |
2461 | err = rdev_add_key(rdev, dev, key.idx, |
2462 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2463 | mac_addr, &key.p); | |
fffd0934 | 2464 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2465 | |
41ade00f JB |
2466 | return err; |
2467 | } | |
2468 | ||
2469 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2470 | { | |
4c476991 | 2471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2472 | int err; |
4c476991 | 2473 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2474 | u8 *mac_addr = NULL; |
b9454e83 | 2475 | struct key_parse key; |
41ade00f | 2476 | |
b9454e83 JB |
2477 | err = nl80211_parse_key(info, &key); |
2478 | if (err) | |
2479 | return err; | |
41ade00f JB |
2480 | |
2481 | if (info->attrs[NL80211_ATTR_MAC]) | |
2482 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2483 | ||
e31b8213 JB |
2484 | if (key.type == -1) { |
2485 | if (mac_addr) | |
2486 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2487 | else | |
2488 | key.type = NL80211_KEYTYPE_GROUP; | |
2489 | } | |
2490 | ||
2491 | /* for now */ | |
2492 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2493 | key.type != NL80211_KEYTYPE_GROUP) | |
2494 | return -EINVAL; | |
2495 | ||
4c476991 JB |
2496 | if (!rdev->ops->del_key) |
2497 | return -EOPNOTSUPP; | |
41ade00f | 2498 | |
fffd0934 JB |
2499 | wdev_lock(dev->ieee80211_ptr); |
2500 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2501 | |
2502 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2503 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2504 | err = -ENOENT; | |
2505 | ||
fffd0934 | 2506 | if (!err) |
e35e4d28 HG |
2507 | err = rdev_del_key(rdev, dev, key.idx, |
2508 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2509 | mac_addr); | |
41ade00f | 2510 | |
3d23e349 | 2511 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2512 | if (!err) { |
b9454e83 | 2513 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2514 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2515 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2516 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2517 | } | |
2518 | #endif | |
fffd0934 | 2519 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2520 | |
41ade00f JB |
2521 | return err; |
2522 | } | |
2523 | ||
77765eaf VT |
2524 | /* This function returns an error or the number of nested attributes */ |
2525 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2526 | { | |
2527 | struct nlattr *attr; | |
2528 | int n_entries = 0, tmp; | |
2529 | ||
2530 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2531 | if (nla_len(attr) != ETH_ALEN) | |
2532 | return -EINVAL; | |
2533 | ||
2534 | n_entries++; | |
2535 | } | |
2536 | ||
2537 | return n_entries; | |
2538 | } | |
2539 | ||
2540 | /* | |
2541 | * This function parses ACL information and allocates memory for ACL data. | |
2542 | * On successful return, the calling function is responsible to free the | |
2543 | * ACL buffer returned by this function. | |
2544 | */ | |
2545 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2546 | struct genl_info *info) | |
2547 | { | |
2548 | enum nl80211_acl_policy acl_policy; | |
2549 | struct nlattr *attr; | |
2550 | struct cfg80211_acl_data *acl; | |
2551 | int i = 0, n_entries, tmp; | |
2552 | ||
2553 | if (!wiphy->max_acl_mac_addrs) | |
2554 | return ERR_PTR(-EOPNOTSUPP); | |
2555 | ||
2556 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2557 | return ERR_PTR(-EINVAL); | |
2558 | ||
2559 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2560 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2561 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2562 | return ERR_PTR(-EINVAL); | |
2563 | ||
2564 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2565 | return ERR_PTR(-EINVAL); | |
2566 | ||
2567 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2568 | if (n_entries < 0) | |
2569 | return ERR_PTR(n_entries); | |
2570 | ||
2571 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2572 | return ERR_PTR(-ENOTSUPP); | |
2573 | ||
2574 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2575 | GFP_KERNEL); | |
2576 | if (!acl) | |
2577 | return ERR_PTR(-ENOMEM); | |
2578 | ||
2579 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2580 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2581 | i++; | |
2582 | } | |
2583 | ||
2584 | acl->n_acl_entries = n_entries; | |
2585 | acl->acl_policy = acl_policy; | |
2586 | ||
2587 | return acl; | |
2588 | } | |
2589 | ||
2590 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2591 | { | |
2592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2593 | struct net_device *dev = info->user_ptr[1]; | |
2594 | struct cfg80211_acl_data *acl; | |
2595 | int err; | |
2596 | ||
2597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2598 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2599 | return -EOPNOTSUPP; | |
2600 | ||
2601 | if (!dev->ieee80211_ptr->beacon_interval) | |
2602 | return -EINVAL; | |
2603 | ||
2604 | acl = parse_acl_data(&rdev->wiphy, info); | |
2605 | if (IS_ERR(acl)) | |
2606 | return PTR_ERR(acl); | |
2607 | ||
2608 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2609 | ||
2610 | kfree(acl); | |
2611 | ||
2612 | return err; | |
2613 | } | |
2614 | ||
8860020e JB |
2615 | static int nl80211_parse_beacon(struct genl_info *info, |
2616 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2617 | { |
8860020e | 2618 | bool haveinfo = false; |
ed1b6cc7 | 2619 | |
9946ecfb JM |
2620 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2621 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2622 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2623 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2624 | return -EINVAL; |
2625 | ||
8860020e | 2626 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2627 | |
ed1b6cc7 | 2628 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2629 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2630 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2631 | if (!bcn->head_len) | |
2632 | return -EINVAL; | |
2633 | haveinfo = true; | |
ed1b6cc7 JB |
2634 | } |
2635 | ||
2636 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2637 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2638 | bcn->tail_len = | |
ed1b6cc7 | 2639 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2640 | haveinfo = true; |
ed1b6cc7 JB |
2641 | } |
2642 | ||
4c476991 JB |
2643 | if (!haveinfo) |
2644 | return -EINVAL; | |
3b85875a | 2645 | |
9946ecfb | 2646 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2647 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2648 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2649 | } |
2650 | ||
2651 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2652 | bcn->proberesp_ies = |
9946ecfb | 2653 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2654 | bcn->proberesp_ies_len = |
9946ecfb JM |
2655 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2656 | } | |
2657 | ||
2658 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2659 | bcn->assocresp_ies = |
9946ecfb | 2660 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2661 | bcn->assocresp_ies_len = |
9946ecfb JM |
2662 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2663 | } | |
2664 | ||
00f740e1 | 2665 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2666 | bcn->probe_resp = |
00f740e1 | 2667 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2668 | bcn->probe_resp_len = |
00f740e1 AN |
2669 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2670 | } | |
2671 | ||
8860020e JB |
2672 | return 0; |
2673 | } | |
2674 | ||
46c1dd0c FF |
2675 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2676 | struct cfg80211_ap_settings *params) | |
2677 | { | |
2678 | struct wireless_dev *wdev; | |
2679 | bool ret = false; | |
2680 | ||
2681 | mutex_lock(&rdev->devlist_mtx); | |
2682 | ||
89a54e48 | 2683 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
2684 | if (wdev->iftype != NL80211_IFTYPE_AP && |
2685 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2686 | continue; | |
2687 | ||
683b6d3b | 2688 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
2689 | continue; |
2690 | ||
683b6d3b | 2691 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
2692 | ret = true; |
2693 | break; | |
2694 | } | |
2695 | ||
2696 | mutex_unlock(&rdev->devlist_mtx); | |
2697 | ||
2698 | return ret; | |
2699 | } | |
2700 | ||
e39e5b5e JM |
2701 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
2702 | enum nl80211_auth_type auth_type, | |
2703 | enum nl80211_commands cmd) | |
2704 | { | |
2705 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
2706 | return false; | |
2707 | ||
2708 | switch (cmd) { | |
2709 | case NL80211_CMD_AUTHENTICATE: | |
2710 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
2711 | auth_type == NL80211_AUTHTYPE_SAE) | |
2712 | return false; | |
2713 | return true; | |
2714 | case NL80211_CMD_CONNECT: | |
2715 | case NL80211_CMD_START_AP: | |
2716 | /* SAE not supported yet */ | |
2717 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
2718 | return false; | |
2719 | return true; | |
2720 | default: | |
2721 | return false; | |
2722 | } | |
2723 | } | |
2724 | ||
8860020e JB |
2725 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
2726 | { | |
2727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2728 | struct net_device *dev = info->user_ptr[1]; | |
2729 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2730 | struct cfg80211_ap_settings params; | |
2731 | int err; | |
04f39047 | 2732 | u8 radar_detect_width = 0; |
8860020e JB |
2733 | |
2734 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2735 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2736 | return -EOPNOTSUPP; | |
2737 | ||
2738 | if (!rdev->ops->start_ap) | |
2739 | return -EOPNOTSUPP; | |
2740 | ||
2741 | if (wdev->beacon_interval) | |
2742 | return -EALREADY; | |
2743 | ||
2744 | memset(¶ms, 0, sizeof(params)); | |
2745 | ||
2746 | /* these are required for START_AP */ | |
2747 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
2748 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
2749 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
2750 | return -EINVAL; | |
2751 | ||
2752 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
2753 | if (err) | |
2754 | return err; | |
2755 | ||
2756 | params.beacon_interval = | |
2757 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
2758 | params.dtim_period = | |
2759 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
2760 | ||
2761 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
2762 | if (err) | |
2763 | return err; | |
2764 | ||
2765 | /* | |
2766 | * In theory, some of these attributes should be required here | |
2767 | * but since they were not used when the command was originally | |
2768 | * added, keep them optional for old user space programs to let | |
2769 | * them continue to work with drivers that do not need the | |
2770 | * additional information -- drivers must check! | |
2771 | */ | |
2772 | if (info->attrs[NL80211_ATTR_SSID]) { | |
2773 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
2774 | params.ssid_len = | |
2775 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
2776 | if (params.ssid_len == 0 || | |
2777 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
2778 | return -EINVAL; | |
2779 | } | |
2780 | ||
2781 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
2782 | params.hidden_ssid = nla_get_u32( | |
2783 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
2784 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
2785 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
2786 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
2787 | return -EINVAL; | |
2788 | } | |
2789 | ||
2790 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
2791 | ||
2792 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
2793 | params.auth_type = nla_get_u32( | |
2794 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
2795 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
2796 | NL80211_CMD_START_AP)) | |
8860020e JB |
2797 | return -EINVAL; |
2798 | } else | |
2799 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
2800 | ||
2801 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
2802 | NL80211_MAX_NR_CIPHER_SUITES); | |
2803 | if (err) | |
2804 | return err; | |
2805 | ||
1b658f11 VT |
2806 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
2807 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
2808 | return -EOPNOTSUPP; | |
2809 | params.inactivity_timeout = nla_get_u16( | |
2810 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
2811 | } | |
2812 | ||
53cabad7 JB |
2813 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
2814 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2815 | return -EINVAL; | |
2816 | params.p2p_ctwindow = | |
2817 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
2818 | if (params.p2p_ctwindow > 127) | |
2819 | return -EINVAL; | |
2820 | if (params.p2p_ctwindow != 0 && | |
2821 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
2822 | return -EINVAL; | |
2823 | } | |
2824 | ||
2825 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
2826 | u8 tmp; | |
2827 | ||
2828 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2829 | return -EINVAL; | |
2830 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
2831 | if (tmp > 1) | |
2832 | return -EINVAL; | |
2833 | params.p2p_opp_ps = tmp; | |
2834 | if (params.p2p_opp_ps != 0 && | |
2835 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
2836 | return -EINVAL; | |
2837 | } | |
2838 | ||
aa430da4 | 2839 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
2840 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
2841 | if (err) | |
2842 | return err; | |
2843 | } else if (wdev->preset_chandef.chan) { | |
2844 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 2845 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
2846 | return -EINVAL; |
2847 | ||
683b6d3b | 2848 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
2849 | return -EINVAL; |
2850 | ||
04f39047 SW |
2851 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
2852 | if (err < 0) | |
2853 | return err; | |
2854 | if (err) { | |
2855 | radar_detect_width = BIT(params.chandef.width); | |
2856 | params.radar_required = true; | |
2857 | } | |
2858 | ||
e4e32459 | 2859 | mutex_lock(&rdev->devlist_mtx); |
04f39047 SW |
2860 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
2861 | params.chandef.chan, | |
2862 | CHAN_MODE_SHARED, | |
2863 | radar_detect_width); | |
e4e32459 MK |
2864 | mutex_unlock(&rdev->devlist_mtx); |
2865 | ||
2866 | if (err) | |
2867 | return err; | |
2868 | ||
77765eaf VT |
2869 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
2870 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
2871 | if (IS_ERR(params.acl)) | |
2872 | return PTR_ERR(params.acl); | |
2873 | } | |
2874 | ||
e35e4d28 | 2875 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 2876 | if (!err) { |
683b6d3b | 2877 | wdev->preset_chandef = params.chandef; |
8860020e | 2878 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 2879 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
2880 | wdev->ssid_len = params.ssid_len; |
2881 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 2882 | } |
77765eaf VT |
2883 | |
2884 | kfree(params.acl); | |
2885 | ||
56d1893d | 2886 | return err; |
ed1b6cc7 JB |
2887 | } |
2888 | ||
8860020e JB |
2889 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
2890 | { | |
2891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2892 | struct net_device *dev = info->user_ptr[1]; | |
2893 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2894 | struct cfg80211_beacon_data params; | |
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 (!rdev->ops->change_beacon) | |
2902 | return -EOPNOTSUPP; | |
2903 | ||
2904 | if (!wdev->beacon_interval) | |
2905 | return -EINVAL; | |
2906 | ||
2907 | err = nl80211_parse_beacon(info, ¶ms); | |
2908 | if (err) | |
2909 | return err; | |
2910 | ||
e35e4d28 | 2911 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
2912 | } |
2913 | ||
2914 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 2915 | { |
4c476991 JB |
2916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2917 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 2918 | |
60771780 | 2919 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
2920 | } |
2921 | ||
5727ef1b JB |
2922 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
2923 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
2924 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
2925 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 2926 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 2927 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 2928 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
2929 | }; |
2930 | ||
eccb8e8f | 2931 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 2932 | enum nl80211_iftype iftype, |
eccb8e8f | 2933 | struct station_parameters *params) |
5727ef1b JB |
2934 | { |
2935 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 2936 | struct nlattr *nla; |
5727ef1b JB |
2937 | int flag; |
2938 | ||
eccb8e8f JB |
2939 | /* |
2940 | * Try parsing the new attribute first so userspace | |
2941 | * can specify both for older kernels. | |
2942 | */ | |
2943 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
2944 | if (nla) { | |
2945 | struct nl80211_sta_flag_update *sta_flags; | |
2946 | ||
2947 | sta_flags = nla_data(nla); | |
2948 | params->sta_flags_mask = sta_flags->mask; | |
2949 | params->sta_flags_set = sta_flags->set; | |
2950 | if ((params->sta_flags_mask | | |
2951 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
2952 | return -EINVAL; | |
2953 | return 0; | |
2954 | } | |
2955 | ||
2956 | /* if present, parse the old attribute */ | |
5727ef1b | 2957 | |
eccb8e8f | 2958 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
2959 | if (!nla) |
2960 | return 0; | |
2961 | ||
2962 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
2963 | nla, sta_flags_policy)) | |
2964 | return -EINVAL; | |
2965 | ||
bdd3ae3d JB |
2966 | /* |
2967 | * Only allow certain flags for interface types so that | |
2968 | * other attributes are silently ignored. Remember that | |
2969 | * this is backward compatibility code with old userspace | |
2970 | * and shouldn't be hit in other cases anyway. | |
2971 | */ | |
2972 | switch (iftype) { | |
2973 | case NL80211_IFTYPE_AP: | |
2974 | case NL80211_IFTYPE_AP_VLAN: | |
2975 | case NL80211_IFTYPE_P2P_GO: | |
2976 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2977 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
2978 | BIT(NL80211_STA_FLAG_WME) | | |
2979 | BIT(NL80211_STA_FLAG_MFP); | |
2980 | break; | |
2981 | case NL80211_IFTYPE_P2P_CLIENT: | |
2982 | case NL80211_IFTYPE_STATION: | |
2983 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2984 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
2985 | break; | |
2986 | case NL80211_IFTYPE_MESH_POINT: | |
2987 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
2988 | BIT(NL80211_STA_FLAG_MFP) | | |
2989 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
2990 | default: | |
2991 | return -EINVAL; | |
2992 | } | |
5727ef1b | 2993 | |
3383b5a6 JB |
2994 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
2995 | if (flags[flag]) { | |
eccb8e8f | 2996 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 2997 | |
3383b5a6 JB |
2998 | /* no longer support new API additions in old API */ |
2999 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3000 | return -EINVAL; | |
3001 | } | |
3002 | } | |
3003 | ||
5727ef1b JB |
3004 | return 0; |
3005 | } | |
3006 | ||
c8dcfd8a FF |
3007 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3008 | int attr) | |
3009 | { | |
3010 | struct nlattr *rate; | |
8eb41c8d VK |
3011 | u32 bitrate; |
3012 | u16 bitrate_compat; | |
c8dcfd8a FF |
3013 | |
3014 | rate = nla_nest_start(msg, attr); | |
3015 | if (!rate) | |
db9c64cf | 3016 | return false; |
c8dcfd8a FF |
3017 | |
3018 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3019 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3020 | /* report 16-bit bitrate only if we can */ |
3021 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3022 | if (bitrate > 0 && |
3023 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3024 | return false; | |
3025 | if (bitrate_compat > 0 && | |
3026 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3027 | return false; | |
3028 | ||
3029 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3030 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3031 | return false; | |
3032 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3033 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3034 | return false; | |
3035 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3036 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3037 | return false; | |
3038 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3039 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3040 | return false; | |
3041 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3042 | return false; | |
3043 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3044 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3045 | return false; | |
3046 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3047 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3048 | return false; | |
3049 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3050 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3051 | return false; | |
3052 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3053 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3054 | return false; | |
3055 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3056 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3057 | return false; | |
3058 | } | |
c8dcfd8a FF |
3059 | |
3060 | nla_nest_end(msg, rate); | |
3061 | return true; | |
c8dcfd8a FF |
3062 | } |
3063 | ||
15e47304 | 3064 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3065 | int flags, |
3066 | struct cfg80211_registered_device *rdev, | |
3067 | struct net_device *dev, | |
98b62183 | 3068 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3069 | { |
3070 | void *hdr; | |
f4263c98 | 3071 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3072 | |
15e47304 | 3073 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3074 | if (!hdr) |
3075 | return -1; | |
3076 | ||
9360ffd1 DM |
3077 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3078 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3079 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3080 | goto nla_put_failure; | |
f5ea9120 | 3081 | |
2ec600d6 LCC |
3082 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3083 | if (!sinfoattr) | |
fd5b74dc | 3084 | goto nla_put_failure; |
9360ffd1 DM |
3085 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3086 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3087 | sinfo->connected_time)) | |
3088 | goto nla_put_failure; | |
3089 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3090 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3091 | sinfo->inactive_time)) | |
3092 | goto nla_put_failure; | |
42745e03 VK |
3093 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3094 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3095 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3096 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3097 | goto nla_put_failure; |
42745e03 VK |
3098 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
3099 | NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3100 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3101 | (u32)sinfo->tx_bytes)) |
3102 | goto nla_put_failure; | |
3103 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3104 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3105 | sinfo->rx_bytes)) | |
3106 | goto nla_put_failure; | |
3107 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3108 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3109 | sinfo->tx_bytes)) |
3110 | goto nla_put_failure; | |
3111 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3112 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3113 | goto nla_put_failure; | |
3114 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3115 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3116 | goto nla_put_failure; | |
3117 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3118 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3119 | sinfo->plink_state)) | |
3120 | goto nla_put_failure; | |
66266b3a JL |
3121 | switch (rdev->wiphy.signal_type) { |
3122 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3123 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3124 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3125 | sinfo->signal)) | |
3126 | goto nla_put_failure; | |
3127 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3128 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3129 | sinfo->signal_avg)) | |
3130 | goto nla_put_failure; | |
66266b3a JL |
3131 | break; |
3132 | default: | |
3133 | break; | |
3134 | } | |
420e7fab | 3135 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3136 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3137 | NL80211_STA_INFO_TX_BITRATE)) | |
3138 | goto nla_put_failure; | |
3139 | } | |
3140 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3141 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3142 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3143 | goto nla_put_failure; |
420e7fab | 3144 | } |
9360ffd1 DM |
3145 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3146 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3147 | sinfo->rx_packets)) | |
3148 | goto nla_put_failure; | |
3149 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3150 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3151 | sinfo->tx_packets)) | |
3152 | goto nla_put_failure; | |
3153 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3154 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3155 | sinfo->tx_retries)) | |
3156 | goto nla_put_failure; | |
3157 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3158 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3159 | sinfo->tx_failed)) | |
3160 | goto nla_put_failure; | |
3161 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3162 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3163 | sinfo->beacon_loss_count)) | |
3164 | goto nla_put_failure; | |
3b1c5a53 MP |
3165 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3166 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3167 | sinfo->local_pm)) | |
3168 | goto nla_put_failure; | |
3169 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3170 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3171 | sinfo->peer_pm)) | |
3172 | goto nla_put_failure; | |
3173 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3174 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3175 | sinfo->nonpeer_pm)) | |
3176 | goto nla_put_failure; | |
f4263c98 PS |
3177 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3178 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3179 | if (!bss_param) | |
3180 | goto nla_put_failure; | |
3181 | ||
9360ffd1 DM |
3182 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3183 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3184 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3185 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3186 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3187 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3188 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3189 | sinfo->bss_param.dtim_period) || | |
3190 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3191 | sinfo->bss_param.beacon_interval)) | |
3192 | goto nla_put_failure; | |
f4263c98 PS |
3193 | |
3194 | nla_nest_end(msg, bss_param); | |
3195 | } | |
9360ffd1 DM |
3196 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3197 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3198 | sizeof(struct nl80211_sta_flag_update), | |
3199 | &sinfo->sta_flags)) | |
3200 | goto nla_put_failure; | |
7eab0f64 JL |
3201 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3202 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3203 | sinfo->t_offset)) | |
3204 | goto nla_put_failure; | |
2ec600d6 | 3205 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3206 | |
9360ffd1 DM |
3207 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3208 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3209 | sinfo->assoc_req_ies)) | |
3210 | goto nla_put_failure; | |
50d3dfb7 | 3211 | |
fd5b74dc JB |
3212 | return genlmsg_end(msg, hdr); |
3213 | ||
3214 | nla_put_failure: | |
bc3ed28c TG |
3215 | genlmsg_cancel(msg, hdr); |
3216 | return -EMSGSIZE; | |
fd5b74dc JB |
3217 | } |
3218 | ||
2ec600d6 | 3219 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3220 | struct netlink_callback *cb) |
2ec600d6 | 3221 | { |
2ec600d6 LCC |
3222 | struct station_info sinfo; |
3223 | struct cfg80211_registered_device *dev; | |
bba95fef | 3224 | struct net_device *netdev; |
2ec600d6 | 3225 | u8 mac_addr[ETH_ALEN]; |
bba95fef | 3226 | int sta_idx = cb->args[1]; |
2ec600d6 | 3227 | int err; |
2ec600d6 | 3228 | |
67748893 JB |
3229 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3230 | if (err) | |
3231 | return err; | |
bba95fef JB |
3232 | |
3233 | if (!dev->ops->dump_station) { | |
eec60b03 | 3234 | err = -EOPNOTSUPP; |
bba95fef JB |
3235 | goto out_err; |
3236 | } | |
3237 | ||
bba95fef | 3238 | while (1) { |
f612cedf | 3239 | memset(&sinfo, 0, sizeof(sinfo)); |
e35e4d28 HG |
3240 | err = rdev_dump_station(dev, netdev, sta_idx, |
3241 | mac_addr, &sinfo); | |
bba95fef JB |
3242 | if (err == -ENOENT) |
3243 | break; | |
3244 | if (err) | |
3b85875a | 3245 | goto out_err; |
bba95fef JB |
3246 | |
3247 | if (nl80211_send_station(skb, | |
15e47304 | 3248 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3249 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
66266b3a | 3250 | dev, netdev, mac_addr, |
bba95fef JB |
3251 | &sinfo) < 0) |
3252 | goto out; | |
3253 | ||
3254 | sta_idx++; | |
3255 | } | |
3256 | ||
3257 | ||
3258 | out: | |
3259 | cb->args[1] = sta_idx; | |
3260 | err = skb->len; | |
bba95fef | 3261 | out_err: |
67748893 | 3262 | nl80211_finish_netdev_dump(dev); |
bba95fef JB |
3263 | |
3264 | return err; | |
2ec600d6 | 3265 | } |
fd5b74dc | 3266 | |
5727ef1b JB |
3267 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3268 | { | |
4c476991 JB |
3269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3270 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3271 | struct station_info sinfo; |
fd5b74dc JB |
3272 | struct sk_buff *msg; |
3273 | u8 *mac_addr = NULL; | |
4c476991 | 3274 | int err; |
fd5b74dc | 3275 | |
2ec600d6 | 3276 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3277 | |
3278 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3279 | return -EINVAL; | |
3280 | ||
3281 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3282 | ||
4c476991 JB |
3283 | if (!rdev->ops->get_station) |
3284 | return -EOPNOTSUPP; | |
3b85875a | 3285 | |
e35e4d28 | 3286 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3287 | if (err) |
4c476991 | 3288 | return err; |
2ec600d6 | 3289 | |
fd2120ca | 3290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3291 | if (!msg) |
4c476991 | 3292 | return -ENOMEM; |
fd5b74dc | 3293 | |
15e47304 | 3294 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3295 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3296 | nlmsg_free(msg); |
3297 | return -ENOBUFS; | |
3298 | } | |
3b85875a | 3299 | |
4c476991 | 3300 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3301 | } |
3302 | ||
3303 | /* | |
c258d2de | 3304 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3305 | */ |
80b99899 JB |
3306 | static struct net_device *get_vlan(struct genl_info *info, |
3307 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3308 | { |
463d0183 | 3309 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3310 | struct net_device *v; |
3311 | int ret; | |
3312 | ||
3313 | if (!vlanattr) | |
3314 | return NULL; | |
3315 | ||
3316 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3317 | if (!v) | |
3318 | return ERR_PTR(-ENODEV); | |
3319 | ||
3320 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3321 | ret = -EINVAL; | |
3322 | goto error; | |
5727ef1b | 3323 | } |
80b99899 JB |
3324 | |
3325 | if (!netif_running(v)) { | |
3326 | ret = -ENETDOWN; | |
3327 | goto error; | |
3328 | } | |
3329 | ||
3330 | return v; | |
3331 | error: | |
3332 | dev_put(v); | |
3333 | return ERR_PTR(ret); | |
5727ef1b JB |
3334 | } |
3335 | ||
df881293 JM |
3336 | static struct nla_policy |
3337 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3338 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3339 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3340 | }; | |
3341 | ||
3342 | static int nl80211_set_station_tdls(struct genl_info *info, | |
3343 | struct station_parameters *params) | |
3344 | { | |
df881293 JM |
3345 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3346 | struct nlattr *nla; | |
3347 | int err; | |
3348 | ||
df881293 JM |
3349 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
3350 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | |
3351 | params->ht_capa = | |
3352 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3353 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3354 | params->vht_capa = | |
3355 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3356 | ||
3357 | /* parse WME attributes if present */ | |
3358 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3359 | return 0; | |
3360 | ||
3361 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3362 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3363 | nl80211_sta_wme_policy); | |
3364 | if (err) | |
3365 | return err; | |
3366 | ||
3367 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3368 | params->uapsd_queues = nla_get_u8( | |
3369 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3370 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3371 | return -EINVAL; | |
3372 | ||
3373 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3374 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3375 | ||
3376 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3377 | return -EINVAL; | |
3378 | ||
3379 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3380 | ||
3381 | return 0; | |
3382 | } | |
3383 | ||
5727ef1b JB |
3384 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3385 | { | |
4c476991 | 3386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3387 | int err; |
4c476991 | 3388 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3389 | struct station_parameters params; |
3390 | u8 *mac_addr = NULL; | |
3391 | ||
3392 | memset(¶ms, 0, sizeof(params)); | |
3393 | ||
3394 | params.listen_interval = -1; | |
57cf8043 | 3395 | params.plink_state = -1; |
5727ef1b JB |
3396 | |
3397 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
3398 | return -EINVAL; | |
3399 | ||
3400 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3401 | return -EINVAL; | |
3402 | ||
3403 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3404 | ||
3405 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3406 | params.supported_rates = | |
3407 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3408 | params.supported_rates_len = | |
3409 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3410 | } | |
3411 | ||
9d62a986 JM |
3412 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3413 | params.capability = | |
3414 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3415 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3416 | } | |
3417 | ||
3418 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3419 | params.ext_capab = | |
3420 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3421 | params.ext_capab_len = | |
3422 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3423 | } | |
3424 | ||
df881293 | 3425 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3426 | return -EINVAL; |
36aedc90 | 3427 | |
bdd90d5e JB |
3428 | if (!rdev->ops->change_station) |
3429 | return -EOPNOTSUPP; | |
3430 | ||
bdd3ae3d | 3431 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3432 | return -EINVAL; |
3433 | ||
2ec600d6 LCC |
3434 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
3435 | params.plink_action = | |
3436 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
3437 | ||
9c3990aa JC |
3438 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
3439 | params.plink_state = | |
3440 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | |
3441 | ||
3b1c5a53 MP |
3442 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3443 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3444 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3445 | ||
3446 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3447 | pm > NL80211_MESH_POWER_MAX) | |
3448 | return -EINVAL; | |
3449 | ||
3450 | params.local_pm = pm; | |
3451 | } | |
3452 | ||
a97f4424 JB |
3453 | switch (dev->ieee80211_ptr->iftype) { |
3454 | case NL80211_IFTYPE_AP: | |
3455 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3456 | case NL80211_IFTYPE_P2P_GO: |
a97f4424 JB |
3457 | /* disallow mesh-specific things */ |
3458 | if (params.plink_action) | |
bdd90d5e | 3459 | return -EINVAL; |
3b1c5a53 MP |
3460 | if (params.local_pm) |
3461 | return -EINVAL; | |
bdd90d5e JB |
3462 | |
3463 | /* TDLS can't be set, ... */ | |
3464 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3465 | return -EINVAL; | |
3466 | /* | |
3467 | * ... but don't bother the driver with it. This works around | |
3468 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3469 | * TLDS_PEER flag in the mask even for AP mode. | |
3470 | */ | |
3471 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3472 | ||
3473 | /* accept only the listed bits */ | |
3474 | if (params.sta_flags_mask & | |
3475 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
d582cffb JB |
3476 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
3477 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
bdd90d5e JB |
3478 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
3479 | BIT(NL80211_STA_FLAG_WME) | | |
3480 | BIT(NL80211_STA_FLAG_MFP))) | |
3481 | return -EINVAL; | |
3482 | ||
d582cffb JB |
3483 | /* but authenticated/associated only if driver handles it */ |
3484 | if (!(rdev->wiphy.features & | |
3485 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3486 | params.sta_flags_mask & | |
3487 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3488 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3489 | return -EINVAL; | |
3490 | ||
ba23d206 JB |
3491 | /* reject other things that can't change */ |
3492 | if (params.supported_rates) | |
3493 | return -EINVAL; | |
9d62a986 JM |
3494 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
3495 | return -EINVAL; | |
3496 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) | |
3497 | return -EINVAL; | |
df881293 JM |
3498 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
3499 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3500 | return -EINVAL; | |
ba23d206 | 3501 | |
bdd90d5e JB |
3502 | /* must be last in here for error handling */ |
3503 | params.vlan = get_vlan(info, rdev); | |
3504 | if (IS_ERR(params.vlan)) | |
3505 | return PTR_ERR(params.vlan); | |
a97f4424 | 3506 | break; |
074ac8df | 3507 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3508 | case NL80211_IFTYPE_STATION: |
bdd90d5e JB |
3509 | /* |
3510 | * Don't allow userspace to change the TDLS_PEER flag, | |
3511 | * but silently ignore attempts to change it since we | |
3512 | * don't have state here to verify that it doesn't try | |
3513 | * to change the flag. | |
3514 | */ | |
3515 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
df881293 JM |
3516 | /* Include parameters for TDLS peer (driver will check) */ |
3517 | err = nl80211_set_station_tdls(info, ¶ms); | |
3518 | if (err) | |
3519 | return err; | |
3520 | /* disallow things sta doesn't support */ | |
3521 | if (params.plink_action) | |
3522 | return -EINVAL; | |
3523 | if (params.local_pm) | |
3524 | return -EINVAL; | |
3525 | /* reject any changes other than AUTHORIZED or WME (for TDLS) */ | |
3526 | if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3527 | BIT(NL80211_STA_FLAG_WME))) | |
3528 | return -EINVAL; | |
3529 | break; | |
267335d6 AQ |
3530 | case NL80211_IFTYPE_ADHOC: |
3531 | /* disallow things sta doesn't support */ | |
3532 | if (params.plink_action) | |
3533 | return -EINVAL; | |
3b1c5a53 MP |
3534 | if (params.local_pm) |
3535 | return -EINVAL; | |
df881293 JM |
3536 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
3537 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3538 | return -EINVAL; | |
bdd90d5e JB |
3539 | /* reject any changes other than AUTHORIZED */ |
3540 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3541 | return -EINVAL; | |
a97f4424 JB |
3542 | break; |
3543 | case NL80211_IFTYPE_MESH_POINT: | |
3544 | /* disallow things mesh doesn't support */ | |
3545 | if (params.vlan) | |
bdd90d5e | 3546 | return -EINVAL; |
ba23d206 | 3547 | if (params.supported_rates) |
bdd90d5e | 3548 | return -EINVAL; |
9d62a986 JM |
3549 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
3550 | return -EINVAL; | |
3551 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) | |
3552 | return -EINVAL; | |
df881293 JM |
3553 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
3554 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3555 | return -EINVAL; | |
bdd90d5e JB |
3556 | /* |
3557 | * No special handling for TDLS here -- the userspace | |
3558 | * mesh code doesn't have this bug. | |
3559 | */ | |
b39c48fa JC |
3560 | if (params.sta_flags_mask & |
3561 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
8429828e | 3562 | BIT(NL80211_STA_FLAG_MFP) | |
b39c48fa | 3563 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
bdd90d5e | 3564 | return -EINVAL; |
a97f4424 JB |
3565 | break; |
3566 | default: | |
bdd90d5e | 3567 | return -EOPNOTSUPP; |
034d655e JB |
3568 | } |
3569 | ||
bdd90d5e | 3570 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 3571 | |
e35e4d28 | 3572 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3573 | |
5727ef1b JB |
3574 | if (params.vlan) |
3575 | dev_put(params.vlan); | |
3b85875a | 3576 | |
5727ef1b JB |
3577 | return err; |
3578 | } | |
3579 | ||
3580 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
3581 | { | |
4c476991 | 3582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3583 | int err; |
4c476991 | 3584 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3585 | struct station_parameters params; |
3586 | u8 *mac_addr = NULL; | |
3587 | ||
3588 | memset(¶ms, 0, sizeof(params)); | |
3589 | ||
3590 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3591 | return -EINVAL; | |
3592 | ||
5727ef1b JB |
3593 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3594 | return -EINVAL; | |
3595 | ||
3596 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3597 | return -EINVAL; | |
3598 | ||
0e956c13 TLSC |
3599 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
3600 | return -EINVAL; | |
3601 | ||
5727ef1b JB |
3602 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3603 | params.supported_rates = | |
3604 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3605 | params.supported_rates_len = | |
3606 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3607 | params.listen_interval = | |
3608 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3609 | |
0e956c13 TLSC |
3610 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
3611 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
3612 | return -EINVAL; | |
51b50fbe | 3613 | |
9d62a986 JM |
3614 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3615 | params.capability = | |
3616 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3617 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3618 | } | |
3619 | ||
3620 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3621 | params.ext_capab = | |
3622 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3623 | params.ext_capab_len = | |
3624 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3625 | } | |
3626 | ||
36aedc90 JM |
3627 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3628 | params.ht_capa = | |
3629 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 3630 | |
f461be3e MP |
3631 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
3632 | params.vht_capa = | |
3633 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3634 | ||
96b78dff JC |
3635 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
3636 | params.plink_action = | |
3637 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
3638 | ||
bdd90d5e JB |
3639 | if (!rdev->ops->add_station) |
3640 | return -EOPNOTSUPP; | |
3641 | ||
bdd3ae3d | 3642 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3643 | return -EINVAL; |
3644 | ||
bdd90d5e JB |
3645 | switch (dev->ieee80211_ptr->iftype) { |
3646 | case NL80211_IFTYPE_AP: | |
3647 | case NL80211_IFTYPE_AP_VLAN: | |
3648 | case NL80211_IFTYPE_P2P_GO: | |
3649 | /* parse WME attributes if sta is WME capable */ | |
3650 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
3651 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && | |
3652 | info->attrs[NL80211_ATTR_STA_WME]) { | |
3653 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; | |
3654 | struct nlattr *nla; | |
3655 | ||
3656 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3657 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3658 | nl80211_sta_wme_policy); | |
3659 | if (err) | |
3660 | return err; | |
3661 | ||
3662 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3663 | params.uapsd_queues = | |
3664 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3665 | if (params.uapsd_queues & | |
3666 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3667 | return -EINVAL; | |
c75786c9 | 3668 | |
bdd90d5e JB |
3669 | if (tb[NL80211_STA_WME_MAX_SP]) |
3670 | params.max_sp = | |
3671 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
c75786c9 | 3672 | |
bdd90d5e JB |
3673 | if (params.max_sp & |
3674 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3675 | return -EINVAL; | |
4319e193 | 3676 | |
bdd90d5e JB |
3677 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
3678 | } | |
3679 | /* TDLS peers cannot be added */ | |
3680 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 3681 | return -EINVAL; |
bdd90d5e JB |
3682 | /* but don't bother the driver with it */ |
3683 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 3684 | |
d582cffb JB |
3685 | /* allow authenticated/associated only if driver handles it */ |
3686 | if (!(rdev->wiphy.features & | |
3687 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3688 | params.sta_flags_mask & | |
3689 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3690 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3691 | return -EINVAL; | |
3692 | ||
bdd90d5e JB |
3693 | /* must be last in here for error handling */ |
3694 | params.vlan = get_vlan(info, rdev); | |
3695 | if (IS_ERR(params.vlan)) | |
3696 | return PTR_ERR(params.vlan); | |
3697 | break; | |
3698 | case NL80211_IFTYPE_MESH_POINT: | |
d582cffb JB |
3699 | /* associated is disallowed */ |
3700 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
3701 | return -EINVAL; | |
bdd90d5e JB |
3702 | /* TDLS peers cannot be added */ |
3703 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3704 | return -EINVAL; | |
3705 | break; | |
3706 | case NL80211_IFTYPE_STATION: | |
d582cffb JB |
3707 | /* associated is disallowed */ |
3708 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
3709 | return -EINVAL; | |
bdd90d5e JB |
3710 | /* Only TDLS peers can be added */ |
3711 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3712 | return -EINVAL; | |
3713 | /* Can only add if TDLS ... */ | |
3714 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
3715 | return -EOPNOTSUPP; | |
3716 | /* ... with external setup is supported */ | |
3717 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
3718 | return -EOPNOTSUPP; | |
3719 | break; | |
3720 | default: | |
3721 | return -EOPNOTSUPP; | |
c75786c9 EP |
3722 | } |
3723 | ||
bdd90d5e | 3724 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 3725 | |
e35e4d28 | 3726 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3727 | |
5727ef1b JB |
3728 | if (params.vlan) |
3729 | dev_put(params.vlan); | |
5727ef1b JB |
3730 | return err; |
3731 | } | |
3732 | ||
3733 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
3734 | { | |
4c476991 JB |
3735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3736 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
3737 | u8 *mac_addr = NULL; |
3738 | ||
3739 | if (info->attrs[NL80211_ATTR_MAC]) | |
3740 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3741 | ||
e80cf853 | 3742 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 3743 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 3744 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
3745 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
3746 | return -EINVAL; | |
5727ef1b | 3747 | |
4c476991 JB |
3748 | if (!rdev->ops->del_station) |
3749 | return -EOPNOTSUPP; | |
3b85875a | 3750 | |
e35e4d28 | 3751 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
3752 | } |
3753 | ||
15e47304 | 3754 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
3755 | int flags, struct net_device *dev, |
3756 | u8 *dst, u8 *next_hop, | |
3757 | struct mpath_info *pinfo) | |
3758 | { | |
3759 | void *hdr; | |
3760 | struct nlattr *pinfoattr; | |
3761 | ||
15e47304 | 3762 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
3763 | if (!hdr) |
3764 | return -1; | |
3765 | ||
9360ffd1 DM |
3766 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3767 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
3768 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
3769 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
3770 | goto nla_put_failure; | |
f5ea9120 | 3771 | |
2ec600d6 LCC |
3772 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
3773 | if (!pinfoattr) | |
3774 | goto nla_put_failure; | |
9360ffd1 DM |
3775 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
3776 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
3777 | pinfo->frame_qlen)) | |
3778 | goto nla_put_failure; | |
3779 | if (((pinfo->filled & MPATH_INFO_SN) && | |
3780 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
3781 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
3782 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
3783 | pinfo->metric)) || | |
3784 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
3785 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
3786 | pinfo->exptime)) || | |
3787 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
3788 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
3789 | pinfo->flags)) || | |
3790 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
3791 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
3792 | pinfo->discovery_timeout)) || | |
3793 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
3794 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
3795 | pinfo->discovery_retries))) | |
3796 | goto nla_put_failure; | |
2ec600d6 LCC |
3797 | |
3798 | nla_nest_end(msg, pinfoattr); | |
3799 | ||
3800 | return genlmsg_end(msg, hdr); | |
3801 | ||
3802 | nla_put_failure: | |
bc3ed28c TG |
3803 | genlmsg_cancel(msg, hdr); |
3804 | return -EMSGSIZE; | |
2ec600d6 LCC |
3805 | } |
3806 | ||
3807 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 3808 | struct netlink_callback *cb) |
2ec600d6 | 3809 | { |
2ec600d6 LCC |
3810 | struct mpath_info pinfo; |
3811 | struct cfg80211_registered_device *dev; | |
bba95fef | 3812 | struct net_device *netdev; |
2ec600d6 LCC |
3813 | u8 dst[ETH_ALEN]; |
3814 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 3815 | int path_idx = cb->args[1]; |
2ec600d6 | 3816 | int err; |
2ec600d6 | 3817 | |
67748893 JB |
3818 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3819 | if (err) | |
3820 | return err; | |
bba95fef JB |
3821 | |
3822 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 3823 | err = -EOPNOTSUPP; |
bba95fef JB |
3824 | goto out_err; |
3825 | } | |
3826 | ||
eec60b03 JM |
3827 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
3828 | err = -EOPNOTSUPP; | |
0448b5fc | 3829 | goto out_err; |
eec60b03 JM |
3830 | } |
3831 | ||
bba95fef | 3832 | while (1) { |
e35e4d28 HG |
3833 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
3834 | &pinfo); | |
bba95fef | 3835 | if (err == -ENOENT) |
2ec600d6 | 3836 | break; |
bba95fef | 3837 | if (err) |
3b85875a | 3838 | goto out_err; |
2ec600d6 | 3839 | |
15e47304 | 3840 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef JB |
3841 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
3842 | netdev, dst, next_hop, | |
3843 | &pinfo) < 0) | |
3844 | goto out; | |
2ec600d6 | 3845 | |
bba95fef | 3846 | path_idx++; |
2ec600d6 | 3847 | } |
2ec600d6 | 3848 | |
2ec600d6 | 3849 | |
bba95fef JB |
3850 | out: |
3851 | cb->args[1] = path_idx; | |
3852 | err = skb->len; | |
bba95fef | 3853 | out_err: |
67748893 | 3854 | nl80211_finish_netdev_dump(dev); |
bba95fef | 3855 | return err; |
2ec600d6 LCC |
3856 | } |
3857 | ||
3858 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
3859 | { | |
4c476991 | 3860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 3861 | int err; |
4c476991 | 3862 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
3863 | struct mpath_info pinfo; |
3864 | struct sk_buff *msg; | |
3865 | u8 *dst = NULL; | |
3866 | u8 next_hop[ETH_ALEN]; | |
3867 | ||
3868 | memset(&pinfo, 0, sizeof(pinfo)); | |
3869 | ||
3870 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3871 | return -EINVAL; | |
3872 | ||
3873 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3874 | ||
4c476991 JB |
3875 | if (!rdev->ops->get_mpath) |
3876 | return -EOPNOTSUPP; | |
2ec600d6 | 3877 | |
4c476991 JB |
3878 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3879 | return -EOPNOTSUPP; | |
eec60b03 | 3880 | |
e35e4d28 | 3881 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 3882 | if (err) |
4c476991 | 3883 | return err; |
2ec600d6 | 3884 | |
fd2120ca | 3885 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 3886 | if (!msg) |
4c476991 | 3887 | return -ENOMEM; |
2ec600d6 | 3888 | |
15e47304 | 3889 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
3890 | dev, dst, next_hop, &pinfo) < 0) { |
3891 | nlmsg_free(msg); | |
3892 | return -ENOBUFS; | |
3893 | } | |
3b85875a | 3894 | |
4c476991 | 3895 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
3896 | } |
3897 | ||
3898 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
3899 | { | |
4c476991 JB |
3900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3901 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3902 | u8 *dst = NULL; |
3903 | u8 *next_hop = NULL; | |
3904 | ||
3905 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3906 | return -EINVAL; | |
3907 | ||
3908 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
3909 | return -EINVAL; | |
3910 | ||
3911 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3912 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
3913 | ||
4c476991 JB |
3914 | if (!rdev->ops->change_mpath) |
3915 | return -EOPNOTSUPP; | |
35a8efe1 | 3916 | |
4c476991 JB |
3917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3918 | return -EOPNOTSUPP; | |
2ec600d6 | 3919 | |
e35e4d28 | 3920 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 3921 | } |
4c476991 | 3922 | |
2ec600d6 LCC |
3923 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
3924 | { | |
4c476991 JB |
3925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3926 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3927 | u8 *dst = NULL; |
3928 | u8 *next_hop = NULL; | |
3929 | ||
3930 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3931 | return -EINVAL; | |
3932 | ||
3933 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
3934 | return -EINVAL; | |
3935 | ||
3936 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3937 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
3938 | ||
4c476991 JB |
3939 | if (!rdev->ops->add_mpath) |
3940 | return -EOPNOTSUPP; | |
35a8efe1 | 3941 | |
4c476991 JB |
3942 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3943 | return -EOPNOTSUPP; | |
2ec600d6 | 3944 | |
e35e4d28 | 3945 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
3946 | } |
3947 | ||
3948 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
3949 | { | |
4c476991 JB |
3950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3951 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3952 | u8 *dst = NULL; |
3953 | ||
3954 | if (info->attrs[NL80211_ATTR_MAC]) | |
3955 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3956 | ||
4c476991 JB |
3957 | if (!rdev->ops->del_mpath) |
3958 | return -EOPNOTSUPP; | |
3b85875a | 3959 | |
e35e4d28 | 3960 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
3961 | } |
3962 | ||
9f1ba906 JM |
3963 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
3964 | { | |
4c476991 JB |
3965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3966 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
3967 | struct bss_parameters params; |
3968 | ||
3969 | memset(¶ms, 0, sizeof(params)); | |
3970 | /* default to not changing parameters */ | |
3971 | params.use_cts_prot = -1; | |
3972 | params.use_short_preamble = -1; | |
3973 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 3974 | params.ap_isolate = -1; |
50b12f59 | 3975 | params.ht_opmode = -1; |
53cabad7 JB |
3976 | params.p2p_ctwindow = -1; |
3977 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
3978 | |
3979 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
3980 | params.use_cts_prot = | |
3981 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
3982 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
3983 | params.use_short_preamble = | |
3984 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
3985 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
3986 | params.use_short_slot_time = | |
3987 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
3988 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
3989 | params.basic_rates = | |
3990 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3991 | params.basic_rates_len = | |
3992 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3993 | } | |
fd8aaaf3 FF |
3994 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
3995 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
3996 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
3997 | params.ht_opmode = | |
3998 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 3999 | |
53cabad7 JB |
4000 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4001 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4002 | return -EINVAL; | |
4003 | params.p2p_ctwindow = | |
4004 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4005 | if (params.p2p_ctwindow < 0) | |
4006 | return -EINVAL; | |
4007 | if (params.p2p_ctwindow != 0 && | |
4008 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4009 | return -EINVAL; | |
4010 | } | |
4011 | ||
4012 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4013 | u8 tmp; | |
4014 | ||
4015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4016 | return -EINVAL; | |
4017 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4018 | if (tmp > 1) | |
4019 | return -EINVAL; | |
4020 | params.p2p_opp_ps = tmp; | |
4021 | if (params.p2p_opp_ps && | |
4022 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4023 | return -EINVAL; | |
4024 | } | |
4025 | ||
4c476991 JB |
4026 | if (!rdev->ops->change_bss) |
4027 | return -EOPNOTSUPP; | |
9f1ba906 | 4028 | |
074ac8df | 4029 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4030 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4031 | return -EOPNOTSUPP; | |
3b85875a | 4032 | |
e35e4d28 | 4033 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4034 | } |
4035 | ||
b54452b0 | 4036 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4037 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4038 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4039 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4040 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4041 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4042 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4043 | }; | |
4044 | ||
4045 | static int parse_reg_rule(struct nlattr *tb[], | |
4046 | struct ieee80211_reg_rule *reg_rule) | |
4047 | { | |
4048 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4049 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4050 | ||
4051 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4052 | return -EINVAL; | |
4053 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4054 | return -EINVAL; | |
4055 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4056 | return -EINVAL; | |
4057 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4058 | return -EINVAL; | |
4059 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4060 | return -EINVAL; | |
4061 | ||
4062 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4063 | ||
4064 | freq_range->start_freq_khz = | |
4065 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4066 | freq_range->end_freq_khz = | |
4067 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4068 | freq_range->max_bandwidth_khz = | |
4069 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4070 | ||
4071 | power_rule->max_eirp = | |
4072 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4073 | ||
4074 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4075 | power_rule->max_antenna_gain = | |
4076 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4077 | ||
4078 | return 0; | |
4079 | } | |
4080 | ||
4081 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4082 | { | |
4083 | int r; | |
4084 | char *data = NULL; | |
57b5ce07 | 4085 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4086 | |
80778f18 LR |
4087 | /* |
4088 | * You should only get this when cfg80211 hasn't yet initialized | |
4089 | * completely when built-in to the kernel right between the time | |
4090 | * window between nl80211_init() and regulatory_init(), if that is | |
4091 | * even possible. | |
4092 | */ | |
458f4f9e | 4093 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4094 | return -EINPROGRESS; |
80778f18 | 4095 | |
fe33eb39 LR |
4096 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4097 | return -EINVAL; | |
b2e1b302 LR |
4098 | |
4099 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4100 | ||
57b5ce07 LR |
4101 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4102 | user_reg_hint_type = | |
4103 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4104 | else | |
4105 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4106 | ||
4107 | switch (user_reg_hint_type) { | |
4108 | case NL80211_USER_REG_HINT_USER: | |
4109 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4110 | break; | |
4111 | default: | |
4112 | return -EINVAL; | |
4113 | } | |
4114 | ||
4115 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4116 | |
b2e1b302 LR |
4117 | return r; |
4118 | } | |
4119 | ||
24bdd9f4 | 4120 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4121 | struct genl_info *info) |
93da9cc1 | 4122 | { |
4c476991 | 4123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4124 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4125 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4126 | struct mesh_config cur_params; | |
4127 | int err = 0; | |
93da9cc1 | 4128 | void *hdr; |
4129 | struct nlattr *pinfoattr; | |
4130 | struct sk_buff *msg; | |
4131 | ||
29cbe68c JB |
4132 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4133 | return -EOPNOTSUPP; | |
4134 | ||
24bdd9f4 | 4135 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4136 | return -EOPNOTSUPP; |
f3f92586 | 4137 | |
29cbe68c JB |
4138 | wdev_lock(wdev); |
4139 | /* If not connected, get default parameters */ | |
4140 | if (!wdev->mesh_id_len) | |
4141 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4142 | else | |
e35e4d28 | 4143 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4144 | wdev_unlock(wdev); |
4145 | ||
93da9cc1 | 4146 | if (err) |
4c476991 | 4147 | return err; |
93da9cc1 | 4148 | |
4149 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4151 | if (!msg) |
4152 | return -ENOMEM; | |
15e47304 | 4153 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4154 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4155 | if (!hdr) |
efe1cf0c | 4156 | goto out; |
24bdd9f4 | 4157 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4158 | if (!pinfoattr) |
4159 | goto nla_put_failure; | |
9360ffd1 DM |
4160 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4161 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4162 | cur_params.dot11MeshRetryTimeout) || | |
4163 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4164 | cur_params.dot11MeshConfirmTimeout) || | |
4165 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4166 | cur_params.dot11MeshHoldingTimeout) || | |
4167 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4168 | cur_params.dot11MeshMaxPeerLinks) || | |
4169 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4170 | cur_params.dot11MeshMaxRetries) || | |
4171 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4172 | cur_params.dot11MeshTTL) || | |
4173 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4174 | cur_params.element_ttl) || | |
4175 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4176 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4177 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4178 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4179 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4180 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4181 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4182 | cur_params.path_refresh_time) || | |
4183 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4184 | cur_params.min_discovery_timeout) || | |
4185 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4186 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4187 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4188 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4189 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4190 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4191 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4192 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4193 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4194 | cur_params.dot11MeshHWMPRootMode) || | |
4195 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4196 | cur_params.dot11MeshHWMPRannInterval) || | |
4197 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4198 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4199 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4200 | cur_params.dot11MeshForwarding) || | |
4201 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4202 | cur_params.rssi_threshold) || |
4203 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4204 | cur_params.ht_opmode) || |
4205 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4206 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4207 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4208 | cur_params.dot11MeshHWMProotInterval) || |
4209 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4210 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4211 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4212 | cur_params.power_mode) || | |
4213 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
4214 | cur_params.dot11MeshAwakeWindowDuration)) | |
9360ffd1 | 4215 | goto nla_put_failure; |
93da9cc1 | 4216 | nla_nest_end(msg, pinfoattr); |
4217 | genlmsg_end(msg, hdr); | |
4c476991 | 4218 | return genlmsg_reply(msg, info); |
93da9cc1 | 4219 | |
3b85875a | 4220 | nla_put_failure: |
93da9cc1 | 4221 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4222 | out: |
d080e275 | 4223 | nlmsg_free(msg); |
4c476991 | 4224 | return -ENOBUFS; |
93da9cc1 | 4225 | } |
4226 | ||
b54452b0 | 4227 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4228 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4229 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4230 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4231 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4232 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4233 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4234 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4235 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4236 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4237 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4238 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4239 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4240 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4241 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4242 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4243 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4244 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4245 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4246 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4247 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4248 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4249 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4250 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4251 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4252 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4253 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4254 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
93da9cc1 | 4255 | }; |
4256 | ||
c80d545d JC |
4257 | static const struct nla_policy |
4258 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4259 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4260 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4261 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4262 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
581a8b0f | 4263 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4264 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4265 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4266 | }; |
4267 | ||
24bdd9f4 | 4268 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4269 | struct mesh_config *cfg, |
4270 | u32 *mask_out) | |
93da9cc1 | 4271 | { |
93da9cc1 | 4272 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4273 | u32 mask = 0; |
93da9cc1 | 4274 | |
ea54fba2 MP |
4275 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4276 | do { \ | |
4277 | if (tb[attr]) { \ | |
4278 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4279 | return -EINVAL; \ | |
4280 | cfg->param = fn(tb[attr]); \ | |
4281 | mask |= (1 << (attr - 1)); \ | |
4282 | } \ | |
4283 | } while (0) | |
bd90fdcc JB |
4284 | |
4285 | ||
24bdd9f4 | 4286 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4287 | return -EINVAL; |
4288 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4289 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4290 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4291 | return -EINVAL; |
4292 | ||
93da9cc1 | 4293 | /* This makes sure that there aren't more than 32 mesh config |
4294 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4295 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4296 | ||
4297 | /* Fill in the params struct */ | |
ea54fba2 | 4298 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4299 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4300 | nla_get_u16); | |
ea54fba2 | 4301 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4302 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4303 | nla_get_u16); | |
ea54fba2 | 4304 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4305 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4306 | nla_get_u16); | |
ea54fba2 | 4307 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4308 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4309 | nla_get_u16); | |
ea54fba2 | 4310 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4311 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4312 | nla_get_u8); | |
ea54fba2 | 4313 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4314 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4315 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4316 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4317 | nla_get_u8); | |
ea54fba2 | 4318 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4319 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4320 | nla_get_u8); | |
ea54fba2 MP |
4321 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4322 | 1, 255, mask, | |
a4f606ea CYY |
4323 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4324 | nla_get_u32); | |
ea54fba2 | 4325 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4326 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4327 | nla_get_u8); | |
ea54fba2 | 4328 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4329 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4330 | nla_get_u32); | |
ea54fba2 | 4331 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4332 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4333 | nla_get_u16); | |
ea54fba2 MP |
4334 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4335 | 1, 65535, mask, | |
a4f606ea CYY |
4336 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4337 | nla_get_u32); | |
93da9cc1 | 4338 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4339 | 1, 65535, mask, |
4340 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4341 | nla_get_u16); |
dca7e943 | 4342 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4343 | 1, 65535, mask, |
4344 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4345 | nla_get_u16); |
93da9cc1 | 4346 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4347 | dot11MeshHWMPnetDiameterTraversalTime, |
4348 | 1, 65535, mask, | |
a4f606ea CYY |
4349 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4350 | nla_get_u16); | |
ea54fba2 MP |
4351 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4352 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4353 | nla_get_u8); | |
4354 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4355 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4356 | nla_get_u16); |
63c5723b | 4357 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4358 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4359 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4360 | nla_get_u8); |
ea54fba2 | 4361 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4362 | mask, NL80211_MESHCONF_FORWARDING, |
4363 | nla_get_u8); | |
ea54fba2 | 4364 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4365 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4366 | nla_get_u32); | |
ea54fba2 | 4367 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4368 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4369 | nla_get_u16); |
4370 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4371 | 1, 65535, mask, |
ac1073a6 CYY |
4372 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4373 | nla_get_u32); | |
ea54fba2 | 4374 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4375 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4376 | nla_get_u16); |
4377 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4378 | dot11MeshHWMPconfirmationInterval, |
4379 | 1, 65535, mask, | |
728b19e5 | 4380 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4381 | nla_get_u16); |
3b1c5a53 MP |
4382 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4383 | NL80211_MESH_POWER_ACTIVE, | |
4384 | NL80211_MESH_POWER_MAX, | |
4385 | mask, NL80211_MESHCONF_POWER_MODE, | |
4386 | nla_get_u32); | |
4387 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4388 | 0, 65535, mask, | |
4389 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
bd90fdcc JB |
4390 | if (mask_out) |
4391 | *mask_out = mask; | |
c80d545d | 4392 | |
bd90fdcc JB |
4393 | return 0; |
4394 | ||
4395 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4396 | } | |
4397 | ||
c80d545d JC |
4398 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4399 | struct mesh_setup *setup) | |
4400 | { | |
4401 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | |
4402 | ||
4403 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4404 | return -EINVAL; | |
4405 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4406 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4407 | nl80211_mesh_setup_params_policy)) | |
4408 | return -EINVAL; | |
4409 | ||
d299a1f2 JC |
4410 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4411 | setup->sync_method = | |
4412 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4413 | IEEE80211_SYNC_METHOD_VENDOR : | |
4414 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4415 | ||
c80d545d JC |
4416 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4417 | setup->path_sel_proto = | |
4418 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4419 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4420 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4421 | ||
4422 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4423 | setup->path_metric = | |
4424 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4425 | IEEE80211_PATH_METRIC_VENDOR : | |
4426 | IEEE80211_PATH_METRIC_AIRTIME; | |
4427 | ||
581a8b0f JC |
4428 | |
4429 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4430 | struct nlattr *ieattr = |
581a8b0f | 4431 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4432 | if (!is_valid_ie_attr(ieattr)) |
4433 | return -EINVAL; | |
581a8b0f JC |
4434 | setup->ie = nla_data(ieattr); |
4435 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4436 | } |
b130e5ce JC |
4437 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4438 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
c80d545d JC |
4439 | |
4440 | return 0; | |
4441 | } | |
4442 | ||
24bdd9f4 | 4443 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4444 | struct genl_info *info) |
bd90fdcc JB |
4445 | { |
4446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4447 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4448 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4449 | struct mesh_config cfg; |
4450 | u32 mask; | |
4451 | int err; | |
4452 | ||
29cbe68c JB |
4453 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4454 | return -EOPNOTSUPP; | |
4455 | ||
24bdd9f4 | 4456 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4457 | return -EOPNOTSUPP; |
4458 | ||
24bdd9f4 | 4459 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4460 | if (err) |
4461 | return err; | |
4462 | ||
29cbe68c JB |
4463 | wdev_lock(wdev); |
4464 | if (!wdev->mesh_id_len) | |
4465 | err = -ENOLINK; | |
4466 | ||
4467 | if (!err) | |
e35e4d28 | 4468 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4469 | |
4470 | wdev_unlock(wdev); | |
4471 | ||
4472 | return err; | |
93da9cc1 | 4473 | } |
4474 | ||
f130347c LR |
4475 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4476 | { | |
458f4f9e | 4477 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4478 | struct sk_buff *msg; |
4479 | void *hdr = NULL; | |
4480 | struct nlattr *nl_reg_rules; | |
4481 | unsigned int i; | |
4482 | int err = -EINVAL; | |
4483 | ||
a1794390 | 4484 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
4485 | |
4486 | if (!cfg80211_regdomain) | |
4487 | goto out; | |
4488 | ||
fd2120ca | 4489 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
4490 | if (!msg) { |
4491 | err = -ENOBUFS; | |
4492 | goto out; | |
4493 | } | |
4494 | ||
15e47304 | 4495 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4496 | NL80211_CMD_GET_REG); |
4497 | if (!hdr) | |
efe1cf0c | 4498 | goto put_failure; |
f130347c | 4499 | |
57b5ce07 LR |
4500 | if (reg_last_request_cell_base() && |
4501 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4502 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4503 | goto nla_put_failure; | |
4504 | ||
458f4f9e JB |
4505 | rcu_read_lock(); |
4506 | regdom = rcu_dereference(cfg80211_regdomain); | |
4507 | ||
4508 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4509 | (regdom->dfs_region && | |
4510 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4511 | goto nla_put_failure_rcu; | |
4512 | ||
f130347c LR |
4513 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4514 | if (!nl_reg_rules) | |
458f4f9e | 4515 | goto nla_put_failure_rcu; |
f130347c | 4516 | |
458f4f9e | 4517 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4518 | struct nlattr *nl_reg_rule; |
4519 | const struct ieee80211_reg_rule *reg_rule; | |
4520 | const struct ieee80211_freq_range *freq_range; | |
4521 | const struct ieee80211_power_rule *power_rule; | |
4522 | ||
458f4f9e | 4523 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4524 | freq_range = ®_rule->freq_range; |
4525 | power_rule = ®_rule->power_rule; | |
4526 | ||
4527 | nl_reg_rule = nla_nest_start(msg, i); | |
4528 | if (!nl_reg_rule) | |
458f4f9e | 4529 | goto nla_put_failure_rcu; |
f130347c | 4530 | |
9360ffd1 DM |
4531 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4532 | reg_rule->flags) || | |
4533 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4534 | freq_range->start_freq_khz) || | |
4535 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4536 | freq_range->end_freq_khz) || | |
4537 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4538 | freq_range->max_bandwidth_khz) || | |
4539 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4540 | power_rule->max_antenna_gain) || | |
4541 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4542 | power_rule->max_eirp)) | |
458f4f9e | 4543 | goto nla_put_failure_rcu; |
f130347c LR |
4544 | |
4545 | nla_nest_end(msg, nl_reg_rule); | |
4546 | } | |
458f4f9e | 4547 | rcu_read_unlock(); |
f130347c LR |
4548 | |
4549 | nla_nest_end(msg, nl_reg_rules); | |
4550 | ||
4551 | genlmsg_end(msg, hdr); | |
134e6375 | 4552 | err = genlmsg_reply(msg, info); |
f130347c LR |
4553 | goto out; |
4554 | ||
458f4f9e JB |
4555 | nla_put_failure_rcu: |
4556 | rcu_read_unlock(); | |
f130347c LR |
4557 | nla_put_failure: |
4558 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4559 | put_failure: |
d080e275 | 4560 | nlmsg_free(msg); |
f130347c LR |
4561 | err = -EMSGSIZE; |
4562 | out: | |
a1794390 | 4563 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
4564 | return err; |
4565 | } | |
4566 | ||
b2e1b302 LR |
4567 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
4568 | { | |
4569 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
4570 | struct nlattr *nl_reg_rule; | |
4571 | char *alpha2 = NULL; | |
4572 | int rem_reg_rules = 0, r = 0; | |
4573 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 4574 | u8 dfs_region = 0; |
b2e1b302 LR |
4575 | struct ieee80211_regdomain *rd = NULL; |
4576 | ||
4577 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
4578 | return -EINVAL; | |
4579 | ||
4580 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
4581 | return -EINVAL; | |
4582 | ||
4583 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4584 | ||
8b60b078 LR |
4585 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
4586 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
4587 | ||
b2e1b302 | 4588 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4589 | rem_reg_rules) { |
b2e1b302 LR |
4590 | num_rules++; |
4591 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 4592 | return -EINVAL; |
b2e1b302 LR |
4593 | } |
4594 | ||
b2e1b302 | 4595 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 4596 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
4597 | |
4598 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
4599 | if (!rd) |
4600 | return -ENOMEM; | |
b2e1b302 LR |
4601 | |
4602 | rd->n_reg_rules = num_rules; | |
4603 | rd->alpha2[0] = alpha2[0]; | |
4604 | rd->alpha2[1] = alpha2[1]; | |
4605 | ||
8b60b078 LR |
4606 | /* |
4607 | * Disable DFS master mode if the DFS region was | |
4608 | * not supported or known on this kernel. | |
4609 | */ | |
4610 | if (reg_supported_dfs_region(dfs_region)) | |
4611 | rd->dfs_region = dfs_region; | |
4612 | ||
b2e1b302 | 4613 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4614 | rem_reg_rules) { |
b2e1b302 | 4615 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
4616 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
4617 | reg_rule_policy); | |
b2e1b302 LR |
4618 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
4619 | if (r) | |
4620 | goto bad_reg; | |
4621 | ||
4622 | rule_idx++; | |
4623 | ||
d0e18f83 LR |
4624 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
4625 | r = -EINVAL; | |
b2e1b302 | 4626 | goto bad_reg; |
d0e18f83 | 4627 | } |
b2e1b302 LR |
4628 | } |
4629 | ||
6913b49a JB |
4630 | mutex_lock(&cfg80211_mutex); |
4631 | ||
b2e1b302 | 4632 | r = set_regdom(rd); |
6913b49a | 4633 | /* set_regdom took ownership */ |
1a919318 | 4634 | rd = NULL; |
6913b49a | 4635 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 4636 | |
d2372b31 | 4637 | bad_reg: |
b2e1b302 | 4638 | kfree(rd); |
d0e18f83 | 4639 | return r; |
b2e1b302 LR |
4640 | } |
4641 | ||
83f5e2cf JB |
4642 | static int validate_scan_freqs(struct nlattr *freqs) |
4643 | { | |
4644 | struct nlattr *attr1, *attr2; | |
4645 | int n_channels = 0, tmp1, tmp2; | |
4646 | ||
4647 | nla_for_each_nested(attr1, freqs, tmp1) { | |
4648 | n_channels++; | |
4649 | /* | |
4650 | * Some hardware has a limited channel list for | |
4651 | * scanning, and it is pretty much nonsensical | |
4652 | * to scan for a channel twice, so disallow that | |
4653 | * and don't require drivers to check that the | |
4654 | * channel list they get isn't longer than what | |
4655 | * they can scan, as long as they can scan all | |
4656 | * the channels they registered at once. | |
4657 | */ | |
4658 | nla_for_each_nested(attr2, freqs, tmp2) | |
4659 | if (attr1 != attr2 && | |
4660 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
4661 | return 0; | |
4662 | } | |
4663 | ||
4664 | return n_channels; | |
4665 | } | |
4666 | ||
2a519311 JB |
4667 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
4668 | { | |
4c476991 | 4669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 4670 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 4671 | struct cfg80211_scan_request *request; |
2a519311 JB |
4672 | struct nlattr *attr; |
4673 | struct wiphy *wiphy; | |
83f5e2cf | 4674 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 4675 | size_t ie_len; |
2a519311 | 4676 | |
f4a11bb0 JB |
4677 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4678 | return -EINVAL; | |
4679 | ||
79c97e97 | 4680 | wiphy = &rdev->wiphy; |
2a519311 | 4681 | |
4c476991 JB |
4682 | if (!rdev->ops->scan) |
4683 | return -EOPNOTSUPP; | |
2a519311 | 4684 | |
4c476991 JB |
4685 | if (rdev->scan_req) |
4686 | return -EBUSY; | |
2a519311 JB |
4687 | |
4688 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
4689 | n_channels = validate_scan_freqs( |
4690 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
4691 | if (!n_channels) |
4692 | return -EINVAL; | |
2a519311 | 4693 | } else { |
34850ab2 | 4694 | enum ieee80211_band band; |
83f5e2cf JB |
4695 | n_channels = 0; |
4696 | ||
2a519311 JB |
4697 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
4698 | if (wiphy->bands[band]) | |
4699 | n_channels += wiphy->bands[band]->n_channels; | |
4700 | } | |
4701 | ||
4702 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
4703 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
4704 | n_ssids++; | |
4705 | ||
4c476991 JB |
4706 | if (n_ssids > wiphy->max_scan_ssids) |
4707 | return -EINVAL; | |
2a519311 | 4708 | |
70692ad2 JM |
4709 | if (info->attrs[NL80211_ATTR_IE]) |
4710 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4711 | else | |
4712 | ie_len = 0; | |
4713 | ||
4c476991 JB |
4714 | if (ie_len > wiphy->max_scan_ie_len) |
4715 | return -EINVAL; | |
18a83659 | 4716 | |
2a519311 | 4717 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
4718 | + sizeof(*request->ssids) * n_ssids |
4719 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 4720 | + ie_len, GFP_KERNEL); |
4c476991 JB |
4721 | if (!request) |
4722 | return -ENOMEM; | |
2a519311 | 4723 | |
2a519311 | 4724 | if (n_ssids) |
5ba63533 | 4725 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 4726 | request->n_ssids = n_ssids; |
70692ad2 JM |
4727 | if (ie_len) { |
4728 | if (request->ssids) | |
4729 | request->ie = (void *)(request->ssids + n_ssids); | |
4730 | else | |
4731 | request->ie = (void *)(request->channels + n_channels); | |
4732 | } | |
2a519311 | 4733 | |
584991dc | 4734 | i = 0; |
2a519311 JB |
4735 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
4736 | /* user specified, bail out if channel not found */ | |
2a519311 | 4737 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
4738 | struct ieee80211_channel *chan; |
4739 | ||
4740 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
4741 | ||
4742 | if (!chan) { | |
2a519311 JB |
4743 | err = -EINVAL; |
4744 | goto out_free; | |
4745 | } | |
584991dc JB |
4746 | |
4747 | /* ignore disabled channels */ | |
4748 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4749 | continue; | |
4750 | ||
4751 | request->channels[i] = chan; | |
2a519311 JB |
4752 | i++; |
4753 | } | |
4754 | } else { | |
34850ab2 JB |
4755 | enum ieee80211_band band; |
4756 | ||
2a519311 | 4757 | /* all channels */ |
2a519311 JB |
4758 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
4759 | int j; | |
4760 | if (!wiphy->bands[band]) | |
4761 | continue; | |
4762 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
4763 | struct ieee80211_channel *chan; |
4764 | ||
4765 | chan = &wiphy->bands[band]->channels[j]; | |
4766 | ||
4767 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4768 | continue; | |
4769 | ||
4770 | request->channels[i] = chan; | |
2a519311 JB |
4771 | i++; |
4772 | } | |
4773 | } | |
4774 | } | |
4775 | ||
584991dc JB |
4776 | if (!i) { |
4777 | err = -EINVAL; | |
4778 | goto out_free; | |
4779 | } | |
4780 | ||
4781 | request->n_channels = i; | |
4782 | ||
2a519311 JB |
4783 | i = 0; |
4784 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
4785 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 4786 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
4787 | err = -EINVAL; |
4788 | goto out_free; | |
4789 | } | |
57a27e1d | 4790 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 4791 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
4792 | i++; |
4793 | } | |
4794 | } | |
4795 | ||
70692ad2 JM |
4796 | if (info->attrs[NL80211_ATTR_IE]) { |
4797 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
4798 | memcpy((void *)request->ie, |
4799 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
4800 | request->ie_len); |
4801 | } | |
4802 | ||
34850ab2 | 4803 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
4804 | if (wiphy->bands[i]) |
4805 | request->rates[i] = | |
4806 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
4807 | |
4808 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
4809 | nla_for_each_nested(attr, | |
4810 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
4811 | tmp) { | |
4812 | enum ieee80211_band band = nla_type(attr); | |
4813 | ||
84404623 | 4814 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
4815 | err = -EINVAL; |
4816 | goto out_free; | |
4817 | } | |
4818 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
4819 | nla_data(attr), | |
4820 | nla_len(attr), | |
4821 | &request->rates[band]); | |
4822 | if (err) | |
4823 | goto out_free; | |
4824 | } | |
4825 | } | |
4826 | ||
46856bbf | 4827 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
4828 | request->flags = nla_get_u32( |
4829 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
4830 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
4831 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
4832 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
4833 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
4834 | err = -EOPNOTSUPP; |
4835 | goto out_free; | |
4836 | } | |
4837 | } | |
ed473771 | 4838 | |
e9f935e3 RM |
4839 | request->no_cck = |
4840 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
4841 | ||
fd014284 | 4842 | request->wdev = wdev; |
79c97e97 | 4843 | request->wiphy = &rdev->wiphy; |
15d6030b | 4844 | request->scan_start = jiffies; |
2a519311 | 4845 | |
79c97e97 | 4846 | rdev->scan_req = request; |
e35e4d28 | 4847 | err = rdev_scan(rdev, request); |
2a519311 | 4848 | |
463d0183 | 4849 | if (!err) { |
fd014284 JB |
4850 | nl80211_send_scan_start(rdev, wdev); |
4851 | if (wdev->netdev) | |
4852 | dev_hold(wdev->netdev); | |
4c476991 | 4853 | } else { |
2a519311 | 4854 | out_free: |
79c97e97 | 4855 | rdev->scan_req = NULL; |
2a519311 JB |
4856 | kfree(request); |
4857 | } | |
3b85875a | 4858 | |
2a519311 JB |
4859 | return err; |
4860 | } | |
4861 | ||
807f8a8c LC |
4862 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
4863 | struct genl_info *info) | |
4864 | { | |
4865 | struct cfg80211_sched_scan_request *request; | |
4866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4867 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
4868 | struct nlattr *attr; |
4869 | struct wiphy *wiphy; | |
a1f1c21c | 4870 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 4871 | u32 interval; |
807f8a8c LC |
4872 | enum ieee80211_band band; |
4873 | size_t ie_len; | |
a1f1c21c | 4874 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
4875 | |
4876 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
4877 | !rdev->ops->sched_scan_start) | |
4878 | return -EOPNOTSUPP; | |
4879 | ||
4880 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4881 | return -EINVAL; | |
4882 | ||
bbe6ad6d LC |
4883 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
4884 | return -EINVAL; | |
4885 | ||
4886 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
4887 | if (interval == 0) | |
4888 | return -EINVAL; | |
4889 | ||
807f8a8c LC |
4890 | wiphy = &rdev->wiphy; |
4891 | ||
4892 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
4893 | n_channels = validate_scan_freqs( | |
4894 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4895 | if (!n_channels) | |
4896 | return -EINVAL; | |
4897 | } else { | |
4898 | n_channels = 0; | |
4899 | ||
4900 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
4901 | if (wiphy->bands[band]) | |
4902 | n_channels += wiphy->bands[band]->n_channels; | |
4903 | } | |
4904 | ||
4905 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
4906 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
4907 | tmp) | |
4908 | n_ssids++; | |
4909 | ||
93b6aa69 | 4910 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
4911 | return -EINVAL; |
4912 | ||
a1f1c21c LC |
4913 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
4914 | nla_for_each_nested(attr, | |
4915 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
4916 | tmp) | |
4917 | n_match_sets++; | |
4918 | ||
4919 | if (n_match_sets > wiphy->max_match_sets) | |
4920 | return -EINVAL; | |
4921 | ||
807f8a8c LC |
4922 | if (info->attrs[NL80211_ATTR_IE]) |
4923 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4924 | else | |
4925 | ie_len = 0; | |
4926 | ||
5a865bad | 4927 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
4928 | return -EINVAL; |
4929 | ||
c10841ca LC |
4930 | mutex_lock(&rdev->sched_scan_mtx); |
4931 | ||
4932 | if (rdev->sched_scan_req) { | |
4933 | err = -EINPROGRESS; | |
4934 | goto out; | |
4935 | } | |
4936 | ||
807f8a8c | 4937 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 4938 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 4939 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 4940 | + sizeof(*request->channels) * n_channels |
807f8a8c | 4941 | + ie_len, GFP_KERNEL); |
c10841ca LC |
4942 | if (!request) { |
4943 | err = -ENOMEM; | |
4944 | goto out; | |
4945 | } | |
807f8a8c LC |
4946 | |
4947 | if (n_ssids) | |
4948 | request->ssids = (void *)&request->channels[n_channels]; | |
4949 | request->n_ssids = n_ssids; | |
4950 | if (ie_len) { | |
4951 | if (request->ssids) | |
4952 | request->ie = (void *)(request->ssids + n_ssids); | |
4953 | else | |
4954 | request->ie = (void *)(request->channels + n_channels); | |
4955 | } | |
4956 | ||
a1f1c21c LC |
4957 | if (n_match_sets) { |
4958 | if (request->ie) | |
4959 | request->match_sets = (void *)(request->ie + ie_len); | |
4960 | else if (request->ssids) | |
4961 | request->match_sets = | |
4962 | (void *)(request->ssids + n_ssids); | |
4963 | else | |
4964 | request->match_sets = | |
4965 | (void *)(request->channels + n_channels); | |
4966 | } | |
4967 | request->n_match_sets = n_match_sets; | |
4968 | ||
807f8a8c LC |
4969 | i = 0; |
4970 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
4971 | /* user specified, bail out if channel not found */ | |
4972 | nla_for_each_nested(attr, | |
4973 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
4974 | tmp) { | |
4975 | struct ieee80211_channel *chan; | |
4976 | ||
4977 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
4978 | ||
4979 | if (!chan) { | |
4980 | err = -EINVAL; | |
4981 | goto out_free; | |
4982 | } | |
4983 | ||
4984 | /* ignore disabled channels */ | |
4985 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4986 | continue; | |
4987 | ||
4988 | request->channels[i] = chan; | |
4989 | i++; | |
4990 | } | |
4991 | } else { | |
4992 | /* all channels */ | |
4993 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
4994 | int j; | |
4995 | if (!wiphy->bands[band]) | |
4996 | continue; | |
4997 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
4998 | struct ieee80211_channel *chan; | |
4999 | ||
5000 | chan = &wiphy->bands[band]->channels[j]; | |
5001 | ||
5002 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5003 | continue; | |
5004 | ||
5005 | request->channels[i] = chan; | |
5006 | i++; | |
5007 | } | |
5008 | } | |
5009 | } | |
5010 | ||
5011 | if (!i) { | |
5012 | err = -EINVAL; | |
5013 | goto out_free; | |
5014 | } | |
5015 | ||
5016 | request->n_channels = i; | |
5017 | ||
5018 | i = 0; | |
5019 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5020 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5021 | tmp) { | |
57a27e1d | 5022 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5023 | err = -EINVAL; |
5024 | goto out_free; | |
5025 | } | |
57a27e1d | 5026 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5027 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5028 | nla_len(attr)); | |
807f8a8c LC |
5029 | i++; |
5030 | } | |
5031 | } | |
5032 | ||
a1f1c21c LC |
5033 | i = 0; |
5034 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5035 | nla_for_each_nested(attr, | |
5036 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5037 | tmp) { | |
88e920b4 | 5038 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5039 | |
5040 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5041 | nla_data(attr), nla_len(attr), | |
5042 | nl80211_match_policy); | |
4a4ab0d7 | 5043 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5044 | if (ssid) { |
5045 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5046 | err = -EINVAL; | |
5047 | goto out_free; | |
5048 | } | |
5049 | memcpy(request->match_sets[i].ssid.ssid, | |
5050 | nla_data(ssid), nla_len(ssid)); | |
5051 | request->match_sets[i].ssid.ssid_len = | |
5052 | nla_len(ssid); | |
5053 | } | |
88e920b4 TP |
5054 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5055 | if (rssi) | |
5056 | request->rssi_thold = nla_get_u32(rssi); | |
5057 | else | |
5058 | request->rssi_thold = | |
5059 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5060 | i++; |
5061 | } | |
5062 | } | |
5063 | ||
807f8a8c LC |
5064 | if (info->attrs[NL80211_ATTR_IE]) { |
5065 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5066 | memcpy((void *)request->ie, | |
5067 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5068 | request->ie_len); | |
5069 | } | |
5070 | ||
46856bbf | 5071 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5072 | request->flags = nla_get_u32( |
5073 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5074 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5075 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5076 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5077 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5078 | err = -EOPNOTSUPP; |
5079 | goto out_free; | |
5080 | } | |
5081 | } | |
ed473771 | 5082 | |
807f8a8c LC |
5083 | request->dev = dev; |
5084 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5085 | request->interval = interval; |
15d6030b | 5086 | request->scan_start = jiffies; |
807f8a8c | 5087 | |
e35e4d28 | 5088 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5089 | if (!err) { |
5090 | rdev->sched_scan_req = request; | |
5091 | nl80211_send_sched_scan(rdev, dev, | |
5092 | NL80211_CMD_START_SCHED_SCAN); | |
5093 | goto out; | |
5094 | } | |
5095 | ||
5096 | out_free: | |
5097 | kfree(request); | |
5098 | out: | |
c10841ca | 5099 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
5100 | return err; |
5101 | } | |
5102 | ||
5103 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5104 | struct genl_info *info) | |
5105 | { | |
5106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 5107 | int err; |
807f8a8c LC |
5108 | |
5109 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5110 | !rdev->ops->sched_scan_stop) | |
5111 | return -EOPNOTSUPP; | |
5112 | ||
c10841ca LC |
5113 | mutex_lock(&rdev->sched_scan_mtx); |
5114 | err = __cfg80211_stop_sched_scan(rdev, false); | |
5115 | mutex_unlock(&rdev->sched_scan_mtx); | |
5116 | ||
5117 | return err; | |
807f8a8c LC |
5118 | } |
5119 | ||
04f39047 SW |
5120 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5121 | struct genl_info *info) | |
5122 | { | |
5123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5124 | struct net_device *dev = info->user_ptr[1]; | |
5125 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5126 | struct cfg80211_chan_def chandef; | |
5127 | int err; | |
5128 | ||
5129 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5130 | if (err) | |
5131 | return err; | |
5132 | ||
5133 | if (wdev->cac_started) | |
5134 | return -EBUSY; | |
5135 | ||
5136 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5137 | if (err < 0) | |
5138 | return err; | |
5139 | ||
5140 | if (err == 0) | |
5141 | return -EINVAL; | |
5142 | ||
5143 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5144 | return -EINVAL; | |
5145 | ||
5146 | if (!rdev->ops->start_radar_detection) | |
5147 | return -EOPNOTSUPP; | |
5148 | ||
5149 | mutex_lock(&rdev->devlist_mtx); | |
5150 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5151 | chandef.chan, CHAN_MODE_SHARED, | |
5152 | BIT(chandef.width)); | |
5153 | if (err) | |
5154 | goto err_locked; | |
5155 | ||
5156 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5157 | if (!err) { | |
5158 | wdev->channel = chandef.chan; | |
5159 | wdev->cac_started = true; | |
5160 | wdev->cac_start_time = jiffies; | |
5161 | } | |
5162 | err_locked: | |
5163 | mutex_unlock(&rdev->devlist_mtx); | |
5164 | ||
5165 | return err; | |
5166 | } | |
5167 | ||
9720bb3a JB |
5168 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5169 | u32 seq, int flags, | |
2a519311 | 5170 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5171 | struct wireless_dev *wdev, |
5172 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5173 | { |
48ab905d | 5174 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5175 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5176 | void *hdr; |
5177 | struct nlattr *bss; | |
8cef2c9d | 5178 | bool tsf = false; |
48ab905d JB |
5179 | |
5180 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5181 | |
15e47304 | 5182 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5183 | NL80211_CMD_NEW_SCAN_RESULTS); |
5184 | if (!hdr) | |
5185 | return -1; | |
5186 | ||
9720bb3a JB |
5187 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5188 | ||
9360ffd1 DM |
5189 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
5190 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | |
5191 | goto nla_put_failure; | |
2a519311 JB |
5192 | |
5193 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5194 | if (!bss) | |
5195 | goto nla_put_failure; | |
9360ffd1 | 5196 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5197 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5198 | goto nla_put_failure; |
9caf0364 JB |
5199 | |
5200 | rcu_read_lock(); | |
5201 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5202 | if (ies) { |
5203 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5204 | goto fail_unlock_rcu; | |
5205 | tsf = true; | |
5206 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5207 | ies->len, ies->data)) | |
5208 | goto fail_unlock_rcu; | |
9caf0364 JB |
5209 | } |
5210 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5211 | if (ies) { |
5212 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5213 | goto fail_unlock_rcu; | |
5214 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5215 | ies->len, ies->data)) | |
5216 | goto fail_unlock_rcu; | |
9caf0364 JB |
5217 | } |
5218 | rcu_read_unlock(); | |
5219 | ||
9360ffd1 DM |
5220 | if (res->beacon_interval && |
5221 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5222 | goto nla_put_failure; | |
5223 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5224 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5225 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5226 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5227 | goto nla_put_failure; | |
2a519311 | 5228 | |
77965c97 | 5229 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5230 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5231 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5232 | goto nla_put_failure; | |
2a519311 JB |
5233 | break; |
5234 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5235 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5236 | goto nla_put_failure; | |
2a519311 JB |
5237 | break; |
5238 | default: | |
5239 | break; | |
5240 | } | |
5241 | ||
48ab905d | 5242 | switch (wdev->iftype) { |
074ac8df | 5243 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5244 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5245 | if (intbss == wdev->current_bss && |
5246 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5247 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5248 | goto nla_put_failure; | |
48ab905d JB |
5249 | break; |
5250 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5251 | if (intbss == wdev->current_bss && |
5252 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5253 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5254 | goto nla_put_failure; | |
48ab905d JB |
5255 | break; |
5256 | default: | |
5257 | break; | |
5258 | } | |
5259 | ||
2a519311 JB |
5260 | nla_nest_end(msg, bss); |
5261 | ||
5262 | return genlmsg_end(msg, hdr); | |
5263 | ||
8cef2c9d JB |
5264 | fail_unlock_rcu: |
5265 | rcu_read_unlock(); | |
2a519311 JB |
5266 | nla_put_failure: |
5267 | genlmsg_cancel(msg, hdr); | |
5268 | return -EMSGSIZE; | |
5269 | } | |
5270 | ||
5271 | static int nl80211_dump_scan(struct sk_buff *skb, | |
5272 | struct netlink_callback *cb) | |
5273 | { | |
48ab905d JB |
5274 | struct cfg80211_registered_device *rdev; |
5275 | struct net_device *dev; | |
2a519311 | 5276 | struct cfg80211_internal_bss *scan; |
48ab905d | 5277 | struct wireless_dev *wdev; |
2a519311 JB |
5278 | int start = cb->args[1], idx = 0; |
5279 | int err; | |
5280 | ||
67748893 JB |
5281 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
5282 | if (err) | |
5283 | return err; | |
2a519311 | 5284 | |
48ab905d | 5285 | wdev = dev->ieee80211_ptr; |
2a519311 | 5286 | |
48ab905d JB |
5287 | wdev_lock(wdev); |
5288 | spin_lock_bh(&rdev->bss_lock); | |
5289 | cfg80211_bss_expire(rdev); | |
5290 | ||
9720bb3a JB |
5291 | cb->seq = rdev->bss_generation; |
5292 | ||
48ab905d | 5293 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5294 | if (++idx <= start) |
5295 | continue; | |
9720bb3a | 5296 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5297 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5298 | rdev, wdev, scan) < 0) { |
2a519311 | 5299 | idx--; |
67748893 | 5300 | break; |
2a519311 JB |
5301 | } |
5302 | } | |
5303 | ||
48ab905d JB |
5304 | spin_unlock_bh(&rdev->bss_lock); |
5305 | wdev_unlock(wdev); | |
2a519311 JB |
5306 | |
5307 | cb->args[1] = idx; | |
67748893 | 5308 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 5309 | |
67748893 | 5310 | return skb->len; |
2a519311 JB |
5311 | } |
5312 | ||
15e47304 | 5313 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5314 | int flags, struct net_device *dev, |
5315 | struct survey_info *survey) | |
5316 | { | |
5317 | void *hdr; | |
5318 | struct nlattr *infoattr; | |
5319 | ||
15e47304 | 5320 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5321 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5322 | if (!hdr) | |
5323 | return -ENOMEM; | |
5324 | ||
9360ffd1 DM |
5325 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5326 | goto nla_put_failure; | |
61fa713c HS |
5327 | |
5328 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5329 | if (!infoattr) | |
5330 | goto nla_put_failure; | |
5331 | ||
9360ffd1 DM |
5332 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5333 | survey->channel->center_freq)) | |
5334 | goto nla_put_failure; | |
5335 | ||
5336 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5337 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5338 | goto nla_put_failure; | |
5339 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5340 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5341 | goto nla_put_failure; | |
5342 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5343 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5344 | survey->channel_time)) | |
5345 | goto nla_put_failure; | |
5346 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5347 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5348 | survey->channel_time_busy)) | |
5349 | goto nla_put_failure; | |
5350 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5351 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5352 | survey->channel_time_ext_busy)) | |
5353 | goto nla_put_failure; | |
5354 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5355 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5356 | survey->channel_time_rx)) | |
5357 | goto nla_put_failure; | |
5358 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5359 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5360 | survey->channel_time_tx)) | |
5361 | goto nla_put_failure; | |
61fa713c HS |
5362 | |
5363 | nla_nest_end(msg, infoattr); | |
5364 | ||
5365 | return genlmsg_end(msg, hdr); | |
5366 | ||
5367 | nla_put_failure: | |
5368 | genlmsg_cancel(msg, hdr); | |
5369 | return -EMSGSIZE; | |
5370 | } | |
5371 | ||
5372 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5373 | struct netlink_callback *cb) | |
5374 | { | |
5375 | struct survey_info survey; | |
5376 | struct cfg80211_registered_device *dev; | |
5377 | struct net_device *netdev; | |
61fa713c HS |
5378 | int survey_idx = cb->args[1]; |
5379 | int res; | |
5380 | ||
67748893 JB |
5381 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
5382 | if (res) | |
5383 | return res; | |
61fa713c HS |
5384 | |
5385 | if (!dev->ops->dump_survey) { | |
5386 | res = -EOPNOTSUPP; | |
5387 | goto out_err; | |
5388 | } | |
5389 | ||
5390 | while (1) { | |
180cdc79 LR |
5391 | struct ieee80211_channel *chan; |
5392 | ||
e35e4d28 | 5393 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
61fa713c HS |
5394 | if (res == -ENOENT) |
5395 | break; | |
5396 | if (res) | |
5397 | goto out_err; | |
5398 | ||
180cdc79 LR |
5399 | /* Survey without a channel doesn't make sense */ |
5400 | if (!survey.channel) { | |
5401 | res = -EINVAL; | |
5402 | goto out; | |
5403 | } | |
5404 | ||
5405 | chan = ieee80211_get_channel(&dev->wiphy, | |
5406 | survey.channel->center_freq); | |
5407 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5408 | survey_idx++; | |
5409 | continue; | |
5410 | } | |
5411 | ||
61fa713c | 5412 | if (nl80211_send_survey(skb, |
15e47304 | 5413 | NETLINK_CB(cb->skb).portid, |
61fa713c HS |
5414 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
5415 | netdev, | |
5416 | &survey) < 0) | |
5417 | goto out; | |
5418 | survey_idx++; | |
5419 | } | |
5420 | ||
5421 | out: | |
5422 | cb->args[1] = survey_idx; | |
5423 | res = skb->len; | |
5424 | out_err: | |
67748893 | 5425 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
5426 | return res; |
5427 | } | |
5428 | ||
b23aa676 SO |
5429 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5430 | { | |
5431 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5432 | NL80211_WPA_VERSION_2)); | |
5433 | } | |
5434 | ||
636a5d36 JM |
5435 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5436 | { | |
4c476991 JB |
5437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5438 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5439 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5440 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5441 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5442 | enum nl80211_auth_type auth_type; |
fffd0934 | 5443 | struct key_parse key; |
d5cdfacb | 5444 | bool local_state_change; |
636a5d36 | 5445 | |
f4a11bb0 JB |
5446 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5447 | return -EINVAL; | |
5448 | ||
5449 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5450 | return -EINVAL; | |
5451 | ||
1778092e JM |
5452 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5453 | return -EINVAL; | |
5454 | ||
19957bb3 JB |
5455 | if (!info->attrs[NL80211_ATTR_SSID]) |
5456 | return -EINVAL; | |
5457 | ||
5458 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5459 | return -EINVAL; | |
5460 | ||
fffd0934 JB |
5461 | err = nl80211_parse_key(info, &key); |
5462 | if (err) | |
5463 | return err; | |
5464 | ||
5465 | if (key.idx >= 0) { | |
e31b8213 JB |
5466 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5467 | return -EINVAL; | |
fffd0934 JB |
5468 | if (!key.p.key || !key.p.key_len) |
5469 | return -EINVAL; | |
5470 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5471 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5472 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5473 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5474 | return -EINVAL; | |
5475 | if (key.idx > 4) | |
5476 | return -EINVAL; | |
5477 | } else { | |
5478 | key.p.key_len = 0; | |
5479 | key.p.key = NULL; | |
5480 | } | |
5481 | ||
afea0b7a JB |
5482 | if (key.idx >= 0) { |
5483 | int i; | |
5484 | bool ok = false; | |
5485 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5486 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5487 | ok = true; | |
5488 | break; | |
5489 | } | |
5490 | } | |
4c476991 JB |
5491 | if (!ok) |
5492 | return -EINVAL; | |
afea0b7a JB |
5493 | } |
5494 | ||
4c476991 JB |
5495 | if (!rdev->ops->auth) |
5496 | return -EOPNOTSUPP; | |
636a5d36 | 5497 | |
074ac8df | 5498 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5499 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5500 | return -EOPNOTSUPP; | |
eec60b03 | 5501 | |
19957bb3 | 5502 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5503 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5504 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5505 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5506 | return -EINVAL; | |
636a5d36 | 5507 | |
19957bb3 JB |
5508 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5509 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5510 | |
5511 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5512 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5513 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5514 | } |
5515 | ||
19957bb3 | 5516 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5517 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5518 | return -EINVAL; |
636a5d36 | 5519 | |
e39e5b5e JM |
5520 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5521 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5522 | return -EINVAL; | |
5523 | ||
5524 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5525 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5526 | return -EINVAL; | |
5527 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5528 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5529 | /* need to include at least Auth Transaction and Status Code */ | |
5530 | if (sae_data_len < 4) | |
5531 | return -EINVAL; | |
5532 | } | |
5533 | ||
d5cdfacb JM |
5534 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5535 | ||
95de817b JB |
5536 | /* |
5537 | * Since we no longer track auth state, ignore | |
5538 | * requests to only change local state. | |
5539 | */ | |
5540 | if (local_state_change) | |
5541 | return 0; | |
5542 | ||
4c476991 JB |
5543 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
5544 | ssid, ssid_len, ie, ie_len, | |
e39e5b5e JM |
5545 | key.p.key, key.p.key_len, key.idx, |
5546 | sae_data, sae_data_len); | |
636a5d36 JM |
5547 | } |
5548 | ||
c0692b8f JB |
5549 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
5550 | struct genl_info *info, | |
3dc27d25 JB |
5551 | struct cfg80211_crypto_settings *settings, |
5552 | int cipher_limit) | |
b23aa676 | 5553 | { |
c0b2bbd8 JB |
5554 | memset(settings, 0, sizeof(*settings)); |
5555 | ||
b23aa676 SO |
5556 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
5557 | ||
c0692b8f JB |
5558 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
5559 | u16 proto; | |
5560 | proto = nla_get_u16( | |
5561 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
5562 | settings->control_port_ethertype = cpu_to_be16(proto); | |
5563 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
5564 | proto != ETH_P_PAE) | |
5565 | return -EINVAL; | |
5566 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
5567 | settings->control_port_no_encrypt = true; | |
5568 | } else | |
5569 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
5570 | ||
b23aa676 SO |
5571 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
5572 | void *data; | |
5573 | int len, i; | |
5574 | ||
5575 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5576 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5577 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
5578 | ||
5579 | if (len % sizeof(u32)) | |
5580 | return -EINVAL; | |
5581 | ||
3dc27d25 | 5582 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
5583 | return -EINVAL; |
5584 | ||
5585 | memcpy(settings->ciphers_pairwise, data, len); | |
5586 | ||
5587 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
5588 | if (!cfg80211_supported_cipher_suite( |
5589 | &rdev->wiphy, | |
b23aa676 SO |
5590 | settings->ciphers_pairwise[i])) |
5591 | return -EINVAL; | |
5592 | } | |
5593 | ||
5594 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
5595 | settings->cipher_group = | |
5596 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
5597 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
5598 | settings->cipher_group)) | |
b23aa676 SO |
5599 | return -EINVAL; |
5600 | } | |
5601 | ||
5602 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
5603 | settings->wpa_versions = | |
5604 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
5605 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
5606 | return -EINVAL; | |
5607 | } | |
5608 | ||
5609 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
5610 | void *data; | |
6d30240e | 5611 | int len; |
b23aa676 SO |
5612 | |
5613 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5614 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5615 | settings->n_akm_suites = len / sizeof(u32); | |
5616 | ||
5617 | if (len % sizeof(u32)) | |
5618 | return -EINVAL; | |
5619 | ||
1b9ca027 JM |
5620 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
5621 | return -EINVAL; | |
5622 | ||
b23aa676 | 5623 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
5624 | } |
5625 | ||
5626 | return 0; | |
5627 | } | |
5628 | ||
636a5d36 JM |
5629 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
5630 | { | |
4c476991 JB |
5631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5632 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5633 | struct cfg80211_crypto_settings crypto; |
f444de05 | 5634 | struct ieee80211_channel *chan; |
3e5d7649 | 5635 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
5636 | int err, ssid_len, ie_len = 0; |
5637 | bool use_mfp = false; | |
7e7c8926 BG |
5638 | u32 flags = 0; |
5639 | struct ieee80211_ht_cap *ht_capa = NULL; | |
5640 | struct ieee80211_ht_cap *ht_capa_mask = NULL; | |
636a5d36 | 5641 | |
f4a11bb0 JB |
5642 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5643 | return -EINVAL; | |
5644 | ||
5645 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
5646 | !info->attrs[NL80211_ATTR_SSID] || |
5647 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
5648 | return -EINVAL; |
5649 | ||
4c476991 JB |
5650 | if (!rdev->ops->assoc) |
5651 | return -EOPNOTSUPP; | |
636a5d36 | 5652 | |
074ac8df | 5653 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5654 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5655 | return -EOPNOTSUPP; | |
eec60b03 | 5656 | |
19957bb3 | 5657 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 5658 | |
19957bb3 JB |
5659 | chan = ieee80211_get_channel(&rdev->wiphy, |
5660 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
5661 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5662 | return -EINVAL; | |
636a5d36 | 5663 | |
19957bb3 JB |
5664 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5665 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5666 | |
5667 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5668 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5669 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5670 | } |
5671 | ||
dc6382ce | 5672 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 5673 | enum nl80211_mfp mfp = |
dc6382ce | 5674 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 5675 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 5676 | use_mfp = true; |
4c476991 JB |
5677 | else if (mfp != NL80211_MFP_NO) |
5678 | return -EINVAL; | |
dc6382ce JM |
5679 | } |
5680 | ||
3e5d7649 JB |
5681 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
5682 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
5683 | ||
7e7c8926 BG |
5684 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
5685 | flags |= ASSOC_REQ_DISABLE_HT; | |
5686 | ||
5687 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
5688 | ht_capa_mask = | |
5689 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); | |
5690 | ||
5691 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
5692 | if (!ht_capa_mask) | |
5693 | return -EINVAL; | |
5694 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5695 | } | |
5696 | ||
c0692b8f | 5697 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 5698 | if (!err) |
3e5d7649 JB |
5699 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
5700 | ssid, ssid_len, ie, ie_len, use_mfp, | |
7e7c8926 BG |
5701 | &crypto, flags, ht_capa, |
5702 | ht_capa_mask); | |
636a5d36 | 5703 | |
636a5d36 JM |
5704 | return err; |
5705 | } | |
5706 | ||
5707 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
5708 | { | |
4c476991 JB |
5709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5710 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5711 | const u8 *ie = NULL, *bssid; |
4c476991 | 5712 | int ie_len = 0; |
19957bb3 | 5713 | u16 reason_code; |
d5cdfacb | 5714 | bool local_state_change; |
636a5d36 | 5715 | |
f4a11bb0 JB |
5716 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5717 | return -EINVAL; | |
5718 | ||
5719 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5720 | return -EINVAL; | |
5721 | ||
5722 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
5723 | return -EINVAL; | |
5724 | ||
4c476991 JB |
5725 | if (!rdev->ops->deauth) |
5726 | return -EOPNOTSUPP; | |
636a5d36 | 5727 | |
074ac8df | 5728 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5729 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5730 | return -EOPNOTSUPP; | |
eec60b03 | 5731 | |
19957bb3 | 5732 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 5733 | |
19957bb3 JB |
5734 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
5735 | if (reason_code == 0) { | |
f4a11bb0 | 5736 | /* Reason Code 0 is reserved */ |
4c476991 | 5737 | return -EINVAL; |
255e737e | 5738 | } |
636a5d36 JM |
5739 | |
5740 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5741 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5742 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5743 | } |
5744 | ||
d5cdfacb JM |
5745 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5746 | ||
4c476991 JB |
5747 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
5748 | local_state_change); | |
636a5d36 JM |
5749 | } |
5750 | ||
5751 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
5752 | { | |
4c476991 JB |
5753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5754 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5755 | const u8 *ie = NULL, *bssid; |
4c476991 | 5756 | int ie_len = 0; |
19957bb3 | 5757 | u16 reason_code; |
d5cdfacb | 5758 | bool local_state_change; |
636a5d36 | 5759 | |
f4a11bb0 JB |
5760 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5761 | return -EINVAL; | |
5762 | ||
5763 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5764 | return -EINVAL; | |
5765 | ||
5766 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
5767 | return -EINVAL; | |
5768 | ||
4c476991 JB |
5769 | if (!rdev->ops->disassoc) |
5770 | return -EOPNOTSUPP; | |
636a5d36 | 5771 | |
074ac8df | 5772 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5773 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5774 | return -EOPNOTSUPP; | |
eec60b03 | 5775 | |
19957bb3 | 5776 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 5777 | |
19957bb3 JB |
5778 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
5779 | if (reason_code == 0) { | |
f4a11bb0 | 5780 | /* Reason Code 0 is reserved */ |
4c476991 | 5781 | return -EINVAL; |
255e737e | 5782 | } |
636a5d36 JM |
5783 | |
5784 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5785 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5786 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5787 | } |
5788 | ||
d5cdfacb JM |
5789 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5790 | ||
4c476991 JB |
5791 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
5792 | local_state_change); | |
636a5d36 JM |
5793 | } |
5794 | ||
dd5b4cc7 FF |
5795 | static bool |
5796 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
5797 | int mcast_rate[IEEE80211_NUM_BANDS], | |
5798 | int rateval) | |
5799 | { | |
5800 | struct wiphy *wiphy = &rdev->wiphy; | |
5801 | bool found = false; | |
5802 | int band, i; | |
5803 | ||
5804 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5805 | struct ieee80211_supported_band *sband; | |
5806 | ||
5807 | sband = wiphy->bands[band]; | |
5808 | if (!sband) | |
5809 | continue; | |
5810 | ||
5811 | for (i = 0; i < sband->n_bitrates; i++) { | |
5812 | if (sband->bitrates[i].bitrate == rateval) { | |
5813 | mcast_rate[band] = i + 1; | |
5814 | found = true; | |
5815 | break; | |
5816 | } | |
5817 | } | |
5818 | } | |
5819 | ||
5820 | return found; | |
5821 | } | |
5822 | ||
04a773ad JB |
5823 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
5824 | { | |
4c476991 JB |
5825 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5826 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
5827 | struct cfg80211_ibss_params ibss; |
5828 | struct wiphy *wiphy; | |
fffd0934 | 5829 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
5830 | int err; |
5831 | ||
8e30bc55 JB |
5832 | memset(&ibss, 0, sizeof(ibss)); |
5833 | ||
04a773ad JB |
5834 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5835 | return -EINVAL; | |
5836 | ||
683b6d3b | 5837 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
5838 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
5839 | return -EINVAL; | |
5840 | ||
8e30bc55 JB |
5841 | ibss.beacon_interval = 100; |
5842 | ||
5843 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
5844 | ibss.beacon_interval = | |
5845 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
5846 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
5847 | return -EINVAL; | |
5848 | } | |
5849 | ||
4c476991 JB |
5850 | if (!rdev->ops->join_ibss) |
5851 | return -EOPNOTSUPP; | |
04a773ad | 5852 | |
4c476991 JB |
5853 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
5854 | return -EOPNOTSUPP; | |
04a773ad | 5855 | |
79c97e97 | 5856 | wiphy = &rdev->wiphy; |
04a773ad | 5857 | |
39193498 | 5858 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 5859 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
5860 | |
5861 | if (!is_valid_ether_addr(ibss.bssid)) | |
5862 | return -EINVAL; | |
5863 | } | |
04a773ad JB |
5864 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5865 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
5866 | ||
5867 | if (info->attrs[NL80211_ATTR_IE]) { | |
5868 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
5869 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5870 | } | |
5871 | ||
683b6d3b JB |
5872 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
5873 | if (err) | |
5874 | return err; | |
04a773ad | 5875 | |
683b6d3b | 5876 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
5877 | return -EINVAL; |
5878 | ||
db9c64cf JB |
5879 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
5880 | return -EINVAL; | |
5881 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
5882 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
c04d6150 | 5883 | return -EINVAL; |
db9c64cf | 5884 | |
04a773ad | 5885 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
5886 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
5887 | ||
fbd2c8dc TP |
5888 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5889 | u8 *rates = | |
5890 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5891 | int n_rates = | |
5892 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5893 | struct ieee80211_supported_band *sband = | |
683b6d3b | 5894 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 5895 | |
34850ab2 JB |
5896 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
5897 | &ibss.basic_rates); | |
5898 | if (err) | |
5899 | return err; | |
fbd2c8dc | 5900 | } |
dd5b4cc7 FF |
5901 | |
5902 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
5903 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
5904 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
5905 | return -EINVAL; | |
fbd2c8dc | 5906 | |
4c476991 | 5907 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
5908 | bool no_ht = false; |
5909 | ||
4c476991 | 5910 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
5911 | info->attrs[NL80211_ATTR_KEYS], |
5912 | &no_ht); | |
4c476991 JB |
5913 | if (IS_ERR(connkeys)) |
5914 | return PTR_ERR(connkeys); | |
de7044ee | 5915 | |
3d9d1d66 JB |
5916 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
5917 | no_ht) { | |
de7044ee SM |
5918 | kfree(connkeys); |
5919 | return -EINVAL; | |
5920 | } | |
4c476991 | 5921 | } |
04a773ad | 5922 | |
267335d6 AQ |
5923 | ibss.control_port = |
5924 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
5925 | ||
4c476991 | 5926 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
5927 | if (err) |
5928 | kfree(connkeys); | |
04a773ad JB |
5929 | return err; |
5930 | } | |
5931 | ||
5932 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
5933 | { | |
4c476991 JB |
5934 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5935 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 5936 | |
4c476991 JB |
5937 | if (!rdev->ops->leave_ibss) |
5938 | return -EOPNOTSUPP; | |
04a773ad | 5939 | |
4c476991 JB |
5940 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
5941 | return -EOPNOTSUPP; | |
04a773ad | 5942 | |
4c476991 | 5943 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
5944 | } |
5945 | ||
f4e583c8 AQ |
5946 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
5947 | { | |
5948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5949 | struct net_device *dev = info->user_ptr[1]; | |
5950 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
5951 | u32 nla_rate; | |
5952 | int err; | |
5953 | ||
5954 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
5955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
5956 | return -EOPNOTSUPP; | |
5957 | ||
5958 | if (!rdev->ops->set_mcast_rate) | |
5959 | return -EOPNOTSUPP; | |
5960 | ||
5961 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
5962 | ||
5963 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
5964 | return -EINVAL; | |
5965 | ||
5966 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
5967 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
5968 | return -EINVAL; | |
5969 | ||
5970 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
5971 | ||
5972 | return err; | |
5973 | } | |
5974 | ||
5975 | ||
aff89a9b JB |
5976 | #ifdef CONFIG_NL80211_TESTMODE |
5977 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
5978 | .name = "testmode", | |
5979 | }; | |
5980 | ||
5981 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
5982 | { | |
4c476991 | 5983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
5984 | int err; |
5985 | ||
5986 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
5987 | return -EINVAL; | |
5988 | ||
aff89a9b JB |
5989 | err = -EOPNOTSUPP; |
5990 | if (rdev->ops->testmode_cmd) { | |
5991 | rdev->testmode_info = info; | |
e35e4d28 | 5992 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
5993 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
5994 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
5995 | rdev->testmode_info = NULL; | |
5996 | } | |
5997 | ||
aff89a9b JB |
5998 | return err; |
5999 | } | |
6000 | ||
71063f0e WYG |
6001 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6002 | struct netlink_callback *cb) | |
6003 | { | |
00918d33 | 6004 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6005 | int err; |
6006 | long phy_idx; | |
6007 | void *data = NULL; | |
6008 | int data_len = 0; | |
6009 | ||
6010 | if (cb->args[0]) { | |
6011 | /* | |
6012 | * 0 is a valid index, but not valid for args[0], | |
6013 | * so we need to offset by 1. | |
6014 | */ | |
6015 | phy_idx = cb->args[0] - 1; | |
6016 | } else { | |
6017 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6018 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6019 | nl80211_policy); | |
6020 | if (err) | |
6021 | return err; | |
00918d33 | 6022 | |
2bd7e35d JB |
6023 | mutex_lock(&cfg80211_mutex); |
6024 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
6025 | nl80211_fam.attrbuf); | |
6026 | if (IS_ERR(rdev)) { | |
6027 | mutex_unlock(&cfg80211_mutex); | |
6028 | return PTR_ERR(rdev); | |
00918d33 | 6029 | } |
2bd7e35d JB |
6030 | phy_idx = rdev->wiphy_idx; |
6031 | rdev = NULL; | |
6032 | mutex_unlock(&cfg80211_mutex); | |
6033 | ||
71063f0e WYG |
6034 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6035 | cb->args[1] = | |
6036 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6037 | } | |
6038 | ||
6039 | if (cb->args[1]) { | |
6040 | data = nla_data((void *)cb->args[1]); | |
6041 | data_len = nla_len((void *)cb->args[1]); | |
6042 | } | |
6043 | ||
6044 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
6045 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6046 | if (!rdev) { | |
71063f0e WYG |
6047 | mutex_unlock(&cfg80211_mutex); |
6048 | return -ENOENT; | |
6049 | } | |
00918d33 | 6050 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
6051 | mutex_unlock(&cfg80211_mutex); |
6052 | ||
00918d33 | 6053 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6054 | err = -EOPNOTSUPP; |
6055 | goto out_err; | |
6056 | } | |
6057 | ||
6058 | while (1) { | |
15e47304 | 6059 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6060 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6061 | NL80211_CMD_TESTMODE); | |
6062 | struct nlattr *tmdata; | |
6063 | ||
9360ffd1 | 6064 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6065 | genlmsg_cancel(skb, hdr); |
6066 | break; | |
6067 | } | |
6068 | ||
6069 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6070 | if (!tmdata) { | |
6071 | genlmsg_cancel(skb, hdr); | |
6072 | break; | |
6073 | } | |
e35e4d28 | 6074 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6075 | nla_nest_end(skb, tmdata); |
6076 | ||
6077 | if (err == -ENOBUFS || err == -ENOENT) { | |
6078 | genlmsg_cancel(skb, hdr); | |
6079 | break; | |
6080 | } else if (err) { | |
6081 | genlmsg_cancel(skb, hdr); | |
6082 | goto out_err; | |
6083 | } | |
6084 | ||
6085 | genlmsg_end(skb, hdr); | |
6086 | } | |
6087 | ||
6088 | err = skb->len; | |
6089 | /* see above */ | |
6090 | cb->args[0] = phy_idx + 1; | |
6091 | out_err: | |
00918d33 | 6092 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
6093 | return err; |
6094 | } | |
6095 | ||
aff89a9b JB |
6096 | static struct sk_buff * |
6097 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6098 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6099 | { |
6100 | struct sk_buff *skb; | |
6101 | void *hdr; | |
6102 | struct nlattr *data; | |
6103 | ||
6104 | skb = nlmsg_new(approxlen + 100, gfp); | |
6105 | if (!skb) | |
6106 | return NULL; | |
6107 | ||
15e47304 | 6108 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6109 | if (!hdr) { |
6110 | kfree_skb(skb); | |
6111 | return NULL; | |
6112 | } | |
6113 | ||
9360ffd1 DM |
6114 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6115 | goto nla_put_failure; | |
aff89a9b JB |
6116 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6117 | ||
6118 | ((void **)skb->cb)[0] = rdev; | |
6119 | ((void **)skb->cb)[1] = hdr; | |
6120 | ((void **)skb->cb)[2] = data; | |
6121 | ||
6122 | return skb; | |
6123 | ||
6124 | nla_put_failure: | |
6125 | kfree_skb(skb); | |
6126 | return NULL; | |
6127 | } | |
6128 | ||
6129 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6130 | int approxlen) | |
6131 | { | |
6132 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6133 | ||
6134 | if (WARN_ON(!rdev->testmode_info)) | |
6135 | return NULL; | |
6136 | ||
6137 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6138 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6139 | rdev->testmode_info->snd_seq, |
6140 | GFP_KERNEL); | |
6141 | } | |
6142 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6143 | ||
6144 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6145 | { | |
6146 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6147 | void *hdr = ((void **)skb->cb)[1]; | |
6148 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6149 | ||
6150 | if (WARN_ON(!rdev->testmode_info)) { | |
6151 | kfree_skb(skb); | |
6152 | return -EINVAL; | |
6153 | } | |
6154 | ||
6155 | nla_nest_end(skb, data); | |
6156 | genlmsg_end(skb, hdr); | |
6157 | return genlmsg_reply(skb, rdev->testmode_info); | |
6158 | } | |
6159 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6160 | ||
6161 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6162 | int approxlen, gfp_t gfp) | |
6163 | { | |
6164 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6165 | ||
6166 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6167 | } | |
6168 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6169 | ||
6170 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6171 | { | |
6172 | void *hdr = ((void **)skb->cb)[1]; | |
6173 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6174 | ||
6175 | nla_nest_end(skb, data); | |
6176 | genlmsg_end(skb, hdr); | |
6177 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6178 | } | |
6179 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6180 | #endif | |
6181 | ||
b23aa676 SO |
6182 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6183 | { | |
4c476991 JB |
6184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6185 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6186 | struct cfg80211_connect_params connect; |
6187 | struct wiphy *wiphy; | |
fffd0934 | 6188 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6189 | int err; |
6190 | ||
6191 | memset(&connect, 0, sizeof(connect)); | |
6192 | ||
6193 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6194 | return -EINVAL; | |
6195 | ||
6196 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6197 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6198 | return -EINVAL; | |
6199 | ||
6200 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6201 | connect.auth_type = | |
6202 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6203 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6204 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6205 | return -EINVAL; |
6206 | } else | |
6207 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6208 | ||
6209 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6210 | ||
c0692b8f | 6211 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6212 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6213 | if (err) |
6214 | return err; | |
b23aa676 | 6215 | |
074ac8df | 6216 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6217 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6218 | return -EOPNOTSUPP; | |
b23aa676 | 6219 | |
79c97e97 | 6220 | wiphy = &rdev->wiphy; |
b23aa676 | 6221 | |
4486ea98 BS |
6222 | connect.bg_scan_period = -1; |
6223 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6224 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6225 | connect.bg_scan_period = | |
6226 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6227 | } | |
6228 | ||
b23aa676 SO |
6229 | if (info->attrs[NL80211_ATTR_MAC]) |
6230 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6231 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6232 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6233 | ||
6234 | if (info->attrs[NL80211_ATTR_IE]) { | |
6235 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6236 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6237 | } | |
6238 | ||
cee00a95 JM |
6239 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6240 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6241 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6242 | connect.mfp != NL80211_MFP_NO) | |
6243 | return -EINVAL; | |
6244 | } else { | |
6245 | connect.mfp = NL80211_MFP_NO; | |
6246 | } | |
6247 | ||
b23aa676 SO |
6248 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6249 | connect.channel = | |
6250 | ieee80211_get_channel(wiphy, | |
6251 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6252 | if (!connect.channel || | |
4c476991 JB |
6253 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6254 | return -EINVAL; | |
b23aa676 SO |
6255 | } |
6256 | ||
fffd0934 JB |
6257 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6258 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6259 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6260 | if (IS_ERR(connkeys)) |
6261 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6262 | } |
6263 | ||
7e7c8926 BG |
6264 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6265 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6266 | ||
6267 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6268 | memcpy(&connect.ht_capa_mask, | |
6269 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6270 | sizeof(connect.ht_capa_mask)); | |
6271 | ||
6272 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6273 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6274 | kfree(connkeys); | |
7e7c8926 | 6275 | return -EINVAL; |
b4e4f47e | 6276 | } |
7e7c8926 BG |
6277 | memcpy(&connect.ht_capa, |
6278 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6279 | sizeof(connect.ht_capa)); | |
6280 | } | |
6281 | ||
fffd0934 | 6282 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
6283 | if (err) |
6284 | kfree(connkeys); | |
b23aa676 SO |
6285 | return err; |
6286 | } | |
6287 | ||
6288 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6289 | { | |
4c476991 JB |
6290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6291 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6292 | u16 reason; |
6293 | ||
6294 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6295 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6296 | else | |
6297 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6298 | ||
6299 | if (reason == 0) | |
6300 | return -EINVAL; | |
6301 | ||
074ac8df | 6302 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6303 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6304 | return -EOPNOTSUPP; | |
b23aa676 | 6305 | |
4c476991 | 6306 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
6307 | } |
6308 | ||
463d0183 JB |
6309 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6310 | { | |
4c476991 | 6311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6312 | struct net *net; |
6313 | int err; | |
6314 | u32 pid; | |
6315 | ||
6316 | if (!info->attrs[NL80211_ATTR_PID]) | |
6317 | return -EINVAL; | |
6318 | ||
6319 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6320 | ||
463d0183 | 6321 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6322 | if (IS_ERR(net)) |
6323 | return PTR_ERR(net); | |
463d0183 JB |
6324 | |
6325 | err = 0; | |
6326 | ||
6327 | /* check if anything to do */ | |
4c476991 JB |
6328 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6329 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6330 | |
463d0183 | 6331 | put_net(net); |
463d0183 JB |
6332 | return err; |
6333 | } | |
6334 | ||
67fbb16b SO |
6335 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6336 | { | |
4c476991 | 6337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6338 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6339 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6340 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6341 | struct cfg80211_pmksa pmksa; |
6342 | ||
6343 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6344 | ||
6345 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6346 | return -EINVAL; | |
6347 | ||
6348 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6349 | return -EINVAL; | |
6350 | ||
67fbb16b SO |
6351 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6352 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6353 | ||
074ac8df | 6354 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6355 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6356 | return -EOPNOTSUPP; | |
67fbb16b SO |
6357 | |
6358 | switch (info->genlhdr->cmd) { | |
6359 | case NL80211_CMD_SET_PMKSA: | |
6360 | rdev_ops = rdev->ops->set_pmksa; | |
6361 | break; | |
6362 | case NL80211_CMD_DEL_PMKSA: | |
6363 | rdev_ops = rdev->ops->del_pmksa; | |
6364 | break; | |
6365 | default: | |
6366 | WARN_ON(1); | |
6367 | break; | |
6368 | } | |
6369 | ||
4c476991 JB |
6370 | if (!rdev_ops) |
6371 | return -EOPNOTSUPP; | |
67fbb16b | 6372 | |
4c476991 | 6373 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6374 | } |
6375 | ||
6376 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6377 | { | |
4c476991 JB |
6378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6379 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6380 | |
074ac8df | 6381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6383 | return -EOPNOTSUPP; | |
67fbb16b | 6384 | |
4c476991 JB |
6385 | if (!rdev->ops->flush_pmksa) |
6386 | return -EOPNOTSUPP; | |
67fbb16b | 6387 | |
e35e4d28 | 6388 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6389 | } |
6390 | ||
109086ce AN |
6391 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6392 | { | |
6393 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6394 | struct net_device *dev = info->user_ptr[1]; | |
6395 | u8 action_code, dialog_token; | |
6396 | u16 status_code; | |
6397 | u8 *peer; | |
6398 | ||
6399 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6400 | !rdev->ops->tdls_mgmt) | |
6401 | return -EOPNOTSUPP; | |
6402 | ||
6403 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6404 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6405 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6406 | !info->attrs[NL80211_ATTR_IE] || | |
6407 | !info->attrs[NL80211_ATTR_MAC]) | |
6408 | return -EINVAL; | |
6409 | ||
6410 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6411 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6412 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6413 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6414 | ||
e35e4d28 HG |
6415 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6416 | dialog_token, status_code, | |
6417 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6418 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6419 | } |
6420 | ||
6421 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6422 | { | |
6423 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6424 | struct net_device *dev = info->user_ptr[1]; | |
6425 | enum nl80211_tdls_operation operation; | |
6426 | u8 *peer; | |
6427 | ||
6428 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6429 | !rdev->ops->tdls_oper) | |
6430 | return -EOPNOTSUPP; | |
6431 | ||
6432 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6433 | !info->attrs[NL80211_ATTR_MAC]) | |
6434 | return -EINVAL; | |
6435 | ||
6436 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6437 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6438 | ||
e35e4d28 | 6439 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6440 | } |
6441 | ||
9588bbd5 JM |
6442 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6443 | struct genl_info *info) | |
6444 | { | |
4c476991 | 6445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6446 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6447 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6448 | struct sk_buff *msg; |
6449 | void *hdr; | |
6450 | u64 cookie; | |
683b6d3b | 6451 | u32 duration; |
9588bbd5 JM |
6452 | int err; |
6453 | ||
6454 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6455 | !info->attrs[NL80211_ATTR_DURATION]) | |
6456 | return -EINVAL; | |
6457 | ||
6458 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6459 | ||
ebf348fc JB |
6460 | if (!rdev->ops->remain_on_channel || |
6461 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6462 | return -EOPNOTSUPP; | |
6463 | ||
9588bbd5 | 6464 | /* |
ebf348fc JB |
6465 | * We should be on that channel for at least a minimum amount of |
6466 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6467 | */ |
ebf348fc | 6468 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6469 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6470 | return -EINVAL; |
6471 | ||
683b6d3b JB |
6472 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6473 | if (err) | |
6474 | return err; | |
9588bbd5 JM |
6475 | |
6476 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6477 | if (!msg) |
6478 | return -ENOMEM; | |
9588bbd5 | 6479 | |
15e47304 | 6480 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6481 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6482 | ||
6483 | if (IS_ERR(hdr)) { | |
6484 | err = PTR_ERR(hdr); | |
6485 | goto free_msg; | |
6486 | } | |
6487 | ||
683b6d3b JB |
6488 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6489 | duration, &cookie); | |
9588bbd5 JM |
6490 | |
6491 | if (err) | |
6492 | goto free_msg; | |
6493 | ||
9360ffd1 DM |
6494 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6495 | goto nla_put_failure; | |
9588bbd5 JM |
6496 | |
6497 | genlmsg_end(msg, hdr); | |
4c476991 JB |
6498 | |
6499 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
6500 | |
6501 | nla_put_failure: | |
6502 | err = -ENOBUFS; | |
6503 | free_msg: | |
6504 | nlmsg_free(msg); | |
9588bbd5 JM |
6505 | return err; |
6506 | } | |
6507 | ||
6508 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
6509 | struct genl_info *info) | |
6510 | { | |
4c476991 | 6511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6512 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 6513 | u64 cookie; |
9588bbd5 JM |
6514 | |
6515 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6516 | return -EINVAL; | |
6517 | ||
4c476991 JB |
6518 | if (!rdev->ops->cancel_remain_on_channel) |
6519 | return -EOPNOTSUPP; | |
9588bbd5 | 6520 | |
9588bbd5 JM |
6521 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
6522 | ||
e35e4d28 | 6523 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
6524 | } |
6525 | ||
13ae75b1 JM |
6526 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
6527 | u8 *rates, u8 rates_len) | |
6528 | { | |
6529 | u8 i; | |
6530 | u32 mask = 0; | |
6531 | ||
6532 | for (i = 0; i < rates_len; i++) { | |
6533 | int rate = (rates[i] & 0x7f) * 5; | |
6534 | int ridx; | |
6535 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
6536 | struct ieee80211_rate *srate = | |
6537 | &sband->bitrates[ridx]; | |
6538 | if (rate == srate->bitrate) { | |
6539 | mask |= 1 << ridx; | |
6540 | break; | |
6541 | } | |
6542 | } | |
6543 | if (ridx == sband->n_bitrates) | |
6544 | return 0; /* rate not found */ | |
6545 | } | |
6546 | ||
6547 | return mask; | |
6548 | } | |
6549 | ||
24db78c0 SW |
6550 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
6551 | u8 *rates, u8 rates_len, | |
6552 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
6553 | { | |
6554 | u8 i; | |
6555 | ||
6556 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
6557 | ||
6558 | for (i = 0; i < rates_len; i++) { | |
6559 | int ridx, rbit; | |
6560 | ||
6561 | ridx = rates[i] / 8; | |
6562 | rbit = BIT(rates[i] % 8); | |
6563 | ||
6564 | /* check validity */ | |
910570b5 | 6565 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
6566 | return false; |
6567 | ||
6568 | /* check availability */ | |
6569 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
6570 | mcs[ridx] |= rbit; | |
6571 | else | |
6572 | return false; | |
6573 | } | |
6574 | ||
6575 | return true; | |
6576 | } | |
6577 | ||
b54452b0 | 6578 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
6579 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
6580 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
6581 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
6582 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
6583 | }; |
6584 | ||
6585 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
6586 | struct genl_info *info) | |
6587 | { | |
6588 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 6589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 6590 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
6591 | int rem, i; |
6592 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
6593 | struct nlattr *tx_rates; |
6594 | struct ieee80211_supported_band *sband; | |
6595 | ||
6596 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
6597 | return -EINVAL; | |
6598 | ||
4c476991 JB |
6599 | if (!rdev->ops->set_bitrate_mask) |
6600 | return -EOPNOTSUPP; | |
13ae75b1 JM |
6601 | |
6602 | memset(&mask, 0, sizeof(mask)); | |
6603 | /* Default to all rates enabled */ | |
6604 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
6605 | sband = rdev->wiphy.bands[i]; | |
6606 | mask.control[i].legacy = | |
6607 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
6608 | if (sband) |
6609 | memcpy(mask.control[i].mcs, | |
6610 | sband->ht_cap.mcs.rx_mask, | |
6611 | sizeof(mask.control[i].mcs)); | |
6612 | else | |
6613 | memset(mask.control[i].mcs, 0, | |
6614 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
6615 | } |
6616 | ||
6617 | /* | |
6618 | * The nested attribute uses enum nl80211_band as the index. This maps | |
6619 | * directly to the enum ieee80211_band values used in cfg80211. | |
6620 | */ | |
24db78c0 | 6621 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
6622 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
6623 | { | |
6624 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
6625 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
6626 | return -EINVAL; | |
13ae75b1 | 6627 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
6628 | if (sband == NULL) |
6629 | return -EINVAL; | |
13ae75b1 JM |
6630 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
6631 | nla_len(tx_rates), nl80211_txattr_policy); | |
6632 | if (tb[NL80211_TXRATE_LEGACY]) { | |
6633 | mask.control[band].legacy = rateset_to_mask( | |
6634 | sband, | |
6635 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
6636 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
6637 | if ((mask.control[band].legacy == 0) && |
6638 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
6639 | return -EINVAL; | |
24db78c0 SW |
6640 | } |
6641 | if (tb[NL80211_TXRATE_MCS]) { | |
6642 | if (!ht_rateset_to_mask( | |
6643 | sband, | |
6644 | nla_data(tb[NL80211_TXRATE_MCS]), | |
6645 | nla_len(tb[NL80211_TXRATE_MCS]), | |
6646 | mask.control[band].mcs)) | |
6647 | return -EINVAL; | |
6648 | } | |
6649 | ||
6650 | if (mask.control[band].legacy == 0) { | |
6651 | /* don't allow empty legacy rates if HT | |
6652 | * is not even supported. */ | |
6653 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
6654 | return -EINVAL; | |
6655 | ||
6656 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
6657 | if (mask.control[band].mcs[i]) | |
6658 | break; | |
6659 | ||
6660 | /* legacy and mcs rates may not be both empty */ | |
6661 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 6662 | return -EINVAL; |
13ae75b1 JM |
6663 | } |
6664 | } | |
6665 | ||
e35e4d28 | 6666 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
6667 | } |
6668 | ||
2e161f78 | 6669 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 6670 | { |
4c476991 | 6671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6672 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 6673 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
6674 | |
6675 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
6676 | return -EINVAL; | |
6677 | ||
2e161f78 JB |
6678 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
6679 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 6680 | |
71bbc994 JB |
6681 | switch (wdev->iftype) { |
6682 | case NL80211_IFTYPE_STATION: | |
6683 | case NL80211_IFTYPE_ADHOC: | |
6684 | case NL80211_IFTYPE_P2P_CLIENT: | |
6685 | case NL80211_IFTYPE_AP: | |
6686 | case NL80211_IFTYPE_AP_VLAN: | |
6687 | case NL80211_IFTYPE_MESH_POINT: | |
6688 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 6689 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
6690 | break; |
6691 | default: | |
4c476991 | 6692 | return -EOPNOTSUPP; |
71bbc994 | 6693 | } |
026331c4 JM |
6694 | |
6695 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
6696 | if (!rdev->ops->mgmt_tx) |
6697 | return -EOPNOTSUPP; | |
026331c4 | 6698 | |
15e47304 | 6699 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
6700 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
6701 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
6702 | } |
6703 | ||
2e161f78 | 6704 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 6705 | { |
4c476991 | 6706 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6707 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6708 | struct cfg80211_chan_def chandef; |
026331c4 | 6709 | int err; |
d64d373f | 6710 | void *hdr = NULL; |
026331c4 | 6711 | u64 cookie; |
e247bd90 | 6712 | struct sk_buff *msg = NULL; |
f7ca38df | 6713 | unsigned int wait = 0; |
e247bd90 JB |
6714 | bool offchan, no_cck, dont_wait_for_ack; |
6715 | ||
6716 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 6717 | |
683b6d3b | 6718 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
6719 | return -EINVAL; |
6720 | ||
4c476991 JB |
6721 | if (!rdev->ops->mgmt_tx) |
6722 | return -EOPNOTSUPP; | |
026331c4 | 6723 | |
71bbc994 JB |
6724 | switch (wdev->iftype) { |
6725 | case NL80211_IFTYPE_STATION: | |
6726 | case NL80211_IFTYPE_ADHOC: | |
6727 | case NL80211_IFTYPE_P2P_CLIENT: | |
6728 | case NL80211_IFTYPE_AP: | |
6729 | case NL80211_IFTYPE_AP_VLAN: | |
6730 | case NL80211_IFTYPE_MESH_POINT: | |
6731 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 6732 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
6733 | break; |
6734 | default: | |
4c476991 | 6735 | return -EOPNOTSUPP; |
71bbc994 | 6736 | } |
026331c4 | 6737 | |
f7ca38df | 6738 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 6739 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
6740 | return -EINVAL; |
6741 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
6742 | |
6743 | /* | |
6744 | * We should wait on the channel for at least a minimum amount | |
6745 | * of time (10ms) but no longer than the driver supports. | |
6746 | */ | |
6747 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
6748 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
6749 | return -EINVAL; | |
6750 | ||
f7ca38df JB |
6751 | } |
6752 | ||
f7ca38df JB |
6753 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
6754 | ||
7c4ef712 JB |
6755 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
6756 | return -EINVAL; | |
6757 | ||
e9f935e3 RM |
6758 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
6759 | ||
683b6d3b JB |
6760 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6761 | if (err) | |
6762 | return err; | |
026331c4 | 6763 | |
e247bd90 JB |
6764 | if (!dont_wait_for_ack) { |
6765 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6766 | if (!msg) | |
6767 | return -ENOMEM; | |
026331c4 | 6768 | |
15e47304 | 6769 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 6770 | NL80211_CMD_FRAME); |
026331c4 | 6771 | |
e247bd90 JB |
6772 | if (IS_ERR(hdr)) { |
6773 | err = PTR_ERR(hdr); | |
6774 | goto free_msg; | |
6775 | } | |
026331c4 | 6776 | } |
e247bd90 | 6777 | |
683b6d3b | 6778 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
6779 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
6780 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 6781 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
6782 | if (err) |
6783 | goto free_msg; | |
6784 | ||
e247bd90 | 6785 | if (msg) { |
9360ffd1 DM |
6786 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6787 | goto nla_put_failure; | |
026331c4 | 6788 | |
e247bd90 JB |
6789 | genlmsg_end(msg, hdr); |
6790 | return genlmsg_reply(msg, info); | |
6791 | } | |
6792 | ||
6793 | return 0; | |
026331c4 JM |
6794 | |
6795 | nla_put_failure: | |
6796 | err = -ENOBUFS; | |
6797 | free_msg: | |
6798 | nlmsg_free(msg); | |
026331c4 JM |
6799 | return err; |
6800 | } | |
6801 | ||
f7ca38df JB |
6802 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
6803 | { | |
6804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 6805 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
6806 | u64 cookie; |
6807 | ||
6808 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6809 | return -EINVAL; | |
6810 | ||
6811 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
6812 | return -EOPNOTSUPP; | |
6813 | ||
71bbc994 JB |
6814 | switch (wdev->iftype) { |
6815 | case NL80211_IFTYPE_STATION: | |
6816 | case NL80211_IFTYPE_ADHOC: | |
6817 | case NL80211_IFTYPE_P2P_CLIENT: | |
6818 | case NL80211_IFTYPE_AP: | |
6819 | case NL80211_IFTYPE_AP_VLAN: | |
6820 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 6821 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
6822 | break; |
6823 | default: | |
f7ca38df | 6824 | return -EOPNOTSUPP; |
71bbc994 | 6825 | } |
f7ca38df JB |
6826 | |
6827 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
6828 | ||
e35e4d28 | 6829 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
6830 | } |
6831 | ||
ffb9eb3d KV |
6832 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
6833 | { | |
4c476991 | 6834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 6835 | struct wireless_dev *wdev; |
4c476991 | 6836 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
6837 | u8 ps_state; |
6838 | bool state; | |
6839 | int err; | |
6840 | ||
4c476991 JB |
6841 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
6842 | return -EINVAL; | |
ffb9eb3d KV |
6843 | |
6844 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
6845 | ||
4c476991 JB |
6846 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
6847 | return -EINVAL; | |
ffb9eb3d KV |
6848 | |
6849 | wdev = dev->ieee80211_ptr; | |
6850 | ||
4c476991 JB |
6851 | if (!rdev->ops->set_power_mgmt) |
6852 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
6853 | |
6854 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
6855 | ||
6856 | if (state == wdev->ps) | |
4c476991 | 6857 | return 0; |
ffb9eb3d | 6858 | |
e35e4d28 | 6859 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
6860 | if (!err) |
6861 | wdev->ps = state; | |
ffb9eb3d KV |
6862 | return err; |
6863 | } | |
6864 | ||
6865 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
6866 | { | |
4c476991 | 6867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
6868 | enum nl80211_ps_state ps_state; |
6869 | struct wireless_dev *wdev; | |
4c476991 | 6870 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
6871 | struct sk_buff *msg; |
6872 | void *hdr; | |
6873 | int err; | |
6874 | ||
ffb9eb3d KV |
6875 | wdev = dev->ieee80211_ptr; |
6876 | ||
4c476991 JB |
6877 | if (!rdev->ops->set_power_mgmt) |
6878 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
6879 | |
6880 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6881 | if (!msg) |
6882 | return -ENOMEM; | |
ffb9eb3d | 6883 | |
15e47304 | 6884 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
6885 | NL80211_CMD_GET_POWER_SAVE); |
6886 | if (!hdr) { | |
4c476991 | 6887 | err = -ENOBUFS; |
ffb9eb3d KV |
6888 | goto free_msg; |
6889 | } | |
6890 | ||
6891 | if (wdev->ps) | |
6892 | ps_state = NL80211_PS_ENABLED; | |
6893 | else | |
6894 | ps_state = NL80211_PS_DISABLED; | |
6895 | ||
9360ffd1 DM |
6896 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
6897 | goto nla_put_failure; | |
ffb9eb3d KV |
6898 | |
6899 | genlmsg_end(msg, hdr); | |
4c476991 | 6900 | return genlmsg_reply(msg, info); |
ffb9eb3d | 6901 | |
4c476991 | 6902 | nla_put_failure: |
ffb9eb3d | 6903 | err = -ENOBUFS; |
4c476991 | 6904 | free_msg: |
ffb9eb3d | 6905 | nlmsg_free(msg); |
ffb9eb3d KV |
6906 | return err; |
6907 | } | |
6908 | ||
d6dc1a38 JO |
6909 | static struct nla_policy |
6910 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
6911 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
6912 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
6913 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
6914 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
6915 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
6916 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
6917 | }; |
6918 | ||
84f10708 | 6919 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 6920 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
6921 | { |
6922 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6923 | struct wireless_dev *wdev; | |
6924 | struct net_device *dev = info->user_ptr[1]; | |
6925 | ||
d9d8b019 | 6926 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
6927 | return -EINVAL; |
6928 | ||
6929 | wdev = dev->ieee80211_ptr; | |
6930 | ||
6931 | if (!rdev->ops->set_cqm_txe_config) | |
6932 | return -EOPNOTSUPP; | |
6933 | ||
6934 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
6935 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
6936 | return -EOPNOTSUPP; | |
6937 | ||
e35e4d28 | 6938 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
6939 | } |
6940 | ||
d6dc1a38 JO |
6941 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
6942 | s32 threshold, u32 hysteresis) | |
6943 | { | |
4c476991 | 6944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 6945 | struct wireless_dev *wdev; |
4c476991 | 6946 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
6947 | |
6948 | if (threshold > 0) | |
6949 | return -EINVAL; | |
6950 | ||
d6dc1a38 JO |
6951 | wdev = dev->ieee80211_ptr; |
6952 | ||
4c476991 JB |
6953 | if (!rdev->ops->set_cqm_rssi_config) |
6954 | return -EOPNOTSUPP; | |
d6dc1a38 | 6955 | |
074ac8df | 6956 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6957 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6958 | return -EOPNOTSUPP; | |
d6dc1a38 | 6959 | |
e35e4d28 | 6960 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
6961 | } |
6962 | ||
6963 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
6964 | { | |
6965 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
6966 | struct nlattr *cqm; | |
6967 | int err; | |
6968 | ||
6969 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
6970 | if (!cqm) { | |
6971 | err = -EINVAL; | |
6972 | goto out; | |
6973 | } | |
6974 | ||
6975 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
6976 | nl80211_attr_cqm_policy); | |
6977 | if (err) | |
6978 | goto out; | |
6979 | ||
6980 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
6981 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
6982 | s32 threshold; | |
6983 | u32 hysteresis; | |
6984 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
6985 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
6986 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
6987 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
6988 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
6989 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
6990 | u32 rate, pkts, intvl; | |
6991 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
6992 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
6993 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
6994 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
6995 | } else |
6996 | err = -EINVAL; | |
6997 | ||
6998 | out: | |
6999 | return err; | |
7000 | } | |
7001 | ||
29cbe68c JB |
7002 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7003 | { | |
7004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7005 | struct net_device *dev = info->user_ptr[1]; | |
7006 | struct mesh_config cfg; | |
c80d545d | 7007 | struct mesh_setup setup; |
29cbe68c JB |
7008 | int err; |
7009 | ||
7010 | /* start with default */ | |
7011 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7012 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7013 | |
24bdd9f4 | 7014 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7015 | /* and parse parameters if given */ |
24bdd9f4 | 7016 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7017 | if (err) |
7018 | return err; | |
7019 | } | |
7020 | ||
7021 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7022 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7023 | return -EINVAL; | |
7024 | ||
c80d545d JC |
7025 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7026 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7027 | ||
4bb62344 CYY |
7028 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7029 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7030 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7031 | return -EINVAL; | |
7032 | ||
9bdbf04d MP |
7033 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7034 | setup.beacon_interval = | |
7035 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7036 | if (setup.beacon_interval < 10 || | |
7037 | setup.beacon_interval > 10000) | |
7038 | return -EINVAL; | |
7039 | } | |
7040 | ||
7041 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7042 | setup.dtim_period = | |
7043 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7044 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7045 | return -EINVAL; | |
7046 | } | |
7047 | ||
c80d545d JC |
7048 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7049 | /* parse additional setup parameters if given */ | |
7050 | err = nl80211_parse_mesh_setup(info, &setup); | |
7051 | if (err) | |
7052 | return err; | |
7053 | } | |
7054 | ||
cc1d2806 | 7055 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7056 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7057 | if (err) | |
7058 | return err; | |
cc1d2806 JB |
7059 | } else { |
7060 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7061 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7062 | } |
7063 | ||
c80d545d | 7064 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7065 | } |
7066 | ||
7067 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7068 | { | |
7069 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7070 | struct net_device *dev = info->user_ptr[1]; | |
7071 | ||
7072 | return cfg80211_leave_mesh(rdev, dev); | |
7073 | } | |
7074 | ||
dfb89c56 | 7075 | #ifdef CONFIG_PM |
bb92d199 AK |
7076 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7077 | struct cfg80211_registered_device *rdev) | |
7078 | { | |
7079 | struct nlattr *nl_pats, *nl_pat; | |
7080 | int i, pat_len; | |
7081 | ||
7082 | if (!rdev->wowlan->n_patterns) | |
7083 | return 0; | |
7084 | ||
7085 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7086 | if (!nl_pats) | |
7087 | return -ENOBUFS; | |
7088 | ||
7089 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
7090 | nl_pat = nla_nest_start(msg, i + 1); | |
7091 | if (!nl_pat) | |
7092 | return -ENOBUFS; | |
7093 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
7094 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
7095 | DIV_ROUND_UP(pat_len, 8), | |
7096 | rdev->wowlan->patterns[i].mask) || | |
7097 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
7098 | pat_len, rdev->wowlan->patterns[i].pattern) || | |
7099 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, | |
7100 | rdev->wowlan->patterns[i].pkt_offset)) | |
7101 | return -ENOBUFS; | |
7102 | nla_nest_end(msg, nl_pat); | |
7103 | } | |
7104 | nla_nest_end(msg, nl_pats); | |
7105 | ||
7106 | return 0; | |
7107 | } | |
7108 | ||
2a0e047e JB |
7109 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7110 | struct cfg80211_wowlan_tcp *tcp) | |
7111 | { | |
7112 | struct nlattr *nl_tcp; | |
7113 | ||
7114 | if (!tcp) | |
7115 | return 0; | |
7116 | ||
7117 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7118 | if (!nl_tcp) | |
7119 | return -ENOBUFS; | |
7120 | ||
7121 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7122 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7123 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7124 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7125 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7126 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7127 | tcp->payload_len, tcp->payload) || | |
7128 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7129 | tcp->data_interval) || | |
7130 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7131 | tcp->wake_len, tcp->wake_data) || | |
7132 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7133 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7134 | return -ENOBUFS; | |
7135 | ||
7136 | if (tcp->payload_seq.len && | |
7137 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7138 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7139 | return -ENOBUFS; | |
7140 | ||
7141 | if (tcp->payload_tok.len && | |
7142 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7143 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7144 | &tcp->payload_tok)) | |
7145 | return -ENOBUFS; | |
7146 | ||
7147 | return 0; | |
7148 | } | |
7149 | ||
ff1b6e69 JB |
7150 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7151 | { | |
7152 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7153 | struct sk_buff *msg; | |
7154 | void *hdr; | |
2a0e047e | 7155 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7156 | |
2a0e047e JB |
7157 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7158 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7159 | return -EOPNOTSUPP; |
7160 | ||
2a0e047e JB |
7161 | if (rdev->wowlan && rdev->wowlan->tcp) { |
7162 | /* adjust size to have room for all the data */ | |
7163 | size += rdev->wowlan->tcp->tokens_size + | |
7164 | rdev->wowlan->tcp->payload_len + | |
7165 | rdev->wowlan->tcp->wake_len + | |
7166 | rdev->wowlan->tcp->wake_len / 8; | |
7167 | } | |
7168 | ||
7169 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7170 | if (!msg) |
7171 | return -ENOMEM; | |
7172 | ||
15e47304 | 7173 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7174 | NL80211_CMD_GET_WOWLAN); |
7175 | if (!hdr) | |
7176 | goto nla_put_failure; | |
7177 | ||
7178 | if (rdev->wowlan) { | |
7179 | struct nlattr *nl_wowlan; | |
7180 | ||
7181 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7182 | if (!nl_wowlan) | |
7183 | goto nla_put_failure; | |
7184 | ||
9360ffd1 DM |
7185 | if ((rdev->wowlan->any && |
7186 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7187 | (rdev->wowlan->disconnect && | |
7188 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7189 | (rdev->wowlan->magic_pkt && | |
7190 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7191 | (rdev->wowlan->gtk_rekey_failure && | |
7192 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7193 | (rdev->wowlan->eap_identity_req && | |
7194 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7195 | (rdev->wowlan->four_way_handshake && | |
7196 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7197 | (rdev->wowlan->rfkill_release && | |
7198 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
7199 | goto nla_put_failure; | |
2a0e047e | 7200 | |
bb92d199 AK |
7201 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7202 | goto nla_put_failure; | |
2a0e047e JB |
7203 | |
7204 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) | |
7205 | goto nla_put_failure; | |
7206 | ||
ff1b6e69 JB |
7207 | nla_nest_end(msg, nl_wowlan); |
7208 | } | |
7209 | ||
7210 | genlmsg_end(msg, hdr); | |
7211 | return genlmsg_reply(msg, info); | |
7212 | ||
7213 | nla_put_failure: | |
7214 | nlmsg_free(msg); | |
7215 | return -ENOBUFS; | |
7216 | } | |
7217 | ||
2a0e047e JB |
7218 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7219 | struct nlattr *attr, | |
7220 | struct cfg80211_wowlan *trig) | |
7221 | { | |
7222 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7223 | struct cfg80211_wowlan_tcp *cfg; | |
7224 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7225 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7226 | u32 size; | |
7227 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7228 | int err, port; | |
7229 | ||
7230 | if (!rdev->wiphy.wowlan.tcp) | |
7231 | return -EINVAL; | |
7232 | ||
7233 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7234 | nla_data(attr), nla_len(attr), | |
7235 | nl80211_wowlan_tcp_policy); | |
7236 | if (err) | |
7237 | return err; | |
7238 | ||
7239 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7240 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7241 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7242 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7243 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7244 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7245 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7246 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7247 | return -EINVAL; | |
7248 | ||
7249 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
7250 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) | |
7251 | return -EINVAL; | |
7252 | ||
7253 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
7254 | rdev->wiphy.wowlan.tcp->data_interval_max) | |
7255 | return -EINVAL; | |
7256 | ||
7257 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
7258 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) | |
7259 | return -EINVAL; | |
7260 | ||
7261 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7262 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7263 | return -EINVAL; | |
7264 | ||
7265 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7266 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7267 | ||
7268 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7269 | tokens_size = tokln - sizeof(*tok); | |
7270 | ||
7271 | if (!tok->len || tokens_size % tok->len) | |
7272 | return -EINVAL; | |
7273 | if (!rdev->wiphy.wowlan.tcp->tok) | |
7274 | return -EINVAL; | |
7275 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) | |
7276 | return -EINVAL; | |
7277 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) | |
7278 | return -EINVAL; | |
7279 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) | |
7280 | return -EINVAL; | |
7281 | if (tok->offset + tok->len > data_size) | |
7282 | return -EINVAL; | |
7283 | } | |
7284 | ||
7285 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7286 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
7287 | if (!rdev->wiphy.wowlan.tcp->seq) | |
7288 | return -EINVAL; | |
7289 | if (seq->len == 0 || seq->len > 4) | |
7290 | return -EINVAL; | |
7291 | if (seq->len + seq->offset > data_size) | |
7292 | return -EINVAL; | |
7293 | } | |
7294 | ||
7295 | size = sizeof(*cfg); | |
7296 | size += data_size; | |
7297 | size += wake_size + wake_mask_size; | |
7298 | size += tokens_size; | |
7299 | ||
7300 | cfg = kzalloc(size, GFP_KERNEL); | |
7301 | if (!cfg) | |
7302 | return -ENOMEM; | |
7303 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7304 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7305 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7306 | ETH_ALEN); | |
7307 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7308 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7309 | else | |
7310 | port = 0; | |
7311 | #ifdef CONFIG_INET | |
7312 | /* allocate a socket and port for it and use it */ | |
7313 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7314 | IPPROTO_TCP, &cfg->sock, 1); | |
7315 | if (err) { | |
7316 | kfree(cfg); | |
7317 | return err; | |
7318 | } | |
7319 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7320 | sock_release(cfg->sock); | |
7321 | kfree(cfg); | |
7322 | return -EADDRINUSE; | |
7323 | } | |
7324 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7325 | #else | |
7326 | if (!port) { | |
7327 | kfree(cfg); | |
7328 | return -EINVAL; | |
7329 | } | |
7330 | cfg->src_port = port; | |
7331 | #endif | |
7332 | ||
7333 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7334 | cfg->payload_len = data_size; | |
7335 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7336 | memcpy((void *)cfg->payload, | |
7337 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7338 | data_size); | |
7339 | if (seq) | |
7340 | cfg->payload_seq = *seq; | |
7341 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7342 | cfg->wake_len = wake_size; | |
7343 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7344 | memcpy((void *)cfg->wake_data, | |
7345 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7346 | wake_size); | |
7347 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7348 | data_size + wake_size; | |
7349 | memcpy((void *)cfg->wake_mask, | |
7350 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7351 | wake_mask_size); | |
7352 | if (tok) { | |
7353 | cfg->tokens_size = tokens_size; | |
7354 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7355 | } | |
7356 | ||
7357 | trig->tcp = cfg; | |
7358 | ||
7359 | return 0; | |
7360 | } | |
7361 | ||
ff1b6e69 JB |
7362 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7363 | { | |
7364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7365 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7366 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7367 | struct cfg80211_wowlan *ntrig; |
ff1b6e69 JB |
7368 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
7369 | int err, i; | |
6d52563f | 7370 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 | 7371 | |
2a0e047e JB |
7372 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7373 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7374 | return -EOPNOTSUPP; |
7375 | ||
ae33bd81 JB |
7376 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7377 | cfg80211_rdev_free_wowlan(rdev); | |
7378 | rdev->wowlan = NULL; | |
7379 | goto set_wakeup; | |
7380 | } | |
ff1b6e69 JB |
7381 | |
7382 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7383 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7384 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7385 | nl80211_wowlan_policy); | |
7386 | if (err) | |
7387 | return err; | |
7388 | ||
7389 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7390 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7391 | return -EINVAL; | |
7392 | new_triggers.any = true; | |
7393 | } | |
7394 | ||
7395 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7396 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7397 | return -EINVAL; | |
7398 | new_triggers.disconnect = true; | |
7399 | } | |
7400 | ||
7401 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7402 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7403 | return -EINVAL; | |
7404 | new_triggers.magic_pkt = true; | |
7405 | } | |
7406 | ||
77dbbb13 JB |
7407 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7408 | return -EINVAL; | |
7409 | ||
7410 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7411 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7412 | return -EINVAL; | |
7413 | new_triggers.gtk_rekey_failure = true; | |
7414 | } | |
7415 | ||
7416 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7417 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7418 | return -EINVAL; | |
7419 | new_triggers.eap_identity_req = true; | |
7420 | } | |
7421 | ||
7422 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7423 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7424 | return -EINVAL; | |
7425 | new_triggers.four_way_handshake = true; | |
7426 | } | |
7427 | ||
7428 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7429 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7430 | return -EINVAL; | |
7431 | new_triggers.rfkill_release = true; | |
7432 | } | |
7433 | ||
ff1b6e69 JB |
7434 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7435 | struct nlattr *pat; | |
7436 | int n_patterns = 0; | |
bb92d199 | 7437 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7438 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7439 | ||
7440 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7441 | rem) | |
7442 | n_patterns++; | |
7443 | if (n_patterns > wowlan->n_patterns) | |
7444 | return -EINVAL; | |
7445 | ||
7446 | new_triggers.patterns = kcalloc(n_patterns, | |
7447 | sizeof(new_triggers.patterns[0]), | |
7448 | GFP_KERNEL); | |
7449 | if (!new_triggers.patterns) | |
7450 | return -ENOMEM; | |
7451 | ||
7452 | new_triggers.n_patterns = n_patterns; | |
7453 | i = 0; | |
7454 | ||
7455 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7456 | rem) { | |
7457 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7458 | nla_data(pat), nla_len(pat), NULL); | |
7459 | err = -EINVAL; | |
7460 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7461 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7462 | goto error; | |
7463 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7464 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7465 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7466 | mask_len) | |
7467 | goto error; | |
7468 | if (pat_len > wowlan->pattern_max_len || | |
7469 | pat_len < wowlan->pattern_min_len) | |
7470 | goto error; | |
7471 | ||
bb92d199 AK |
7472 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7473 | pkt_offset = 0; | |
7474 | else | |
7475 | pkt_offset = nla_get_u32( | |
7476 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7477 | if (pkt_offset > wowlan->max_pkt_offset) | |
7478 | goto error; | |
7479 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7480 | ||
ff1b6e69 JB |
7481 | new_triggers.patterns[i].mask = |
7482 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7483 | if (!new_triggers.patterns[i].mask) { | |
7484 | err = -ENOMEM; | |
7485 | goto error; | |
7486 | } | |
7487 | new_triggers.patterns[i].pattern = | |
7488 | new_triggers.patterns[i].mask + mask_len; | |
7489 | memcpy(new_triggers.patterns[i].mask, | |
7490 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
7491 | mask_len); | |
7492 | new_triggers.patterns[i].pattern_len = pat_len; | |
7493 | memcpy(new_triggers.patterns[i].pattern, | |
7494 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
7495 | pat_len); | |
7496 | i++; | |
7497 | } | |
7498 | } | |
7499 | ||
2a0e047e JB |
7500 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
7501 | err = nl80211_parse_wowlan_tcp( | |
7502 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
7503 | &new_triggers); | |
7504 | if (err) | |
7505 | goto error; | |
7506 | } | |
7507 | ||
ae33bd81 JB |
7508 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
7509 | if (!ntrig) { | |
7510 | err = -ENOMEM; | |
7511 | goto error; | |
ff1b6e69 | 7512 | } |
ae33bd81 JB |
7513 | cfg80211_rdev_free_wowlan(rdev); |
7514 | rdev->wowlan = ntrig; | |
ff1b6e69 | 7515 | |
ae33bd81 | 7516 | set_wakeup: |
6d52563f | 7517 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
e35e4d28 | 7518 | rdev_set_wakeup(rdev, rdev->wowlan); |
6d52563f | 7519 | |
ff1b6e69 JB |
7520 | return 0; |
7521 | error: | |
7522 | for (i = 0; i < new_triggers.n_patterns; i++) | |
7523 | kfree(new_triggers.patterns[i].mask); | |
7524 | kfree(new_triggers.patterns); | |
2a0e047e JB |
7525 | if (new_triggers.tcp && new_triggers.tcp->sock) |
7526 | sock_release(new_triggers.tcp->sock); | |
7527 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
7528 | return err; |
7529 | } | |
dfb89c56 | 7530 | #endif |
ff1b6e69 | 7531 | |
e5497d76 JB |
7532 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
7533 | { | |
7534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7535 | struct net_device *dev = info->user_ptr[1]; | |
7536 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7537 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
7538 | struct cfg80211_gtk_rekey_data rekey_data; | |
7539 | int err; | |
7540 | ||
7541 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
7542 | return -EINVAL; | |
7543 | ||
7544 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
7545 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7546 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7547 | nl80211_rekey_policy); | |
7548 | if (err) | |
7549 | return err; | |
7550 | ||
7551 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
7552 | return -ERANGE; | |
7553 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
7554 | return -ERANGE; | |
7555 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
7556 | return -ERANGE; | |
7557 | ||
7558 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
7559 | NL80211_KEK_LEN); | |
7560 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
7561 | NL80211_KCK_LEN); | |
7562 | memcpy(rekey_data.replay_ctr, | |
7563 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
7564 | NL80211_REPLAY_CTR_LEN); | |
7565 | ||
7566 | wdev_lock(wdev); | |
7567 | if (!wdev->current_bss) { | |
7568 | err = -ENOTCONN; | |
7569 | goto out; | |
7570 | } | |
7571 | ||
7572 | if (!rdev->ops->set_rekey_data) { | |
7573 | err = -EOPNOTSUPP; | |
7574 | goto out; | |
7575 | } | |
7576 | ||
e35e4d28 | 7577 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
7578 | out: |
7579 | wdev_unlock(wdev); | |
7580 | return err; | |
7581 | } | |
7582 | ||
28946da7 JB |
7583 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
7584 | struct genl_info *info) | |
7585 | { | |
7586 | struct net_device *dev = info->user_ptr[1]; | |
7587 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7588 | ||
7589 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
7590 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
7591 | return -EINVAL; | |
7592 | ||
15e47304 | 7593 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
7594 | return -EBUSY; |
7595 | ||
15e47304 | 7596 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
7597 | return 0; |
7598 | } | |
7599 | ||
7f6cf311 JB |
7600 | static int nl80211_probe_client(struct sk_buff *skb, |
7601 | struct genl_info *info) | |
7602 | { | |
7603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7604 | struct net_device *dev = info->user_ptr[1]; | |
7605 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7606 | struct sk_buff *msg; | |
7607 | void *hdr; | |
7608 | const u8 *addr; | |
7609 | u64 cookie; | |
7610 | int err; | |
7611 | ||
7612 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
7613 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
7614 | return -EOPNOTSUPP; | |
7615 | ||
7616 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7617 | return -EINVAL; | |
7618 | ||
7619 | if (!rdev->ops->probe_client) | |
7620 | return -EOPNOTSUPP; | |
7621 | ||
7622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7623 | if (!msg) | |
7624 | return -ENOMEM; | |
7625 | ||
15e47304 | 7626 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
7627 | NL80211_CMD_PROBE_CLIENT); |
7628 | ||
7629 | if (IS_ERR(hdr)) { | |
7630 | err = PTR_ERR(hdr); | |
7631 | goto free_msg; | |
7632 | } | |
7633 | ||
7634 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7635 | ||
e35e4d28 | 7636 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
7637 | if (err) |
7638 | goto free_msg; | |
7639 | ||
9360ffd1 DM |
7640 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7641 | goto nla_put_failure; | |
7f6cf311 JB |
7642 | |
7643 | genlmsg_end(msg, hdr); | |
7644 | ||
7645 | return genlmsg_reply(msg, info); | |
7646 | ||
7647 | nla_put_failure: | |
7648 | err = -ENOBUFS; | |
7649 | free_msg: | |
7650 | nlmsg_free(msg); | |
7651 | return err; | |
7652 | } | |
7653 | ||
5e760230 JB |
7654 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
7655 | { | |
7656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
7657 | struct cfg80211_beacon_registration *reg, *nreg; |
7658 | int rv; | |
5e760230 JB |
7659 | |
7660 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
7661 | return -EOPNOTSUPP; | |
7662 | ||
37c73b5f BG |
7663 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
7664 | if (!nreg) | |
7665 | return -ENOMEM; | |
7666 | ||
7667 | /* First, check if already registered. */ | |
7668 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
7669 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
7670 | if (reg->nlportid == info->snd_portid) { | |
7671 | rv = -EALREADY; | |
7672 | goto out_err; | |
7673 | } | |
7674 | } | |
7675 | /* Add it to the list */ | |
7676 | nreg->nlportid = info->snd_portid; | |
7677 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 7678 | |
37c73b5f | 7679 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
7680 | |
7681 | return 0; | |
37c73b5f BG |
7682 | out_err: |
7683 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
7684 | kfree(nreg); | |
7685 | return rv; | |
5e760230 JB |
7686 | } |
7687 | ||
98104fde JB |
7688 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
7689 | { | |
7690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7691 | struct wireless_dev *wdev = info->user_ptr[1]; | |
7692 | int err; | |
7693 | ||
7694 | if (!rdev->ops->start_p2p_device) | |
7695 | return -EOPNOTSUPP; | |
7696 | ||
7697 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
7698 | return -EOPNOTSUPP; | |
7699 | ||
7700 | if (wdev->p2p_started) | |
7701 | return 0; | |
7702 | ||
7703 | mutex_lock(&rdev->devlist_mtx); | |
7704 | err = cfg80211_can_add_interface(rdev, wdev->iftype); | |
7705 | mutex_unlock(&rdev->devlist_mtx); | |
7706 | if (err) | |
7707 | return err; | |
7708 | ||
eeb126e9 | 7709 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
7710 | if (err) |
7711 | return err; | |
7712 | ||
7713 | wdev->p2p_started = true; | |
7714 | mutex_lock(&rdev->devlist_mtx); | |
7715 | rdev->opencount++; | |
7716 | mutex_unlock(&rdev->devlist_mtx); | |
7717 | ||
7718 | return 0; | |
7719 | } | |
7720 | ||
7721 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
7722 | { | |
7723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7724 | struct wireless_dev *wdev = info->user_ptr[1]; | |
7725 | ||
7726 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
7727 | return -EOPNOTSUPP; | |
7728 | ||
7729 | if (!rdev->ops->stop_p2p_device) | |
7730 | return -EOPNOTSUPP; | |
7731 | ||
7732 | if (!wdev->p2p_started) | |
7733 | return 0; | |
7734 | ||
eeb126e9 | 7735 | rdev_stop_p2p_device(rdev, wdev); |
98104fde JB |
7736 | wdev->p2p_started = false; |
7737 | ||
7738 | mutex_lock(&rdev->devlist_mtx); | |
7739 | rdev->opencount--; | |
7740 | mutex_unlock(&rdev->devlist_mtx); | |
7741 | ||
7742 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { | |
7743 | rdev->scan_req->aborted = true; | |
7744 | ___cfg80211_scan_done(rdev, true); | |
7745 | } | |
7746 | ||
7747 | return 0; | |
7748 | } | |
7749 | ||
4c476991 JB |
7750 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
7751 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
7752 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
7753 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
7754 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
7755 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 7756 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 7757 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
7758 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
7759 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
7760 | |
7761 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
7762 | struct genl_info *info) | |
7763 | { | |
7764 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 7765 | struct wireless_dev *wdev; |
4c476991 | 7766 | struct net_device *dev; |
4c476991 JB |
7767 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
7768 | ||
7769 | if (rtnl) | |
7770 | rtnl_lock(); | |
7771 | ||
7772 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 7773 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
7774 | if (IS_ERR(rdev)) { |
7775 | if (rtnl) | |
7776 | rtnl_unlock(); | |
7777 | return PTR_ERR(rdev); | |
7778 | } | |
7779 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
7780 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
7781 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
89a54e48 JB |
7782 | mutex_lock(&cfg80211_mutex); |
7783 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | |
7784 | info->attrs); | |
7785 | if (IS_ERR(wdev)) { | |
7786 | mutex_unlock(&cfg80211_mutex); | |
4c476991 JB |
7787 | if (rtnl) |
7788 | rtnl_unlock(); | |
89a54e48 | 7789 | return PTR_ERR(wdev); |
4c476991 | 7790 | } |
89a54e48 | 7791 | |
89a54e48 JB |
7792 | dev = wdev->netdev; |
7793 | rdev = wiphy_to_dev(wdev->wiphy); | |
7794 | ||
1bf614ef JB |
7795 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
7796 | if (!dev) { | |
7797 | mutex_unlock(&cfg80211_mutex); | |
7798 | if (rtnl) | |
7799 | rtnl_unlock(); | |
7800 | return -EINVAL; | |
7801 | } | |
7802 | ||
7803 | info->user_ptr[1] = dev; | |
7804 | } else { | |
7805 | info->user_ptr[1] = wdev; | |
41265714 | 7806 | } |
1bf614ef JB |
7807 | |
7808 | if (dev) { | |
7809 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
7810 | !netif_running(dev)) { | |
7811 | mutex_unlock(&cfg80211_mutex); | |
7812 | if (rtnl) | |
7813 | rtnl_unlock(); | |
7814 | return -ENETDOWN; | |
7815 | } | |
7816 | ||
7817 | dev_hold(dev); | |
98104fde JB |
7818 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
7819 | if (!wdev->p2p_started) { | |
7820 | mutex_unlock(&cfg80211_mutex); | |
7821 | if (rtnl) | |
7822 | rtnl_unlock(); | |
7823 | return -ENETDOWN; | |
7824 | } | |
41265714 | 7825 | } |
89a54e48 | 7826 | |
89a54e48 JB |
7827 | cfg80211_lock_rdev(rdev); |
7828 | ||
7829 | mutex_unlock(&cfg80211_mutex); | |
7830 | ||
4c476991 | 7831 | info->user_ptr[0] = rdev; |
4c476991 JB |
7832 | } |
7833 | ||
7834 | return 0; | |
7835 | } | |
7836 | ||
7837 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
7838 | struct genl_info *info) | |
7839 | { | |
7840 | if (info->user_ptr[0]) | |
7841 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
1bf614ef JB |
7842 | if (info->user_ptr[1]) { |
7843 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
7844 | struct wireless_dev *wdev = info->user_ptr[1]; | |
7845 | ||
7846 | if (wdev->netdev) | |
7847 | dev_put(wdev->netdev); | |
7848 | } else { | |
7849 | dev_put(info->user_ptr[1]); | |
7850 | } | |
7851 | } | |
4c476991 JB |
7852 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
7853 | rtnl_unlock(); | |
7854 | } | |
7855 | ||
55682965 JB |
7856 | static struct genl_ops nl80211_ops[] = { |
7857 | { | |
7858 | .cmd = NL80211_CMD_GET_WIPHY, | |
7859 | .doit = nl80211_get_wiphy, | |
7860 | .dumpit = nl80211_dump_wiphy, | |
7861 | .policy = nl80211_policy, | |
7862 | /* can be retrieved by unprivileged users */ | |
4c476991 | 7863 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
7864 | }, |
7865 | { | |
7866 | .cmd = NL80211_CMD_SET_WIPHY, | |
7867 | .doit = nl80211_set_wiphy, | |
7868 | .policy = nl80211_policy, | |
7869 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 7870 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
7871 | }, |
7872 | { | |
7873 | .cmd = NL80211_CMD_GET_INTERFACE, | |
7874 | .doit = nl80211_get_interface, | |
7875 | .dumpit = nl80211_dump_interface, | |
7876 | .policy = nl80211_policy, | |
7877 | /* can be retrieved by unprivileged users */ | |
72fb2abc | 7878 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
55682965 JB |
7879 | }, |
7880 | { | |
7881 | .cmd = NL80211_CMD_SET_INTERFACE, | |
7882 | .doit = nl80211_set_interface, | |
7883 | .policy = nl80211_policy, | |
7884 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7885 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7886 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
7887 | }, |
7888 | { | |
7889 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
7890 | .doit = nl80211_new_interface, | |
7891 | .policy = nl80211_policy, | |
7892 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7893 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
7894 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
7895 | }, |
7896 | { | |
7897 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
7898 | .doit = nl80211_del_interface, | |
7899 | .policy = nl80211_policy, | |
41ade00f | 7900 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 7901 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 7902 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
7903 | }, |
7904 | { | |
7905 | .cmd = NL80211_CMD_GET_KEY, | |
7906 | .doit = nl80211_get_key, | |
7907 | .policy = nl80211_policy, | |
7908 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7909 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7910 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
7911 | }, |
7912 | { | |
7913 | .cmd = NL80211_CMD_SET_KEY, | |
7914 | .doit = nl80211_set_key, | |
7915 | .policy = nl80211_policy, | |
7916 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7917 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7918 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
7919 | }, |
7920 | { | |
7921 | .cmd = NL80211_CMD_NEW_KEY, | |
7922 | .doit = nl80211_new_key, | |
7923 | .policy = nl80211_policy, | |
7924 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7925 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7926 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
7927 | }, |
7928 | { | |
7929 | .cmd = NL80211_CMD_DEL_KEY, | |
7930 | .doit = nl80211_del_key, | |
7931 | .policy = nl80211_policy, | |
55682965 | 7932 | .flags = GENL_ADMIN_PERM, |
41265714 | 7933 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7934 | NL80211_FLAG_NEED_RTNL, |
55682965 | 7935 | }, |
ed1b6cc7 JB |
7936 | { |
7937 | .cmd = NL80211_CMD_SET_BEACON, | |
7938 | .policy = nl80211_policy, | |
7939 | .flags = GENL_ADMIN_PERM, | |
8860020e | 7940 | .doit = nl80211_set_beacon, |
2b5f8b0b | 7941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7942 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
7943 | }, |
7944 | { | |
8860020e | 7945 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
7946 | .policy = nl80211_policy, |
7947 | .flags = GENL_ADMIN_PERM, | |
8860020e | 7948 | .doit = nl80211_start_ap, |
2b5f8b0b | 7949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7950 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
7951 | }, |
7952 | { | |
8860020e | 7953 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
7954 | .policy = nl80211_policy, |
7955 | .flags = GENL_ADMIN_PERM, | |
8860020e | 7956 | .doit = nl80211_stop_ap, |
2b5f8b0b | 7957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7958 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 7959 | }, |
5727ef1b JB |
7960 | { |
7961 | .cmd = NL80211_CMD_GET_STATION, | |
7962 | .doit = nl80211_get_station, | |
2ec600d6 | 7963 | .dumpit = nl80211_dump_station, |
5727ef1b | 7964 | .policy = nl80211_policy, |
4c476991 JB |
7965 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7966 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
7967 | }, |
7968 | { | |
7969 | .cmd = NL80211_CMD_SET_STATION, | |
7970 | .doit = nl80211_set_station, | |
7971 | .policy = nl80211_policy, | |
7972 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7973 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7974 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
7975 | }, |
7976 | { | |
7977 | .cmd = NL80211_CMD_NEW_STATION, | |
7978 | .doit = nl80211_new_station, | |
7979 | .policy = nl80211_policy, | |
7980 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7981 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7982 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
7983 | }, |
7984 | { | |
7985 | .cmd = NL80211_CMD_DEL_STATION, | |
7986 | .doit = nl80211_del_station, | |
7987 | .policy = nl80211_policy, | |
2ec600d6 | 7988 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 7989 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7990 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
7991 | }, |
7992 | { | |
7993 | .cmd = NL80211_CMD_GET_MPATH, | |
7994 | .doit = nl80211_get_mpath, | |
7995 | .dumpit = nl80211_dump_mpath, | |
7996 | .policy = nl80211_policy, | |
7997 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7999 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8000 | }, |
8001 | { | |
8002 | .cmd = NL80211_CMD_SET_MPATH, | |
8003 | .doit = nl80211_set_mpath, | |
8004 | .policy = nl80211_policy, | |
8005 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8007 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8008 | }, |
8009 | { | |
8010 | .cmd = NL80211_CMD_NEW_MPATH, | |
8011 | .doit = nl80211_new_mpath, | |
8012 | .policy = nl80211_policy, | |
8013 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8014 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8015 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8016 | }, |
8017 | { | |
8018 | .cmd = NL80211_CMD_DEL_MPATH, | |
8019 | .doit = nl80211_del_mpath, | |
8020 | .policy = nl80211_policy, | |
9f1ba906 | 8021 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8023 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8024 | }, |
8025 | { | |
8026 | .cmd = NL80211_CMD_SET_BSS, | |
8027 | .doit = nl80211_set_bss, | |
8028 | .policy = nl80211_policy, | |
b2e1b302 | 8029 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8031 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8032 | }, |
f130347c LR |
8033 | { |
8034 | .cmd = NL80211_CMD_GET_REG, | |
8035 | .doit = nl80211_get_reg, | |
8036 | .policy = nl80211_policy, | |
8037 | /* can be retrieved by unprivileged users */ | |
8038 | }, | |
b2e1b302 LR |
8039 | { |
8040 | .cmd = NL80211_CMD_SET_REG, | |
8041 | .doit = nl80211_set_reg, | |
8042 | .policy = nl80211_policy, | |
8043 | .flags = GENL_ADMIN_PERM, | |
8044 | }, | |
8045 | { | |
8046 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8047 | .doit = nl80211_req_set_reg, | |
8048 | .policy = nl80211_policy, | |
93da9cc1 | 8049 | .flags = GENL_ADMIN_PERM, |
8050 | }, | |
8051 | { | |
24bdd9f4 JC |
8052 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8053 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8054 | .policy = nl80211_policy, |
8055 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8056 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8057 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8058 | }, |
8059 | { | |
24bdd9f4 JC |
8060 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8061 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8062 | .policy = nl80211_policy, |
9aed3cc1 | 8063 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8064 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8065 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8066 | }, |
2a519311 JB |
8067 | { |
8068 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8069 | .doit = nl80211_trigger_scan, | |
8070 | .policy = nl80211_policy, | |
8071 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8072 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8073 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8074 | }, |
8075 | { | |
8076 | .cmd = NL80211_CMD_GET_SCAN, | |
8077 | .policy = nl80211_policy, | |
8078 | .dumpit = nl80211_dump_scan, | |
8079 | }, | |
807f8a8c LC |
8080 | { |
8081 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8082 | .doit = nl80211_start_sched_scan, | |
8083 | .policy = nl80211_policy, | |
8084 | .flags = GENL_ADMIN_PERM, | |
8085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8086 | NL80211_FLAG_NEED_RTNL, | |
8087 | }, | |
8088 | { | |
8089 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8090 | .doit = nl80211_stop_sched_scan, | |
8091 | .policy = nl80211_policy, | |
8092 | .flags = GENL_ADMIN_PERM, | |
8093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8094 | NL80211_FLAG_NEED_RTNL, | |
8095 | }, | |
636a5d36 JM |
8096 | { |
8097 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8098 | .doit = nl80211_authenticate, | |
8099 | .policy = nl80211_policy, | |
8100 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8102 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8103 | }, |
8104 | { | |
8105 | .cmd = NL80211_CMD_ASSOCIATE, | |
8106 | .doit = nl80211_associate, | |
8107 | .policy = nl80211_policy, | |
8108 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8110 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8111 | }, |
8112 | { | |
8113 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8114 | .doit = nl80211_deauthenticate, | |
8115 | .policy = nl80211_policy, | |
8116 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8118 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8119 | }, |
8120 | { | |
8121 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8122 | .doit = nl80211_disassociate, | |
8123 | .policy = nl80211_policy, | |
8124 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8125 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8126 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8127 | }, |
04a773ad JB |
8128 | { |
8129 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8130 | .doit = nl80211_join_ibss, | |
8131 | .policy = nl80211_policy, | |
8132 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8133 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8134 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8135 | }, |
8136 | { | |
8137 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8138 | .doit = nl80211_leave_ibss, | |
8139 | .policy = nl80211_policy, | |
8140 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8141 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8142 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8143 | }, |
aff89a9b JB |
8144 | #ifdef CONFIG_NL80211_TESTMODE |
8145 | { | |
8146 | .cmd = NL80211_CMD_TESTMODE, | |
8147 | .doit = nl80211_testmode_do, | |
71063f0e | 8148 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8149 | .policy = nl80211_policy, |
8150 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8151 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8152 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8153 | }, |
8154 | #endif | |
b23aa676 SO |
8155 | { |
8156 | .cmd = NL80211_CMD_CONNECT, | |
8157 | .doit = nl80211_connect, | |
8158 | .policy = nl80211_policy, | |
8159 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8160 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8161 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8162 | }, |
8163 | { | |
8164 | .cmd = NL80211_CMD_DISCONNECT, | |
8165 | .doit = nl80211_disconnect, | |
8166 | .policy = nl80211_policy, | |
8167 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8168 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8169 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8170 | }, |
463d0183 JB |
8171 | { |
8172 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8173 | .doit = nl80211_wiphy_netns, | |
8174 | .policy = nl80211_policy, | |
8175 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8176 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8177 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8178 | }, |
61fa713c HS |
8179 | { |
8180 | .cmd = NL80211_CMD_GET_SURVEY, | |
8181 | .policy = nl80211_policy, | |
8182 | .dumpit = nl80211_dump_survey, | |
8183 | }, | |
67fbb16b SO |
8184 | { |
8185 | .cmd = NL80211_CMD_SET_PMKSA, | |
8186 | .doit = nl80211_setdel_pmksa, | |
8187 | .policy = nl80211_policy, | |
8188 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8189 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8190 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8191 | }, |
8192 | { | |
8193 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8194 | .doit = nl80211_setdel_pmksa, | |
8195 | .policy = nl80211_policy, | |
8196 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8197 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8198 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8199 | }, |
8200 | { | |
8201 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8202 | .doit = nl80211_flush_pmksa, | |
8203 | .policy = nl80211_policy, | |
8204 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8205 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8206 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8207 | }, |
9588bbd5 JM |
8208 | { |
8209 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8210 | .doit = nl80211_remain_on_channel, | |
8211 | .policy = nl80211_policy, | |
8212 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8213 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8214 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8215 | }, |
8216 | { | |
8217 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8218 | .doit = nl80211_cancel_remain_on_channel, | |
8219 | .policy = nl80211_policy, | |
8220 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8221 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8222 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8223 | }, |
13ae75b1 JM |
8224 | { |
8225 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8226 | .doit = nl80211_set_tx_bitrate_mask, | |
8227 | .policy = nl80211_policy, | |
8228 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8229 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8230 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8231 | }, |
026331c4 | 8232 | { |
2e161f78 JB |
8233 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8234 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8235 | .policy = nl80211_policy, |
8236 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8237 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8238 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8239 | }, |
8240 | { | |
2e161f78 JB |
8241 | .cmd = NL80211_CMD_FRAME, |
8242 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8243 | .policy = nl80211_policy, |
f7ca38df | 8244 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8245 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8246 | NL80211_FLAG_NEED_RTNL, |
8247 | }, | |
8248 | { | |
8249 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8250 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8251 | .policy = nl80211_policy, | |
026331c4 | 8252 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8253 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8254 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8255 | }, |
ffb9eb3d KV |
8256 | { |
8257 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8258 | .doit = nl80211_set_power_save, | |
8259 | .policy = nl80211_policy, | |
8260 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8261 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8262 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8263 | }, |
8264 | { | |
8265 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8266 | .doit = nl80211_get_power_save, | |
8267 | .policy = nl80211_policy, | |
8268 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8269 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8270 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8271 | }, |
d6dc1a38 JO |
8272 | { |
8273 | .cmd = NL80211_CMD_SET_CQM, | |
8274 | .doit = nl80211_set_cqm, | |
8275 | .policy = nl80211_policy, | |
8276 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8277 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8278 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8279 | }, |
f444de05 JB |
8280 | { |
8281 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8282 | .doit = nl80211_set_channel, | |
8283 | .policy = nl80211_policy, | |
8284 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8285 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8286 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 8287 | }, |
e8347eba BJ |
8288 | { |
8289 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
8290 | .doit = nl80211_set_wds_peer, | |
8291 | .policy = nl80211_policy, | |
8292 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
8293 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8294 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 8295 | }, |
29cbe68c JB |
8296 | { |
8297 | .cmd = NL80211_CMD_JOIN_MESH, | |
8298 | .doit = nl80211_join_mesh, | |
8299 | .policy = nl80211_policy, | |
8300 | .flags = GENL_ADMIN_PERM, | |
8301 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8302 | NL80211_FLAG_NEED_RTNL, | |
8303 | }, | |
8304 | { | |
8305 | .cmd = NL80211_CMD_LEAVE_MESH, | |
8306 | .doit = nl80211_leave_mesh, | |
8307 | .policy = nl80211_policy, | |
8308 | .flags = GENL_ADMIN_PERM, | |
8309 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8310 | NL80211_FLAG_NEED_RTNL, | |
8311 | }, | |
dfb89c56 | 8312 | #ifdef CONFIG_PM |
ff1b6e69 JB |
8313 | { |
8314 | .cmd = NL80211_CMD_GET_WOWLAN, | |
8315 | .doit = nl80211_get_wowlan, | |
8316 | .policy = nl80211_policy, | |
8317 | /* can be retrieved by unprivileged users */ | |
8318 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8319 | NL80211_FLAG_NEED_RTNL, | |
8320 | }, | |
8321 | { | |
8322 | .cmd = NL80211_CMD_SET_WOWLAN, | |
8323 | .doit = nl80211_set_wowlan, | |
8324 | .policy = nl80211_policy, | |
8325 | .flags = GENL_ADMIN_PERM, | |
8326 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8327 | NL80211_FLAG_NEED_RTNL, | |
8328 | }, | |
dfb89c56 | 8329 | #endif |
e5497d76 JB |
8330 | { |
8331 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
8332 | .doit = nl80211_set_rekey_data, | |
8333 | .policy = nl80211_policy, | |
8334 | .flags = GENL_ADMIN_PERM, | |
8335 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8336 | NL80211_FLAG_NEED_RTNL, | |
8337 | }, | |
109086ce AN |
8338 | { |
8339 | .cmd = NL80211_CMD_TDLS_MGMT, | |
8340 | .doit = nl80211_tdls_mgmt, | |
8341 | .policy = nl80211_policy, | |
8342 | .flags = GENL_ADMIN_PERM, | |
8343 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8344 | NL80211_FLAG_NEED_RTNL, | |
8345 | }, | |
8346 | { | |
8347 | .cmd = NL80211_CMD_TDLS_OPER, | |
8348 | .doit = nl80211_tdls_oper, | |
8349 | .policy = nl80211_policy, | |
8350 | .flags = GENL_ADMIN_PERM, | |
8351 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8352 | NL80211_FLAG_NEED_RTNL, | |
8353 | }, | |
28946da7 JB |
8354 | { |
8355 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
8356 | .doit = nl80211_register_unexpected_frame, | |
8357 | .policy = nl80211_policy, | |
8358 | .flags = GENL_ADMIN_PERM, | |
8359 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8360 | NL80211_FLAG_NEED_RTNL, | |
8361 | }, | |
7f6cf311 JB |
8362 | { |
8363 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
8364 | .doit = nl80211_probe_client, | |
8365 | .policy = nl80211_policy, | |
8366 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8367 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
8368 | NL80211_FLAG_NEED_RTNL, |
8369 | }, | |
5e760230 JB |
8370 | { |
8371 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
8372 | .doit = nl80211_register_beacons, | |
8373 | .policy = nl80211_policy, | |
8374 | .flags = GENL_ADMIN_PERM, | |
8375 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8376 | NL80211_FLAG_NEED_RTNL, | |
8377 | }, | |
1d9d9213 SW |
8378 | { |
8379 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
8380 | .doit = nl80211_set_noack_map, | |
8381 | .policy = nl80211_policy, | |
8382 | .flags = GENL_ADMIN_PERM, | |
8383 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8384 | NL80211_FLAG_NEED_RTNL, | |
8385 | }, | |
98104fde JB |
8386 | { |
8387 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
8388 | .doit = nl80211_start_p2p_device, | |
8389 | .policy = nl80211_policy, | |
8390 | .flags = GENL_ADMIN_PERM, | |
8391 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
8392 | NL80211_FLAG_NEED_RTNL, | |
8393 | }, | |
8394 | { | |
8395 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
8396 | .doit = nl80211_stop_p2p_device, | |
8397 | .policy = nl80211_policy, | |
8398 | .flags = GENL_ADMIN_PERM, | |
8399 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8400 | NL80211_FLAG_NEED_RTNL, | |
8401 | }, | |
f4e583c8 AQ |
8402 | { |
8403 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
8404 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
8405 | .policy = nl80211_policy, |
8406 | .flags = GENL_ADMIN_PERM, | |
8407 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8408 | NL80211_FLAG_NEED_RTNL, | |
8409 | }, | |
8410 | { | |
8411 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
8412 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
8413 | .policy = nl80211_policy, |
8414 | .flags = GENL_ADMIN_PERM, | |
8415 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8416 | NL80211_FLAG_NEED_RTNL, | |
8417 | }, | |
04f39047 SW |
8418 | { |
8419 | .cmd = NL80211_CMD_RADAR_DETECT, | |
8420 | .doit = nl80211_start_radar_detection, | |
8421 | .policy = nl80211_policy, | |
8422 | .flags = GENL_ADMIN_PERM, | |
8423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8424 | NL80211_FLAG_NEED_RTNL, | |
8425 | }, | |
55682965 | 8426 | }; |
9588bbd5 | 8427 | |
6039f6d2 JM |
8428 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
8429 | .name = "mlme", | |
8430 | }; | |
55682965 JB |
8431 | |
8432 | /* multicast groups */ | |
8433 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
8434 | .name = "config", | |
8435 | }; | |
2a519311 JB |
8436 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
8437 | .name = "scan", | |
8438 | }; | |
73d54c9e LR |
8439 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
8440 | .name = "regulatory", | |
8441 | }; | |
55682965 JB |
8442 | |
8443 | /* notification functions */ | |
8444 | ||
8445 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
8446 | { | |
8447 | struct sk_buff *msg; | |
8448 | ||
fd2120ca | 8449 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
8450 | if (!msg) |
8451 | return; | |
8452 | ||
8453 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
8454 | nlmsg_free(msg); | |
8455 | return; | |
8456 | } | |
8457 | ||
463d0183 JB |
8458 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8459 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
8460 | } |
8461 | ||
362a415d JB |
8462 | static int nl80211_add_scan_req(struct sk_buff *msg, |
8463 | struct cfg80211_registered_device *rdev) | |
8464 | { | |
8465 | struct cfg80211_scan_request *req = rdev->scan_req; | |
8466 | struct nlattr *nest; | |
8467 | int i; | |
8468 | ||
667503dd JB |
8469 | ASSERT_RDEV_LOCK(rdev); |
8470 | ||
362a415d JB |
8471 | if (WARN_ON(!req)) |
8472 | return 0; | |
8473 | ||
8474 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
8475 | if (!nest) | |
8476 | goto nla_put_failure; | |
9360ffd1 DM |
8477 | for (i = 0; i < req->n_ssids; i++) { |
8478 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
8479 | goto nla_put_failure; | |
8480 | } | |
362a415d JB |
8481 | nla_nest_end(msg, nest); |
8482 | ||
8483 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8484 | if (!nest) | |
8485 | goto nla_put_failure; | |
9360ffd1 DM |
8486 | for (i = 0; i < req->n_channels; i++) { |
8487 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
8488 | goto nla_put_failure; | |
8489 | } | |
362a415d JB |
8490 | nla_nest_end(msg, nest); |
8491 | ||
9360ffd1 DM |
8492 | if (req->ie && |
8493 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
8494 | goto nla_put_failure; | |
362a415d | 8495 | |
ed473771 SL |
8496 | if (req->flags) |
8497 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
8498 | ||
362a415d JB |
8499 | return 0; |
8500 | nla_put_failure: | |
8501 | return -ENOBUFS; | |
8502 | } | |
8503 | ||
a538e2d5 JB |
8504 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
8505 | struct cfg80211_registered_device *rdev, | |
fd014284 | 8506 | struct wireless_dev *wdev, |
15e47304 | 8507 | u32 portid, u32 seq, int flags, |
a538e2d5 | 8508 | u32 cmd) |
2a519311 JB |
8509 | { |
8510 | void *hdr; | |
8511 | ||
15e47304 | 8512 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
8513 | if (!hdr) |
8514 | return -1; | |
8515 | ||
9360ffd1 | 8516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
8517 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
8518 | wdev->netdev->ifindex)) || | |
8519 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 8520 | goto nla_put_failure; |
2a519311 | 8521 | |
362a415d JB |
8522 | /* ignore errors and send incomplete event anyway */ |
8523 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
8524 | |
8525 | return genlmsg_end(msg, hdr); | |
8526 | ||
8527 | nla_put_failure: | |
8528 | genlmsg_cancel(msg, hdr); | |
8529 | return -EMSGSIZE; | |
8530 | } | |
8531 | ||
807f8a8c LC |
8532 | static int |
8533 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
8534 | struct cfg80211_registered_device *rdev, | |
8535 | struct net_device *netdev, | |
15e47304 | 8536 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
8537 | { |
8538 | void *hdr; | |
8539 | ||
15e47304 | 8540 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
8541 | if (!hdr) |
8542 | return -1; | |
8543 | ||
9360ffd1 DM |
8544 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8545 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
8546 | goto nla_put_failure; | |
807f8a8c LC |
8547 | |
8548 | return genlmsg_end(msg, hdr); | |
8549 | ||
8550 | nla_put_failure: | |
8551 | genlmsg_cancel(msg, hdr); | |
8552 | return -EMSGSIZE; | |
8553 | } | |
8554 | ||
a538e2d5 | 8555 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 8556 | struct wireless_dev *wdev) |
a538e2d5 JB |
8557 | { |
8558 | struct sk_buff *msg; | |
8559 | ||
58050fce | 8560 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
8561 | if (!msg) |
8562 | return; | |
8563 | ||
fd014284 | 8564 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
8565 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
8566 | nlmsg_free(msg); | |
8567 | return; | |
8568 | } | |
8569 | ||
463d0183 JB |
8570 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8571 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
8572 | } |
8573 | ||
2a519311 | 8574 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 8575 | struct wireless_dev *wdev) |
2a519311 JB |
8576 | { |
8577 | struct sk_buff *msg; | |
8578 | ||
fd2120ca | 8579 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
8580 | if (!msg) |
8581 | return; | |
8582 | ||
fd014284 | 8583 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 8584 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
8585 | nlmsg_free(msg); |
8586 | return; | |
8587 | } | |
8588 | ||
463d0183 JB |
8589 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8590 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
8591 | } |
8592 | ||
8593 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 8594 | struct wireless_dev *wdev) |
2a519311 JB |
8595 | { |
8596 | struct sk_buff *msg; | |
8597 | ||
fd2120ca | 8598 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
8599 | if (!msg) |
8600 | return; | |
8601 | ||
fd014284 | 8602 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 8603 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
8604 | nlmsg_free(msg); |
8605 | return; | |
8606 | } | |
8607 | ||
463d0183 JB |
8608 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8609 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
8610 | } |
8611 | ||
807f8a8c LC |
8612 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
8613 | struct net_device *netdev) | |
8614 | { | |
8615 | struct sk_buff *msg; | |
8616 | ||
8617 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8618 | if (!msg) | |
8619 | return; | |
8620 | ||
8621 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
8622 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
8623 | nlmsg_free(msg); | |
8624 | return; | |
8625 | } | |
8626 | ||
8627 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8628 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
8629 | } | |
8630 | ||
8631 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
8632 | struct net_device *netdev, u32 cmd) | |
8633 | { | |
8634 | struct sk_buff *msg; | |
8635 | ||
58050fce | 8636 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
8637 | if (!msg) |
8638 | return; | |
8639 | ||
8640 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
8641 | nlmsg_free(msg); | |
8642 | return; | |
8643 | } | |
8644 | ||
8645 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8646 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
8647 | } | |
8648 | ||
73d54c9e LR |
8649 | /* |
8650 | * This can happen on global regulatory changes or device specific settings | |
8651 | * based on custom world regulatory domains. | |
8652 | */ | |
8653 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
8654 | { | |
8655 | struct sk_buff *msg; | |
8656 | void *hdr; | |
8657 | ||
fd2120ca | 8658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
8659 | if (!msg) |
8660 | return; | |
8661 | ||
8662 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
8663 | if (!hdr) { | |
8664 | nlmsg_free(msg); | |
8665 | return; | |
8666 | } | |
8667 | ||
8668 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
8669 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
8670 | goto nla_put_failure; | |
8671 | ||
8672 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
8673 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
8674 | NL80211_REGDOM_TYPE_WORLD)) | |
8675 | goto nla_put_failure; | |
8676 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
8677 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
8678 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
8679 | goto nla_put_failure; | |
8680 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
8681 | request->intersect) { | |
8682 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
8683 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
8684 | goto nla_put_failure; | |
8685 | } else { | |
8686 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
8687 | NL80211_REGDOM_TYPE_COUNTRY) || | |
8688 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
8689 | request->alpha2)) | |
8690 | goto nla_put_failure; | |
8691 | } | |
8692 | ||
f4173766 | 8693 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
8694 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
8695 | goto nla_put_failure; | |
73d54c9e | 8696 | |
3b7b72ee | 8697 | genlmsg_end(msg, hdr); |
73d54c9e | 8698 | |
bc43b28c | 8699 | rcu_read_lock(); |
463d0183 | 8700 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
8701 | GFP_ATOMIC); |
8702 | rcu_read_unlock(); | |
73d54c9e LR |
8703 | |
8704 | return; | |
8705 | ||
8706 | nla_put_failure: | |
8707 | genlmsg_cancel(msg, hdr); | |
8708 | nlmsg_free(msg); | |
8709 | } | |
8710 | ||
6039f6d2 JM |
8711 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
8712 | struct net_device *netdev, | |
8713 | const u8 *buf, size_t len, | |
e6d6e342 | 8714 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
8715 | { |
8716 | struct sk_buff *msg; | |
8717 | void *hdr; | |
8718 | ||
e6d6e342 | 8719 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
8720 | if (!msg) |
8721 | return; | |
8722 | ||
8723 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
8724 | if (!hdr) { | |
8725 | nlmsg_free(msg); | |
8726 | return; | |
8727 | } | |
8728 | ||
9360ffd1 DM |
8729 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8730 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8731 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
8732 | goto nla_put_failure; | |
6039f6d2 | 8733 | |
3b7b72ee | 8734 | genlmsg_end(msg, hdr); |
6039f6d2 | 8735 | |
463d0183 JB |
8736 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8737 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
8738 | return; |
8739 | ||
8740 | nla_put_failure: | |
8741 | genlmsg_cancel(msg, hdr); | |
8742 | nlmsg_free(msg); | |
8743 | } | |
8744 | ||
8745 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
8746 | struct net_device *netdev, const u8 *buf, |
8747 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
8748 | { |
8749 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 8750 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
8751 | } |
8752 | ||
8753 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
8754 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 8755 | size_t len, gfp_t gfp) |
6039f6d2 | 8756 | { |
e6d6e342 JB |
8757 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
8758 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
8759 | } |
8760 | ||
53b46b84 | 8761 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
8762 | struct net_device *netdev, const u8 *buf, |
8763 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
8764 | { |
8765 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 8766 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
8767 | } |
8768 | ||
53b46b84 JM |
8769 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
8770 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 8771 | size_t len, gfp_t gfp) |
6039f6d2 JM |
8772 | { |
8773 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 8774 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
8775 | } |
8776 | ||
cf4e594e JM |
8777 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
8778 | struct net_device *netdev, const u8 *buf, | |
8779 | size_t len, gfp_t gfp) | |
8780 | { | |
8781 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
8782 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); | |
8783 | } | |
8784 | ||
8785 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, | |
8786 | struct net_device *netdev, const u8 *buf, | |
8787 | size_t len, gfp_t gfp) | |
8788 | { | |
8789 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
8790 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); | |
8791 | } | |
8792 | ||
1b06bb40 LR |
8793 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
8794 | struct net_device *netdev, int cmd, | |
e6d6e342 | 8795 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
8796 | { |
8797 | struct sk_buff *msg; | |
8798 | void *hdr; | |
8799 | ||
e6d6e342 | 8800 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
8801 | if (!msg) |
8802 | return; | |
8803 | ||
8804 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
8805 | if (!hdr) { | |
8806 | nlmsg_free(msg); | |
8807 | return; | |
8808 | } | |
8809 | ||
9360ffd1 DM |
8810 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8811 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8812 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
8813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
8814 | goto nla_put_failure; | |
1965c853 | 8815 | |
3b7b72ee | 8816 | genlmsg_end(msg, hdr); |
1965c853 | 8817 | |
463d0183 JB |
8818 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8819 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
8820 | return; |
8821 | ||
8822 | nla_put_failure: | |
8823 | genlmsg_cancel(msg, hdr); | |
8824 | nlmsg_free(msg); | |
8825 | } | |
8826 | ||
8827 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
8828 | struct net_device *netdev, const u8 *addr, |
8829 | gfp_t gfp) | |
1965c853 JM |
8830 | { |
8831 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 8832 | addr, gfp); |
1965c853 JM |
8833 | } |
8834 | ||
8835 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
8836 | struct net_device *netdev, const u8 *addr, |
8837 | gfp_t gfp) | |
1965c853 | 8838 | { |
e6d6e342 JB |
8839 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
8840 | addr, gfp); | |
1965c853 JM |
8841 | } |
8842 | ||
b23aa676 SO |
8843 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
8844 | struct net_device *netdev, const u8 *bssid, | |
8845 | const u8 *req_ie, size_t req_ie_len, | |
8846 | const u8 *resp_ie, size_t resp_ie_len, | |
8847 | u16 status, gfp_t gfp) | |
8848 | { | |
8849 | struct sk_buff *msg; | |
8850 | void *hdr; | |
8851 | ||
58050fce | 8852 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
8853 | if (!msg) |
8854 | return; | |
8855 | ||
8856 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
8857 | if (!hdr) { | |
8858 | nlmsg_free(msg); | |
8859 | return; | |
8860 | } | |
8861 | ||
9360ffd1 DM |
8862 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8863 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8864 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
8865 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
8866 | (req_ie && | |
8867 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
8868 | (resp_ie && | |
8869 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
8870 | goto nla_put_failure; | |
b23aa676 | 8871 | |
3b7b72ee | 8872 | genlmsg_end(msg, hdr); |
b23aa676 | 8873 | |
463d0183 JB |
8874 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8875 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
8876 | return; |
8877 | ||
8878 | nla_put_failure: | |
8879 | genlmsg_cancel(msg, hdr); | |
8880 | nlmsg_free(msg); | |
8881 | ||
8882 | } | |
8883 | ||
8884 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
8885 | struct net_device *netdev, const u8 *bssid, | |
8886 | const u8 *req_ie, size_t req_ie_len, | |
8887 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
8888 | { | |
8889 | struct sk_buff *msg; | |
8890 | void *hdr; | |
8891 | ||
58050fce | 8892 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
8893 | if (!msg) |
8894 | return; | |
8895 | ||
8896 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
8897 | if (!hdr) { | |
8898 | nlmsg_free(msg); | |
8899 | return; | |
8900 | } | |
8901 | ||
9360ffd1 DM |
8902 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8903 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8904 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
8905 | (req_ie && | |
8906 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
8907 | (resp_ie && | |
8908 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
8909 | goto nla_put_failure; | |
b23aa676 | 8910 | |
3b7b72ee | 8911 | genlmsg_end(msg, hdr); |
b23aa676 | 8912 | |
463d0183 JB |
8913 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8914 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
8915 | return; |
8916 | ||
8917 | nla_put_failure: | |
8918 | genlmsg_cancel(msg, hdr); | |
8919 | nlmsg_free(msg); | |
8920 | ||
8921 | } | |
8922 | ||
8923 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
8924 | struct net_device *netdev, u16 reason, | |
667503dd | 8925 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
8926 | { |
8927 | struct sk_buff *msg; | |
8928 | void *hdr; | |
8929 | ||
58050fce | 8930 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
8931 | if (!msg) |
8932 | return; | |
8933 | ||
8934 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
8935 | if (!hdr) { | |
8936 | nlmsg_free(msg); | |
8937 | return; | |
8938 | } | |
8939 | ||
9360ffd1 DM |
8940 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8941 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8942 | (from_ap && reason && | |
8943 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
8944 | (from_ap && | |
8945 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
8946 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
8947 | goto nla_put_failure; | |
b23aa676 | 8948 | |
3b7b72ee | 8949 | genlmsg_end(msg, hdr); |
b23aa676 | 8950 | |
463d0183 JB |
8951 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8952 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
8953 | return; |
8954 | ||
8955 | nla_put_failure: | |
8956 | genlmsg_cancel(msg, hdr); | |
8957 | nlmsg_free(msg); | |
8958 | ||
8959 | } | |
8960 | ||
04a773ad JB |
8961 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
8962 | struct net_device *netdev, const u8 *bssid, | |
8963 | gfp_t gfp) | |
8964 | { | |
8965 | struct sk_buff *msg; | |
8966 | void *hdr; | |
8967 | ||
fd2120ca | 8968 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
8969 | if (!msg) |
8970 | return; | |
8971 | ||
8972 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
8973 | if (!hdr) { | |
8974 | nlmsg_free(msg); | |
8975 | return; | |
8976 | } | |
8977 | ||
9360ffd1 DM |
8978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8979 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8980 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
8981 | goto nla_put_failure; | |
04a773ad | 8982 | |
3b7b72ee | 8983 | genlmsg_end(msg, hdr); |
04a773ad | 8984 | |
463d0183 JB |
8985 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8986 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
8987 | return; |
8988 | ||
8989 | nla_put_failure: | |
8990 | genlmsg_cancel(msg, hdr); | |
8991 | nlmsg_free(msg); | |
8992 | } | |
8993 | ||
c93b5e71 JC |
8994 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
8995 | struct net_device *netdev, | |
8996 | const u8 *macaddr, const u8* ie, u8 ie_len, | |
8997 | gfp_t gfp) | |
8998 | { | |
8999 | struct sk_buff *msg; | |
9000 | void *hdr; | |
9001 | ||
9002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9003 | if (!msg) | |
9004 | return; | |
9005 | ||
9006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9007 | if (!hdr) { | |
9008 | nlmsg_free(msg); | |
9009 | return; | |
9010 | } | |
9011 | ||
9360ffd1 DM |
9012 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9013 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9014 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || | |
9015 | (ie_len && ie && | |
9016 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9017 | goto nla_put_failure; | |
c93b5e71 | 9018 | |
3b7b72ee | 9019 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9020 | |
9021 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9022 | nl80211_mlme_mcgrp.id, gfp); | |
9023 | return; | |
9024 | ||
9025 | nla_put_failure: | |
9026 | genlmsg_cancel(msg, hdr); | |
9027 | nlmsg_free(msg); | |
9028 | } | |
9029 | ||
a3b8b056 JM |
9030 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9031 | struct net_device *netdev, const u8 *addr, | |
9032 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9033 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9034 | { |
9035 | struct sk_buff *msg; | |
9036 | void *hdr; | |
9037 | ||
e6d6e342 | 9038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9039 | if (!msg) |
9040 | return; | |
9041 | ||
9042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9043 | if (!hdr) { | |
9044 | nlmsg_free(msg); | |
9045 | return; | |
9046 | } | |
9047 | ||
9360ffd1 DM |
9048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9049 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9050 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9051 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9052 | (key_id != -1 && | |
9053 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9054 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9055 | goto nla_put_failure; | |
a3b8b056 | 9056 | |
3b7b72ee | 9057 | genlmsg_end(msg, hdr); |
a3b8b056 | 9058 | |
463d0183 JB |
9059 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9060 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9061 | return; |
9062 | ||
9063 | nla_put_failure: | |
9064 | genlmsg_cancel(msg, hdr); | |
9065 | nlmsg_free(msg); | |
9066 | } | |
9067 | ||
6bad8766 LR |
9068 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9069 | struct ieee80211_channel *channel_before, | |
9070 | struct ieee80211_channel *channel_after) | |
9071 | { | |
9072 | struct sk_buff *msg; | |
9073 | void *hdr; | |
9074 | struct nlattr *nl_freq; | |
9075 | ||
fd2120ca | 9076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9077 | if (!msg) |
9078 | return; | |
9079 | ||
9080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9081 | if (!hdr) { | |
9082 | nlmsg_free(msg); | |
9083 | return; | |
9084 | } | |
9085 | ||
9086 | /* | |
9087 | * Since we are applying the beacon hint to a wiphy we know its | |
9088 | * wiphy_idx is valid | |
9089 | */ | |
9360ffd1 DM |
9090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9091 | goto nla_put_failure; | |
6bad8766 LR |
9092 | |
9093 | /* Before */ | |
9094 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9095 | if (!nl_freq) | |
9096 | goto nla_put_failure; | |
9097 | if (nl80211_msg_put_channel(msg, channel_before)) | |
9098 | goto nla_put_failure; | |
9099 | nla_nest_end(msg, nl_freq); | |
9100 | ||
9101 | /* After */ | |
9102 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9103 | if (!nl_freq) | |
9104 | goto nla_put_failure; | |
9105 | if (nl80211_msg_put_channel(msg, channel_after)) | |
9106 | goto nla_put_failure; | |
9107 | nla_nest_end(msg, nl_freq); | |
9108 | ||
3b7b72ee | 9109 | genlmsg_end(msg, hdr); |
6bad8766 | 9110 | |
463d0183 JB |
9111 | rcu_read_lock(); |
9112 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9113 | GFP_ATOMIC); | |
9114 | rcu_read_unlock(); | |
6bad8766 LR |
9115 | |
9116 | return; | |
9117 | ||
9118 | nla_put_failure: | |
9119 | genlmsg_cancel(msg, hdr); | |
9120 | nlmsg_free(msg); | |
9121 | } | |
9122 | ||
9588bbd5 JM |
9123 | static void nl80211_send_remain_on_chan_event( |
9124 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9125 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9126 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9127 | unsigned int duration, gfp_t gfp) |
9128 | { | |
9129 | struct sk_buff *msg; | |
9130 | void *hdr; | |
9131 | ||
9132 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9133 | if (!msg) | |
9134 | return; | |
9135 | ||
9136 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9137 | if (!hdr) { | |
9138 | nlmsg_free(msg); | |
9139 | return; | |
9140 | } | |
9141 | ||
9360ffd1 | 9142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9143 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9144 | wdev->netdev->ifindex)) || | |
00f53350 | 9145 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9146 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9147 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9148 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9149 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9150 | goto nla_put_failure; | |
9588bbd5 | 9151 | |
9360ffd1 DM |
9152 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9153 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9154 | goto nla_put_failure; | |
9588bbd5 | 9155 | |
3b7b72ee | 9156 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9157 | |
9158 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9159 | nl80211_mlme_mcgrp.id, gfp); | |
9160 | return; | |
9161 | ||
9162 | nla_put_failure: | |
9163 | genlmsg_cancel(msg, hdr); | |
9164 | nlmsg_free(msg); | |
9165 | } | |
9166 | ||
9167 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
71bbc994 | 9168 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9169 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9170 | unsigned int duration, gfp_t gfp) |
9171 | { | |
9172 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
71bbc994 | 9173 | rdev, wdev, cookie, chan, |
42d97a59 | 9174 | duration, gfp); |
9588bbd5 JM |
9175 | } |
9176 | ||
9177 | void nl80211_send_remain_on_channel_cancel( | |
71bbc994 JB |
9178 | struct cfg80211_registered_device *rdev, |
9179 | struct wireless_dev *wdev, | |
42d97a59 | 9180 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
9588bbd5 JM |
9181 | { |
9182 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
42d97a59 | 9183 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 JM |
9184 | } |
9185 | ||
98b62183 JB |
9186 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
9187 | struct net_device *dev, const u8 *mac_addr, | |
9188 | struct station_info *sinfo, gfp_t gfp) | |
9189 | { | |
9190 | struct sk_buff *msg; | |
9191 | ||
58050fce | 9192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9193 | if (!msg) |
9194 | return; | |
9195 | ||
66266b3a JL |
9196 | if (nl80211_send_station(msg, 0, 0, 0, |
9197 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9198 | nlmsg_free(msg); |
9199 | return; | |
9200 | } | |
9201 | ||
9202 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9203 | nl80211_mlme_mcgrp.id, gfp); | |
9204 | } | |
9205 | ||
ec15e68b JM |
9206 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
9207 | struct net_device *dev, const u8 *mac_addr, | |
9208 | gfp_t gfp) | |
9209 | { | |
9210 | struct sk_buff *msg; | |
9211 | void *hdr; | |
9212 | ||
58050fce | 9213 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9214 | if (!msg) |
9215 | return; | |
9216 | ||
9217 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
9218 | if (!hdr) { | |
9219 | nlmsg_free(msg); | |
9220 | return; | |
9221 | } | |
9222 | ||
9360ffd1 DM |
9223 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9224 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
9225 | goto nla_put_failure; | |
ec15e68b | 9226 | |
3b7b72ee | 9227 | genlmsg_end(msg, hdr); |
ec15e68b JM |
9228 | |
9229 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9230 | nl80211_mlme_mcgrp.id, gfp); | |
9231 | return; | |
9232 | ||
9233 | nla_put_failure: | |
9234 | genlmsg_cancel(msg, hdr); | |
9235 | nlmsg_free(msg); | |
9236 | } | |
9237 | ||
ed44a951 PP |
9238 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
9239 | struct net_device *dev, const u8 *mac_addr, | |
9240 | enum nl80211_connect_failed_reason reason, | |
9241 | gfp_t gfp) | |
9242 | { | |
9243 | struct sk_buff *msg; | |
9244 | void *hdr; | |
9245 | ||
9246 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9247 | if (!msg) | |
9248 | return; | |
9249 | ||
9250 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
9251 | if (!hdr) { | |
9252 | nlmsg_free(msg); | |
9253 | return; | |
9254 | } | |
9255 | ||
9256 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9257 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
9258 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
9259 | goto nla_put_failure; | |
9260 | ||
9261 | genlmsg_end(msg, hdr); | |
9262 | ||
9263 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9264 | nl80211_mlme_mcgrp.id, gfp); | |
9265 | return; | |
9266 | ||
9267 | nla_put_failure: | |
9268 | genlmsg_cancel(msg, hdr); | |
9269 | nlmsg_free(msg); | |
9270 | } | |
9271 | ||
b92ab5d8 JB |
9272 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
9273 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
9274 | { |
9275 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9276 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9277 | struct sk_buff *msg; | |
9278 | void *hdr; | |
9279 | int err; | |
15e47304 | 9280 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 9281 | |
15e47304 | 9282 | if (!nlportid) |
28946da7 JB |
9283 | return false; |
9284 | ||
9285 | msg = nlmsg_new(100, gfp); | |
9286 | if (!msg) | |
9287 | return true; | |
9288 | ||
b92ab5d8 | 9289 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
9290 | if (!hdr) { |
9291 | nlmsg_free(msg); | |
9292 | return true; | |
9293 | } | |
9294 | ||
9360ffd1 DM |
9295 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9296 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9297 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9298 | goto nla_put_failure; | |
28946da7 JB |
9299 | |
9300 | err = genlmsg_end(msg, hdr); | |
9301 | if (err < 0) { | |
9302 | nlmsg_free(msg); | |
9303 | return true; | |
9304 | } | |
9305 | ||
15e47304 | 9306 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
9307 | return true; |
9308 | ||
9309 | nla_put_failure: | |
9310 | genlmsg_cancel(msg, hdr); | |
9311 | nlmsg_free(msg); | |
9312 | return true; | |
9313 | } | |
9314 | ||
b92ab5d8 JB |
9315 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
9316 | { | |
9317 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
9318 | addr, gfp); | |
9319 | } | |
9320 | ||
9321 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, | |
9322 | const u8 *addr, gfp_t gfp) | |
9323 | { | |
9324 | return __nl80211_unexpected_frame(dev, | |
9325 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
9326 | addr, gfp); | |
9327 | } | |
9328 | ||
2e161f78 | 9329 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 9330 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
9331 | int freq, int sig_dbm, |
9332 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 9333 | { |
71bbc994 | 9334 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9335 | struct sk_buff *msg; |
9336 | void *hdr; | |
026331c4 JM |
9337 | |
9338 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9339 | if (!msg) | |
9340 | return -ENOMEM; | |
9341 | ||
2e161f78 | 9342 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
9343 | if (!hdr) { |
9344 | nlmsg_free(msg); | |
9345 | return -ENOMEM; | |
9346 | } | |
9347 | ||
9360ffd1 | 9348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9349 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9350 | netdev->ifindex)) || | |
9360ffd1 DM |
9351 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
9352 | (sig_dbm && | |
9353 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9354 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9355 | goto nla_put_failure; | |
026331c4 | 9356 | |
3b7b72ee | 9357 | genlmsg_end(msg, hdr); |
026331c4 | 9358 | |
15e47304 | 9359 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
9360 | |
9361 | nla_put_failure: | |
9362 | genlmsg_cancel(msg, hdr); | |
9363 | nlmsg_free(msg); | |
9364 | return -ENOBUFS; | |
9365 | } | |
9366 | ||
2e161f78 | 9367 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
71bbc994 | 9368 | struct wireless_dev *wdev, u64 cookie, |
2e161f78 JB |
9369 | const u8 *buf, size_t len, bool ack, |
9370 | gfp_t gfp) | |
026331c4 | 9371 | { |
71bbc994 | 9372 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9373 | struct sk_buff *msg; |
9374 | void *hdr; | |
9375 | ||
9376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9377 | if (!msg) | |
9378 | return; | |
9379 | ||
2e161f78 | 9380 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
9381 | if (!hdr) { |
9382 | nlmsg_free(msg); | |
9383 | return; | |
9384 | } | |
9385 | ||
9360ffd1 | 9386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9387 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9388 | netdev->ifindex)) || | |
9360ffd1 DM |
9389 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
9390 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
9391 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
9392 | goto nla_put_failure; | |
026331c4 | 9393 | |
3b7b72ee | 9394 | genlmsg_end(msg, hdr); |
026331c4 JM |
9395 | |
9396 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
9397 | return; | |
9398 | ||
9399 | nla_put_failure: | |
9400 | genlmsg_cancel(msg, hdr); | |
9401 | nlmsg_free(msg); | |
9402 | } | |
9403 | ||
d6dc1a38 JO |
9404 | void |
9405 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |
9406 | struct net_device *netdev, | |
9407 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
9408 | gfp_t gfp) | |
9409 | { | |
9410 | struct sk_buff *msg; | |
9411 | struct nlattr *pinfoattr; | |
9412 | void *hdr; | |
9413 | ||
58050fce | 9414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
9415 | if (!msg) |
9416 | return; | |
9417 | ||
9418 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9419 | if (!hdr) { | |
9420 | nlmsg_free(msg); | |
9421 | return; | |
9422 | } | |
9423 | ||
9360ffd1 DM |
9424 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9425 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9426 | goto nla_put_failure; | |
d6dc1a38 JO |
9427 | |
9428 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
9429 | if (!pinfoattr) | |
9430 | goto nla_put_failure; | |
9431 | ||
9360ffd1 DM |
9432 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
9433 | rssi_event)) | |
9434 | goto nla_put_failure; | |
d6dc1a38 JO |
9435 | |
9436 | nla_nest_end(msg, pinfoattr); | |
9437 | ||
3b7b72ee | 9438 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
9439 | |
9440 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9441 | nl80211_mlme_mcgrp.id, gfp); | |
9442 | return; | |
9443 | ||
9444 | nla_put_failure: | |
9445 | genlmsg_cancel(msg, hdr); | |
9446 | nlmsg_free(msg); | |
9447 | } | |
9448 | ||
e5497d76 JB |
9449 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
9450 | struct net_device *netdev, const u8 *bssid, | |
9451 | const u8 *replay_ctr, gfp_t gfp) | |
9452 | { | |
9453 | struct sk_buff *msg; | |
9454 | struct nlattr *rekey_attr; | |
9455 | void *hdr; | |
9456 | ||
58050fce | 9457 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
9458 | if (!msg) |
9459 | return; | |
9460 | ||
9461 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
9462 | if (!hdr) { | |
9463 | nlmsg_free(msg); | |
9464 | return; | |
9465 | } | |
9466 | ||
9360ffd1 DM |
9467 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9468 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9469 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9470 | goto nla_put_failure; | |
e5497d76 JB |
9471 | |
9472 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
9473 | if (!rekey_attr) | |
9474 | goto nla_put_failure; | |
9475 | ||
9360ffd1 DM |
9476 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
9477 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
9478 | goto nla_put_failure; | |
e5497d76 JB |
9479 | |
9480 | nla_nest_end(msg, rekey_attr); | |
9481 | ||
3b7b72ee | 9482 | genlmsg_end(msg, hdr); |
e5497d76 JB |
9483 | |
9484 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9485 | nl80211_mlme_mcgrp.id, gfp); | |
9486 | return; | |
9487 | ||
9488 | nla_put_failure: | |
9489 | genlmsg_cancel(msg, hdr); | |
9490 | nlmsg_free(msg); | |
9491 | } | |
9492 | ||
c9df56b4 JM |
9493 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
9494 | struct net_device *netdev, int index, | |
9495 | const u8 *bssid, bool preauth, gfp_t gfp) | |
9496 | { | |
9497 | struct sk_buff *msg; | |
9498 | struct nlattr *attr; | |
9499 | void *hdr; | |
9500 | ||
58050fce | 9501 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
9502 | if (!msg) |
9503 | return; | |
9504 | ||
9505 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
9506 | if (!hdr) { | |
9507 | nlmsg_free(msg); | |
9508 | return; | |
9509 | } | |
9510 | ||
9360ffd1 DM |
9511 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9512 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9513 | goto nla_put_failure; | |
c9df56b4 JM |
9514 | |
9515 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
9516 | if (!attr) | |
9517 | goto nla_put_failure; | |
9518 | ||
9360ffd1 DM |
9519 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
9520 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
9521 | (preauth && | |
9522 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
9523 | goto nla_put_failure; | |
c9df56b4 JM |
9524 | |
9525 | nla_nest_end(msg, attr); | |
9526 | ||
3b7b72ee | 9527 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
9528 | |
9529 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9530 | nl80211_mlme_mcgrp.id, gfp); | |
9531 | return; | |
9532 | ||
9533 | nla_put_failure: | |
9534 | genlmsg_cancel(msg, hdr); | |
9535 | nlmsg_free(msg); | |
9536 | } | |
9537 | ||
5314526b | 9538 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
683b6d3b JB |
9539 | struct net_device *netdev, |
9540 | struct cfg80211_chan_def *chandef, gfp_t gfp) | |
5314526b TP |
9541 | { |
9542 | struct sk_buff *msg; | |
9543 | void *hdr; | |
9544 | ||
58050fce | 9545 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
9546 | if (!msg) |
9547 | return; | |
9548 | ||
9549 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
9550 | if (!hdr) { | |
9551 | nlmsg_free(msg); | |
9552 | return; | |
9553 | } | |
9554 | ||
683b6d3b JB |
9555 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
9556 | goto nla_put_failure; | |
9557 | ||
9558 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 9559 | goto nla_put_failure; |
5314526b TP |
9560 | |
9561 | genlmsg_end(msg, hdr); | |
9562 | ||
9563 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9564 | nl80211_mlme_mcgrp.id, gfp); | |
9565 | return; | |
9566 | ||
9567 | nla_put_failure: | |
9568 | genlmsg_cancel(msg, hdr); | |
9569 | nlmsg_free(msg); | |
9570 | } | |
9571 | ||
84f10708 TP |
9572 | void |
9573 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, | |
9574 | struct net_device *netdev, const u8 *peer, | |
9575 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) | |
9576 | { | |
9577 | struct sk_buff *msg; | |
9578 | struct nlattr *pinfoattr; | |
9579 | void *hdr; | |
9580 | ||
9581 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9582 | if (!msg) | |
9583 | return; | |
9584 | ||
9585 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9586 | if (!hdr) { | |
9587 | nlmsg_free(msg); | |
9588 | return; | |
9589 | } | |
9590 | ||
9591 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
9592 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9593 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) | |
9594 | goto nla_put_failure; | |
9595 | ||
9596 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
9597 | if (!pinfoattr) | |
9598 | goto nla_put_failure; | |
9599 | ||
9600 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
9601 | goto nla_put_failure; | |
9602 | ||
9603 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
9604 | goto nla_put_failure; | |
9605 | ||
9606 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
9607 | goto nla_put_failure; | |
9608 | ||
9609 | nla_nest_end(msg, pinfoattr); | |
9610 | ||
9611 | genlmsg_end(msg, hdr); | |
9612 | ||
9613 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9614 | nl80211_mlme_mcgrp.id, gfp); | |
9615 | return; | |
9616 | ||
9617 | nla_put_failure: | |
9618 | genlmsg_cancel(msg, hdr); | |
9619 | nlmsg_free(msg); | |
9620 | } | |
9621 | ||
04f39047 SW |
9622 | void |
9623 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
9624 | struct cfg80211_chan_def *chandef, | |
9625 | enum nl80211_radar_event event, | |
9626 | struct net_device *netdev, gfp_t gfp) | |
9627 | { | |
9628 | struct sk_buff *msg; | |
9629 | void *hdr; | |
9630 | ||
9631 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9632 | if (!msg) | |
9633 | return; | |
9634 | ||
9635 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
9636 | if (!hdr) { | |
9637 | nlmsg_free(msg); | |
9638 | return; | |
9639 | } | |
9640 | ||
9641 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
9642 | goto nla_put_failure; | |
9643 | ||
9644 | /* NOP and radar events don't need a netdev parameter */ | |
9645 | if (netdev) { | |
9646 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
9647 | ||
9648 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9649 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9650 | goto nla_put_failure; | |
9651 | } | |
9652 | ||
9653 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
9654 | goto nla_put_failure; | |
9655 | ||
9656 | if (nl80211_send_chandef(msg, chandef)) | |
9657 | goto nla_put_failure; | |
9658 | ||
9659 | if (genlmsg_end(msg, hdr) < 0) { | |
9660 | nlmsg_free(msg); | |
9661 | return; | |
9662 | } | |
9663 | ||
9664 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9665 | nl80211_mlme_mcgrp.id, gfp); | |
9666 | return; | |
9667 | ||
9668 | nla_put_failure: | |
9669 | genlmsg_cancel(msg, hdr); | |
9670 | nlmsg_free(msg); | |
9671 | } | |
9672 | ||
c063dbf5 JB |
9673 | void |
9674 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, | |
9675 | struct net_device *netdev, const u8 *peer, | |
9676 | u32 num_packets, gfp_t gfp) | |
9677 | { | |
9678 | struct sk_buff *msg; | |
9679 | struct nlattr *pinfoattr; | |
9680 | void *hdr; | |
9681 | ||
58050fce | 9682 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
9683 | if (!msg) |
9684 | return; | |
9685 | ||
9686 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9687 | if (!hdr) { | |
9688 | nlmsg_free(msg); | |
9689 | return; | |
9690 | } | |
9691 | ||
9360ffd1 DM |
9692 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9693 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9694 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) | |
9695 | goto nla_put_failure; | |
c063dbf5 JB |
9696 | |
9697 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
9698 | if (!pinfoattr) | |
9699 | goto nla_put_failure; | |
9700 | ||
9360ffd1 DM |
9701 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
9702 | goto nla_put_failure; | |
c063dbf5 JB |
9703 | |
9704 | nla_nest_end(msg, pinfoattr); | |
9705 | ||
3b7b72ee | 9706 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
9707 | |
9708 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9709 | nl80211_mlme_mcgrp.id, gfp); | |
9710 | return; | |
9711 | ||
9712 | nla_put_failure: | |
9713 | genlmsg_cancel(msg, hdr); | |
9714 | nlmsg_free(msg); | |
9715 | } | |
9716 | ||
7f6cf311 JB |
9717 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
9718 | u64 cookie, bool acked, gfp_t gfp) | |
9719 | { | |
9720 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9721 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9722 | struct sk_buff *msg; | |
9723 | void *hdr; | |
9724 | int err; | |
9725 | ||
4ee3e063 BL |
9726 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
9727 | ||
58050fce | 9728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 9729 | |
7f6cf311 JB |
9730 | if (!msg) |
9731 | return; | |
9732 | ||
9733 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
9734 | if (!hdr) { | |
9735 | nlmsg_free(msg); | |
9736 | return; | |
9737 | } | |
9738 | ||
9360ffd1 DM |
9739 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9740 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9741 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9742 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
9743 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
9744 | goto nla_put_failure; | |
7f6cf311 JB |
9745 | |
9746 | err = genlmsg_end(msg, hdr); | |
9747 | if (err < 0) { | |
9748 | nlmsg_free(msg); | |
9749 | return; | |
9750 | } | |
9751 | ||
9752 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9753 | nl80211_mlme_mcgrp.id, gfp); | |
9754 | return; | |
9755 | ||
9756 | nla_put_failure: | |
9757 | genlmsg_cancel(msg, hdr); | |
9758 | nlmsg_free(msg); | |
9759 | } | |
9760 | EXPORT_SYMBOL(cfg80211_probe_status); | |
9761 | ||
5e760230 JB |
9762 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
9763 | const u8 *frame, size_t len, | |
37c73b5f | 9764 | int freq, int sig_dbm) |
5e760230 JB |
9765 | { |
9766 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9767 | struct sk_buff *msg; | |
9768 | void *hdr; | |
37c73b5f | 9769 | struct cfg80211_beacon_registration *reg; |
5e760230 | 9770 | |
4ee3e063 BL |
9771 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
9772 | ||
37c73b5f BG |
9773 | spin_lock_bh(&rdev->beacon_registrations_lock); |
9774 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9775 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
9776 | if (!msg) { | |
9777 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9778 | return; | |
9779 | } | |
5e760230 | 9780 | |
37c73b5f BG |
9781 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
9782 | if (!hdr) | |
9783 | goto nla_put_failure; | |
5e760230 | 9784 | |
37c73b5f BG |
9785 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9786 | (freq && | |
9787 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
9788 | (sig_dbm && | |
9789 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9790 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
9791 | goto nla_put_failure; | |
5e760230 | 9792 | |
37c73b5f | 9793 | genlmsg_end(msg, hdr); |
5e760230 | 9794 | |
37c73b5f BG |
9795 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
9796 | } | |
9797 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
9798 | return; |
9799 | ||
9800 | nla_put_failure: | |
37c73b5f BG |
9801 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
9802 | if (hdr) | |
9803 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
9804 | nlmsg_free(msg); |
9805 | } | |
9806 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
9807 | ||
cd8f7cb4 JB |
9808 | #ifdef CONFIG_PM |
9809 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
9810 | struct cfg80211_wowlan_wakeup *wakeup, | |
9811 | gfp_t gfp) | |
9812 | { | |
9813 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9814 | struct sk_buff *msg; | |
9815 | void *hdr; | |
9816 | int err, size = 200; | |
9817 | ||
9818 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
9819 | ||
9820 | if (wakeup) | |
9821 | size += wakeup->packet_present_len; | |
9822 | ||
9823 | msg = nlmsg_new(size, gfp); | |
9824 | if (!msg) | |
9825 | return; | |
9826 | ||
9827 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
9828 | if (!hdr) | |
9829 | goto free_msg; | |
9830 | ||
9831 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
9832 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9833 | goto free_msg; | |
9834 | ||
9835 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
9836 | wdev->netdev->ifindex)) | |
9837 | goto free_msg; | |
9838 | ||
9839 | if (wakeup) { | |
9840 | struct nlattr *reasons; | |
9841 | ||
9842 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
9843 | ||
9844 | if (wakeup->disconnect && | |
9845 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
9846 | goto free_msg; | |
9847 | if (wakeup->magic_pkt && | |
9848 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
9849 | goto free_msg; | |
9850 | if (wakeup->gtk_rekey_failure && | |
9851 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
9852 | goto free_msg; | |
9853 | if (wakeup->eap_identity_req && | |
9854 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
9855 | goto free_msg; | |
9856 | if (wakeup->four_way_handshake && | |
9857 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
9858 | goto free_msg; | |
9859 | if (wakeup->rfkill_release && | |
9860 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
9861 | goto free_msg; | |
9862 | ||
9863 | if (wakeup->pattern_idx >= 0 && | |
9864 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
9865 | wakeup->pattern_idx)) | |
9866 | goto free_msg; | |
9867 | ||
2a0e047e JB |
9868 | if (wakeup->tcp_match) |
9869 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
9870 | ||
9871 | if (wakeup->tcp_connlost) | |
9872 | nla_put_flag(msg, | |
9873 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
9874 | ||
9875 | if (wakeup->tcp_nomoretokens) | |
9876 | nla_put_flag(msg, | |
9877 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
9878 | ||
cd8f7cb4 JB |
9879 | if (wakeup->packet) { |
9880 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
9881 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
9882 | ||
9883 | if (!wakeup->packet_80211) { | |
9884 | pkt_attr = | |
9885 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
9886 | len_attr = | |
9887 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
9888 | } | |
9889 | ||
9890 | if (wakeup->packet_len && | |
9891 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
9892 | goto free_msg; | |
9893 | ||
9894 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
9895 | wakeup->packet)) | |
9896 | goto free_msg; | |
9897 | } | |
9898 | ||
9899 | nla_nest_end(msg, reasons); | |
9900 | } | |
9901 | ||
9902 | err = genlmsg_end(msg, hdr); | |
9903 | if (err < 0) | |
9904 | goto free_msg; | |
9905 | ||
9906 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9907 | nl80211_mlme_mcgrp.id, gfp); | |
9908 | return; | |
9909 | ||
9910 | free_msg: | |
9911 | nlmsg_free(msg); | |
9912 | } | |
9913 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
9914 | #endif | |
9915 | ||
3475b094 JM |
9916 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
9917 | enum nl80211_tdls_operation oper, | |
9918 | u16 reason_code, gfp_t gfp) | |
9919 | { | |
9920 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9921 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9922 | struct sk_buff *msg; | |
9923 | void *hdr; | |
9924 | int err; | |
9925 | ||
9926 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
9927 | reason_code); | |
9928 | ||
9929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9930 | if (!msg) | |
9931 | return; | |
9932 | ||
9933 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
9934 | if (!hdr) { | |
9935 | nlmsg_free(msg); | |
9936 | return; | |
9937 | } | |
9938 | ||
9939 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
9940 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9941 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
9942 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
9943 | (reason_code > 0 && | |
9944 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
9945 | goto nla_put_failure; | |
9946 | ||
9947 | err = genlmsg_end(msg, hdr); | |
9948 | if (err < 0) { | |
9949 | nlmsg_free(msg); | |
9950 | return; | |
9951 | } | |
9952 | ||
9953 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9954 | nl80211_mlme_mcgrp.id, gfp); | |
9955 | return; | |
9956 | ||
9957 | nla_put_failure: | |
9958 | genlmsg_cancel(msg, hdr); | |
9959 | nlmsg_free(msg); | |
9960 | } | |
9961 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
9962 | ||
026331c4 JM |
9963 | static int nl80211_netlink_notify(struct notifier_block * nb, |
9964 | unsigned long state, | |
9965 | void *_notify) | |
9966 | { | |
9967 | struct netlink_notify *notify = _notify; | |
9968 | struct cfg80211_registered_device *rdev; | |
9969 | struct wireless_dev *wdev; | |
37c73b5f | 9970 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
9971 | |
9972 | if (state != NETLINK_URELEASE) | |
9973 | return NOTIFY_DONE; | |
9974 | ||
9975 | rcu_read_lock(); | |
9976 | ||
5e760230 | 9977 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 9978 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 9979 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
9980 | |
9981 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9982 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
9983 | list) { | |
9984 | if (reg->nlportid == notify->portid) { | |
9985 | list_del(®->list); | |
9986 | kfree(reg); | |
9987 | break; | |
9988 | } | |
9989 | } | |
9990 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 9991 | } |
026331c4 JM |
9992 | |
9993 | rcu_read_unlock(); | |
9994 | ||
9995 | return NOTIFY_DONE; | |
9996 | } | |
9997 | ||
9998 | static struct notifier_block nl80211_netlink_notifier = { | |
9999 | .notifier_call = nl80211_netlink_notify, | |
10000 | }; | |
10001 | ||
55682965 JB |
10002 | /* initialisation/exit functions */ |
10003 | ||
10004 | int nl80211_init(void) | |
10005 | { | |
0d63cbb5 | 10006 | int err; |
55682965 | 10007 | |
0d63cbb5 MM |
10008 | err = genl_register_family_with_ops(&nl80211_fam, |
10009 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10010 | if (err) |
10011 | return err; | |
10012 | ||
55682965 JB |
10013 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10014 | if (err) | |
10015 | goto err_out; | |
10016 | ||
2a519311 JB |
10017 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10018 | if (err) | |
10019 | goto err_out; | |
10020 | ||
73d54c9e LR |
10021 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10022 | if (err) | |
10023 | goto err_out; | |
10024 | ||
6039f6d2 JM |
10025 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10026 | if (err) | |
10027 | goto err_out; | |
10028 | ||
aff89a9b JB |
10029 | #ifdef CONFIG_NL80211_TESTMODE |
10030 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10031 | if (err) | |
10032 | goto err_out; | |
10033 | #endif | |
10034 | ||
026331c4 JM |
10035 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
10036 | if (err) | |
10037 | goto err_out; | |
10038 | ||
55682965 JB |
10039 | return 0; |
10040 | err_out: | |
10041 | genl_unregister_family(&nl80211_fam); | |
10042 | return err; | |
10043 | } | |
10044 | ||
10045 | void nl80211_exit(void) | |
10046 | { | |
026331c4 | 10047 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
10048 | genl_unregister_family(&nl80211_fam); |
10049 | } |