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