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 }, |
9efa3d52 | 313 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, |
9588bbd5 JM |
314 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
315 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 316 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
317 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
318 | .len = IEEE80211_MAX_DATA_LEN }, | |
319 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 320 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 321 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 322 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 323 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
324 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
325 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 326 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
327 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
328 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 329 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 330 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 331 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 332 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 333 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 334 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 335 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 336 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 337 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
338 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
339 | .len = IEEE80211_MAX_DATA_LEN }, | |
340 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
341 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 342 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 343 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 344 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
345 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
346 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
347 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
348 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
349 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 350 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
351 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
352 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 353 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
354 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
355 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
356 | .len = NL80211_HT_CAPABILITY_LEN | |
357 | }, | |
1d9d9213 | 358 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 359 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 360 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 361 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 362 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 363 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 364 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 365 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
366 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
367 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
368 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
369 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
370 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 372 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
373 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
374 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
375 | .len = NL80211_VHT_CAPABILITY_LEN, | |
376 | }, | |
355199e0 JM |
377 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
378 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
379 | .len = IEEE80211_MAX_DATA_LEN }, | |
6fa3eb70 S |
380 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
381 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, | |
382 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, | |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
55682965 JB |
386 | }; |
387 | ||
e31b8213 | 388 | /* policy for the key attributes */ |
b54452b0 | 389 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 390 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
391 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
392 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 393 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
394 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
395 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 396 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
397 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
398 | }; | |
399 | ||
400 | /* policy for the key default flags */ | |
401 | static const struct nla_policy | |
402 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
403 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
404 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
405 | }; |
406 | ||
ff1b6e69 JB |
407 | /* policy for WoWLAN attributes */ |
408 | static const struct nla_policy | |
409 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
410 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
411 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
412 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
413 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
414 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
415 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
416 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
417 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
418 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
419 | }; | |
420 | ||
421 | static const struct nla_policy | |
422 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
423 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
424 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
425 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
426 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
427 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
428 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
429 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
430 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
431 | }, | |
432 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
433 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
434 | }, | |
435 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
436 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
437 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
438 | }; |
439 | ||
e5497d76 JB |
440 | /* policy for GTK rekey offload attributes */ |
441 | static const struct nla_policy | |
442 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
443 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
444 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
445 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
446 | }; | |
447 | ||
a1f1c21c LC |
448 | static const struct nla_policy |
449 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 450 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 451 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 452 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
453 | }; |
454 | ||
97990a06 JB |
455 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
456 | struct netlink_callback *cb, | |
457 | struct cfg80211_registered_device **rdev, | |
458 | struct wireless_dev **wdev) | |
a043897a | 459 | { |
97990a06 | 460 | int err; |
a043897a | 461 | |
97990a06 JB |
462 | rtnl_lock(); |
463 | mutex_lock(&cfg80211_mutex); | |
a043897a | 464 | |
97990a06 JB |
465 | if (!cb->args[0]) { |
466 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
467 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
468 | nl80211_policy); | |
469 | if (err) | |
470 | goto out_unlock; | |
67748893 | 471 | |
97990a06 JB |
472 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
473 | nl80211_fam.attrbuf); | |
474 | if (IS_ERR(*wdev)) { | |
475 | err = PTR_ERR(*wdev); | |
476 | goto out_unlock; | |
477 | } | |
478 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
289813a7 JB |
479 | /* 0 is the first index - add 1 to parse only once */ |
480 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
481 | cb->args[1] = (*wdev)->identifier; |
482 | } else { | |
289813a7 JB |
483 | /* subtract the 1 again here */ |
484 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 485 | struct wireless_dev *tmp; |
67748893 | 486 | |
97990a06 JB |
487 | if (!wiphy) { |
488 | err = -ENODEV; | |
489 | goto out_unlock; | |
490 | } | |
491 | *rdev = wiphy_to_dev(wiphy); | |
492 | *wdev = NULL; | |
67748893 | 493 | |
97990a06 JB |
494 | mutex_lock(&(*rdev)->devlist_mtx); |
495 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { | |
496 | if (tmp->identifier == cb->args[1]) { | |
497 | *wdev = tmp; | |
498 | break; | |
499 | } | |
500 | } | |
501 | mutex_unlock(&(*rdev)->devlist_mtx); | |
67748893 | 502 | |
97990a06 JB |
503 | if (!*wdev) { |
504 | err = -ENODEV; | |
505 | goto out_unlock; | |
506 | } | |
67748893 JB |
507 | } |
508 | ||
97990a06 | 509 | cfg80211_lock_rdev(*rdev); |
67748893 | 510 | |
97990a06 | 511 | mutex_unlock(&cfg80211_mutex); |
67748893 | 512 | return 0; |
97990a06 JB |
513 | out_unlock: |
514 | mutex_unlock(&cfg80211_mutex); | |
67748893 JB |
515 | rtnl_unlock(); |
516 | return err; | |
517 | } | |
518 | ||
97990a06 | 519 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 JB |
520 | { |
521 | cfg80211_unlock_rdev(rdev); | |
522 | rtnl_unlock(); | |
523 | } | |
524 | ||
f4a11bb0 JB |
525 | /* IE validation */ |
526 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
527 | { | |
528 | const u8 *pos; | |
529 | int len; | |
530 | ||
531 | if (!attr) | |
532 | return true; | |
533 | ||
534 | pos = nla_data(attr); | |
535 | len = nla_len(attr); | |
536 | ||
537 | while (len) { | |
538 | u8 elemlen; | |
539 | ||
540 | if (len < 2) | |
541 | return false; | |
542 | len -= 2; | |
543 | ||
544 | elemlen = pos[1]; | |
545 | if (elemlen > len) | |
546 | return false; | |
547 | ||
548 | len -= elemlen; | |
549 | pos += 2 + elemlen; | |
550 | } | |
551 | ||
552 | return true; | |
553 | } | |
554 | ||
55682965 | 555 | /* message building helper */ |
15e47304 | 556 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
557 | int flags, u8 cmd) |
558 | { | |
559 | /* since there is no private header just add the generic one */ | |
15e47304 | 560 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
561 | } |
562 | ||
5dab3b8a | 563 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
564 | struct ieee80211_channel *chan, |
565 | bool large) | |
5dab3b8a | 566 | { |
9360ffd1 DM |
567 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
568 | chan->center_freq)) | |
569 | goto nla_put_failure; | |
5dab3b8a | 570 | |
9360ffd1 DM |
571 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
572 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
573 | goto nla_put_failure; | |
574 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
575 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
576 | goto nla_put_failure; | |
577 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
578 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
579 | goto nla_put_failure; | |
cdc89b97 JB |
580 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
581 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
582 | goto nla_put_failure; | |
583 | if (large) { | |
584 | u32 time; | |
585 | ||
586 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
587 | ||
588 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
589 | chan->dfs_state)) | |
590 | goto nla_put_failure; | |
591 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
592 | time)) | |
593 | goto nla_put_failure; | |
594 | } | |
595 | } | |
5dab3b8a | 596 | |
fe1abafd JB |
597 | if (large) { |
598 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
599 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
600 | goto nla_put_failure; | |
601 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
602 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
603 | goto nla_put_failure; | |
604 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
605 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
606 | goto nla_put_failure; | |
607 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
608 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
609 | goto nla_put_failure; | |
610 | } | |
611 | ||
9360ffd1 DM |
612 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
613 | DBM_TO_MBM(chan->max_power))) | |
614 | goto nla_put_failure; | |
5dab3b8a LR |
615 | |
616 | return 0; | |
617 | ||
618 | nla_put_failure: | |
619 | return -ENOBUFS; | |
620 | } | |
621 | ||
55682965 JB |
622 | /* netlink command implementations */ |
623 | ||
b9454e83 JB |
624 | struct key_parse { |
625 | struct key_params p; | |
626 | int idx; | |
e31b8213 | 627 | int type; |
b9454e83 | 628 | bool def, defmgmt; |
dbd2fd65 | 629 | bool def_uni, def_multi; |
b9454e83 JB |
630 | }; |
631 | ||
632 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
633 | { | |
634 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
635 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
636 | nl80211_key_policy); | |
637 | if (err) | |
638 | return err; | |
639 | ||
640 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
641 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
642 | ||
dbd2fd65 JB |
643 | if (k->def) { |
644 | k->def_uni = true; | |
645 | k->def_multi = true; | |
646 | } | |
647 | if (k->defmgmt) | |
648 | k->def_multi = true; | |
649 | ||
b9454e83 JB |
650 | if (tb[NL80211_KEY_IDX]) |
651 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
652 | ||
653 | if (tb[NL80211_KEY_DATA]) { | |
654 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
655 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
656 | } | |
657 | ||
658 | if (tb[NL80211_KEY_SEQ]) { | |
659 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
660 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
661 | } | |
662 | ||
663 | if (tb[NL80211_KEY_CIPHER]) | |
664 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
665 | ||
e31b8213 JB |
666 | if (tb[NL80211_KEY_TYPE]) { |
667 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
668 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
669 | return -EINVAL; | |
670 | } | |
671 | ||
dbd2fd65 JB |
672 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
673 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
674 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
675 | tb[NL80211_KEY_DEFAULT_TYPES], | |
676 | nl80211_key_default_policy); | |
dbd2fd65 JB |
677 | if (err) |
678 | return err; | |
679 | ||
680 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
681 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
682 | } | |
683 | ||
b9454e83 JB |
684 | return 0; |
685 | } | |
686 | ||
687 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
688 | { | |
689 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
690 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
691 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
692 | } | |
693 | ||
694 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
695 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
696 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
697 | } | |
698 | ||
699 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
700 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
701 | ||
702 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
703 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
704 | ||
705 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
706 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
707 | ||
dbd2fd65 JB |
708 | if (k->def) { |
709 | k->def_uni = true; | |
710 | k->def_multi = true; | |
711 | } | |
712 | if (k->defmgmt) | |
713 | k->def_multi = true; | |
714 | ||
e31b8213 JB |
715 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
716 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
717 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
718 | return -EINVAL; | |
719 | } | |
720 | ||
dbd2fd65 JB |
721 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
722 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
723 | int err = nla_parse_nested( | |
724 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
725 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
726 | nl80211_key_default_policy); | |
727 | if (err) | |
728 | return err; | |
729 | ||
730 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
731 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
732 | } | |
733 | ||
b9454e83 JB |
734 | return 0; |
735 | } | |
736 | ||
737 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
738 | { | |
739 | int err; | |
740 | ||
741 | memset(k, 0, sizeof(*k)); | |
742 | k->idx = -1; | |
e31b8213 | 743 | k->type = -1; |
b9454e83 JB |
744 | |
745 | if (info->attrs[NL80211_ATTR_KEY]) | |
746 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
747 | else | |
748 | err = nl80211_parse_key_old(info, k); | |
749 | ||
750 | if (err) | |
751 | return err; | |
752 | ||
753 | if (k->def && k->defmgmt) | |
754 | return -EINVAL; | |
755 | ||
dbd2fd65 JB |
756 | if (k->defmgmt) { |
757 | if (k->def_uni || !k->def_multi) | |
758 | return -EINVAL; | |
759 | } | |
760 | ||
b9454e83 JB |
761 | if (k->idx != -1) { |
762 | if (k->defmgmt) { | |
763 | if (k->idx < 4 || k->idx > 5) | |
764 | return -EINVAL; | |
765 | } else if (k->def) { | |
766 | if (k->idx < 0 || k->idx > 3) | |
767 | return -EINVAL; | |
768 | } else { | |
769 | if (k->idx < 0 || k->idx > 5) | |
770 | return -EINVAL; | |
771 | } | |
772 | } | |
773 | ||
774 | return 0; | |
775 | } | |
776 | ||
fffd0934 JB |
777 | static struct cfg80211_cached_keys * |
778 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 779 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
780 | { |
781 | struct key_parse parse; | |
782 | struct nlattr *key; | |
783 | struct cfg80211_cached_keys *result; | |
784 | int rem, err, def = 0; | |
785 | ||
786 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
787 | if (!result) | |
788 | return ERR_PTR(-ENOMEM); | |
789 | ||
790 | result->def = -1; | |
791 | result->defmgmt = -1; | |
792 | ||
793 | nla_for_each_nested(key, keys, rem) { | |
794 | memset(&parse, 0, sizeof(parse)); | |
795 | parse.idx = -1; | |
796 | ||
797 | err = nl80211_parse_key_new(key, &parse); | |
798 | if (err) | |
799 | goto error; | |
800 | err = -EINVAL; | |
801 | if (!parse.p.key) | |
802 | goto error; | |
803 | if (parse.idx < 0 || parse.idx > 4) | |
804 | goto error; | |
805 | if (parse.def) { | |
806 | if (def) | |
807 | goto error; | |
808 | def = 1; | |
809 | result->def = parse.idx; | |
dbd2fd65 JB |
810 | if (!parse.def_uni || !parse.def_multi) |
811 | goto error; | |
fffd0934 JB |
812 | } else if (parse.defmgmt) |
813 | goto error; | |
814 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 815 | parse.idx, false, NULL); |
fffd0934 JB |
816 | if (err) |
817 | goto error; | |
818 | result->params[parse.idx].cipher = parse.p.cipher; | |
819 | result->params[parse.idx].key_len = parse.p.key_len; | |
820 | result->params[parse.idx].key = result->data[parse.idx]; | |
821 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
822 | |
823 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
824 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
825 | if (no_ht) | |
826 | *no_ht = true; | |
827 | } | |
fffd0934 JB |
828 | } |
829 | ||
830 | return result; | |
831 | error: | |
832 | kfree(result); | |
833 | return ERR_PTR(err); | |
834 | } | |
835 | ||
836 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
837 | { | |
838 | ASSERT_WDEV_LOCK(wdev); | |
839 | ||
fffd0934 JB |
840 | switch (wdev->iftype) { |
841 | case NL80211_IFTYPE_AP: | |
842 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 843 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 844 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
845 | break; |
846 | case NL80211_IFTYPE_ADHOC: | |
847 | if (!wdev->current_bss) | |
848 | return -ENOLINK; | |
849 | break; | |
850 | case NL80211_IFTYPE_STATION: | |
074ac8df | 851 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
852 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
853 | return -ENOLINK; | |
854 | break; | |
855 | default: | |
856 | return -EINVAL; | |
857 | } | |
858 | ||
859 | return 0; | |
860 | } | |
861 | ||
7527a782 JB |
862 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
863 | { | |
864 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
865 | int i; | |
866 | ||
867 | if (!nl_modes) | |
868 | goto nla_put_failure; | |
869 | ||
870 | i = 0; | |
871 | while (ifmodes) { | |
9360ffd1 DM |
872 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
873 | goto nla_put_failure; | |
7527a782 JB |
874 | ifmodes >>= 1; |
875 | i++; | |
876 | } | |
877 | ||
878 | nla_nest_end(msg, nl_modes); | |
879 | return 0; | |
880 | ||
881 | nla_put_failure: | |
882 | return -ENOBUFS; | |
883 | } | |
884 | ||
885 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
886 | struct sk_buff *msg, |
887 | bool large) | |
7527a782 JB |
888 | { |
889 | struct nlattr *nl_combis; | |
890 | int i, j; | |
891 | ||
892 | nl_combis = nla_nest_start(msg, | |
893 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
894 | if (!nl_combis) | |
895 | goto nla_put_failure; | |
896 | ||
897 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
898 | const struct ieee80211_iface_combination *c; | |
899 | struct nlattr *nl_combi, *nl_limits; | |
900 | ||
901 | c = &wiphy->iface_combinations[i]; | |
902 | ||
903 | nl_combi = nla_nest_start(msg, i + 1); | |
904 | if (!nl_combi) | |
905 | goto nla_put_failure; | |
906 | ||
907 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
908 | if (!nl_limits) | |
909 | goto nla_put_failure; | |
910 | ||
911 | for (j = 0; j < c->n_limits; j++) { | |
912 | struct nlattr *nl_limit; | |
913 | ||
914 | nl_limit = nla_nest_start(msg, j + 1); | |
915 | if (!nl_limit) | |
916 | goto nla_put_failure; | |
9360ffd1 DM |
917 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
918 | c->limits[j].max)) | |
919 | goto nla_put_failure; | |
7527a782 JB |
920 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
921 | c->limits[j].types)) | |
922 | goto nla_put_failure; | |
923 | nla_nest_end(msg, nl_limit); | |
924 | } | |
925 | ||
926 | nla_nest_end(msg, nl_limits); | |
927 | ||
9360ffd1 DM |
928 | if (c->beacon_int_infra_match && |
929 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
930 | goto nla_put_failure; | |
931 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
932 | c->num_different_channels) || | |
933 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
934 | c->max_interfaces)) | |
935 | goto nla_put_failure; | |
cdc89b97 JB |
936 | if (large && |
937 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
938 | c->radar_detect_widths)) | |
939 | goto nla_put_failure; | |
7527a782 JB |
940 | |
941 | nla_nest_end(msg, nl_combi); | |
942 | } | |
943 | ||
944 | nla_nest_end(msg, nl_combis); | |
945 | ||
946 | return 0; | |
947 | nla_put_failure: | |
948 | return -ENOBUFS; | |
949 | } | |
950 | ||
3713b4e3 | 951 | #ifdef CONFIG_PM |
b56cf720 JB |
952 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
953 | struct sk_buff *msg) | |
954 | { | |
955 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; | |
956 | struct nlattr *nl_tcp; | |
957 | ||
958 | if (!tcp) | |
959 | return 0; | |
960 | ||
961 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
962 | if (!nl_tcp) | |
963 | return -ENOBUFS; | |
964 | ||
965 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
966 | tcp->data_payload_max)) | |
967 | return -ENOBUFS; | |
968 | ||
969 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
970 | tcp->data_payload_max)) | |
971 | return -ENOBUFS; | |
972 | ||
973 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
974 | return -ENOBUFS; | |
975 | ||
976 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
977 | sizeof(*tcp->tok), tcp->tok)) | |
978 | return -ENOBUFS; | |
979 | ||
980 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
981 | tcp->data_interval_max)) | |
982 | return -ENOBUFS; | |
983 | ||
984 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
985 | tcp->wake_payload_max)) | |
986 | return -ENOBUFS; | |
987 | ||
988 | nla_nest_end(msg, nl_tcp); | |
989 | return 0; | |
990 | } | |
991 | ||
3713b4e3 | 992 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
993 | struct cfg80211_registered_device *dev, |
994 | bool large) | |
55682965 | 995 | { |
3713b4e3 | 996 | struct nlattr *nl_wowlan; |
55682965 | 997 | |
3713b4e3 JB |
998 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
999 | return 0; | |
55682965 | 1000 | |
3713b4e3 JB |
1001 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1002 | if (!nl_wowlan) | |
1003 | return -ENOBUFS; | |
9360ffd1 | 1004 | |
3713b4e3 JB |
1005 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
1007 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
1008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
1009 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
1010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
1011 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
1012 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
1013 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
1014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
1015 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
1016 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1017 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1018 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1019 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1020 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1021 | return -ENOBUFS; | |
9360ffd1 | 1022 | |
3713b4e3 JB |
1023 | if (dev->wiphy.wowlan.n_patterns) { |
1024 | struct nl80211_wowlan_pattern_support pat = { | |
1025 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1026 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, | |
1027 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, | |
1028 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, | |
1029 | }; | |
9360ffd1 | 1030 | |
3713b4e3 JB |
1031 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1032 | sizeof(pat), &pat)) | |
1033 | return -ENOBUFS; | |
1034 | } | |
9360ffd1 | 1035 | |
b56cf720 JB |
1036 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1037 | return -ENOBUFS; | |
1038 | ||
3713b4e3 | 1039 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1040 | |
3713b4e3 JB |
1041 | return 0; |
1042 | } | |
1043 | #endif | |
9360ffd1 | 1044 | |
3713b4e3 JB |
1045 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1046 | struct ieee80211_supported_band *sband) | |
1047 | { | |
1048 | struct nlattr *nl_rates, *nl_rate; | |
1049 | struct ieee80211_rate *rate; | |
1050 | int i; | |
87bbbe22 | 1051 | |
3713b4e3 JB |
1052 | /* add HT info */ |
1053 | if (sband->ht_cap.ht_supported && | |
1054 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1055 | sizeof(sband->ht_cap.mcs), | |
1056 | &sband->ht_cap.mcs) || | |
1057 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1058 | sband->ht_cap.cap) || | |
1059 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1060 | sband->ht_cap.ampdu_factor) || | |
1061 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1062 | sband->ht_cap.ampdu_density))) | |
1063 | return -ENOBUFS; | |
afe0cbf8 | 1064 | |
3713b4e3 JB |
1065 | /* add VHT info */ |
1066 | if (sband->vht_cap.vht_supported && | |
1067 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1068 | sizeof(sband->vht_cap.vht_mcs), | |
1069 | &sband->vht_cap.vht_mcs) || | |
1070 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1071 | sband->vht_cap.cap))) | |
1072 | return -ENOBUFS; | |
f59ac048 | 1073 | |
3713b4e3 JB |
1074 | /* add bitrates */ |
1075 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1076 | if (!nl_rates) | |
1077 | return -ENOBUFS; | |
ee688b00 | 1078 | |
3713b4e3 JB |
1079 | for (i = 0; i < sband->n_bitrates; i++) { |
1080 | nl_rate = nla_nest_start(msg, i); | |
1081 | if (!nl_rate) | |
1082 | return -ENOBUFS; | |
ee688b00 | 1083 | |
3713b4e3 JB |
1084 | rate = &sband->bitrates[i]; |
1085 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1086 | rate->bitrate)) | |
1087 | return -ENOBUFS; | |
1088 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1089 | nla_put_flag(msg, | |
1090 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1091 | return -ENOBUFS; | |
ee688b00 | 1092 | |
3713b4e3 JB |
1093 | nla_nest_end(msg, nl_rate); |
1094 | } | |
d51626df | 1095 | |
3713b4e3 | 1096 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1097 | |
3713b4e3 JB |
1098 | return 0; |
1099 | } | |
ee688b00 | 1100 | |
3713b4e3 JB |
1101 | static int |
1102 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1103 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1104 | { | |
1105 | u16 stypes; | |
1106 | struct nlattr *nl_ftypes, *nl_ifs; | |
1107 | enum nl80211_iftype ift; | |
1108 | int i; | |
ee688b00 | 1109 | |
3713b4e3 JB |
1110 | if (!mgmt_stypes) |
1111 | return 0; | |
5dab3b8a | 1112 | |
3713b4e3 JB |
1113 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1114 | if (!nl_ifs) | |
1115 | return -ENOBUFS; | |
e2f367f2 | 1116 | |
3713b4e3 JB |
1117 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1118 | nl_ftypes = nla_nest_start(msg, ift); | |
1119 | if (!nl_ftypes) | |
1120 | return -ENOBUFS; | |
1121 | i = 0; | |
1122 | stypes = mgmt_stypes[ift].tx; | |
1123 | while (stypes) { | |
1124 | if ((stypes & 1) && | |
1125 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1126 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1127 | return -ENOBUFS; | |
1128 | stypes >>= 1; | |
1129 | i++; | |
ee688b00 | 1130 | } |
3713b4e3 JB |
1131 | nla_nest_end(msg, nl_ftypes); |
1132 | } | |
ee688b00 | 1133 | |
3713b4e3 | 1134 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1135 | |
3713b4e3 JB |
1136 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1137 | if (!nl_ifs) | |
1138 | return -ENOBUFS; | |
ee688b00 | 1139 | |
3713b4e3 JB |
1140 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1141 | nl_ftypes = nla_nest_start(msg, ift); | |
1142 | if (!nl_ftypes) | |
1143 | return -ENOBUFS; | |
1144 | i = 0; | |
1145 | stypes = mgmt_stypes[ift].rx; | |
1146 | while (stypes) { | |
1147 | if ((stypes & 1) && | |
1148 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1149 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1150 | return -ENOBUFS; | |
1151 | stypes >>= 1; | |
1152 | i++; | |
1153 | } | |
1154 | nla_nest_end(msg, nl_ftypes); | |
1155 | } | |
1156 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1157 | |
3713b4e3 JB |
1158 | return 0; |
1159 | } | |
ee688b00 | 1160 | |
3713b4e3 JB |
1161 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1162 | struct sk_buff *msg, u32 portid, u32 seq, | |
1163 | int flags, bool split, long *split_start, | |
1164 | long *band_start, long *chan_start) | |
1165 | { | |
1166 | void *hdr; | |
1167 | struct nlattr *nl_bands, *nl_band; | |
1168 | struct nlattr *nl_freqs, *nl_freq; | |
1169 | struct nlattr *nl_cmds; | |
1170 | enum ieee80211_band band; | |
1171 | struct ieee80211_channel *chan; | |
1172 | int i; | |
1173 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1174 | dev->wiphy.mgmt_stypes; | |
1175 | long start = 0, start_chan = 0, start_band = 0; | |
fe1abafd | 1176 | u32 features; |
ee688b00 | 1177 | |
3713b4e3 JB |
1178 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1179 | if (!hdr) | |
1180 | return -ENOBUFS; | |
ee688b00 | 1181 | |
3713b4e3 JB |
1182 | /* allow always using the variables */ |
1183 | if (!split) { | |
1184 | split_start = &start; | |
1185 | band_start = &start_band; | |
1186 | chan_start = &start_chan; | |
ee688b00 | 1187 | } |
ee688b00 | 1188 | |
3713b4e3 JB |
1189 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1190 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1191 | wiphy_name(&dev->wiphy)) || | |
1192 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1193 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1194 | goto nla_put_failure; |
1195 | ||
3713b4e3 JB |
1196 | switch (*split_start) { |
1197 | case 0: | |
1198 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1199 | dev->wiphy.retry_short) || | |
1200 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1201 | dev->wiphy.retry_long) || | |
1202 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1203 | dev->wiphy.frag_threshold) || | |
1204 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1205 | dev->wiphy.rts_threshold) || | |
1206 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1207 | dev->wiphy.coverage_class) || | |
1208 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1209 | dev->wiphy.max_scan_ssids) || | |
1210 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1211 | dev->wiphy.max_sched_scan_ssids) || | |
1212 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1213 | dev->wiphy.max_scan_ie_len) || | |
1214 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1215 | dev->wiphy.max_sched_scan_ie_len) || | |
1216 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1217 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1218 | goto nla_put_failure; |
3713b4e3 JB |
1219 | |
1220 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1221 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1222 | goto nla_put_failure; |
3713b4e3 JB |
1223 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1224 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1225 | goto nla_put_failure; | |
1226 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1227 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1228 | goto nla_put_failure; | |
1229 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1230 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1231 | goto nla_put_failure; | |
1232 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1233 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1234 | goto nla_put_failure; | |
1235 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1236 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1237 | goto nla_put_failure; |
8fdc621d | 1238 | |
3713b4e3 JB |
1239 | (*split_start)++; |
1240 | if (split) | |
1241 | break; | |
1242 | case 1: | |
1243 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1244 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1245 | dev->wiphy.cipher_suites)) | |
1246 | goto nla_put_failure; | |
4745fc09 | 1247 | |
3713b4e3 JB |
1248 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1249 | dev->wiphy.max_num_pmkids)) | |
1250 | goto nla_put_failure; | |
b23aa676 | 1251 | |
3713b4e3 JB |
1252 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1253 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1254 | goto nla_put_failure; |
b23aa676 | 1255 | |
3713b4e3 JB |
1256 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1257 | dev->wiphy.available_antennas_tx) || | |
1258 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1259 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1260 | goto nla_put_failure; |
b23aa676 | 1261 | |
3713b4e3 JB |
1262 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1263 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1264 | dev->wiphy.probe_resp_offload)) | |
1265 | goto nla_put_failure; | |
8fdc621d | 1266 | |
3713b4e3 JB |
1267 | if ((dev->wiphy.available_antennas_tx || |
1268 | dev->wiphy.available_antennas_rx) && | |
1269 | dev->ops->get_antenna) { | |
1270 | u32 tx_ant = 0, rx_ant = 0; | |
1271 | int res; | |
1272 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1273 | if (!res) { | |
1274 | if (nla_put_u32(msg, | |
1275 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1276 | tx_ant) || | |
1277 | nla_put_u32(msg, | |
1278 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1279 | rx_ant)) | |
1280 | goto nla_put_failure; | |
1281 | } | |
1282 | } | |
a293911d | 1283 | |
3713b4e3 JB |
1284 | (*split_start)++; |
1285 | if (split) | |
1286 | break; | |
1287 | case 2: | |
1288 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1289 | dev->wiphy.interface_modes)) | |
1290 | goto nla_put_failure; | |
1291 | (*split_start)++; | |
1292 | if (split) | |
1293 | break; | |
1294 | case 3: | |
1295 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1296 | if (!nl_bands) | |
1297 | goto nla_put_failure; | |
f7ca38df | 1298 | |
3713b4e3 JB |
1299 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
1300 | struct ieee80211_supported_band *sband; | |
2e161f78 | 1301 | |
3713b4e3 | 1302 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1303 | |
3713b4e3 JB |
1304 | if (!sband) |
1305 | continue; | |
1306 | ||
1307 | nl_band = nla_nest_start(msg, band); | |
1308 | if (!nl_band) | |
2e161f78 | 1309 | goto nla_put_failure; |
3713b4e3 JB |
1310 | |
1311 | switch (*chan_start) { | |
1312 | case 0: | |
1313 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1314 | goto nla_put_failure; |
3713b4e3 JB |
1315 | (*chan_start)++; |
1316 | if (split) | |
1317 | break; | |
1318 | default: | |
1319 | /* add frequencies */ | |
1320 | nl_freqs = nla_nest_start( | |
1321 | msg, NL80211_BAND_ATTR_FREQS); | |
1322 | if (!nl_freqs) | |
1323 | goto nla_put_failure; | |
1324 | ||
1325 | for (i = *chan_start - 1; | |
1326 | i < sband->n_channels; | |
1327 | i++) { | |
1328 | nl_freq = nla_nest_start(msg, i); | |
1329 | if (!nl_freq) | |
1330 | goto nla_put_failure; | |
1331 | ||
1332 | chan = &sband->channels[i]; | |
1333 | ||
cdc89b97 JB |
1334 | if (nl80211_msg_put_channel(msg, chan, |
1335 | split)) | |
3713b4e3 JB |
1336 | goto nla_put_failure; |
1337 | ||
1338 | nla_nest_end(msg, nl_freq); | |
1339 | if (split) | |
1340 | break; | |
1341 | } | |
1342 | if (i < sband->n_channels) | |
1343 | *chan_start = i + 2; | |
1344 | else | |
1345 | *chan_start = 0; | |
1346 | nla_nest_end(msg, nl_freqs); | |
1347 | } | |
1348 | ||
1349 | nla_nest_end(msg, nl_band); | |
1350 | ||
1351 | if (split) { | |
1352 | /* start again here */ | |
1353 | if (*chan_start) | |
1354 | band--; | |
1355 | break; | |
2e161f78 | 1356 | } |
2e161f78 | 1357 | } |
3713b4e3 | 1358 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1359 | |
3713b4e3 JB |
1360 | if (band < IEEE80211_NUM_BANDS) |
1361 | *band_start = band + 1; | |
1362 | else | |
1363 | *band_start = 0; | |
74b70a4e | 1364 | |
3713b4e3 JB |
1365 | /* if bands & channels are done, continue outside */ |
1366 | if (*band_start == 0 && *chan_start == 0) | |
1367 | (*split_start)++; | |
1368 | if (split) | |
1369 | break; | |
1370 | case 4: | |
1371 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1372 | if (!nl_cmds) | |
2e161f78 JB |
1373 | goto nla_put_failure; |
1374 | ||
3713b4e3 JB |
1375 | i = 0; |
1376 | #define CMD(op, n) \ | |
1377 | do { \ | |
1378 | if (dev->ops->op) { \ | |
1379 | i++; \ | |
1380 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1381 | goto nla_put_failure; \ | |
1382 | } \ | |
1383 | } while (0) | |
1384 | ||
1385 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1386 | CMD(change_virtual_intf, SET_INTERFACE); | |
1387 | CMD(add_key, NEW_KEY); | |
1388 | CMD(start_ap, START_AP); | |
1389 | CMD(add_station, NEW_STATION); | |
1390 | CMD(add_mpath, NEW_MPATH); | |
1391 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1392 | CMD(change_bss, SET_BSS); | |
1393 | CMD(auth, AUTHENTICATE); | |
1394 | CMD(assoc, ASSOCIATE); | |
1395 | CMD(deauth, DEAUTHENTICATE); | |
1396 | CMD(disassoc, DISASSOCIATE); | |
1397 | CMD(join_ibss, JOIN_IBSS); | |
1398 | CMD(join_mesh, JOIN_MESH); | |
1399 | CMD(set_pmksa, SET_PMKSA); | |
1400 | CMD(del_pmksa, DEL_PMKSA); | |
1401 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1402 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1403 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1404 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1405 | CMD(mgmt_tx, FRAME); | |
1406 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1407 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1408 | i++; | |
1409 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1410 | goto nla_put_failure; |
2e161f78 | 1411 | } |
3713b4e3 JB |
1412 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1413 | dev->ops->join_mesh) { | |
1414 | i++; | |
1415 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1416 | goto nla_put_failure; | |
1417 | } | |
1418 | CMD(set_wds_peer, SET_WDS_PEER); | |
1419 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1420 | CMD(tdls_mgmt, TDLS_MGMT); | |
1421 | CMD(tdls_oper, TDLS_OPER); | |
1422 | } | |
1423 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1424 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1425 | CMD(probe_client, PROBE_CLIENT); | |
1426 | CMD(set_noack_map, SET_NOACK_MAP); | |
1427 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1428 | i++; | |
1429 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1430 | goto nla_put_failure; | |
1431 | } | |
1432 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1433 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
5de17984 AS |
1434 | if (split) { |
1435 | CMD(crit_proto_start, CRIT_PROTOCOL_START); | |
1436 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1437 | } | |
2e161f78 | 1438 | |
3713b4e3 JB |
1439 | #ifdef CONFIG_NL80211_TESTMODE |
1440 | CMD(testmode_cmd, TESTMODE); | |
1441 | #endif | |
ff1b6e69 | 1442 | |
3713b4e3 | 1443 | #undef CMD |
ff1b6e69 | 1444 | |
3713b4e3 JB |
1445 | if (dev->ops->connect || dev->ops->auth) { |
1446 | i++; | |
1447 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1448 | goto nla_put_failure; |
ff1b6e69 JB |
1449 | } |
1450 | ||
3713b4e3 JB |
1451 | if (dev->ops->disconnect || dev->ops->deauth) { |
1452 | i++; | |
1453 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1454 | goto nla_put_failure; | |
1455 | } | |
1456 | ||
1457 | nla_nest_end(msg, nl_cmds); | |
1458 | (*split_start)++; | |
1459 | if (split) | |
1460 | break; | |
1461 | case 5: | |
1462 | if (dev->ops->remain_on_channel && | |
1463 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1464 | nla_put_u32(msg, | |
1465 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1466 | dev->wiphy.max_remain_on_channel_duration)) | |
1467 | goto nla_put_failure; | |
1468 | ||
1469 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1470 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1471 | goto nla_put_failure; | |
1472 | ||
1473 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1474 | goto nla_put_failure; | |
1475 | (*split_start)++; | |
1476 | if (split) | |
1477 | break; | |
1478 | case 6: | |
1479 | #ifdef CONFIG_PM | |
b56cf720 | 1480 | if (nl80211_send_wowlan(msg, dev, split)) |
3713b4e3 JB |
1481 | goto nla_put_failure; |
1482 | (*split_start)++; | |
1483 | if (split) | |
1484 | break; | |
1485 | #else | |
1486 | (*split_start)++; | |
dfb89c56 | 1487 | #endif |
3713b4e3 JB |
1488 | case 7: |
1489 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1490 | dev->wiphy.software_iftypes)) | |
1491 | goto nla_put_failure; | |
ff1b6e69 | 1492 | |
cdc89b97 | 1493 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
3713b4e3 | 1494 | goto nla_put_failure; |
7527a782 | 1495 | |
3713b4e3 JB |
1496 | (*split_start)++; |
1497 | if (split) | |
1498 | break; | |
1499 | case 8: | |
1500 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1501 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1502 | dev->wiphy.ap_sme_capa)) | |
1503 | goto nla_put_failure; | |
7527a782 | 1504 | |
fe1abafd JB |
1505 | features = dev->wiphy.features; |
1506 | /* | |
1507 | * We can only add the per-channel limit information if the | |
1508 | * dump is split, otherwise it makes it too big. Therefore | |
1509 | * only advertise it in that case. | |
1510 | */ | |
1511 | if (split) | |
1512 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | |
1513 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1514 | goto nla_put_failure; |
562a7480 | 1515 | |
3713b4e3 JB |
1516 | if (dev->wiphy.ht_capa_mod_mask && |
1517 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1518 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1519 | dev->wiphy.ht_capa_mod_mask)) | |
1520 | goto nla_put_failure; | |
1f074bd8 | 1521 | |
3713b4e3 JB |
1522 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1523 | dev->wiphy.max_acl_mac_addrs && | |
1524 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1525 | dev->wiphy.max_acl_mac_addrs)) | |
1526 | goto nla_put_failure; | |
7e7c8926 | 1527 | |
6fa3eb70 S |
1528 | if (dev->wiphy.n_vendor_commands) { |
1529 | const struct nl80211_vendor_cmd_info *info; | |
1530 | struct nlattr *nested; | |
1531 | ||
1532 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1533 | if (!nested) | |
1534 | goto nla_put_failure; | |
1535 | ||
1536 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { | |
1537 | info = &dev->wiphy.vendor_commands[i].info; | |
1538 | if (nla_put(msg, i + 1, sizeof(*info), info)) | |
1539 | goto nla_put_failure; | |
1540 | } | |
1541 | nla_nest_end(msg, nested); | |
1542 | } | |
1543 | ||
1544 | if (dev->wiphy.n_vendor_events) { | |
1545 | const struct nl80211_vendor_cmd_info *info; | |
1546 | struct nlattr *nested; | |
1547 | ||
1548 | nested = nla_nest_start(msg, | |
1549 | NL80211_ATTR_VENDOR_EVENTS); | |
1550 | if (!nested) | |
1551 | goto nla_put_failure; | |
1552 | ||
1553 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { | |
1554 | info = &dev->wiphy.vendor_events[i]; | |
1555 | if (nla_put(msg, i + 1, sizeof(*info), info)) | |
1556 | goto nla_put_failure; | |
1557 | } | |
1558 | nla_nest_end(msg, nested); | |
1559 | } | |
1560 | ||
3713b4e3 JB |
1561 | /* |
1562 | * Any information below this point is only available to | |
1563 | * applications that can deal with it being split. This | |
1564 | * helps ensure that newly added capabilities don't break | |
1565 | * older tools by overrunning their buffers. | |
1566 | * | |
1567 | * We still increment split_start so that in the split | |
1568 | * case we'll continue with more data in the next round, | |
1569 | * but break unconditionally so unsplit data stops here. | |
1570 | */ | |
1571 | (*split_start)++; | |
1572 | break; | |
1573 | case 9: | |
fe1abafd JB |
1574 | if (dev->wiphy.extended_capabilities && |
1575 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1576 | dev->wiphy.extended_capabilities_len, | |
1577 | dev->wiphy.extended_capabilities) || | |
1578 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1579 | dev->wiphy.extended_capabilities_len, | |
1580 | dev->wiphy.extended_capabilities_mask))) | |
1581 | goto nla_put_failure; | |
a50df0c4 | 1582 | |
ee2aca34 JB |
1583 | if (dev->wiphy.vht_capa_mod_mask && |
1584 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1585 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1586 | dev->wiphy.vht_capa_mod_mask)) | |
1587 | goto nla_put_failure; | |
1588 | ||
3713b4e3 JB |
1589 | /* done */ |
1590 | *split_start = 0; | |
1591 | break; | |
1592 | } | |
55682965 JB |
1593 | return genlmsg_end(msg, hdr); |
1594 | ||
1595 | nla_put_failure: | |
bc3ed28c TG |
1596 | genlmsg_cancel(msg, hdr); |
1597 | return -EMSGSIZE; | |
55682965 JB |
1598 | } |
1599 | ||
1600 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1601 | { | |
645e77de | 1602 | int idx = 0, ret; |
55682965 JB |
1603 | int start = cb->args[0]; |
1604 | struct cfg80211_registered_device *dev; | |
3713b4e3 JB |
1605 | s64 filter_wiphy = -1; |
1606 | bool split = false; | |
3a5a423b | 1607 | struct nlattr **tb; |
3713b4e3 | 1608 | int res; |
55682965 | 1609 | |
3a5a423b JB |
1610 | /* will be zeroed in nlmsg_parse() */ |
1611 | tb = kmalloc(sizeof(*tb) * (NL80211_ATTR_MAX + 1), GFP_KERNEL); | |
1612 | if (!tb) | |
1613 | return -ENOMEM; | |
1614 | ||
a1794390 | 1615 | mutex_lock(&cfg80211_mutex); |
3713b4e3 | 1616 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
3a5a423b | 1617 | tb, NL80211_ATTR_MAX, nl80211_policy); |
3713b4e3 JB |
1618 | if (res == 0) { |
1619 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1620 | if (tb[NL80211_ATTR_WIPHY]) | |
1621 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1622 | if (tb[NL80211_ATTR_WDEV]) | |
1623 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1624 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1625 | struct net_device *netdev; | |
1626 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1627 | ||
1628 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1629 | if (!netdev) { | |
1630 | mutex_unlock(&cfg80211_mutex); | |
3a5a423b | 1631 | kfree(tb); |
3713b4e3 JB |
1632 | return -ENODEV; |
1633 | } | |
1634 | if (netdev->ieee80211_ptr) { | |
1635 | dev = wiphy_to_dev( | |
1636 | netdev->ieee80211_ptr->wiphy); | |
1637 | filter_wiphy = dev->wiphy_idx; | |
1638 | } | |
1639 | dev_put(netdev); | |
1640 | } | |
1641 | } | |
3a5a423b | 1642 | kfree(tb); |
3713b4e3 | 1643 | |
79c97e97 | 1644 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1645 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1646 | continue; | |
b4637271 | 1647 | if (++idx <= start) |
55682965 | 1648 | continue; |
3713b4e3 JB |
1649 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
1650 | continue; | |
1651 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1652 | do { | |
1653 | ret = nl80211_send_wiphy(dev, skb, | |
1654 | NETLINK_CB(cb->skb).portid, | |
1655 | cb->nlh->nlmsg_seq, | |
1656 | NLM_F_MULTI, | |
1657 | split, &cb->args[1], | |
1658 | &cb->args[2], | |
1659 | &cb->args[3]); | |
1660 | if (ret < 0) { | |
1661 | /* | |
1662 | * If sending the wiphy data didn't fit (ENOBUFS | |
1663 | * or EMSGSIZE returned), this SKB is still | |
1664 | * empty (so it's not too big because another | |
1665 | * wiphy dataset is already in the skb) and | |
1666 | * we've not tried to adjust the dump allocation | |
1667 | * yet ... then adjust the alloc size to be | |
1668 | * bigger, and return 1 but with the empty skb. | |
1669 | * This results in an empty message being RX'ed | |
1670 | * in userspace, but that is ignored. | |
1671 | * | |
1672 | * We can then retry with the larger buffer. | |
1673 | */ | |
1674 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1675 | !skb->len && | |
1676 | cb->min_dump_alloc < 4096) { | |
1677 | cb->min_dump_alloc = 4096; | |
1678 | mutex_unlock(&cfg80211_mutex); | |
1679 | return 1; | |
1680 | } | |
1681 | idx--; | |
1682 | break; | |
645e77de | 1683 | } |
3713b4e3 JB |
1684 | } while (cb->args[1] > 0); |
1685 | break; | |
55682965 | 1686 | } |
a1794390 | 1687 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1688 | |
1689 | cb->args[0] = idx; | |
1690 | ||
1691 | return skb->len; | |
1692 | } | |
1693 | ||
1694 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1695 | { | |
1696 | struct sk_buff *msg; | |
4c476991 | 1697 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1698 | |
645e77de | 1699 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1700 | if (!msg) |
4c476991 | 1701 | return -ENOMEM; |
55682965 | 1702 | |
3713b4e3 JB |
1703 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
1704 | false, NULL, NULL, NULL) < 0) { | |
4c476991 JB |
1705 | nlmsg_free(msg); |
1706 | return -ENOBUFS; | |
1707 | } | |
55682965 | 1708 | |
134e6375 | 1709 | return genlmsg_reply(msg, info); |
55682965 JB |
1710 | } |
1711 | ||
31888487 JM |
1712 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1713 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1714 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1715 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1716 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1717 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1718 | }; | |
1719 | ||
1720 | static int parse_txq_params(struct nlattr *tb[], | |
1721 | struct ieee80211_txq_params *txq_params) | |
1722 | { | |
a3304b0a | 1723 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1724 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1725 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1726 | return -EINVAL; | |
1727 | ||
a3304b0a | 1728 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1729 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1730 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1731 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1732 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1733 | ||
a3304b0a JB |
1734 | if (txq_params->ac >= NL80211_NUM_ACS) |
1735 | return -EINVAL; | |
1736 | ||
31888487 JM |
1737 | return 0; |
1738 | } | |
1739 | ||
f444de05 JB |
1740 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1741 | { | |
1742 | /* | |
cc1d2806 JB |
1743 | * You can only set the channel explicitly for WDS interfaces, |
1744 | * all others have their channel managed via their respective | |
1745 | * "establish a connection" command (connect, join, ...) | |
1746 | * | |
1747 | * For AP/GO and mesh mode, the channel can be set with the | |
1748 | * channel userspace API, but is only stored and passed to the | |
1749 | * low-level driver when the AP starts or the mesh is joined. | |
1750 | * This is for backward compatibility, userspace can also give | |
1751 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1752 | * |
1753 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1754 | * whatever else is going on, so they have their own special |
1755 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1756 | */ |
1757 | return !wdev || | |
1758 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1759 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1760 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1761 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1762 | } |
1763 | ||
683b6d3b JB |
1764 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1765 | struct genl_info *info, | |
1766 | struct cfg80211_chan_def *chandef) | |
1767 | { | |
dbeca2ea | 1768 | u32 control_freq; |
683b6d3b JB |
1769 | |
1770 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1771 | return -EINVAL; | |
1772 | ||
1773 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1774 | ||
1775 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1776 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1777 | chandef->center_freq1 = control_freq; | |
1778 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1779 | |
1780 | /* Primary channel not allowed */ | |
1781 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1782 | return -EINVAL; | |
1783 | ||
3d9d1d66 JB |
1784 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1785 | enum nl80211_channel_type chantype; | |
1786 | ||
1787 | chantype = nla_get_u32( | |
1788 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1789 | ||
1790 | switch (chantype) { | |
1791 | case NL80211_CHAN_NO_HT: | |
1792 | case NL80211_CHAN_HT20: | |
1793 | case NL80211_CHAN_HT40PLUS: | |
1794 | case NL80211_CHAN_HT40MINUS: | |
1795 | cfg80211_chandef_create(chandef, chandef->chan, | |
1796 | chantype); | |
1797 | break; | |
1798 | default: | |
1799 | return -EINVAL; | |
1800 | } | |
1801 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1802 | chandef->width = | |
1803 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1804 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1805 | chandef->center_freq1 = | |
1806 | nla_get_u32( | |
1807 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1808 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1809 | chandef->center_freq2 = | |
1810 | nla_get_u32( | |
1811 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1812 | } | |
1813 | ||
9f5e8f6e | 1814 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1815 | return -EINVAL; |
1816 | ||
9f5e8f6e JB |
1817 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1818 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1819 | return -EINVAL; |
1820 | ||
683b6d3b JB |
1821 | return 0; |
1822 | } | |
1823 | ||
f444de05 JB |
1824 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1825 | struct wireless_dev *wdev, | |
1826 | struct genl_info *info) | |
1827 | { | |
683b6d3b | 1828 | struct cfg80211_chan_def chandef; |
f444de05 | 1829 | int result; |
e8c9bd5b JB |
1830 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1831 | ||
1832 | if (wdev) | |
1833 | iftype = wdev->iftype; | |
f444de05 | 1834 | |
f444de05 JB |
1835 | if (!nl80211_can_set_dev_channel(wdev)) |
1836 | return -EOPNOTSUPP; | |
1837 | ||
683b6d3b JB |
1838 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1839 | if (result) | |
1840 | return result; | |
f444de05 JB |
1841 | |
1842 | mutex_lock(&rdev->devlist_mtx); | |
e8c9bd5b | 1843 | switch (iftype) { |
aa430da4 JB |
1844 | case NL80211_IFTYPE_AP: |
1845 | case NL80211_IFTYPE_P2P_GO: | |
1846 | if (wdev->beacon_interval) { | |
1847 | result = -EBUSY; | |
1848 | break; | |
1849 | } | |
683b6d3b | 1850 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1851 | result = -EINVAL; |
1852 | break; | |
1853 | } | |
683b6d3b | 1854 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1855 | result = 0; |
1856 | break; | |
cc1d2806 | 1857 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1858 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1859 | break; |
e8c9bd5b | 1860 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1861 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1862 | break; |
aa430da4 | 1863 | default: |
e8c9bd5b | 1864 | result = -EINVAL; |
f444de05 JB |
1865 | } |
1866 | mutex_unlock(&rdev->devlist_mtx); | |
1867 | ||
1868 | return result; | |
1869 | } | |
1870 | ||
1871 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1872 | { | |
4c476991 JB |
1873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1874 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1875 | |
4c476991 | 1876 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1877 | } |
1878 | ||
e8347eba BJ |
1879 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1880 | { | |
43b19952 JB |
1881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1882 | struct net_device *dev = info->user_ptr[1]; | |
1883 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1884 | const u8 *bssid; |
e8347eba BJ |
1885 | |
1886 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1887 | return -EINVAL; | |
1888 | ||
43b19952 JB |
1889 | if (netif_running(dev)) |
1890 | return -EBUSY; | |
e8347eba | 1891 | |
43b19952 JB |
1892 | if (!rdev->ops->set_wds_peer) |
1893 | return -EOPNOTSUPP; | |
e8347eba | 1894 | |
43b19952 JB |
1895 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1896 | return -EOPNOTSUPP; | |
e8347eba BJ |
1897 | |
1898 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1899 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1900 | } |
1901 | ||
1902 | ||
55682965 JB |
1903 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1904 | { | |
1905 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1906 | struct net_device *netdev = NULL; |
1907 | struct wireless_dev *wdev; | |
a1e567c8 | 1908 | int result = 0, rem_txq_params = 0; |
31888487 | 1909 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1910 | u32 changed; |
1911 | u8 retry_short = 0, retry_long = 0; | |
1912 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1913 | u8 coverage_class = 0; |
55682965 | 1914 | |
f444de05 JB |
1915 | /* |
1916 | * Try to find the wiphy and netdev. Normally this | |
1917 | * function shouldn't need the netdev, but this is | |
1918 | * done for backward compatibility -- previously | |
1919 | * setting the channel was done per wiphy, but now | |
1920 | * it is per netdev. Previous userland like hostapd | |
1921 | * also passed a netdev to set_wiphy, so that it is | |
1922 | * possible to let that go to the right netdev! | |
1923 | */ | |
4bbf4d56 JB |
1924 | mutex_lock(&cfg80211_mutex); |
1925 | ||
f444de05 JB |
1926 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1927 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1928 | ||
1929 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1930 | if (netdev && netdev->ieee80211_ptr) { | |
1931 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1932 | mutex_lock(&rdev->mtx); | |
1933 | } else | |
1934 | netdev = NULL; | |
4bbf4d56 JB |
1935 | } |
1936 | ||
f444de05 | 1937 | if (!netdev) { |
878d9ec7 JB |
1938 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1939 | info->attrs); | |
f444de05 JB |
1940 | if (IS_ERR(rdev)) { |
1941 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1942 | return PTR_ERR(rdev); |
f444de05 JB |
1943 | } |
1944 | wdev = NULL; | |
1945 | netdev = NULL; | |
1946 | result = 0; | |
1947 | ||
1948 | mutex_lock(&rdev->mtx); | |
71fe96bf | 1949 | } else |
f444de05 | 1950 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1951 | |
1952 | /* | |
1953 | * end workaround code, by now the rdev is available | |
1954 | * and locked, and wdev may or may not be NULL. | |
1955 | */ | |
4bbf4d56 JB |
1956 | |
1957 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1958 | result = cfg80211_dev_rename( |
1959 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1960 | |
1961 | mutex_unlock(&cfg80211_mutex); | |
1962 | ||
1963 | if (result) | |
1964 | goto bad_res; | |
31888487 JM |
1965 | |
1966 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1967 | struct ieee80211_txq_params txq_params; | |
1968 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1969 | ||
1970 | if (!rdev->ops->set_txq_params) { | |
1971 | result = -EOPNOTSUPP; | |
1972 | goto bad_res; | |
1973 | } | |
1974 | ||
f70f01c2 EP |
1975 | if (!netdev) { |
1976 | result = -EINVAL; | |
1977 | goto bad_res; | |
1978 | } | |
1979 | ||
133a3ff2 JB |
1980 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1981 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1982 | result = -EINVAL; | |
1983 | goto bad_res; | |
1984 | } | |
1985 | ||
2b5f8b0b JB |
1986 | if (!netif_running(netdev)) { |
1987 | result = -ENETDOWN; | |
1988 | goto bad_res; | |
1989 | } | |
1990 | ||
31888487 JM |
1991 | nla_for_each_nested(nl_txq_params, |
1992 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1993 | rem_txq_params) { | |
1994 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1995 | nla_data(nl_txq_params), | |
1996 | nla_len(nl_txq_params), | |
1997 | txq_params_policy); | |
1998 | result = parse_txq_params(tb, &txq_params); | |
1999 | if (result) | |
2000 | goto bad_res; | |
2001 | ||
e35e4d28 HG |
2002 | result = rdev_set_txq_params(rdev, netdev, |
2003 | &txq_params); | |
31888487 JM |
2004 | if (result) |
2005 | goto bad_res; | |
2006 | } | |
2007 | } | |
55682965 | 2008 | |
72bdcf34 | 2009 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
2010 | result = __nl80211_set_channel(rdev, |
2011 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
2012 | info); | |
72bdcf34 JM |
2013 | if (result) |
2014 | goto bad_res; | |
2015 | } | |
2016 | ||
98d2ff8b | 2017 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2018 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2019 | enum nl80211_tx_power_setting type; |
2020 | int idx, mbm = 0; | |
2021 | ||
c8442118 JB |
2022 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2023 | txp_wdev = NULL; | |
2024 | ||
98d2ff8b | 2025 | if (!rdev->ops->set_tx_power) { |
60ea385f | 2026 | result = -EOPNOTSUPP; |
98d2ff8b JO |
2027 | goto bad_res; |
2028 | } | |
2029 | ||
2030 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2031 | type = nla_get_u32(info->attrs[idx]); | |
2032 | ||
2033 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
2034 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
2035 | result = -EINVAL; | |
2036 | goto bad_res; | |
2037 | } | |
2038 | ||
2039 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2040 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2041 | mbm = nla_get_u32(info->attrs[idx]); | |
2042 | } | |
2043 | ||
c8442118 | 2044 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
2045 | if (result) |
2046 | goto bad_res; | |
2047 | } | |
2048 | ||
afe0cbf8 BR |
2049 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2050 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2051 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2052 | if ((!rdev->wiphy.available_antennas_tx && |
2053 | !rdev->wiphy.available_antennas_rx) || | |
2054 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
2055 | result = -EOPNOTSUPP; |
2056 | goto bad_res; | |
2057 | } | |
2058 | ||
2059 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2060 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2061 | ||
a7ffac95 | 2062 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2063 | * available antenna masks, except for the "all" mask */ |
2064 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2065 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2066 | result = -EINVAL; |
2067 | goto bad_res; | |
2068 | } | |
2069 | ||
7f531e03 BR |
2070 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2071 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2072 | |
e35e4d28 | 2073 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2074 | if (result) |
2075 | goto bad_res; | |
2076 | } | |
2077 | ||
b9a5f8ca JM |
2078 | changed = 0; |
2079 | ||
2080 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2081 | retry_short = nla_get_u8( | |
2082 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2083 | if (retry_short == 0) { | |
2084 | result = -EINVAL; | |
2085 | goto bad_res; | |
2086 | } | |
2087 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2088 | } | |
2089 | ||
2090 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2091 | retry_long = nla_get_u8( | |
2092 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2093 | if (retry_long == 0) { | |
2094 | result = -EINVAL; | |
2095 | goto bad_res; | |
2096 | } | |
2097 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2098 | } | |
2099 | ||
2100 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2101 | frag_threshold = nla_get_u32( | |
2102 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2103 | if (frag_threshold < 256) { | |
2104 | result = -EINVAL; | |
2105 | goto bad_res; | |
2106 | } | |
2107 | if (frag_threshold != (u32) -1) { | |
2108 | /* | |
2109 | * Fragments (apart from the last one) are required to | |
2110 | * have even length. Make the fragmentation code | |
2111 | * simpler by stripping LSB should someone try to use | |
2112 | * odd threshold value. | |
2113 | */ | |
2114 | frag_threshold &= ~0x1; | |
2115 | } | |
2116 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2117 | } | |
2118 | ||
2119 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2120 | rts_threshold = nla_get_u32( | |
2121 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2122 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2123 | } | |
2124 | ||
81077e82 LT |
2125 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2126 | coverage_class = nla_get_u8( | |
2127 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2128 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2129 | } | |
2130 | ||
b9a5f8ca JM |
2131 | if (changed) { |
2132 | u8 old_retry_short, old_retry_long; | |
2133 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2134 | u8 old_coverage_class; |
b9a5f8ca JM |
2135 | |
2136 | if (!rdev->ops->set_wiphy_params) { | |
2137 | result = -EOPNOTSUPP; | |
2138 | goto bad_res; | |
2139 | } | |
2140 | ||
2141 | old_retry_short = rdev->wiphy.retry_short; | |
2142 | old_retry_long = rdev->wiphy.retry_long; | |
2143 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2144 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2145 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2146 | |
2147 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2148 | rdev->wiphy.retry_short = retry_short; | |
2149 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2150 | rdev->wiphy.retry_long = retry_long; | |
2151 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2152 | rdev->wiphy.frag_threshold = frag_threshold; | |
2153 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2154 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2155 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2156 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2157 | |
e35e4d28 | 2158 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2159 | if (result) { |
2160 | rdev->wiphy.retry_short = old_retry_short; | |
2161 | rdev->wiphy.retry_long = old_retry_long; | |
2162 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2163 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2164 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2165 | } |
2166 | } | |
72bdcf34 | 2167 | |
306d6112 | 2168 | bad_res: |
4bbf4d56 | 2169 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
2170 | if (netdev) |
2171 | dev_put(netdev); | |
55682965 JB |
2172 | return result; |
2173 | } | |
2174 | ||
71bbc994 JB |
2175 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2176 | { | |
2177 | return (u64)wdev->identifier | | |
2178 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2179 | } | |
55682965 | 2180 | |
683b6d3b JB |
2181 | static int nl80211_send_chandef(struct sk_buff *msg, |
2182 | struct cfg80211_chan_def *chandef) | |
2183 | { | |
9f5e8f6e | 2184 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2185 | |
683b6d3b JB |
2186 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2187 | chandef->chan->center_freq)) | |
2188 | return -ENOBUFS; | |
3d9d1d66 JB |
2189 | switch (chandef->width) { |
2190 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2191 | case NL80211_CHAN_WIDTH_20: | |
2192 | case NL80211_CHAN_WIDTH_40: | |
2193 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2194 | cfg80211_get_chandef_type(chandef))) | |
2195 | return -ENOBUFS; | |
2196 | break; | |
2197 | default: | |
2198 | break; | |
2199 | } | |
2200 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2201 | return -ENOBUFS; | |
2202 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2203 | return -ENOBUFS; | |
2204 | if (chandef->center_freq2 && | |
2205 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2206 | return -ENOBUFS; |
2207 | return 0; | |
2208 | } | |
2209 | ||
15e47304 | 2210 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2211 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2212 | struct wireless_dev *wdev) |
55682965 | 2213 | { |
72fb2abc | 2214 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2215 | void *hdr; |
2216 | ||
15e47304 | 2217 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2218 | if (!hdr) |
2219 | return -1; | |
2220 | ||
72fb2abc JB |
2221 | if (dev && |
2222 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2223 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2224 | goto nla_put_failure; |
2225 | ||
2226 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2227 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2228 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2229 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2230 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2231 | rdev->devlist_generation ^ | |
2232 | (cfg80211_rdev_list_generation << 2))) | |
2233 | goto nla_put_failure; | |
f5ea9120 | 2234 | |
5b7ccaf3 | 2235 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2236 | int ret; |
2237 | struct cfg80211_chan_def chandef; | |
2238 | ||
2239 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2240 | if (ret == 0) { | |
2241 | if (nl80211_send_chandef(msg, &chandef)) | |
2242 | goto nla_put_failure; | |
2243 | } | |
d91df0e3 PF |
2244 | } |
2245 | ||
b84e7a05 AQ |
2246 | if (wdev->ssid_len) { |
2247 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2248 | goto nla_put_failure; | |
2249 | } | |
2250 | ||
55682965 JB |
2251 | return genlmsg_end(msg, hdr); |
2252 | ||
2253 | nla_put_failure: | |
bc3ed28c TG |
2254 | genlmsg_cancel(msg, hdr); |
2255 | return -EMSGSIZE; | |
55682965 JB |
2256 | } |
2257 | ||
2258 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2259 | { | |
2260 | int wp_idx = 0; | |
2261 | int if_idx = 0; | |
2262 | int wp_start = cb->args[0]; | |
2263 | int if_start = cb->args[1]; | |
f5ea9120 | 2264 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2265 | struct wireless_dev *wdev; |
2266 | ||
a1794390 | 2267 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
2268 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2269 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2270 | continue; |
bba95fef JB |
2271 | if (wp_idx < wp_start) { |
2272 | wp_idx++; | |
55682965 | 2273 | continue; |
bba95fef | 2274 | } |
55682965 JB |
2275 | if_idx = 0; |
2276 | ||
f5ea9120 | 2277 | mutex_lock(&rdev->devlist_mtx); |
89a54e48 | 2278 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2279 | if (if_idx < if_start) { |
2280 | if_idx++; | |
55682965 | 2281 | continue; |
bba95fef | 2282 | } |
15e47304 | 2283 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2284 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2285 | rdev, wdev) < 0) { |
f5ea9120 | 2286 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2287 | goto out; |
2288 | } | |
2289 | if_idx++; | |
55682965 | 2290 | } |
f5ea9120 | 2291 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
2292 | |
2293 | wp_idx++; | |
55682965 | 2294 | } |
bba95fef | 2295 | out: |
a1794390 | 2296 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
2297 | |
2298 | cb->args[0] = wp_idx; | |
2299 | cb->args[1] = if_idx; | |
2300 | ||
2301 | return skb->len; | |
2302 | } | |
2303 | ||
2304 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2305 | { | |
2306 | struct sk_buff *msg; | |
4c476991 | 2307 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2308 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2309 | |
fd2120ca | 2310 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2311 | if (!msg) |
4c476991 | 2312 | return -ENOMEM; |
55682965 | 2313 | |
15e47304 | 2314 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2315 | dev, wdev) < 0) { |
4c476991 JB |
2316 | nlmsg_free(msg); |
2317 | return -ENOBUFS; | |
2318 | } | |
55682965 | 2319 | |
134e6375 | 2320 | return genlmsg_reply(msg, info); |
55682965 JB |
2321 | } |
2322 | ||
66f7ac50 MW |
2323 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2324 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2325 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2326 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2327 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2328 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
2329 | }; | |
2330 | ||
2331 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2332 | { | |
2333 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2334 | int flag; | |
2335 | ||
2336 | *mntrflags = 0; | |
2337 | ||
2338 | if (!nla) | |
2339 | return -EINVAL; | |
2340 | ||
2341 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2342 | nla, mntr_flags_policy)) | |
2343 | return -EINVAL; | |
2344 | ||
2345 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2346 | if (flags[flag]) | |
2347 | *mntrflags |= (1<<flag); | |
2348 | ||
2349 | return 0; | |
2350 | } | |
2351 | ||
9bc383de | 2352 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2353 | struct net_device *netdev, u8 use_4addr, |
2354 | enum nl80211_iftype iftype) | |
9bc383de | 2355 | { |
ad4bb6f8 | 2356 | if (!use_4addr) { |
f350a0a8 | 2357 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2358 | return -EBUSY; |
9bc383de | 2359 | return 0; |
ad4bb6f8 | 2360 | } |
9bc383de JB |
2361 | |
2362 | switch (iftype) { | |
2363 | case NL80211_IFTYPE_AP_VLAN: | |
2364 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2365 | return 0; | |
2366 | break; | |
2367 | case NL80211_IFTYPE_STATION: | |
2368 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2369 | return 0; | |
2370 | break; | |
2371 | default: | |
2372 | break; | |
2373 | } | |
2374 | ||
2375 | return -EOPNOTSUPP; | |
2376 | } | |
2377 | ||
55682965 JB |
2378 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2379 | { | |
4c476991 | 2380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2381 | struct vif_params params; |
e36d56b6 | 2382 | int err; |
04a773ad | 2383 | enum nl80211_iftype otype, ntype; |
4c476991 | 2384 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2385 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2386 | bool change = false; |
55682965 | 2387 | |
2ec600d6 LCC |
2388 | memset(¶ms, 0, sizeof(params)); |
2389 | ||
04a773ad | 2390 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2391 | |
723b038d | 2392 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2393 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2394 | if (otype != ntype) |
ac7f9cfa | 2395 | change = true; |
4c476991 JB |
2396 | if (ntype > NL80211_IFTYPE_MAX) |
2397 | return -EINVAL; | |
723b038d JB |
2398 | } |
2399 | ||
92ffe055 | 2400 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2401 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2402 | ||
4c476991 JB |
2403 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2404 | return -EINVAL; | |
29cbe68c JB |
2405 | if (netif_running(dev)) |
2406 | return -EBUSY; | |
2407 | ||
2408 | wdev_lock(wdev); | |
2409 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2410 | IEEE80211_MAX_MESH_ID_LEN); | |
2411 | wdev->mesh_id_up_len = | |
2412 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2413 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2414 | wdev->mesh_id_up_len); | |
2415 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2416 | } |
2417 | ||
8b787643 FF |
2418 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2419 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2420 | change = true; | |
ad4bb6f8 | 2421 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2422 | if (err) |
4c476991 | 2423 | return err; |
8b787643 FF |
2424 | } else { |
2425 | params.use_4addr = -1; | |
2426 | } | |
2427 | ||
92ffe055 | 2428 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2429 | if (ntype != NL80211_IFTYPE_MONITOR) |
2430 | return -EINVAL; | |
92ffe055 JB |
2431 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2432 | &_flags); | |
ac7f9cfa | 2433 | if (err) |
4c476991 | 2434 | return err; |
ac7f9cfa JB |
2435 | |
2436 | flags = &_flags; | |
2437 | change = true; | |
92ffe055 | 2438 | } |
3b85875a | 2439 | |
ac7f9cfa | 2440 | if (change) |
3d54d255 | 2441 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2442 | else |
2443 | err = 0; | |
60719ffd | 2444 | |
9bc383de JB |
2445 | if (!err && params.use_4addr != -1) |
2446 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2447 | ||
55682965 JB |
2448 | return err; |
2449 | } | |
2450 | ||
2451 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2452 | { | |
4c476991 | 2453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2454 | struct vif_params params; |
84efbb84 | 2455 | struct wireless_dev *wdev; |
1c90f9d4 | 2456 | struct sk_buff *msg; |
55682965 JB |
2457 | int err; |
2458 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2459 | u32 flags; |
55682965 | 2460 | |
2ec600d6 LCC |
2461 | memset(¶ms, 0, sizeof(params)); |
2462 | ||
55682965 JB |
2463 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2464 | return -EINVAL; | |
2465 | ||
2466 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2467 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2468 | if (type > NL80211_IFTYPE_MAX) | |
2469 | return -EINVAL; | |
2470 | } | |
2471 | ||
79c97e97 | 2472 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2473 | !(rdev->wiphy.interface_modes & (1 << type))) |
2474 | return -EOPNOTSUPP; | |
55682965 | 2475 | |
1c18f145 AS |
2476 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2477 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2478 | ETH_ALEN); | |
2479 | if (!is_valid_ether_addr(params.macaddr)) | |
2480 | return -EADDRNOTAVAIL; | |
2481 | } | |
2482 | ||
9bc383de | 2483 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2484 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2485 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2486 | if (err) |
4c476991 | 2487 | return err; |
9bc383de | 2488 | } |
8b787643 | 2489 | |
1c90f9d4 JB |
2490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2491 | if (!msg) | |
2492 | return -ENOMEM; | |
2493 | ||
66f7ac50 MW |
2494 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2495 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2496 | &flags); | |
e35e4d28 HG |
2497 | wdev = rdev_add_virtual_intf(rdev, |
2498 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2499 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2500 | if (IS_ERR(wdev)) { |
2501 | nlmsg_free(msg); | |
84efbb84 | 2502 | return PTR_ERR(wdev); |
1c90f9d4 | 2503 | } |
2ec600d6 | 2504 | |
98104fde JB |
2505 | switch (type) { |
2506 | case NL80211_IFTYPE_MESH_POINT: | |
2507 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2508 | break; | |
29cbe68c JB |
2509 | wdev_lock(wdev); |
2510 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2511 | IEEE80211_MAX_MESH_ID_LEN); | |
2512 | wdev->mesh_id_up_len = | |
2513 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2514 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2515 | wdev->mesh_id_up_len); | |
2516 | wdev_unlock(wdev); | |
98104fde JB |
2517 | break; |
2518 | case NL80211_IFTYPE_P2P_DEVICE: | |
2519 | /* | |
2520 | * P2P Device doesn't have a netdev, so doesn't go | |
2521 | * through the netdev notifier and must be added here | |
2522 | */ | |
2523 | mutex_init(&wdev->mtx); | |
2524 | INIT_LIST_HEAD(&wdev->event_list); | |
2525 | spin_lock_init(&wdev->event_lock); | |
2526 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2527 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2528 | ||
2529 | mutex_lock(&rdev->devlist_mtx); | |
2530 | wdev->identifier = ++rdev->wdev_id; | |
2531 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2532 | rdev->devlist_generation++; | |
2533 | mutex_unlock(&rdev->devlist_mtx); | |
2534 | break; | |
2535 | default: | |
2536 | break; | |
29cbe68c JB |
2537 | } |
2538 | ||
15e47304 | 2539 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2540 | rdev, wdev) < 0) { |
2541 | nlmsg_free(msg); | |
2542 | return -ENOBUFS; | |
2543 | } | |
2544 | ||
2545 | return genlmsg_reply(msg, info); | |
55682965 JB |
2546 | } |
2547 | ||
2548 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2549 | { | |
4c476991 | 2550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2551 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2552 | |
4c476991 JB |
2553 | if (!rdev->ops->del_virtual_intf) |
2554 | return -EOPNOTSUPP; | |
55682965 | 2555 | |
84efbb84 JB |
2556 | /* |
2557 | * If we remove a wireless device without a netdev then clear | |
2558 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2559 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2560 | * since the wdev has been freed, unlike with a netdev where | |
2561 | * we need the dev_put() for the netdev to really be freed. | |
2562 | */ | |
2563 | if (!wdev->netdev) | |
2564 | info->user_ptr[1] = NULL; | |
2565 | ||
e35e4d28 | 2566 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2567 | } |
2568 | ||
1d9d9213 SW |
2569 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2570 | { | |
2571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2572 | struct net_device *dev = info->user_ptr[1]; | |
2573 | u16 noack_map; | |
2574 | ||
2575 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2576 | return -EINVAL; | |
2577 | ||
2578 | if (!rdev->ops->set_noack_map) | |
2579 | return -EOPNOTSUPP; | |
2580 | ||
2581 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2582 | ||
e35e4d28 | 2583 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2584 | } |
2585 | ||
41ade00f JB |
2586 | struct get_key_cookie { |
2587 | struct sk_buff *msg; | |
2588 | int error; | |
b9454e83 | 2589 | int idx; |
41ade00f JB |
2590 | }; |
2591 | ||
2592 | static void get_key_callback(void *c, struct key_params *params) | |
2593 | { | |
b9454e83 | 2594 | struct nlattr *key; |
41ade00f JB |
2595 | struct get_key_cookie *cookie = c; |
2596 | ||
9360ffd1 DM |
2597 | if ((params->key && |
2598 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2599 | params->key_len, params->key)) || | |
2600 | (params->seq && | |
2601 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2602 | params->seq_len, params->seq)) || | |
2603 | (params->cipher && | |
2604 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2605 | params->cipher))) | |
2606 | goto nla_put_failure; | |
41ade00f | 2607 | |
b9454e83 JB |
2608 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2609 | if (!key) | |
2610 | goto nla_put_failure; | |
2611 | ||
9360ffd1 DM |
2612 | if ((params->key && |
2613 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2614 | params->key_len, params->key)) || | |
2615 | (params->seq && | |
2616 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2617 | params->seq_len, params->seq)) || | |
2618 | (params->cipher && | |
2619 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2620 | params->cipher))) | |
2621 | goto nla_put_failure; | |
b9454e83 | 2622 | |
9360ffd1 DM |
2623 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2624 | goto nla_put_failure; | |
b9454e83 JB |
2625 | |
2626 | nla_nest_end(cookie->msg, key); | |
2627 | ||
41ade00f JB |
2628 | return; |
2629 | nla_put_failure: | |
2630 | cookie->error = 1; | |
2631 | } | |
2632 | ||
2633 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2634 | { | |
4c476991 | 2635 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2636 | int err; |
4c476991 | 2637 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2638 | u8 key_idx = 0; |
e31b8213 JB |
2639 | const u8 *mac_addr = NULL; |
2640 | bool pairwise; | |
41ade00f JB |
2641 | struct get_key_cookie cookie = { |
2642 | .error = 0, | |
2643 | }; | |
2644 | void *hdr; | |
2645 | struct sk_buff *msg; | |
2646 | ||
2647 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2648 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2649 | ||
3cfcf6ac | 2650 | if (key_idx > 5) |
41ade00f JB |
2651 | return -EINVAL; |
2652 | ||
2653 | if (info->attrs[NL80211_ATTR_MAC]) | |
2654 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2655 | ||
e31b8213 JB |
2656 | pairwise = !!mac_addr; |
2657 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2658 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2659 | if (kt >= NUM_NL80211_KEYTYPES) | |
2660 | return -EINVAL; | |
2661 | if (kt != NL80211_KEYTYPE_GROUP && | |
2662 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2663 | return -EINVAL; | |
2664 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2665 | } | |
2666 | ||
4c476991 JB |
2667 | if (!rdev->ops->get_key) |
2668 | return -EOPNOTSUPP; | |
41ade00f | 2669 | |
2811d3a0 JB |
2670 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
2671 | return -ENOENT; | |
2672 | ||
fd2120ca | 2673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2674 | if (!msg) |
2675 | return -ENOMEM; | |
41ade00f | 2676 | |
15e47304 | 2677 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2678 | NL80211_CMD_NEW_KEY); |
6fa3eb70 S |
2679 | if (!hdr) |
2680 | goto nla_put_failure; | |
41ade00f JB |
2681 | |
2682 | cookie.msg = msg; | |
b9454e83 | 2683 | cookie.idx = key_idx; |
41ade00f | 2684 | |
9360ffd1 DM |
2685 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2686 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2687 | goto nla_put_failure; | |
2688 | if (mac_addr && | |
2689 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2690 | goto nla_put_failure; | |
41ade00f | 2691 | |
e35e4d28 HG |
2692 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2693 | get_key_callback); | |
41ade00f JB |
2694 | |
2695 | if (err) | |
6c95e2a2 | 2696 | goto free_msg; |
41ade00f JB |
2697 | |
2698 | if (cookie.error) | |
2699 | goto nla_put_failure; | |
2700 | ||
2701 | genlmsg_end(msg, hdr); | |
4c476991 | 2702 | return genlmsg_reply(msg, info); |
41ade00f JB |
2703 | |
2704 | nla_put_failure: | |
2705 | err = -ENOBUFS; | |
6c95e2a2 | 2706 | free_msg: |
41ade00f | 2707 | nlmsg_free(msg); |
41ade00f JB |
2708 | return err; |
2709 | } | |
2710 | ||
2711 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2712 | { | |
4c476991 | 2713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2714 | struct key_parse key; |
41ade00f | 2715 | int err; |
4c476991 | 2716 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2717 | |
b9454e83 JB |
2718 | err = nl80211_parse_key(info, &key); |
2719 | if (err) | |
2720 | return err; | |
41ade00f | 2721 | |
b9454e83 | 2722 | if (key.idx < 0) |
41ade00f JB |
2723 | return -EINVAL; |
2724 | ||
b9454e83 JB |
2725 | /* only support setting default key */ |
2726 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2727 | return -EINVAL; |
2728 | ||
dbd2fd65 | 2729 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2730 | |
dbd2fd65 JB |
2731 | if (key.def) { |
2732 | if (!rdev->ops->set_default_key) { | |
2733 | err = -EOPNOTSUPP; | |
2734 | goto out; | |
2735 | } | |
41ade00f | 2736 | |
dbd2fd65 JB |
2737 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2738 | if (err) | |
2739 | goto out; | |
2740 | ||
e35e4d28 | 2741 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2742 | key.def_uni, key.def_multi); |
2743 | ||
2744 | if (err) | |
2745 | goto out; | |
fffd0934 | 2746 | |
3d23e349 | 2747 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2748 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2749 | #endif | |
2750 | } else { | |
2751 | if (key.def_uni || !key.def_multi) { | |
2752 | err = -EINVAL; | |
2753 | goto out; | |
2754 | } | |
2755 | ||
2756 | if (!rdev->ops->set_default_mgmt_key) { | |
2757 | err = -EOPNOTSUPP; | |
2758 | goto out; | |
2759 | } | |
2760 | ||
2761 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2762 | if (err) | |
2763 | goto out; | |
2764 | ||
e35e4d28 | 2765 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2766 | if (err) |
2767 | goto out; | |
2768 | ||
2769 | #ifdef CONFIG_CFG80211_WEXT | |
2770 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2771 | #endif |
dbd2fd65 JB |
2772 | } |
2773 | ||
2774 | out: | |
fffd0934 | 2775 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2776 | |
41ade00f JB |
2777 | return err; |
2778 | } | |
2779 | ||
2780 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2781 | { | |
4c476991 | 2782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2783 | int err; |
4c476991 | 2784 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2785 | struct key_parse key; |
e31b8213 | 2786 | const u8 *mac_addr = NULL; |
41ade00f | 2787 | |
b9454e83 JB |
2788 | err = nl80211_parse_key(info, &key); |
2789 | if (err) | |
2790 | return err; | |
41ade00f | 2791 | |
b9454e83 | 2792 | if (!key.p.key) |
41ade00f JB |
2793 | return -EINVAL; |
2794 | ||
41ade00f JB |
2795 | if (info->attrs[NL80211_ATTR_MAC]) |
2796 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2797 | ||
e31b8213 JB |
2798 | if (key.type == -1) { |
2799 | if (mac_addr) | |
2800 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2801 | else | |
2802 | key.type = NL80211_KEYTYPE_GROUP; | |
2803 | } | |
2804 | ||
2805 | /* for now */ | |
2806 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2807 | key.type != NL80211_KEYTYPE_GROUP) | |
2808 | return -EINVAL; | |
2809 | ||
4c476991 JB |
2810 | if (!rdev->ops->add_key) |
2811 | return -EOPNOTSUPP; | |
25e47c18 | 2812 | |
e31b8213 JB |
2813 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2814 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2815 | mac_addr)) | |
4c476991 | 2816 | return -EINVAL; |
41ade00f | 2817 | |
fffd0934 JB |
2818 | wdev_lock(dev->ieee80211_ptr); |
2819 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2820 | if (!err) | |
e35e4d28 HG |
2821 | err = rdev_add_key(rdev, dev, key.idx, |
2822 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2823 | mac_addr, &key.p); | |
fffd0934 | 2824 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2825 | |
41ade00f JB |
2826 | return err; |
2827 | } | |
2828 | ||
2829 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2830 | { | |
4c476991 | 2831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2832 | int err; |
4c476991 | 2833 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2834 | u8 *mac_addr = NULL; |
b9454e83 | 2835 | struct key_parse key; |
41ade00f | 2836 | |
b9454e83 JB |
2837 | err = nl80211_parse_key(info, &key); |
2838 | if (err) | |
2839 | return err; | |
41ade00f JB |
2840 | |
2841 | if (info->attrs[NL80211_ATTR_MAC]) | |
2842 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2843 | ||
e31b8213 JB |
2844 | if (key.type == -1) { |
2845 | if (mac_addr) | |
2846 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2847 | else | |
2848 | key.type = NL80211_KEYTYPE_GROUP; | |
2849 | } | |
2850 | ||
2851 | /* for now */ | |
2852 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2853 | key.type != NL80211_KEYTYPE_GROUP) | |
2854 | return -EINVAL; | |
2855 | ||
4c476991 JB |
2856 | if (!rdev->ops->del_key) |
2857 | return -EOPNOTSUPP; | |
41ade00f | 2858 | |
fffd0934 JB |
2859 | wdev_lock(dev->ieee80211_ptr); |
2860 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 2861 | |
2811d3a0 | 2862 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
2863 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
2864 | err = -ENOENT; | |
2865 | ||
fffd0934 | 2866 | if (!err) |
e35e4d28 HG |
2867 | err = rdev_del_key(rdev, dev, key.idx, |
2868 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2869 | mac_addr); | |
41ade00f | 2870 | |
3d23e349 | 2871 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2872 | if (!err) { |
b9454e83 | 2873 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2874 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2875 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2876 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2877 | } | |
2878 | #endif | |
fffd0934 | 2879 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2880 | |
41ade00f JB |
2881 | return err; |
2882 | } | |
2883 | ||
77765eaf VT |
2884 | /* This function returns an error or the number of nested attributes */ |
2885 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2886 | { | |
2887 | struct nlattr *attr; | |
2888 | int n_entries = 0, tmp; | |
2889 | ||
2890 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2891 | if (nla_len(attr) != ETH_ALEN) | |
2892 | return -EINVAL; | |
2893 | ||
2894 | n_entries++; | |
2895 | } | |
2896 | ||
2897 | return n_entries; | |
2898 | } | |
2899 | ||
2900 | /* | |
2901 | * This function parses ACL information and allocates memory for ACL data. | |
2902 | * On successful return, the calling function is responsible to free the | |
2903 | * ACL buffer returned by this function. | |
2904 | */ | |
2905 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2906 | struct genl_info *info) | |
2907 | { | |
2908 | enum nl80211_acl_policy acl_policy; | |
2909 | struct nlattr *attr; | |
2910 | struct cfg80211_acl_data *acl; | |
2911 | int i = 0, n_entries, tmp; | |
2912 | ||
2913 | if (!wiphy->max_acl_mac_addrs) | |
2914 | return ERR_PTR(-EOPNOTSUPP); | |
2915 | ||
2916 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2917 | return ERR_PTR(-EINVAL); | |
2918 | ||
2919 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2920 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2921 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2922 | return ERR_PTR(-EINVAL); | |
2923 | ||
2924 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2925 | return ERR_PTR(-EINVAL); | |
2926 | ||
2927 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2928 | if (n_entries < 0) | |
2929 | return ERR_PTR(n_entries); | |
2930 | ||
2931 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2932 | return ERR_PTR(-ENOTSUPP); | |
2933 | ||
2934 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2935 | GFP_KERNEL); | |
2936 | if (!acl) | |
2937 | return ERR_PTR(-ENOMEM); | |
2938 | ||
2939 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2940 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2941 | i++; | |
2942 | } | |
2943 | ||
2944 | acl->n_acl_entries = n_entries; | |
2945 | acl->acl_policy = acl_policy; | |
2946 | ||
2947 | return acl; | |
2948 | } | |
2949 | ||
2950 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2951 | { | |
2952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2953 | struct net_device *dev = info->user_ptr[1]; | |
2954 | struct cfg80211_acl_data *acl; | |
2955 | int err; | |
2956 | ||
2957 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2958 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2959 | return -EOPNOTSUPP; | |
2960 | ||
2961 | if (!dev->ieee80211_ptr->beacon_interval) | |
2962 | return -EINVAL; | |
2963 | ||
2964 | acl = parse_acl_data(&rdev->wiphy, info); | |
2965 | if (IS_ERR(acl)) | |
2966 | return PTR_ERR(acl); | |
2967 | ||
2968 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2969 | ||
2970 | kfree(acl); | |
2971 | ||
2972 | return err; | |
2973 | } | |
2974 | ||
8860020e JB |
2975 | static int nl80211_parse_beacon(struct genl_info *info, |
2976 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2977 | { |
8860020e | 2978 | bool haveinfo = false; |
ed1b6cc7 | 2979 | |
9946ecfb JM |
2980 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2981 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2982 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2983 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2984 | return -EINVAL; |
2985 | ||
8860020e | 2986 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2987 | |
ed1b6cc7 | 2988 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2989 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2990 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2991 | if (!bcn->head_len) | |
2992 | return -EINVAL; | |
2993 | haveinfo = true; | |
ed1b6cc7 JB |
2994 | } |
2995 | ||
2996 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2997 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2998 | bcn->tail_len = | |
ed1b6cc7 | 2999 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 3000 | haveinfo = true; |
ed1b6cc7 JB |
3001 | } |
3002 | ||
4c476991 JB |
3003 | if (!haveinfo) |
3004 | return -EINVAL; | |
3b85875a | 3005 | |
9946ecfb | 3006 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
3007 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
3008 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3009 | } |
3010 | ||
3011 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 3012 | bcn->proberesp_ies = |
9946ecfb | 3013 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3014 | bcn->proberesp_ies_len = |
9946ecfb JM |
3015 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
3016 | } | |
3017 | ||
3018 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 3019 | bcn->assocresp_ies = |
9946ecfb | 3020 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3021 | bcn->assocresp_ies_len = |
9946ecfb JM |
3022 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
3023 | } | |
3024 | ||
00f740e1 | 3025 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 3026 | bcn->probe_resp = |
00f740e1 | 3027 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 3028 | bcn->probe_resp_len = |
00f740e1 AN |
3029 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
3030 | } | |
3031 | ||
8860020e JB |
3032 | return 0; |
3033 | } | |
3034 | ||
46c1dd0c FF |
3035 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3036 | struct cfg80211_ap_settings *params) | |
3037 | { | |
3038 | struct wireless_dev *wdev; | |
3039 | bool ret = false; | |
3040 | ||
3041 | mutex_lock(&rdev->devlist_mtx); | |
3042 | ||
89a54e48 | 3043 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3044 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3045 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3046 | continue; | |
3047 | ||
683b6d3b | 3048 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3049 | continue; |
3050 | ||
683b6d3b | 3051 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3052 | ret = true; |
3053 | break; | |
3054 | } | |
3055 | ||
3056 | mutex_unlock(&rdev->devlist_mtx); | |
3057 | ||
3058 | return ret; | |
3059 | } | |
3060 | ||
e39e5b5e JM |
3061 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3062 | enum nl80211_auth_type auth_type, | |
3063 | enum nl80211_commands cmd) | |
3064 | { | |
3065 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3066 | return false; | |
3067 | ||
3068 | switch (cmd) { | |
3069 | case NL80211_CMD_AUTHENTICATE: | |
3070 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3071 | auth_type == NL80211_AUTHTYPE_SAE) | |
3072 | return false; | |
3073 | return true; | |
3074 | case NL80211_CMD_CONNECT: | |
3075 | case NL80211_CMD_START_AP: | |
3076 | /* SAE not supported yet */ | |
3077 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3078 | return false; | |
3079 | return true; | |
3080 | default: | |
3081 | return false; | |
3082 | } | |
3083 | } | |
3084 | ||
8860020e JB |
3085 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3086 | { | |
3087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3088 | struct net_device *dev = info->user_ptr[1]; | |
3089 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3090 | struct cfg80211_ap_settings params; | |
3091 | int err; | |
04f39047 | 3092 | u8 radar_detect_width = 0; |
8860020e JB |
3093 | |
3094 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3095 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3096 | return -EOPNOTSUPP; | |
3097 | ||
3098 | if (!rdev->ops->start_ap) | |
3099 | return -EOPNOTSUPP; | |
3100 | ||
3101 | if (wdev->beacon_interval) | |
3102 | return -EALREADY; | |
3103 | ||
3104 | memset(¶ms, 0, sizeof(params)); | |
3105 | ||
3106 | /* these are required for START_AP */ | |
3107 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3108 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3109 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3110 | return -EINVAL; | |
3111 | ||
3112 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
3113 | if (err) | |
3114 | return err; | |
3115 | ||
3116 | params.beacon_interval = | |
3117 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3118 | params.dtim_period = | |
3119 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3120 | ||
3121 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3122 | if (err) | |
3123 | return err; | |
3124 | ||
3125 | /* | |
3126 | * In theory, some of these attributes should be required here | |
3127 | * but since they were not used when the command was originally | |
3128 | * added, keep them optional for old user space programs to let | |
3129 | * them continue to work with drivers that do not need the | |
3130 | * additional information -- drivers must check! | |
3131 | */ | |
3132 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3133 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3134 | params.ssid_len = | |
3135 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3136 | if (params.ssid_len == 0 || | |
3137 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3138 | return -EINVAL; | |
3139 | } | |
3140 | ||
3141 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3142 | params.hidden_ssid = nla_get_u32( | |
3143 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3144 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3145 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3146 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3147 | return -EINVAL; | |
3148 | } | |
3149 | ||
3150 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3151 | ||
3152 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3153 | params.auth_type = nla_get_u32( | |
3154 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3155 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3156 | NL80211_CMD_START_AP)) | |
8860020e JB |
3157 | return -EINVAL; |
3158 | } else | |
3159 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3160 | ||
3161 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3162 | NL80211_MAX_NR_CIPHER_SUITES); | |
3163 | if (err) | |
3164 | return err; | |
3165 | ||
1b658f11 VT |
3166 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3167 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3168 | return -EOPNOTSUPP; | |
3169 | params.inactivity_timeout = nla_get_u16( | |
3170 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3171 | } | |
3172 | ||
53cabad7 JB |
3173 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3174 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3175 | return -EINVAL; | |
3176 | params.p2p_ctwindow = | |
3177 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3178 | if (params.p2p_ctwindow > 127) | |
3179 | return -EINVAL; | |
3180 | if (params.p2p_ctwindow != 0 && | |
3181 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3182 | return -EINVAL; | |
3183 | } | |
3184 | ||
3185 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3186 | u8 tmp; | |
3187 | ||
3188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3189 | return -EINVAL; | |
3190 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3191 | if (tmp > 1) | |
3192 | return -EINVAL; | |
3193 | params.p2p_opp_ps = tmp; | |
3194 | if (params.p2p_opp_ps != 0 && | |
3195 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3196 | return -EINVAL; | |
3197 | } | |
3198 | ||
aa430da4 | 3199 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3200 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3201 | if (err) | |
3202 | return err; | |
3203 | } else if (wdev->preset_chandef.chan) { | |
3204 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3205 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3206 | return -EINVAL; |
3207 | ||
683b6d3b | 3208 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3209 | return -EINVAL; |
3210 | ||
04f39047 SW |
3211 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3212 | if (err < 0) | |
3213 | return err; | |
3214 | if (err) { | |
3215 | radar_detect_width = BIT(params.chandef.width); | |
3216 | params.radar_required = true; | |
3217 | } | |
3218 | ||
e4e32459 | 3219 | mutex_lock(&rdev->devlist_mtx); |
04f39047 SW |
3220 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3221 | params.chandef.chan, | |
3222 | CHAN_MODE_SHARED, | |
3223 | radar_detect_width); | |
e4e32459 MK |
3224 | mutex_unlock(&rdev->devlist_mtx); |
3225 | ||
3226 | if (err) | |
3227 | return err; | |
3228 | ||
77765eaf VT |
3229 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3230 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3231 | if (IS_ERR(params.acl)) | |
3232 | return PTR_ERR(params.acl); | |
3233 | } | |
3234 | ||
e35e4d28 | 3235 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3236 | if (!err) { |
683b6d3b | 3237 | wdev->preset_chandef = params.chandef; |
8860020e | 3238 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3239 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3240 | wdev->ssid_len = params.ssid_len; |
3241 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3242 | } |
77765eaf VT |
3243 | |
3244 | kfree(params.acl); | |
3245 | ||
56d1893d | 3246 | return err; |
ed1b6cc7 JB |
3247 | } |
3248 | ||
8860020e JB |
3249 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3250 | { | |
3251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3252 | struct net_device *dev = info->user_ptr[1]; | |
3253 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3254 | struct cfg80211_beacon_data params; | |
3255 | int err; | |
3256 | ||
3257 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3258 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3259 | return -EOPNOTSUPP; | |
3260 | ||
3261 | if (!rdev->ops->change_beacon) | |
3262 | return -EOPNOTSUPP; | |
3263 | ||
3264 | if (!wdev->beacon_interval) | |
3265 | return -EINVAL; | |
3266 | ||
3267 | err = nl80211_parse_beacon(info, ¶ms); | |
3268 | if (err) | |
3269 | return err; | |
3270 | ||
e35e4d28 | 3271 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3272 | } |
3273 | ||
3274 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3275 | { |
4c476991 JB |
3276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3277 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3278 | |
60771780 | 3279 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3280 | } |
3281 | ||
5727ef1b JB |
3282 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3283 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3284 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3285 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3286 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3287 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3288 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3289 | }; |
3290 | ||
eccb8e8f | 3291 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3292 | enum nl80211_iftype iftype, |
eccb8e8f | 3293 | struct station_parameters *params) |
5727ef1b JB |
3294 | { |
3295 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3296 | struct nlattr *nla; |
5727ef1b JB |
3297 | int flag; |
3298 | ||
eccb8e8f JB |
3299 | /* |
3300 | * Try parsing the new attribute first so userspace | |
3301 | * can specify both for older kernels. | |
3302 | */ | |
3303 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3304 | if (nla) { | |
3305 | struct nl80211_sta_flag_update *sta_flags; | |
3306 | ||
3307 | sta_flags = nla_data(nla); | |
3308 | params->sta_flags_mask = sta_flags->mask; | |
3309 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3310 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3311 | if ((params->sta_flags_mask | |
3312 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3313 | return -EINVAL; | |
3314 | return 0; | |
3315 | } | |
3316 | ||
3317 | /* if present, parse the old attribute */ | |
5727ef1b | 3318 | |
eccb8e8f | 3319 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3320 | if (!nla) |
3321 | return 0; | |
3322 | ||
3323 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3324 | nla, sta_flags_policy)) | |
3325 | return -EINVAL; | |
3326 | ||
bdd3ae3d JB |
3327 | /* |
3328 | * Only allow certain flags for interface types so that | |
3329 | * other attributes are silently ignored. Remember that | |
3330 | * this is backward compatibility code with old userspace | |
3331 | * and shouldn't be hit in other cases anyway. | |
3332 | */ | |
3333 | switch (iftype) { | |
3334 | case NL80211_IFTYPE_AP: | |
3335 | case NL80211_IFTYPE_AP_VLAN: | |
3336 | case NL80211_IFTYPE_P2P_GO: | |
3337 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3338 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3339 | BIT(NL80211_STA_FLAG_WME) | | |
3340 | BIT(NL80211_STA_FLAG_MFP); | |
3341 | break; | |
3342 | case NL80211_IFTYPE_P2P_CLIENT: | |
3343 | case NL80211_IFTYPE_STATION: | |
3344 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3345 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3346 | break; | |
3347 | case NL80211_IFTYPE_MESH_POINT: | |
3348 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3349 | BIT(NL80211_STA_FLAG_MFP) | | |
3350 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3351 | default: | |
3352 | return -EINVAL; | |
3353 | } | |
5727ef1b | 3354 | |
3383b5a6 JB |
3355 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3356 | if (flags[flag]) { | |
eccb8e8f | 3357 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3358 | |
3383b5a6 JB |
3359 | /* no longer support new API additions in old API */ |
3360 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3361 | return -EINVAL; | |
3362 | } | |
3363 | } | |
3364 | ||
5727ef1b JB |
3365 | return 0; |
3366 | } | |
3367 | ||
c8dcfd8a FF |
3368 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3369 | int attr) | |
3370 | { | |
3371 | struct nlattr *rate; | |
8eb41c8d VK |
3372 | u32 bitrate; |
3373 | u16 bitrate_compat; | |
c8dcfd8a FF |
3374 | |
3375 | rate = nla_nest_start(msg, attr); | |
3376 | if (!rate) | |
db9c64cf | 3377 | return false; |
c8dcfd8a FF |
3378 | |
3379 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3380 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3381 | /* report 16-bit bitrate only if we can */ |
3382 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3383 | if (bitrate > 0 && |
3384 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3385 | return false; | |
3386 | if (bitrate_compat > 0 && | |
3387 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3388 | return false; | |
3389 | ||
3390 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3391 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3392 | return false; | |
3393 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3394 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3395 | return false; | |
3396 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3397 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3398 | return false; | |
3399 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3400 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3401 | return false; | |
3402 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3403 | return false; | |
3404 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3405 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3406 | return false; | |
3407 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3408 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3409 | return false; | |
3410 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3411 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3412 | return false; | |
3413 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3414 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3415 | return false; | |
3416 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3417 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3418 | return false; | |
3419 | } | |
c8dcfd8a FF |
3420 | |
3421 | nla_nest_end(msg, rate); | |
3422 | return true; | |
c8dcfd8a FF |
3423 | } |
3424 | ||
15e47304 | 3425 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3426 | int flags, |
3427 | struct cfg80211_registered_device *rdev, | |
3428 | struct net_device *dev, | |
98b62183 | 3429 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3430 | { |
3431 | void *hdr; | |
f4263c98 | 3432 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3433 | |
15e47304 | 3434 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3435 | if (!hdr) |
3436 | return -1; | |
3437 | ||
9360ffd1 DM |
3438 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3439 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3440 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3441 | goto nla_put_failure; | |
f5ea9120 | 3442 | |
2ec600d6 LCC |
3443 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3444 | if (!sinfoattr) | |
fd5b74dc | 3445 | goto nla_put_failure; |
9360ffd1 DM |
3446 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3447 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3448 | sinfo->connected_time)) | |
3449 | goto nla_put_failure; | |
3450 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3451 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3452 | sinfo->inactive_time)) | |
3453 | goto nla_put_failure; | |
42745e03 VK |
3454 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3455 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3456 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3457 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3458 | goto nla_put_failure; |
42745e03 | 3459 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3460 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3461 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3462 | (u32)sinfo->tx_bytes)) |
3463 | goto nla_put_failure; | |
3464 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3465 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3466 | sinfo->rx_bytes)) | |
3467 | goto nla_put_failure; | |
3468 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3469 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3470 | sinfo->tx_bytes)) |
3471 | goto nla_put_failure; | |
3472 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3473 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3474 | goto nla_put_failure; | |
3475 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3476 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3477 | goto nla_put_failure; | |
3478 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3479 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3480 | sinfo->plink_state)) | |
3481 | goto nla_put_failure; | |
66266b3a JL |
3482 | switch (rdev->wiphy.signal_type) { |
3483 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3484 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3485 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3486 | sinfo->signal)) | |
3487 | goto nla_put_failure; | |
3488 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3489 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3490 | sinfo->signal_avg)) | |
3491 | goto nla_put_failure; | |
66266b3a JL |
3492 | break; |
3493 | default: | |
3494 | break; | |
3495 | } | |
420e7fab | 3496 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3497 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3498 | NL80211_STA_INFO_TX_BITRATE)) | |
3499 | goto nla_put_failure; | |
3500 | } | |
3501 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3502 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3503 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3504 | goto nla_put_failure; |
420e7fab | 3505 | } |
9360ffd1 DM |
3506 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3507 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3508 | sinfo->rx_packets)) | |
3509 | goto nla_put_failure; | |
3510 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3511 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3512 | sinfo->tx_packets)) | |
3513 | goto nla_put_failure; | |
3514 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3515 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3516 | sinfo->tx_retries)) | |
3517 | goto nla_put_failure; | |
3518 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3519 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3520 | sinfo->tx_failed)) | |
3521 | goto nla_put_failure; | |
3522 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3523 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3524 | sinfo->beacon_loss_count)) | |
3525 | goto nla_put_failure; | |
3b1c5a53 MP |
3526 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3527 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3528 | sinfo->local_pm)) | |
3529 | goto nla_put_failure; | |
3530 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3531 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3532 | sinfo->peer_pm)) | |
3533 | goto nla_put_failure; | |
3534 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3535 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3536 | sinfo->nonpeer_pm)) | |
3537 | goto nla_put_failure; | |
f4263c98 PS |
3538 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3539 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3540 | if (!bss_param) | |
3541 | goto nla_put_failure; | |
3542 | ||
9360ffd1 DM |
3543 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3544 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3545 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3546 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3547 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3548 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3549 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3550 | sinfo->bss_param.dtim_period) || | |
3551 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3552 | sinfo->bss_param.beacon_interval)) | |
3553 | goto nla_put_failure; | |
f4263c98 PS |
3554 | |
3555 | nla_nest_end(msg, bss_param); | |
3556 | } | |
9360ffd1 DM |
3557 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3558 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3559 | sizeof(struct nl80211_sta_flag_update), | |
3560 | &sinfo->sta_flags)) | |
3561 | goto nla_put_failure; | |
7eab0f64 JL |
3562 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3563 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3564 | sinfo->t_offset)) | |
3565 | goto nla_put_failure; | |
2ec600d6 | 3566 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3567 | |
9360ffd1 DM |
3568 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3569 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3570 | sinfo->assoc_req_ies)) | |
3571 | goto nla_put_failure; | |
50d3dfb7 | 3572 | |
fd5b74dc JB |
3573 | return genlmsg_end(msg, hdr); |
3574 | ||
3575 | nla_put_failure: | |
bc3ed28c TG |
3576 | genlmsg_cancel(msg, hdr); |
3577 | return -EMSGSIZE; | |
fd5b74dc JB |
3578 | } |
3579 | ||
2ec600d6 | 3580 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3581 | struct netlink_callback *cb) |
2ec600d6 | 3582 | { |
2ec600d6 LCC |
3583 | struct station_info sinfo; |
3584 | struct cfg80211_registered_device *dev; | |
97990a06 | 3585 | struct wireless_dev *wdev; |
2ec600d6 | 3586 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3587 | int sta_idx = cb->args[2]; |
2ec600d6 | 3588 | int err; |
2ec600d6 | 3589 | |
97990a06 | 3590 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3591 | if (err) |
3592 | return err; | |
bba95fef | 3593 | |
97990a06 JB |
3594 | if (!wdev->netdev) { |
3595 | err = -EINVAL; | |
3596 | goto out_err; | |
3597 | } | |
3598 | ||
bba95fef | 3599 | if (!dev->ops->dump_station) { |
eec60b03 | 3600 | err = -EOPNOTSUPP; |
bba95fef JB |
3601 | goto out_err; |
3602 | } | |
3603 | ||
bba95fef | 3604 | while (1) { |
f612cedf | 3605 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3606 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3607 | mac_addr, &sinfo); |
bba95fef JB |
3608 | if (err == -ENOENT) |
3609 | break; | |
3610 | if (err) | |
3b85875a | 3611 | goto out_err; |
bba95fef JB |
3612 | |
3613 | if (nl80211_send_station(skb, | |
15e47304 | 3614 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3615 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3616 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3617 | &sinfo) < 0) |
3618 | goto out; | |
3619 | ||
3620 | sta_idx++; | |
3621 | } | |
3622 | ||
3623 | ||
3624 | out: | |
97990a06 | 3625 | cb->args[2] = sta_idx; |
bba95fef | 3626 | err = skb->len; |
bba95fef | 3627 | out_err: |
97990a06 | 3628 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3629 | |
3630 | return err; | |
2ec600d6 | 3631 | } |
fd5b74dc | 3632 | |
5727ef1b JB |
3633 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3634 | { | |
4c476991 JB |
3635 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3636 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3637 | struct station_info sinfo; |
fd5b74dc JB |
3638 | struct sk_buff *msg; |
3639 | u8 *mac_addr = NULL; | |
4c476991 | 3640 | int err; |
fd5b74dc | 3641 | |
2ec600d6 | 3642 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3643 | |
3644 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3645 | return -EINVAL; | |
3646 | ||
3647 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3648 | ||
4c476991 JB |
3649 | if (!rdev->ops->get_station) |
3650 | return -EOPNOTSUPP; | |
3b85875a | 3651 | |
e35e4d28 | 3652 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3653 | if (err) |
4c476991 | 3654 | return err; |
2ec600d6 | 3655 | |
fd2120ca | 3656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3657 | if (!msg) |
4c476991 | 3658 | return -ENOMEM; |
fd5b74dc | 3659 | |
15e47304 | 3660 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3661 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3662 | nlmsg_free(msg); |
3663 | return -ENOBUFS; | |
3664 | } | |
3b85875a | 3665 | |
4c476991 | 3666 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3667 | } |
3668 | ||
77ee7c89 JB |
3669 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3670 | struct station_parameters *params, | |
3671 | enum cfg80211_station_type statype) | |
3672 | { | |
3673 | if (params->listen_interval != -1) | |
3674 | return -EINVAL; | |
3675 | if (params->aid) | |
3676 | return -EINVAL; | |
3677 | ||
3678 | /* When you run into this, adjust the code below for the new flag */ | |
3679 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3680 | ||
3681 | switch (statype) { | |
eef941e6 TP |
3682 | case CFG80211_STA_MESH_PEER_KERNEL: |
3683 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3684 | /* |
3685 | * No ignoring the TDLS flag here -- the userspace mesh | |
3686 | * code doesn't have the bug of including TDLS in the | |
3687 | * mask everywhere. | |
3688 | */ | |
3689 | if (params->sta_flags_mask & | |
3690 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3691 | BIT(NL80211_STA_FLAG_MFP) | | |
3692 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3693 | return -EINVAL; | |
3694 | break; | |
3695 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3696 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3697 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3698 | return -EINVAL; | |
3699 | /* ignore since it can't change */ | |
3700 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3701 | break; | |
3702 | default: | |
3703 | /* disallow mesh-specific things */ | |
3704 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3705 | return -EINVAL; | |
3706 | if (params->local_pm) | |
3707 | return -EINVAL; | |
3708 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3709 | return -EINVAL; | |
3710 | } | |
3711 | ||
3712 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3713 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3714 | /* TDLS can't be set, ... */ | |
3715 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3716 | return -EINVAL; | |
3717 | /* | |
3718 | * ... but don't bother the driver with it. This works around | |
3719 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3720 | * TLDS_PEER flag in the mask even for AP mode. | |
3721 | */ | |
3722 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3723 | } | |
3724 | ||
3725 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3726 | /* reject other things that can't change */ | |
3727 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3728 | return -EINVAL; | |
3729 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3730 | return -EINVAL; | |
3731 | if (params->supported_rates) | |
3732 | return -EINVAL; | |
3733 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3734 | return -EINVAL; | |
3735 | } | |
3736 | ||
3737 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3738 | if (params->vlan) | |
3739 | return -EINVAL; | |
3740 | } | |
3741 | ||
3742 | switch (statype) { | |
3743 | case CFG80211_STA_AP_MLME_CLIENT: | |
3744 | /* Use this only for authorizing/unauthorizing a station */ | |
3745 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3746 | return -EOPNOTSUPP; | |
3747 | break; | |
3748 | case CFG80211_STA_AP_CLIENT: | |
3749 | /* accept only the listed bits */ | |
3750 | if (params->sta_flags_mask & | |
3751 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3752 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3753 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3754 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3755 | BIT(NL80211_STA_FLAG_WME) | | |
3756 | BIT(NL80211_STA_FLAG_MFP))) | |
3757 | return -EINVAL; | |
3758 | ||
3759 | /* but authenticated/associated only if driver handles it */ | |
3760 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3761 | params->sta_flags_mask & | |
3762 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3763 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3764 | return -EINVAL; | |
3765 | break; | |
3766 | case CFG80211_STA_IBSS: | |
3767 | case CFG80211_STA_AP_STA: | |
3768 | /* reject any changes other than AUTHORIZED */ | |
3769 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3770 | return -EINVAL; | |
3771 | break; | |
3772 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3773 | /* reject any changes other than AUTHORIZED or WME */ | |
3774 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3775 | BIT(NL80211_STA_FLAG_WME))) | |
3776 | return -EINVAL; | |
3777 | /* force (at least) rates when authorizing */ | |
3778 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3779 | !params->supported_rates) | |
3780 | return -EINVAL; | |
3781 | break; | |
3782 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3783 | /* reject any changes */ | |
3784 | return -EINVAL; | |
eef941e6 | 3785 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3786 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3787 | return -EINVAL; | |
3788 | break; | |
eef941e6 | 3789 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3790 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3791 | return -EINVAL; | |
3792 | break; | |
3793 | } | |
3794 | ||
3795 | return 0; | |
3796 | } | |
3797 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3798 | ||
5727ef1b | 3799 | /* |
c258d2de | 3800 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3801 | */ |
80b99899 JB |
3802 | static struct net_device *get_vlan(struct genl_info *info, |
3803 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3804 | { |
463d0183 | 3805 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3806 | struct net_device *v; |
3807 | int ret; | |
3808 | ||
3809 | if (!vlanattr) | |
3810 | return NULL; | |
3811 | ||
3812 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3813 | if (!v) | |
3814 | return ERR_PTR(-ENODEV); | |
3815 | ||
3816 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3817 | ret = -EINVAL; | |
3818 | goto error; | |
5727ef1b | 3819 | } |
80b99899 | 3820 | |
77ee7c89 JB |
3821 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3822 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3823 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3824 | ret = -EINVAL; | |
3825 | goto error; | |
3826 | } | |
3827 | ||
80b99899 JB |
3828 | if (!netif_running(v)) { |
3829 | ret = -ENETDOWN; | |
3830 | goto error; | |
3831 | } | |
3832 | ||
3833 | return v; | |
3834 | error: | |
3835 | dev_put(v); | |
3836 | return ERR_PTR(ret); | |
5727ef1b JB |
3837 | } |
3838 | ||
df881293 JM |
3839 | static struct nla_policy |
3840 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3841 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3842 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3843 | }; | |
3844 | ||
ff276691 JB |
3845 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3846 | struct station_parameters *params) | |
df881293 | 3847 | { |
df881293 JM |
3848 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3849 | struct nlattr *nla; | |
3850 | int err; | |
3851 | ||
df881293 JM |
3852 | /* parse WME attributes if present */ |
3853 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3854 | return 0; | |
3855 | ||
3856 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3857 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3858 | nl80211_sta_wme_policy); | |
3859 | if (err) | |
3860 | return err; | |
3861 | ||
3862 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3863 | params->uapsd_queues = nla_get_u8( | |
3864 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3865 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3866 | return -EINVAL; | |
3867 | ||
3868 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3869 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3870 | ||
3871 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3872 | return -EINVAL; | |
3873 | ||
3874 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3875 | ||
3876 | return 0; | |
3877 | } | |
3878 | ||
ff276691 JB |
3879 | static int nl80211_set_station_tdls(struct genl_info *info, |
3880 | struct station_parameters *params) | |
3881 | { | |
3882 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
3883 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | |
3884 | params->ht_capa = | |
3885 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3886 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3887 | params->vht_capa = | |
3888 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3889 | ||
3890 | return nl80211_parse_sta_wme(info, params); | |
3891 | } | |
3892 | ||
5727ef1b JB |
3893 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3894 | { | |
4c476991 | 3895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3896 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3897 | struct station_parameters params; |
77ee7c89 JB |
3898 | u8 *mac_addr; |
3899 | int err; | |
5727ef1b JB |
3900 | |
3901 | memset(¶ms, 0, sizeof(params)); | |
3902 | ||
3903 | params.listen_interval = -1; | |
3904 | ||
77ee7c89 JB |
3905 | if (!rdev->ops->change_station) |
3906 | return -EOPNOTSUPP; | |
3907 | ||
5727ef1b JB |
3908 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3909 | return -EINVAL; | |
3910 | ||
3911 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3912 | return -EINVAL; | |
3913 | ||
3914 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3915 | ||
3916 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3917 | params.supported_rates = | |
3918 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3919 | params.supported_rates_len = | |
3920 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3921 | } | |
3922 | ||
9d62a986 JM |
3923 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3924 | params.capability = | |
3925 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3926 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3927 | } | |
3928 | ||
3929 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3930 | params.ext_capab = | |
3931 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3932 | params.ext_capab_len = | |
3933 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3934 | } | |
3935 | ||
df881293 | 3936 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3937 | return -EINVAL; |
36aedc90 | 3938 | |
bdd3ae3d | 3939 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3940 | return -EINVAL; |
3941 | ||
f8bacc21 | 3942 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3943 | params.plink_action = |
f8bacc21 JB |
3944 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3945 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3946 | return -EINVAL; | |
3947 | } | |
2ec600d6 | 3948 | |
f8bacc21 | 3949 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3950 | params.plink_state = |
f8bacc21 JB |
3951 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3952 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3953 | return -EINVAL; | |
3954 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3955 | } | |
9c3990aa | 3956 | |
3b1c5a53 MP |
3957 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3958 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3959 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3960 | ||
3961 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3962 | pm > NL80211_MESH_POWER_MAX) | |
3963 | return -EINVAL; | |
3964 | ||
3965 | params.local_pm = pm; | |
3966 | } | |
3967 | ||
77ee7c89 JB |
3968 | /* Include parameters for TDLS peer (will check later) */ |
3969 | err = nl80211_set_station_tdls(info, ¶ms); | |
3970 | if (err) | |
3971 | return err; | |
3972 | ||
3973 | params.vlan = get_vlan(info, rdev); | |
3974 | if (IS_ERR(params.vlan)) | |
3975 | return PTR_ERR(params.vlan); | |
3976 | ||
a97f4424 JB |
3977 | switch (dev->ieee80211_ptr->iftype) { |
3978 | case NL80211_IFTYPE_AP: | |
3979 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3980 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3981 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3982 | case NL80211_IFTYPE_STATION: |
267335d6 | 3983 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3984 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3985 | break; |
3986 | default: | |
77ee7c89 JB |
3987 | err = -EOPNOTSUPP; |
3988 | goto out_put_vlan; | |
034d655e JB |
3989 | } |
3990 | ||
77ee7c89 | 3991 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 3992 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3993 | |
77ee7c89 | 3994 | out_put_vlan: |
5727ef1b JB |
3995 | if (params.vlan) |
3996 | dev_put(params.vlan); | |
3b85875a | 3997 | |
5727ef1b JB |
3998 | return err; |
3999 | } | |
4000 | ||
4001 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4002 | { | |
4c476991 | 4003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4004 | int err; |
4c476991 | 4005 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4006 | struct station_parameters params; |
4007 | u8 *mac_addr = NULL; | |
4008 | ||
4009 | memset(¶ms, 0, sizeof(params)); | |
4010 | ||
984c311b JB |
4011 | if (!rdev->ops->add_station) |
4012 | return -EOPNOTSUPP; | |
4013 | ||
5727ef1b JB |
4014 | if (!info->attrs[NL80211_ATTR_MAC]) |
4015 | return -EINVAL; | |
4016 | ||
5727ef1b JB |
4017 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4018 | return -EINVAL; | |
4019 | ||
4020 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4021 | return -EINVAL; | |
4022 | ||
0e956c13 TLSC |
4023 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
4024 | return -EINVAL; | |
4025 | ||
5727ef1b JB |
4026 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4027 | params.supported_rates = | |
4028 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4029 | params.supported_rates_len = | |
4030 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4031 | params.listen_interval = | |
4032 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4033 | |
0e956c13 TLSC |
4034 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
4035 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
4036 | return -EINVAL; | |
51b50fbe | 4037 | |
9d62a986 JM |
4038 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4039 | params.capability = | |
4040 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4041 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4042 | } | |
4043 | ||
4044 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4045 | params.ext_capab = | |
4046 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4047 | params.ext_capab_len = | |
4048 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4049 | } | |
4050 | ||
36aedc90 JM |
4051 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4052 | params.ht_capa = | |
4053 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4054 | |
f461be3e MP |
4055 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4056 | params.vht_capa = | |
4057 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4058 | ||
f8bacc21 | 4059 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4060 | params.plink_action = |
f8bacc21 JB |
4061 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4062 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4063 | return -EINVAL; | |
4064 | } | |
96b78dff | 4065 | |
ff276691 JB |
4066 | err = nl80211_parse_sta_wme(info, ¶ms); |
4067 | if (err) | |
4068 | return err; | |
bdd90d5e | 4069 | |
bdd3ae3d | 4070 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4071 | return -EINVAL; |
4072 | ||
9de9cea3 JB |
4073 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
4074 | * as userspace might just pass through the capabilities from the IEs | |
4075 | * directly, rather than enforcing this restriction and returning an | |
4076 | * error in this case. | |
4077 | */ | |
4078 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
4079 | params.ht_capa = NULL; | |
4080 | params.vht_capa = NULL; | |
4081 | } | |
4082 | ||
77ee7c89 JB |
4083 | /* When you run into this, adjust the code below for the new flag */ |
4084 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4085 | ||
bdd90d5e JB |
4086 | switch (dev->ieee80211_ptr->iftype) { |
4087 | case NL80211_IFTYPE_AP: | |
4088 | case NL80211_IFTYPE_AP_VLAN: | |
4089 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4090 | /* ignore WME attributes if iface/sta is not capable */ |
4091 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4092 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4093 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4094 | |
bdd90d5e JB |
4095 | /* TDLS peers cannot be added */ |
4096 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 4097 | return -EINVAL; |
bdd90d5e JB |
4098 | /* but don't bother the driver with it */ |
4099 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4100 | |
d582cffb JB |
4101 | /* allow authenticated/associated only if driver handles it */ |
4102 | if (!(rdev->wiphy.features & | |
4103 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4104 | params.sta_flags_mask & | |
4105 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4106 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4107 | return -EINVAL; | |
4108 | ||
bdd90d5e JB |
4109 | /* must be last in here for error handling */ |
4110 | params.vlan = get_vlan(info, rdev); | |
4111 | if (IS_ERR(params.vlan)) | |
4112 | return PTR_ERR(params.vlan); | |
4113 | break; | |
4114 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4115 | /* ignore uAPSD data */ |
4116 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4117 | ||
d582cffb JB |
4118 | /* associated is disallowed */ |
4119 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4120 | return -EINVAL; | |
bdd90d5e JB |
4121 | /* TDLS peers cannot be added */ |
4122 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4123 | return -EINVAL; | |
4124 | break; | |
4125 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4126 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4127 | /* ignore uAPSD data */ |
4128 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4129 | ||
77ee7c89 JB |
4130 | /* these are disallowed */ |
4131 | if (params.sta_flags_mask & | |
4132 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4133 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4134 | return -EINVAL; |
bdd90d5e JB |
4135 | /* Only TDLS peers can be added */ |
4136 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4137 | return -EINVAL; | |
4138 | /* Can only add if TDLS ... */ | |
4139 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4140 | return -EOPNOTSUPP; | |
4141 | /* ... with external setup is supported */ | |
4142 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4143 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4144 | /* |
4145 | * Older wpa_supplicant versions always mark the TDLS peer | |
4146 | * as authorized, but it shouldn't yet be. | |
4147 | */ | |
4148 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4149 | break; |
4150 | default: | |
4151 | return -EOPNOTSUPP; | |
c75786c9 EP |
4152 | } |
4153 | ||
bdd90d5e | 4154 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4155 | |
e35e4d28 | 4156 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4157 | |
5727ef1b JB |
4158 | if (params.vlan) |
4159 | dev_put(params.vlan); | |
5727ef1b JB |
4160 | return err; |
4161 | } | |
4162 | ||
4163 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4164 | { | |
4c476991 JB |
4165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4166 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4167 | u8 *mac_addr = NULL; |
4168 | ||
4169 | if (info->attrs[NL80211_ATTR_MAC]) | |
4170 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4171 | ||
e80cf853 | 4172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4174 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4175 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4176 | return -EINVAL; | |
5727ef1b | 4177 | |
4c476991 JB |
4178 | if (!rdev->ops->del_station) |
4179 | return -EOPNOTSUPP; | |
3b85875a | 4180 | |
e35e4d28 | 4181 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4182 | } |
4183 | ||
15e47304 | 4184 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4185 | int flags, struct net_device *dev, |
4186 | u8 *dst, u8 *next_hop, | |
4187 | struct mpath_info *pinfo) | |
4188 | { | |
4189 | void *hdr; | |
4190 | struct nlattr *pinfoattr; | |
4191 | ||
15e47304 | 4192 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4193 | if (!hdr) |
4194 | return -1; | |
4195 | ||
9360ffd1 DM |
4196 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4197 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4198 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4199 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4200 | goto nla_put_failure; | |
f5ea9120 | 4201 | |
2ec600d6 LCC |
4202 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4203 | if (!pinfoattr) | |
4204 | goto nla_put_failure; | |
9360ffd1 DM |
4205 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4206 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4207 | pinfo->frame_qlen)) | |
4208 | goto nla_put_failure; | |
4209 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4210 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4211 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4212 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4213 | pinfo->metric)) || | |
4214 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4215 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4216 | pinfo->exptime)) || | |
4217 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4218 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4219 | pinfo->flags)) || | |
4220 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4221 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4222 | pinfo->discovery_timeout)) || | |
4223 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4224 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4225 | pinfo->discovery_retries))) | |
4226 | goto nla_put_failure; | |
2ec600d6 LCC |
4227 | |
4228 | nla_nest_end(msg, pinfoattr); | |
4229 | ||
4230 | return genlmsg_end(msg, hdr); | |
4231 | ||
4232 | nla_put_failure: | |
bc3ed28c TG |
4233 | genlmsg_cancel(msg, hdr); |
4234 | return -EMSGSIZE; | |
2ec600d6 LCC |
4235 | } |
4236 | ||
4237 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4238 | struct netlink_callback *cb) |
2ec600d6 | 4239 | { |
2ec600d6 LCC |
4240 | struct mpath_info pinfo; |
4241 | struct cfg80211_registered_device *dev; | |
97990a06 | 4242 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4243 | u8 dst[ETH_ALEN]; |
4244 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4245 | int path_idx = cb->args[2]; |
2ec600d6 | 4246 | int err; |
2ec600d6 | 4247 | |
97990a06 | 4248 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4249 | if (err) |
4250 | return err; | |
bba95fef JB |
4251 | |
4252 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4253 | err = -EOPNOTSUPP; |
bba95fef JB |
4254 | goto out_err; |
4255 | } | |
4256 | ||
97990a06 | 4257 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4258 | err = -EOPNOTSUPP; |
0448b5fc | 4259 | goto out_err; |
eec60b03 JM |
4260 | } |
4261 | ||
bba95fef | 4262 | while (1) { |
97990a06 JB |
4263 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4264 | next_hop, &pinfo); | |
bba95fef | 4265 | if (err == -ENOENT) |
2ec600d6 | 4266 | break; |
bba95fef | 4267 | if (err) |
3b85875a | 4268 | goto out_err; |
2ec600d6 | 4269 | |
15e47304 | 4270 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4271 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4272 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4273 | &pinfo) < 0) |
4274 | goto out; | |
2ec600d6 | 4275 | |
bba95fef | 4276 | path_idx++; |
2ec600d6 | 4277 | } |
2ec600d6 | 4278 | |
2ec600d6 | 4279 | |
bba95fef | 4280 | out: |
97990a06 | 4281 | cb->args[2] = path_idx; |
bba95fef | 4282 | err = skb->len; |
bba95fef | 4283 | out_err: |
97990a06 | 4284 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4285 | return err; |
2ec600d6 LCC |
4286 | } |
4287 | ||
4288 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4289 | { | |
4c476991 | 4290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4291 | int err; |
4c476991 | 4292 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4293 | struct mpath_info pinfo; |
4294 | struct sk_buff *msg; | |
4295 | u8 *dst = NULL; | |
4296 | u8 next_hop[ETH_ALEN]; | |
4297 | ||
4298 | memset(&pinfo, 0, sizeof(pinfo)); | |
4299 | ||
4300 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4301 | return -EINVAL; | |
4302 | ||
4303 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4304 | ||
4c476991 JB |
4305 | if (!rdev->ops->get_mpath) |
4306 | return -EOPNOTSUPP; | |
2ec600d6 | 4307 | |
4c476991 JB |
4308 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4309 | return -EOPNOTSUPP; | |
eec60b03 | 4310 | |
e35e4d28 | 4311 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4312 | if (err) |
4c476991 | 4313 | return err; |
2ec600d6 | 4314 | |
fd2120ca | 4315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4316 | if (!msg) |
4c476991 | 4317 | return -ENOMEM; |
2ec600d6 | 4318 | |
15e47304 | 4319 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4320 | dev, dst, next_hop, &pinfo) < 0) { |
4321 | nlmsg_free(msg); | |
4322 | return -ENOBUFS; | |
4323 | } | |
3b85875a | 4324 | |
4c476991 | 4325 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4326 | } |
4327 | ||
4328 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4329 | { | |
4c476991 JB |
4330 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4331 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4332 | u8 *dst = NULL; |
4333 | u8 *next_hop = NULL; | |
4334 | ||
4335 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4336 | return -EINVAL; | |
4337 | ||
4338 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4339 | return -EINVAL; | |
4340 | ||
4341 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4342 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4343 | ||
4c476991 JB |
4344 | if (!rdev->ops->change_mpath) |
4345 | return -EOPNOTSUPP; | |
35a8efe1 | 4346 | |
4c476991 JB |
4347 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4348 | return -EOPNOTSUPP; | |
2ec600d6 | 4349 | |
e35e4d28 | 4350 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4351 | } |
4c476991 | 4352 | |
2ec600d6 LCC |
4353 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4354 | { | |
4c476991 JB |
4355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4356 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4357 | u8 *dst = NULL; |
4358 | u8 *next_hop = NULL; | |
4359 | ||
4360 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4361 | return -EINVAL; | |
4362 | ||
4363 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4364 | return -EINVAL; | |
4365 | ||
4366 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4367 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4368 | ||
4c476991 JB |
4369 | if (!rdev->ops->add_mpath) |
4370 | return -EOPNOTSUPP; | |
35a8efe1 | 4371 | |
4c476991 JB |
4372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4373 | return -EOPNOTSUPP; | |
2ec600d6 | 4374 | |
e35e4d28 | 4375 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4376 | } |
4377 | ||
4378 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4379 | { | |
4c476991 JB |
4380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4381 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4382 | u8 *dst = NULL; |
4383 | ||
4384 | if (info->attrs[NL80211_ATTR_MAC]) | |
4385 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4386 | ||
4c476991 JB |
4387 | if (!rdev->ops->del_mpath) |
4388 | return -EOPNOTSUPP; | |
3b85875a | 4389 | |
e35e4d28 | 4390 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4391 | } |
4392 | ||
9f1ba906 JM |
4393 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4394 | { | |
4c476991 JB |
4395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4396 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4397 | struct bss_parameters params; |
4398 | ||
4399 | memset(¶ms, 0, sizeof(params)); | |
4400 | /* default to not changing parameters */ | |
4401 | params.use_cts_prot = -1; | |
4402 | params.use_short_preamble = -1; | |
4403 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4404 | params.ap_isolate = -1; |
50b12f59 | 4405 | params.ht_opmode = -1; |
53cabad7 JB |
4406 | params.p2p_ctwindow = -1; |
4407 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4408 | |
4409 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4410 | params.use_cts_prot = | |
4411 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4412 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4413 | params.use_short_preamble = | |
4414 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4415 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4416 | params.use_short_slot_time = | |
4417 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4418 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4419 | params.basic_rates = | |
4420 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4421 | params.basic_rates_len = | |
4422 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4423 | } | |
fd8aaaf3 FF |
4424 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4425 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4426 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4427 | params.ht_opmode = | |
4428 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4429 | |
53cabad7 JB |
4430 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4431 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4432 | return -EINVAL; | |
4433 | params.p2p_ctwindow = | |
4434 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4435 | if (params.p2p_ctwindow < 0) | |
4436 | return -EINVAL; | |
4437 | if (params.p2p_ctwindow != 0 && | |
4438 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4439 | return -EINVAL; | |
4440 | } | |
4441 | ||
4442 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4443 | u8 tmp; | |
4444 | ||
4445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4446 | return -EINVAL; | |
4447 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4448 | if (tmp > 1) | |
4449 | return -EINVAL; | |
4450 | params.p2p_opp_ps = tmp; | |
4451 | if (params.p2p_opp_ps && | |
4452 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4453 | return -EINVAL; | |
4454 | } | |
4455 | ||
4c476991 JB |
4456 | if (!rdev->ops->change_bss) |
4457 | return -EOPNOTSUPP; | |
9f1ba906 | 4458 | |
074ac8df | 4459 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4460 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4461 | return -EOPNOTSUPP; | |
3b85875a | 4462 | |
e35e4d28 | 4463 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4464 | } |
4465 | ||
b54452b0 | 4466 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4467 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4468 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4469 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4470 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4471 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4472 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4473 | }; | |
4474 | ||
4475 | static int parse_reg_rule(struct nlattr *tb[], | |
4476 | struct ieee80211_reg_rule *reg_rule) | |
4477 | { | |
4478 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4479 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4480 | ||
4481 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4482 | return -EINVAL; | |
4483 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4484 | return -EINVAL; | |
4485 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4486 | return -EINVAL; | |
4487 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4488 | return -EINVAL; | |
4489 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4490 | return -EINVAL; | |
4491 | ||
4492 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4493 | ||
4494 | freq_range->start_freq_khz = | |
4495 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4496 | freq_range->end_freq_khz = | |
4497 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4498 | freq_range->max_bandwidth_khz = | |
4499 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4500 | ||
4501 | power_rule->max_eirp = | |
4502 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4503 | ||
4504 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4505 | power_rule->max_antenna_gain = | |
4506 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4507 | ||
4508 | return 0; | |
4509 | } | |
4510 | ||
4511 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4512 | { | |
4513 | int r; | |
4514 | char *data = NULL; | |
57b5ce07 | 4515 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4516 | |
80778f18 LR |
4517 | /* |
4518 | * You should only get this when cfg80211 hasn't yet initialized | |
4519 | * completely when built-in to the kernel right between the time | |
4520 | * window between nl80211_init() and regulatory_init(), if that is | |
4521 | * even possible. | |
4522 | */ | |
458f4f9e | 4523 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4524 | return -EINPROGRESS; |
80778f18 | 4525 | |
fe33eb39 LR |
4526 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4527 | return -EINVAL; | |
b2e1b302 LR |
4528 | |
4529 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4530 | ||
57b5ce07 LR |
4531 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4532 | user_reg_hint_type = | |
4533 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4534 | else | |
4535 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4536 | ||
4537 | switch (user_reg_hint_type) { | |
4538 | case NL80211_USER_REG_HINT_USER: | |
4539 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4540 | break; | |
4541 | default: | |
4542 | return -EINVAL; | |
4543 | } | |
4544 | ||
4545 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4546 | |
b2e1b302 LR |
4547 | return r; |
4548 | } | |
4549 | ||
24bdd9f4 | 4550 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4551 | struct genl_info *info) |
93da9cc1 | 4552 | { |
4c476991 | 4553 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4554 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4555 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4556 | struct mesh_config cur_params; | |
4557 | int err = 0; | |
93da9cc1 | 4558 | void *hdr; |
4559 | struct nlattr *pinfoattr; | |
4560 | struct sk_buff *msg; | |
4561 | ||
29cbe68c JB |
4562 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4563 | return -EOPNOTSUPP; | |
4564 | ||
24bdd9f4 | 4565 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4566 | return -EOPNOTSUPP; |
f3f92586 | 4567 | |
29cbe68c JB |
4568 | wdev_lock(wdev); |
4569 | /* If not connected, get default parameters */ | |
4570 | if (!wdev->mesh_id_len) | |
4571 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4572 | else | |
e35e4d28 | 4573 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4574 | wdev_unlock(wdev); |
4575 | ||
93da9cc1 | 4576 | if (err) |
4c476991 | 4577 | return err; |
93da9cc1 | 4578 | |
4579 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4581 | if (!msg) |
4582 | return -ENOMEM; | |
15e47304 | 4583 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4584 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4585 | if (!hdr) |
efe1cf0c | 4586 | goto out; |
24bdd9f4 | 4587 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4588 | if (!pinfoattr) |
4589 | goto nla_put_failure; | |
9360ffd1 DM |
4590 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4591 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4592 | cur_params.dot11MeshRetryTimeout) || | |
4593 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4594 | cur_params.dot11MeshConfirmTimeout) || | |
4595 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4596 | cur_params.dot11MeshHoldingTimeout) || | |
4597 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4598 | cur_params.dot11MeshMaxPeerLinks) || | |
4599 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4600 | cur_params.dot11MeshMaxRetries) || | |
4601 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4602 | cur_params.dot11MeshTTL) || | |
4603 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4604 | cur_params.element_ttl) || | |
4605 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4606 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4607 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4608 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4609 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4610 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4611 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4612 | cur_params.path_refresh_time) || | |
4613 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4614 | cur_params.min_discovery_timeout) || | |
4615 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4616 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4617 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4618 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4619 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4620 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4621 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4622 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4623 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4624 | cur_params.dot11MeshHWMPRootMode) || | |
4625 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4626 | cur_params.dot11MeshHWMPRannInterval) || | |
4627 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4628 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4629 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4630 | cur_params.dot11MeshForwarding) || | |
4631 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4632 | cur_params.rssi_threshold) || |
4633 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4634 | cur_params.ht_opmode) || |
4635 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4636 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4637 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4638 | cur_params.dot11MeshHWMProotInterval) || |
4639 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4640 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4641 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4642 | cur_params.power_mode) || | |
4643 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
4644 | cur_params.dot11MeshAwakeWindowDuration)) | |
9360ffd1 | 4645 | goto nla_put_failure; |
93da9cc1 | 4646 | nla_nest_end(msg, pinfoattr); |
4647 | genlmsg_end(msg, hdr); | |
4c476991 | 4648 | return genlmsg_reply(msg, info); |
93da9cc1 | 4649 | |
3b85875a | 4650 | nla_put_failure: |
93da9cc1 | 4651 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4652 | out: |
d080e275 | 4653 | nlmsg_free(msg); |
4c476991 | 4654 | return -ENOBUFS; |
93da9cc1 | 4655 | } |
4656 | ||
b54452b0 | 4657 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4658 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4659 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4660 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4661 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4662 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4663 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4664 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4665 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4666 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4667 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4668 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4669 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4670 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4671 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4672 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4673 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4674 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4675 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4676 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4677 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4678 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4679 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4680 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4681 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4682 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4683 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4684 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
93da9cc1 | 4685 | }; |
4686 | ||
c80d545d JC |
4687 | static const struct nla_policy |
4688 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4689 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4690 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4691 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4692 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
bb2798d4 | 4693 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4694 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4695 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4696 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4697 | }; |
4698 | ||
24bdd9f4 | 4699 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4700 | struct mesh_config *cfg, |
4701 | u32 *mask_out) | |
93da9cc1 | 4702 | { |
93da9cc1 | 4703 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4704 | u32 mask = 0; |
93da9cc1 | 4705 | |
ea54fba2 MP |
4706 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4707 | do { \ | |
4708 | if (tb[attr]) { \ | |
4709 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4710 | return -EINVAL; \ | |
4711 | cfg->param = fn(tb[attr]); \ | |
4712 | mask |= (1 << (attr - 1)); \ | |
4713 | } \ | |
4714 | } while (0) | |
bd90fdcc JB |
4715 | |
4716 | ||
24bdd9f4 | 4717 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4718 | return -EINVAL; |
4719 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4720 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4721 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4722 | return -EINVAL; |
4723 | ||
93da9cc1 | 4724 | /* This makes sure that there aren't more than 32 mesh config |
4725 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4726 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4727 | ||
4728 | /* Fill in the params struct */ | |
ea54fba2 | 4729 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4730 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4731 | nla_get_u16); | |
ea54fba2 | 4732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4733 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4734 | nla_get_u16); | |
ea54fba2 | 4735 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4736 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4737 | nla_get_u16); | |
ea54fba2 | 4738 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4739 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4740 | nla_get_u16); | |
ea54fba2 | 4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4742 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4743 | nla_get_u8); | |
ea54fba2 | 4744 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4745 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4747 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4748 | nla_get_u8); | |
ea54fba2 | 4749 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4750 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4751 | nla_get_u8); | |
ea54fba2 MP |
4752 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4753 | 1, 255, mask, | |
a4f606ea CYY |
4754 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4755 | nla_get_u32); | |
ea54fba2 | 4756 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4757 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4758 | nla_get_u8); | |
ea54fba2 | 4759 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4760 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4761 | nla_get_u32); | |
ea54fba2 | 4762 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4763 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4764 | nla_get_u16); | |
ea54fba2 MP |
4765 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4766 | 1, 65535, mask, | |
a4f606ea CYY |
4767 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4768 | nla_get_u32); | |
93da9cc1 | 4769 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4770 | 1, 65535, mask, |
4771 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4772 | nla_get_u16); |
dca7e943 | 4773 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4774 | 1, 65535, mask, |
4775 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4776 | nla_get_u16); |
93da9cc1 | 4777 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4778 | dot11MeshHWMPnetDiameterTraversalTime, |
4779 | 1, 65535, mask, | |
a4f606ea CYY |
4780 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4781 | nla_get_u16); | |
ea54fba2 MP |
4782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4783 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4784 | nla_get_u8); | |
4785 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4786 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4787 | nla_get_u16); |
63c5723b | 4788 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4789 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4790 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4791 | nla_get_u8); |
ea54fba2 | 4792 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4793 | mask, NL80211_MESHCONF_FORWARDING, |
4794 | nla_get_u8); | |
ea54fba2 | 4795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4796 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4797 | nla_get_u32); | |
ea54fba2 | 4798 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4799 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4800 | nla_get_u16); |
4801 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4802 | 1, 65535, mask, |
ac1073a6 CYY |
4803 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4804 | nla_get_u32); | |
ea54fba2 | 4805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4806 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4807 | nla_get_u16); |
4808 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4809 | dot11MeshHWMPconfirmationInterval, |
4810 | 1, 65535, mask, | |
728b19e5 | 4811 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4812 | nla_get_u16); |
3b1c5a53 MP |
4813 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4814 | NL80211_MESH_POWER_ACTIVE, | |
4815 | NL80211_MESH_POWER_MAX, | |
4816 | mask, NL80211_MESHCONF_POWER_MODE, | |
4817 | nla_get_u32); | |
4818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4819 | 0, 65535, mask, | |
4820 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
bd90fdcc JB |
4821 | if (mask_out) |
4822 | *mask_out = mask; | |
c80d545d | 4823 | |
bd90fdcc JB |
4824 | return 0; |
4825 | ||
4826 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4827 | } | |
4828 | ||
c80d545d JC |
4829 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4830 | struct mesh_setup *setup) | |
4831 | { | |
bb2798d4 | 4832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4833 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4834 | ||
4835 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4836 | return -EINVAL; | |
4837 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4838 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4839 | nl80211_mesh_setup_params_policy)) | |
4840 | return -EINVAL; | |
4841 | ||
d299a1f2 JC |
4842 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4843 | setup->sync_method = | |
4844 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4845 | IEEE80211_SYNC_METHOD_VENDOR : | |
4846 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4847 | ||
c80d545d JC |
4848 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4849 | setup->path_sel_proto = | |
4850 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4851 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4852 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4853 | ||
4854 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4855 | setup->path_metric = | |
4856 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4857 | IEEE80211_PATH_METRIC_VENDOR : | |
4858 | IEEE80211_PATH_METRIC_AIRTIME; | |
4859 | ||
581a8b0f JC |
4860 | |
4861 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4862 | struct nlattr *ieattr = |
581a8b0f | 4863 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4864 | if (!is_valid_ie_attr(ieattr)) |
4865 | return -EINVAL; | |
581a8b0f JC |
4866 | setup->ie = nla_data(ieattr); |
4867 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4868 | } |
bb2798d4 TP |
4869 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4870 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4871 | return -EINVAL; | |
4872 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4873 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4874 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4875 | if (setup->is_secure) |
4876 | setup->user_mpm = true; | |
c80d545d JC |
4877 | |
4878 | return 0; | |
4879 | } | |
4880 | ||
24bdd9f4 | 4881 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4882 | struct genl_info *info) |
bd90fdcc JB |
4883 | { |
4884 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4885 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4886 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4887 | struct mesh_config cfg; |
4888 | u32 mask; | |
4889 | int err; | |
4890 | ||
29cbe68c JB |
4891 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4892 | return -EOPNOTSUPP; | |
4893 | ||
24bdd9f4 | 4894 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4895 | return -EOPNOTSUPP; |
4896 | ||
24bdd9f4 | 4897 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4898 | if (err) |
4899 | return err; | |
4900 | ||
29cbe68c JB |
4901 | wdev_lock(wdev); |
4902 | if (!wdev->mesh_id_len) | |
4903 | err = -ENOLINK; | |
4904 | ||
4905 | if (!err) | |
e35e4d28 | 4906 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4907 | |
4908 | wdev_unlock(wdev); | |
4909 | ||
4910 | return err; | |
93da9cc1 | 4911 | } |
4912 | ||
f130347c LR |
4913 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4914 | { | |
458f4f9e | 4915 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4916 | struct sk_buff *msg; |
4917 | void *hdr = NULL; | |
4918 | struct nlattr *nl_reg_rules; | |
4919 | unsigned int i; | |
4920 | int err = -EINVAL; | |
4921 | ||
a1794390 | 4922 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
4923 | |
4924 | if (!cfg80211_regdomain) | |
4925 | goto out; | |
4926 | ||
fd2120ca | 4927 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
4928 | if (!msg) { |
4929 | err = -ENOBUFS; | |
4930 | goto out; | |
4931 | } | |
4932 | ||
15e47304 | 4933 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4934 | NL80211_CMD_GET_REG); |
4935 | if (!hdr) | |
efe1cf0c | 4936 | goto put_failure; |
f130347c | 4937 | |
57b5ce07 LR |
4938 | if (reg_last_request_cell_base() && |
4939 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4940 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4941 | goto nla_put_failure; | |
4942 | ||
458f4f9e JB |
4943 | rcu_read_lock(); |
4944 | regdom = rcu_dereference(cfg80211_regdomain); | |
4945 | ||
4946 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4947 | (regdom->dfs_region && | |
4948 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4949 | goto nla_put_failure_rcu; | |
4950 | ||
f130347c LR |
4951 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4952 | if (!nl_reg_rules) | |
458f4f9e | 4953 | goto nla_put_failure_rcu; |
f130347c | 4954 | |
458f4f9e | 4955 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4956 | struct nlattr *nl_reg_rule; |
4957 | const struct ieee80211_reg_rule *reg_rule; | |
4958 | const struct ieee80211_freq_range *freq_range; | |
4959 | const struct ieee80211_power_rule *power_rule; | |
4960 | ||
458f4f9e | 4961 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4962 | freq_range = ®_rule->freq_range; |
4963 | power_rule = ®_rule->power_rule; | |
4964 | ||
4965 | nl_reg_rule = nla_nest_start(msg, i); | |
4966 | if (!nl_reg_rule) | |
458f4f9e | 4967 | goto nla_put_failure_rcu; |
f130347c | 4968 | |
9360ffd1 DM |
4969 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4970 | reg_rule->flags) || | |
4971 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4972 | freq_range->start_freq_khz) || | |
4973 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4974 | freq_range->end_freq_khz) || | |
4975 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4976 | freq_range->max_bandwidth_khz) || | |
4977 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4978 | power_rule->max_antenna_gain) || | |
4979 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4980 | power_rule->max_eirp)) | |
458f4f9e | 4981 | goto nla_put_failure_rcu; |
f130347c LR |
4982 | |
4983 | nla_nest_end(msg, nl_reg_rule); | |
4984 | } | |
458f4f9e | 4985 | rcu_read_unlock(); |
f130347c LR |
4986 | |
4987 | nla_nest_end(msg, nl_reg_rules); | |
4988 | ||
4989 | genlmsg_end(msg, hdr); | |
134e6375 | 4990 | err = genlmsg_reply(msg, info); |
f130347c LR |
4991 | goto out; |
4992 | ||
458f4f9e JB |
4993 | nla_put_failure_rcu: |
4994 | rcu_read_unlock(); | |
f130347c LR |
4995 | nla_put_failure: |
4996 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4997 | put_failure: |
d080e275 | 4998 | nlmsg_free(msg); |
f130347c LR |
4999 | err = -EMSGSIZE; |
5000 | out: | |
a1794390 | 5001 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
5002 | return err; |
5003 | } | |
5004 | ||
b2e1b302 LR |
5005 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5006 | { | |
5007 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5008 | struct nlattr *nl_reg_rule; | |
5009 | char *alpha2 = NULL; | |
5010 | int rem_reg_rules = 0, r = 0; | |
5011 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 5012 | u8 dfs_region = 0; |
b2e1b302 LR |
5013 | struct ieee80211_regdomain *rd = NULL; |
5014 | ||
5015 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5016 | return -EINVAL; | |
5017 | ||
5018 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5019 | return -EINVAL; | |
5020 | ||
5021 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5022 | ||
8b60b078 LR |
5023 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5024 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5025 | ||
b2e1b302 | 5026 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5027 | rem_reg_rules) { |
b2e1b302 LR |
5028 | num_rules++; |
5029 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5030 | return -EINVAL; |
b2e1b302 LR |
5031 | } |
5032 | ||
b2e1b302 | 5033 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5034 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5035 | |
5036 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5037 | if (!rd) |
5038 | return -ENOMEM; | |
b2e1b302 LR |
5039 | |
5040 | rd->n_reg_rules = num_rules; | |
5041 | rd->alpha2[0] = alpha2[0]; | |
5042 | rd->alpha2[1] = alpha2[1]; | |
5043 | ||
8b60b078 LR |
5044 | /* |
5045 | * Disable DFS master mode if the DFS region was | |
5046 | * not supported or known on this kernel. | |
5047 | */ | |
5048 | if (reg_supported_dfs_region(dfs_region)) | |
5049 | rd->dfs_region = dfs_region; | |
5050 | ||
b2e1b302 | 5051 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5052 | rem_reg_rules) { |
b2e1b302 | 5053 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
5054 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
5055 | reg_rule_policy); | |
b2e1b302 LR |
5056 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5057 | if (r) | |
5058 | goto bad_reg; | |
5059 | ||
5060 | rule_idx++; | |
5061 | ||
d0e18f83 LR |
5062 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5063 | r = -EINVAL; | |
b2e1b302 | 5064 | goto bad_reg; |
d0e18f83 | 5065 | } |
b2e1b302 LR |
5066 | } |
5067 | ||
6913b49a JB |
5068 | mutex_lock(&cfg80211_mutex); |
5069 | ||
b2e1b302 | 5070 | r = set_regdom(rd); |
6913b49a | 5071 | /* set_regdom took ownership */ |
1a919318 | 5072 | rd = NULL; |
6913b49a | 5073 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 5074 | |
d2372b31 | 5075 | bad_reg: |
b2e1b302 | 5076 | kfree(rd); |
d0e18f83 | 5077 | return r; |
b2e1b302 LR |
5078 | } |
5079 | ||
83f5e2cf JB |
5080 | static int validate_scan_freqs(struct nlattr *freqs) |
5081 | { | |
5082 | struct nlattr *attr1, *attr2; | |
5083 | int n_channels = 0, tmp1, tmp2; | |
5084 | ||
d4740818 SD |
5085 | nla_for_each_nested(attr1, freqs, tmp1) |
5086 | if (nla_len(attr1) != sizeof(u32)) | |
5087 | return 0; | |
5088 | ||
83f5e2cf JB |
5089 | nla_for_each_nested(attr1, freqs, tmp1) { |
5090 | n_channels++; | |
5091 | /* | |
5092 | * Some hardware has a limited channel list for | |
5093 | * scanning, and it is pretty much nonsensical | |
5094 | * to scan for a channel twice, so disallow that | |
5095 | * and don't require drivers to check that the | |
5096 | * channel list they get isn't longer than what | |
5097 | * they can scan, as long as they can scan all | |
5098 | * the channels they registered at once. | |
5099 | */ | |
5100 | nla_for_each_nested(attr2, freqs, tmp2) | |
5101 | if (attr1 != attr2 && | |
5102 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5103 | return 0; | |
5104 | } | |
5105 | ||
5106 | return n_channels; | |
5107 | } | |
5108 | ||
2a519311 JB |
5109 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5110 | { | |
4c476991 | 5111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5112 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5113 | struct cfg80211_scan_request *request; |
2a519311 JB |
5114 | struct nlattr *attr; |
5115 | struct wiphy *wiphy; | |
83f5e2cf | 5116 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5117 | size_t ie_len; |
2a519311 | 5118 | |
f4a11bb0 JB |
5119 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5120 | return -EINVAL; | |
5121 | ||
79c97e97 | 5122 | wiphy = &rdev->wiphy; |
2a519311 | 5123 | |
4c476991 JB |
5124 | if (!rdev->ops->scan) |
5125 | return -EOPNOTSUPP; | |
2a519311 | 5126 | |
f9f47529 JB |
5127 | mutex_lock(&rdev->sched_scan_mtx); |
5128 | if (rdev->scan_req) { | |
5129 | err = -EBUSY; | |
5130 | goto unlock; | |
5131 | } | |
2a519311 JB |
5132 | |
5133 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5134 | n_channels = validate_scan_freqs( |
5135 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5136 | if (!n_channels) { |
5137 | err = -EINVAL; | |
5138 | goto unlock; | |
5139 | } | |
2a519311 | 5140 | } else { |
34850ab2 | 5141 | enum ieee80211_band band; |
83f5e2cf JB |
5142 | n_channels = 0; |
5143 | ||
2a519311 JB |
5144 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5145 | if (wiphy->bands[band]) | |
5146 | n_channels += wiphy->bands[band]->n_channels; | |
5147 | } | |
5148 | ||
5149 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5150 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5151 | n_ssids++; | |
5152 | ||
f9f47529 JB |
5153 | if (n_ssids > wiphy->max_scan_ssids) { |
5154 | err = -EINVAL; | |
5155 | goto unlock; | |
5156 | } | |
2a519311 | 5157 | |
70692ad2 JM |
5158 | if (info->attrs[NL80211_ATTR_IE]) |
5159 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5160 | else | |
5161 | ie_len = 0; | |
5162 | ||
f9f47529 JB |
5163 | if (ie_len > wiphy->max_scan_ie_len) { |
5164 | err = -EINVAL; | |
5165 | goto unlock; | |
5166 | } | |
18a83659 | 5167 | |
2a519311 | 5168 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5169 | + sizeof(*request->ssids) * n_ssids |
5170 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5171 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5172 | if (!request) { |
5173 | err = -ENOMEM; | |
5174 | goto unlock; | |
5175 | } | |
2a519311 | 5176 | |
2a519311 | 5177 | if (n_ssids) |
5ba63533 | 5178 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5179 | request->n_ssids = n_ssids; |
70692ad2 JM |
5180 | if (ie_len) { |
5181 | if (request->ssids) | |
5182 | request->ie = (void *)(request->ssids + n_ssids); | |
5183 | else | |
5184 | request->ie = (void *)(request->channels + n_channels); | |
5185 | } | |
2a519311 | 5186 | |
584991dc | 5187 | i = 0; |
2a519311 JB |
5188 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5189 | /* user specified, bail out if channel not found */ | |
2a519311 | 5190 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5191 | struct ieee80211_channel *chan; |
5192 | ||
5193 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5194 | ||
5195 | if (!chan) { | |
2a519311 JB |
5196 | err = -EINVAL; |
5197 | goto out_free; | |
5198 | } | |
584991dc JB |
5199 | |
5200 | /* ignore disabled channels */ | |
5201 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5202 | continue; | |
5203 | ||
5204 | request->channels[i] = chan; | |
2a519311 JB |
5205 | i++; |
5206 | } | |
5207 | } else { | |
34850ab2 JB |
5208 | enum ieee80211_band band; |
5209 | ||
2a519311 | 5210 | /* all channels */ |
2a519311 JB |
5211 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5212 | int j; | |
5213 | if (!wiphy->bands[band]) | |
5214 | continue; | |
5215 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5216 | struct ieee80211_channel *chan; |
5217 | ||
5218 | chan = &wiphy->bands[band]->channels[j]; | |
5219 | ||
5220 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5221 | continue; | |
5222 | ||
5223 | request->channels[i] = chan; | |
2a519311 JB |
5224 | i++; |
5225 | } | |
5226 | } | |
5227 | } | |
5228 | ||
584991dc JB |
5229 | if (!i) { |
5230 | err = -EINVAL; | |
5231 | goto out_free; | |
5232 | } | |
5233 | ||
5234 | request->n_channels = i; | |
5235 | ||
2a519311 JB |
5236 | i = 0; |
5237 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5238 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5239 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5240 | err = -EINVAL; |
5241 | goto out_free; | |
5242 | } | |
57a27e1d | 5243 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5244 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5245 | i++; |
5246 | } | |
5247 | } | |
5248 | ||
70692ad2 JM |
5249 | if (info->attrs[NL80211_ATTR_IE]) { |
5250 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5251 | memcpy((void *)request->ie, |
5252 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5253 | request->ie_len); |
5254 | } | |
5255 | ||
34850ab2 | 5256 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5257 | if (wiphy->bands[i]) |
5258 | request->rates[i] = | |
5259 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5260 | |
5261 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5262 | nla_for_each_nested(attr, | |
5263 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5264 | tmp) { | |
5265 | enum ieee80211_band band = nla_type(attr); | |
5266 | ||
84404623 | 5267 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5268 | err = -EINVAL; |
5269 | goto out_free; | |
5270 | } | |
5271 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5272 | nla_data(attr), | |
5273 | nla_len(attr), | |
5274 | &request->rates[band]); | |
5275 | if (err) | |
5276 | goto out_free; | |
5277 | } | |
5278 | } | |
5279 | ||
46856bbf | 5280 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5281 | request->flags = nla_get_u32( |
5282 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5283 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5284 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5285 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5286 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5287 | err = -EOPNOTSUPP; |
5288 | goto out_free; | |
5289 | } | |
5290 | } | |
ed473771 | 5291 | |
e9f935e3 RM |
5292 | request->no_cck = |
5293 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5294 | ||
fd014284 | 5295 | request->wdev = wdev; |
79c97e97 | 5296 | request->wiphy = &rdev->wiphy; |
15d6030b | 5297 | request->scan_start = jiffies; |
2a519311 | 5298 | |
79c97e97 | 5299 | rdev->scan_req = request; |
e35e4d28 | 5300 | err = rdev_scan(rdev, request); |
2a519311 | 5301 | |
463d0183 | 5302 | if (!err) { |
fd014284 JB |
5303 | nl80211_send_scan_start(rdev, wdev); |
5304 | if (wdev->netdev) | |
5305 | dev_hold(wdev->netdev); | |
4c476991 | 5306 | } else { |
2a519311 | 5307 | out_free: |
79c97e97 | 5308 | rdev->scan_req = NULL; |
2a519311 JB |
5309 | kfree(request); |
5310 | } | |
3b85875a | 5311 | |
f9f47529 JB |
5312 | unlock: |
5313 | mutex_unlock(&rdev->sched_scan_mtx); | |
2a519311 JB |
5314 | return err; |
5315 | } | |
5316 | ||
807f8a8c LC |
5317 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5318 | struct genl_info *info) | |
5319 | { | |
5320 | struct cfg80211_sched_scan_request *request; | |
5321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5322 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5323 | struct nlattr *attr; |
5324 | struct wiphy *wiphy; | |
a1f1c21c | 5325 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5326 | u32 interval; |
807f8a8c LC |
5327 | enum ieee80211_band band; |
5328 | size_t ie_len; | |
a1f1c21c | 5329 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5330 | |
5331 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5332 | !rdev->ops->sched_scan_start) | |
5333 | return -EOPNOTSUPP; | |
5334 | ||
5335 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5336 | return -EINVAL; | |
5337 | ||
bbe6ad6d LC |
5338 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5339 | return -EINVAL; | |
5340 | ||
5341 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5342 | if (interval == 0) | |
5343 | return -EINVAL; | |
5344 | ||
807f8a8c LC |
5345 | wiphy = &rdev->wiphy; |
5346 | ||
5347 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5348 | n_channels = validate_scan_freqs( | |
5349 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5350 | if (!n_channels) | |
5351 | return -EINVAL; | |
5352 | } else { | |
5353 | n_channels = 0; | |
5354 | ||
5355 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5356 | if (wiphy->bands[band]) | |
5357 | n_channels += wiphy->bands[band]->n_channels; | |
5358 | } | |
5359 | ||
5360 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5361 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5362 | tmp) | |
5363 | n_ssids++; | |
5364 | ||
93b6aa69 | 5365 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5366 | return -EINVAL; |
5367 | ||
a1f1c21c LC |
5368 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5369 | nla_for_each_nested(attr, | |
5370 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5371 | tmp) | |
5372 | n_match_sets++; | |
5373 | ||
5374 | if (n_match_sets > wiphy->max_match_sets) | |
5375 | return -EINVAL; | |
5376 | ||
807f8a8c LC |
5377 | if (info->attrs[NL80211_ATTR_IE]) |
5378 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5379 | else | |
5380 | ie_len = 0; | |
5381 | ||
5a865bad | 5382 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5383 | return -EINVAL; |
5384 | ||
c10841ca LC |
5385 | mutex_lock(&rdev->sched_scan_mtx); |
5386 | ||
5387 | if (rdev->sched_scan_req) { | |
5388 | err = -EINPROGRESS; | |
5389 | goto out; | |
5390 | } | |
5391 | ||
807f8a8c | 5392 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5393 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5394 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5395 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5396 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5397 | if (!request) { |
5398 | err = -ENOMEM; | |
5399 | goto out; | |
5400 | } | |
807f8a8c LC |
5401 | |
5402 | if (n_ssids) | |
5403 | request->ssids = (void *)&request->channels[n_channels]; | |
5404 | request->n_ssids = n_ssids; | |
5405 | if (ie_len) { | |
5406 | if (request->ssids) | |
5407 | request->ie = (void *)(request->ssids + n_ssids); | |
5408 | else | |
5409 | request->ie = (void *)(request->channels + n_channels); | |
5410 | } | |
5411 | ||
a1f1c21c LC |
5412 | if (n_match_sets) { |
5413 | if (request->ie) | |
5414 | request->match_sets = (void *)(request->ie + ie_len); | |
5415 | else if (request->ssids) | |
5416 | request->match_sets = | |
5417 | (void *)(request->ssids + n_ssids); | |
5418 | else | |
5419 | request->match_sets = | |
5420 | (void *)(request->channels + n_channels); | |
5421 | } | |
5422 | request->n_match_sets = n_match_sets; | |
5423 | ||
807f8a8c LC |
5424 | i = 0; |
5425 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5426 | /* user specified, bail out if channel not found */ | |
5427 | nla_for_each_nested(attr, | |
5428 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5429 | tmp) { | |
5430 | struct ieee80211_channel *chan; | |
5431 | ||
5432 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5433 | ||
5434 | if (!chan) { | |
5435 | err = -EINVAL; | |
5436 | goto out_free; | |
5437 | } | |
5438 | ||
5439 | /* ignore disabled channels */ | |
5440 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5441 | continue; | |
5442 | ||
5443 | request->channels[i] = chan; | |
5444 | i++; | |
5445 | } | |
5446 | } else { | |
5447 | /* all channels */ | |
5448 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5449 | int j; | |
5450 | if (!wiphy->bands[band]) | |
5451 | continue; | |
5452 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5453 | struct ieee80211_channel *chan; | |
5454 | ||
5455 | chan = &wiphy->bands[band]->channels[j]; | |
5456 | ||
5457 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5458 | continue; | |
5459 | ||
5460 | request->channels[i] = chan; | |
5461 | i++; | |
5462 | } | |
5463 | } | |
5464 | } | |
5465 | ||
5466 | if (!i) { | |
5467 | err = -EINVAL; | |
5468 | goto out_free; | |
5469 | } | |
5470 | ||
5471 | request->n_channels = i; | |
5472 | ||
5473 | i = 0; | |
5474 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5475 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5476 | tmp) { | |
57a27e1d | 5477 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5478 | err = -EINVAL; |
5479 | goto out_free; | |
5480 | } | |
57a27e1d | 5481 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5482 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5483 | nla_len(attr)); | |
807f8a8c LC |
5484 | i++; |
5485 | } | |
5486 | } | |
5487 | ||
a1f1c21c LC |
5488 | i = 0; |
5489 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5490 | nla_for_each_nested(attr, | |
5491 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5492 | tmp) { | |
88e920b4 | 5493 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5494 | |
5495 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5496 | nla_data(attr), nla_len(attr), | |
5497 | nl80211_match_policy); | |
4a4ab0d7 | 5498 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5499 | if (ssid) { |
5500 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5501 | err = -EINVAL; | |
5502 | goto out_free; | |
5503 | } | |
5504 | memcpy(request->match_sets[i].ssid.ssid, | |
5505 | nla_data(ssid), nla_len(ssid)); | |
5506 | request->match_sets[i].ssid.ssid_len = | |
5507 | nla_len(ssid); | |
5508 | } | |
88e920b4 TP |
5509 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5510 | if (rssi) | |
5511 | request->rssi_thold = nla_get_u32(rssi); | |
5512 | else | |
5513 | request->rssi_thold = | |
5514 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5515 | i++; |
5516 | } | |
5517 | } | |
5518 | ||
807f8a8c LC |
5519 | if (info->attrs[NL80211_ATTR_IE]) { |
5520 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5521 | memcpy((void *)request->ie, | |
5522 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5523 | request->ie_len); | |
5524 | } | |
5525 | ||
46856bbf | 5526 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5527 | request->flags = nla_get_u32( |
5528 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5529 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5530 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5531 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5532 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5533 | err = -EOPNOTSUPP; |
5534 | goto out_free; | |
5535 | } | |
5536 | } | |
ed473771 | 5537 | |
807f8a8c LC |
5538 | request->dev = dev; |
5539 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5540 | request->interval = interval; |
15d6030b | 5541 | request->scan_start = jiffies; |
807f8a8c | 5542 | |
e35e4d28 | 5543 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5544 | if (!err) { |
5545 | rdev->sched_scan_req = request; | |
5546 | nl80211_send_sched_scan(rdev, dev, | |
5547 | NL80211_CMD_START_SCHED_SCAN); | |
5548 | goto out; | |
5549 | } | |
5550 | ||
5551 | out_free: | |
5552 | kfree(request); | |
5553 | out: | |
c10841ca | 5554 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
5555 | return err; |
5556 | } | |
5557 | ||
5558 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5559 | struct genl_info *info) | |
5560 | { | |
5561 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 5562 | int err; |
807f8a8c LC |
5563 | |
5564 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5565 | !rdev->ops->sched_scan_stop) | |
5566 | return -EOPNOTSUPP; | |
5567 | ||
c10841ca LC |
5568 | mutex_lock(&rdev->sched_scan_mtx); |
5569 | err = __cfg80211_stop_sched_scan(rdev, false); | |
5570 | mutex_unlock(&rdev->sched_scan_mtx); | |
5571 | ||
5572 | return err; | |
807f8a8c LC |
5573 | } |
5574 | ||
04f39047 SW |
5575 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5576 | struct genl_info *info) | |
5577 | { | |
5578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5579 | struct net_device *dev = info->user_ptr[1]; | |
5580 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5581 | struct cfg80211_chan_def chandef; | |
5582 | int err; | |
5583 | ||
5584 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5585 | if (err) | |
5586 | return err; | |
5587 | ||
5588 | if (wdev->cac_started) | |
5589 | return -EBUSY; | |
5590 | ||
5591 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5592 | if (err < 0) | |
5593 | return err; | |
5594 | ||
5595 | if (err == 0) | |
5596 | return -EINVAL; | |
5597 | ||
5598 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5599 | return -EINVAL; | |
5600 | ||
5601 | if (!rdev->ops->start_radar_detection) | |
5602 | return -EOPNOTSUPP; | |
5603 | ||
5604 | mutex_lock(&rdev->devlist_mtx); | |
5605 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5606 | chandef.chan, CHAN_MODE_SHARED, | |
5607 | BIT(chandef.width)); | |
5608 | if (err) | |
5609 | goto err_locked; | |
5610 | ||
5611 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5612 | if (!err) { | |
5613 | wdev->channel = chandef.chan; | |
5614 | wdev->cac_started = true; | |
5615 | wdev->cac_start_time = jiffies; | |
5616 | } | |
5617 | err_locked: | |
5618 | mutex_unlock(&rdev->devlist_mtx); | |
5619 | ||
5620 | return err; | |
5621 | } | |
5622 | ||
9720bb3a JB |
5623 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5624 | u32 seq, int flags, | |
2a519311 | 5625 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5626 | struct wireless_dev *wdev, |
5627 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5628 | { |
48ab905d | 5629 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5630 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5631 | void *hdr; |
5632 | struct nlattr *bss; | |
8cef2c9d | 5633 | bool tsf = false; |
48ab905d JB |
5634 | |
5635 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5636 | |
15e47304 | 5637 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5638 | NL80211_CMD_NEW_SCAN_RESULTS); |
5639 | if (!hdr) | |
5640 | return -1; | |
5641 | ||
9720bb3a JB |
5642 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5643 | ||
97990a06 JB |
5644 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5645 | goto nla_put_failure; | |
5646 | if (wdev->netdev && | |
9360ffd1 DM |
5647 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5648 | goto nla_put_failure; | |
97990a06 JB |
5649 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5650 | goto nla_put_failure; | |
2a519311 JB |
5651 | |
5652 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5653 | if (!bss) | |
5654 | goto nla_put_failure; | |
9360ffd1 | 5655 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5656 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5657 | goto nla_put_failure; |
9caf0364 JB |
5658 | |
5659 | rcu_read_lock(); | |
5660 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5661 | if (ies) { |
5662 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5663 | goto fail_unlock_rcu; | |
5664 | tsf = true; | |
5665 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5666 | ies->len, ies->data)) | |
5667 | goto fail_unlock_rcu; | |
9caf0364 JB |
5668 | } |
5669 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5670 | if (ies) { |
5671 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5672 | goto fail_unlock_rcu; | |
5673 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5674 | ies->len, ies->data)) | |
5675 | goto fail_unlock_rcu; | |
9caf0364 JB |
5676 | } |
5677 | rcu_read_unlock(); | |
5678 | ||
9360ffd1 DM |
5679 | if (res->beacon_interval && |
5680 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5681 | goto nla_put_failure; | |
5682 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5683 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5684 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5685 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5686 | goto nla_put_failure; | |
2a519311 | 5687 | |
77965c97 | 5688 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5689 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5690 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5691 | goto nla_put_failure; | |
2a519311 JB |
5692 | break; |
5693 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5694 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5695 | goto nla_put_failure; | |
2a519311 JB |
5696 | break; |
5697 | default: | |
5698 | break; | |
5699 | } | |
5700 | ||
48ab905d | 5701 | switch (wdev->iftype) { |
074ac8df | 5702 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5703 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5704 | if (intbss == wdev->current_bss && |
5705 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5706 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5707 | goto nla_put_failure; | |
48ab905d JB |
5708 | break; |
5709 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5710 | if (intbss == wdev->current_bss && |
5711 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5712 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5713 | goto nla_put_failure; | |
48ab905d JB |
5714 | break; |
5715 | default: | |
5716 | break; | |
5717 | } | |
5718 | ||
2a519311 JB |
5719 | nla_nest_end(msg, bss); |
5720 | ||
5721 | return genlmsg_end(msg, hdr); | |
5722 | ||
8cef2c9d JB |
5723 | fail_unlock_rcu: |
5724 | rcu_read_unlock(); | |
2a519311 JB |
5725 | nla_put_failure: |
5726 | genlmsg_cancel(msg, hdr); | |
5727 | return -EMSGSIZE; | |
5728 | } | |
5729 | ||
97990a06 | 5730 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5731 | { |
48ab905d | 5732 | struct cfg80211_registered_device *rdev; |
2a519311 | 5733 | struct cfg80211_internal_bss *scan; |
48ab905d | 5734 | struct wireless_dev *wdev; |
97990a06 | 5735 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5736 | int err; |
5737 | ||
97990a06 | 5738 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5739 | if (err) |
5740 | return err; | |
2a519311 | 5741 | |
48ab905d JB |
5742 | wdev_lock(wdev); |
5743 | spin_lock_bh(&rdev->bss_lock); | |
5744 | cfg80211_bss_expire(rdev); | |
5745 | ||
9720bb3a JB |
5746 | cb->seq = rdev->bss_generation; |
5747 | ||
48ab905d | 5748 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5749 | if (++idx <= start) |
5750 | continue; | |
9720bb3a | 5751 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5752 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5753 | rdev, wdev, scan) < 0) { |
2a519311 | 5754 | idx--; |
67748893 | 5755 | break; |
2a519311 JB |
5756 | } |
5757 | } | |
5758 | ||
48ab905d JB |
5759 | spin_unlock_bh(&rdev->bss_lock); |
5760 | wdev_unlock(wdev); | |
2a519311 | 5761 | |
97990a06 JB |
5762 | cb->args[2] = idx; |
5763 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5764 | |
67748893 | 5765 | return skb->len; |
2a519311 JB |
5766 | } |
5767 | ||
15e47304 | 5768 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5769 | int flags, struct net_device *dev, |
5770 | struct survey_info *survey) | |
5771 | { | |
5772 | void *hdr; | |
5773 | struct nlattr *infoattr; | |
5774 | ||
15e47304 | 5775 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5776 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5777 | if (!hdr) | |
5778 | return -ENOMEM; | |
5779 | ||
9360ffd1 DM |
5780 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5781 | goto nla_put_failure; | |
61fa713c HS |
5782 | |
5783 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5784 | if (!infoattr) | |
5785 | goto nla_put_failure; | |
5786 | ||
9360ffd1 DM |
5787 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5788 | survey->channel->center_freq)) | |
5789 | goto nla_put_failure; | |
5790 | ||
5791 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5792 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5793 | goto nla_put_failure; | |
5794 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5795 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5796 | goto nla_put_failure; | |
5797 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5798 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5799 | survey->channel_time)) | |
5800 | goto nla_put_failure; | |
5801 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5802 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5803 | survey->channel_time_busy)) | |
5804 | goto nla_put_failure; | |
5805 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5806 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5807 | survey->channel_time_ext_busy)) | |
5808 | goto nla_put_failure; | |
5809 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5810 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5811 | survey->channel_time_rx)) | |
5812 | goto nla_put_failure; | |
5813 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5814 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5815 | survey->channel_time_tx)) | |
5816 | goto nla_put_failure; | |
61fa713c HS |
5817 | |
5818 | nla_nest_end(msg, infoattr); | |
5819 | ||
5820 | return genlmsg_end(msg, hdr); | |
5821 | ||
5822 | nla_put_failure: | |
5823 | genlmsg_cancel(msg, hdr); | |
5824 | return -EMSGSIZE; | |
5825 | } | |
5826 | ||
5827 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5828 | struct netlink_callback *cb) | |
5829 | { | |
5830 | struct survey_info survey; | |
5831 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5832 | struct wireless_dev *wdev; |
5833 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5834 | int res; |
5835 | ||
97990a06 | 5836 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5837 | if (res) |
5838 | return res; | |
61fa713c | 5839 | |
97990a06 JB |
5840 | if (!wdev->netdev) { |
5841 | res = -EINVAL; | |
5842 | goto out_err; | |
5843 | } | |
5844 | ||
61fa713c HS |
5845 | if (!dev->ops->dump_survey) { |
5846 | res = -EOPNOTSUPP; | |
5847 | goto out_err; | |
5848 | } | |
5849 | ||
5850 | while (1) { | |
180cdc79 LR |
5851 | struct ieee80211_channel *chan; |
5852 | ||
97990a06 | 5853 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5854 | if (res == -ENOENT) |
5855 | break; | |
5856 | if (res) | |
5857 | goto out_err; | |
5858 | ||
180cdc79 LR |
5859 | /* Survey without a channel doesn't make sense */ |
5860 | if (!survey.channel) { | |
5861 | res = -EINVAL; | |
5862 | goto out; | |
5863 | } | |
5864 | ||
5865 | chan = ieee80211_get_channel(&dev->wiphy, | |
5866 | survey.channel->center_freq); | |
5867 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5868 | survey_idx++; | |
5869 | continue; | |
5870 | } | |
5871 | ||
61fa713c | 5872 | if (nl80211_send_survey(skb, |
15e47304 | 5873 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5874 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5875 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5876 | goto out; |
5877 | survey_idx++; | |
5878 | } | |
5879 | ||
5880 | out: | |
97990a06 | 5881 | cb->args[2] = survey_idx; |
61fa713c HS |
5882 | res = skb->len; |
5883 | out_err: | |
97990a06 | 5884 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5885 | return res; |
5886 | } | |
5887 | ||
b23aa676 SO |
5888 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5889 | { | |
5890 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5891 | NL80211_WPA_VERSION_2)); | |
5892 | } | |
5893 | ||
636a5d36 JM |
5894 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5895 | { | |
4c476991 JB |
5896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5897 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5898 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5899 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5900 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5901 | enum nl80211_auth_type auth_type; |
fffd0934 | 5902 | struct key_parse key; |
d5cdfacb | 5903 | bool local_state_change; |
636a5d36 | 5904 | |
f4a11bb0 JB |
5905 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5906 | return -EINVAL; | |
5907 | ||
5908 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5909 | return -EINVAL; | |
5910 | ||
1778092e JM |
5911 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5912 | return -EINVAL; | |
5913 | ||
19957bb3 JB |
5914 | if (!info->attrs[NL80211_ATTR_SSID]) |
5915 | return -EINVAL; | |
5916 | ||
5917 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5918 | return -EINVAL; | |
5919 | ||
fffd0934 JB |
5920 | err = nl80211_parse_key(info, &key); |
5921 | if (err) | |
5922 | return err; | |
5923 | ||
5924 | if (key.idx >= 0) { | |
e31b8213 JB |
5925 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5926 | return -EINVAL; | |
fffd0934 JB |
5927 | if (!key.p.key || !key.p.key_len) |
5928 | return -EINVAL; | |
5929 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5930 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5931 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5932 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5933 | return -EINVAL; | |
5934 | if (key.idx > 4) | |
5935 | return -EINVAL; | |
5936 | } else { | |
5937 | key.p.key_len = 0; | |
5938 | key.p.key = NULL; | |
5939 | } | |
5940 | ||
afea0b7a JB |
5941 | if (key.idx >= 0) { |
5942 | int i; | |
5943 | bool ok = false; | |
5944 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5945 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5946 | ok = true; | |
5947 | break; | |
5948 | } | |
5949 | } | |
4c476991 JB |
5950 | if (!ok) |
5951 | return -EINVAL; | |
afea0b7a JB |
5952 | } |
5953 | ||
4c476991 JB |
5954 | if (!rdev->ops->auth) |
5955 | return -EOPNOTSUPP; | |
636a5d36 | 5956 | |
074ac8df | 5957 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5958 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5959 | return -EOPNOTSUPP; | |
eec60b03 | 5960 | |
19957bb3 | 5961 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5962 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5963 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5964 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5965 | return -EINVAL; | |
636a5d36 | 5966 | |
19957bb3 JB |
5967 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5968 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5969 | |
5970 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5971 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5972 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5973 | } |
5974 | ||
19957bb3 | 5975 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5976 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5977 | return -EINVAL; |
636a5d36 | 5978 | |
e39e5b5e JM |
5979 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5980 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5981 | return -EINVAL; | |
5982 | ||
5983 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5984 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5985 | return -EINVAL; | |
5986 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5987 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5988 | /* need to include at least Auth Transaction and Status Code */ | |
5989 | if (sae_data_len < 4) | |
5990 | return -EINVAL; | |
5991 | } | |
5992 | ||
d5cdfacb JM |
5993 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5994 | ||
95de817b JB |
5995 | /* |
5996 | * Since we no longer track auth state, ignore | |
5997 | * requests to only change local state. | |
5998 | */ | |
5999 | if (local_state_change) | |
6000 | return 0; | |
6001 | ||
4c476991 JB |
6002 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
6003 | ssid, ssid_len, ie, ie_len, | |
e39e5b5e JM |
6004 | key.p.key, key.p.key_len, key.idx, |
6005 | sae_data, sae_data_len); | |
636a5d36 JM |
6006 | } |
6007 | ||
c0692b8f JB |
6008 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6009 | struct genl_info *info, | |
3dc27d25 JB |
6010 | struct cfg80211_crypto_settings *settings, |
6011 | int cipher_limit) | |
b23aa676 | 6012 | { |
c0b2bbd8 JB |
6013 | memset(settings, 0, sizeof(*settings)); |
6014 | ||
b23aa676 SO |
6015 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6016 | ||
c0692b8f JB |
6017 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6018 | u16 proto; | |
6019 | proto = nla_get_u16( | |
6020 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6021 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6022 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6023 | proto != ETH_P_PAE) | |
6024 | return -EINVAL; | |
6025 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6026 | settings->control_port_no_encrypt = true; | |
6027 | } else | |
6028 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6029 | ||
b23aa676 SO |
6030 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6031 | void *data; | |
6032 | int len, i; | |
6033 | ||
6034 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6035 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6036 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6037 | ||
6038 | if (len % sizeof(u32)) | |
6039 | return -EINVAL; | |
6040 | ||
3dc27d25 | 6041 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6042 | return -EINVAL; |
6043 | ||
6044 | memcpy(settings->ciphers_pairwise, data, len); | |
6045 | ||
6046 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6047 | if (!cfg80211_supported_cipher_suite( |
6048 | &rdev->wiphy, | |
b23aa676 SO |
6049 | settings->ciphers_pairwise[i])) |
6050 | return -EINVAL; | |
6051 | } | |
6052 | ||
6053 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6054 | settings->cipher_group = | |
6055 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6056 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6057 | settings->cipher_group)) | |
b23aa676 SO |
6058 | return -EINVAL; |
6059 | } | |
6060 | ||
6061 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6062 | settings->wpa_versions = | |
6063 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6064 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6065 | return -EINVAL; | |
6066 | } | |
6067 | ||
6068 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6069 | void *data; | |
6d30240e | 6070 | int len; |
b23aa676 SO |
6071 | |
6072 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6073 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6074 | settings->n_akm_suites = len / sizeof(u32); | |
6075 | ||
6076 | if (len % sizeof(u32)) | |
6077 | return -EINVAL; | |
6078 | ||
1b9ca027 JM |
6079 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6080 | return -EINVAL; | |
6081 | ||
b23aa676 | 6082 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6083 | } |
6084 | ||
6085 | return 0; | |
6086 | } | |
6087 | ||
636a5d36 JM |
6088 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6089 | { | |
4c476991 JB |
6090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6091 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6092 | struct ieee80211_channel *chan; |
f62fab73 JB |
6093 | struct cfg80211_assoc_request req = {}; |
6094 | const u8 *bssid, *ssid; | |
6095 | int err, ssid_len = 0; | |
636a5d36 | 6096 | |
f4a11bb0 JB |
6097 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6098 | return -EINVAL; | |
6099 | ||
6100 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6101 | !info->attrs[NL80211_ATTR_SSID] || |
6102 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6103 | return -EINVAL; |
6104 | ||
4c476991 JB |
6105 | if (!rdev->ops->assoc) |
6106 | return -EOPNOTSUPP; | |
636a5d36 | 6107 | |
074ac8df | 6108 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6109 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6110 | return -EOPNOTSUPP; | |
eec60b03 | 6111 | |
19957bb3 | 6112 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6113 | |
19957bb3 JB |
6114 | chan = ieee80211_get_channel(&rdev->wiphy, |
6115 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6116 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6117 | return -EINVAL; | |
636a5d36 | 6118 | |
19957bb3 JB |
6119 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6120 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6121 | |
6122 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6123 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6124 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6125 | } |
6126 | ||
dc6382ce | 6127 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6128 | enum nl80211_mfp mfp = |
dc6382ce | 6129 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6130 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6131 | req.use_mfp = true; |
4c476991 JB |
6132 | else if (mfp != NL80211_MFP_NO) |
6133 | return -EINVAL; | |
dc6382ce JM |
6134 | } |
6135 | ||
3e5d7649 | 6136 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6137 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6138 | |
7e7c8926 | 6139 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6140 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6141 | |
6142 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6143 | memcpy(&req.ht_capa_mask, |
6144 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6145 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6146 | |
6147 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6148 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6149 | return -EINVAL; |
f62fab73 JB |
6150 | memcpy(&req.ht_capa, |
6151 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6152 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6153 | } |
6154 | ||
ee2aca34 | 6155 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6156 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6157 | |
6158 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6159 | memcpy(&req.vht_capa_mask, |
6160 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6161 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6162 | |
6163 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6164 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6165 | return -EINVAL; |
f62fab73 JB |
6166 | memcpy(&req.vht_capa, |
6167 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6168 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6169 | } |
6170 | ||
f62fab73 | 6171 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
b23aa676 | 6172 | if (!err) |
f62fab73 JB |
6173 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6174 | ssid, ssid_len, &req); | |
636a5d36 | 6175 | |
636a5d36 JM |
6176 | return err; |
6177 | } | |
6178 | ||
6179 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6180 | { | |
4c476991 JB |
6181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6182 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6183 | const u8 *ie = NULL, *bssid; |
4c476991 | 6184 | int ie_len = 0; |
19957bb3 | 6185 | u16 reason_code; |
d5cdfacb | 6186 | bool local_state_change; |
636a5d36 | 6187 | |
f4a11bb0 JB |
6188 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6189 | return -EINVAL; | |
6190 | ||
6191 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6192 | return -EINVAL; | |
6193 | ||
6194 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6195 | return -EINVAL; | |
6196 | ||
4c476991 JB |
6197 | if (!rdev->ops->deauth) |
6198 | return -EOPNOTSUPP; | |
636a5d36 | 6199 | |
074ac8df | 6200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6202 | return -EOPNOTSUPP; | |
eec60b03 | 6203 | |
19957bb3 | 6204 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6205 | |
19957bb3 JB |
6206 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6207 | if (reason_code == 0) { | |
f4a11bb0 | 6208 | /* Reason Code 0 is reserved */ |
4c476991 | 6209 | return -EINVAL; |
255e737e | 6210 | } |
636a5d36 JM |
6211 | |
6212 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6213 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6214 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6215 | } |
6216 | ||
d5cdfacb JM |
6217 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6218 | ||
4c476991 JB |
6219 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
6220 | local_state_change); | |
636a5d36 JM |
6221 | } |
6222 | ||
6223 | static int nl80211_disassociate(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]; | |
19957bb3 | 6227 | const u8 *ie = NULL, *bssid; |
4c476991 | 6228 | int ie_len = 0; |
19957bb3 | 6229 | u16 reason_code; |
d5cdfacb | 6230 | bool local_state_change; |
636a5d36 | 6231 | |
f4a11bb0 JB |
6232 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6233 | return -EINVAL; | |
6234 | ||
6235 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6236 | return -EINVAL; | |
6237 | ||
6238 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6239 | return -EINVAL; | |
6240 | ||
4c476991 JB |
6241 | if (!rdev->ops->disassoc) |
6242 | return -EOPNOTSUPP; | |
636a5d36 | 6243 | |
074ac8df | 6244 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6245 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6246 | return -EOPNOTSUPP; | |
eec60b03 | 6247 | |
19957bb3 | 6248 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6249 | |
19957bb3 JB |
6250 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6251 | if (reason_code == 0) { | |
f4a11bb0 | 6252 | /* Reason Code 0 is reserved */ |
4c476991 | 6253 | return -EINVAL; |
255e737e | 6254 | } |
636a5d36 JM |
6255 | |
6256 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6257 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6258 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6259 | } |
6260 | ||
d5cdfacb JM |
6261 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6262 | ||
4c476991 JB |
6263 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
6264 | local_state_change); | |
636a5d36 JM |
6265 | } |
6266 | ||
dd5b4cc7 FF |
6267 | static bool |
6268 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6269 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6270 | int rateval) | |
6271 | { | |
6272 | struct wiphy *wiphy = &rdev->wiphy; | |
6273 | bool found = false; | |
6274 | int band, i; | |
6275 | ||
6276 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6277 | struct ieee80211_supported_band *sband; | |
6278 | ||
6279 | sband = wiphy->bands[band]; | |
6280 | if (!sband) | |
6281 | continue; | |
6282 | ||
6283 | for (i = 0; i < sband->n_bitrates; i++) { | |
6284 | if (sband->bitrates[i].bitrate == rateval) { | |
6285 | mcast_rate[band] = i + 1; | |
6286 | found = true; | |
6287 | break; | |
6288 | } | |
6289 | } | |
6290 | } | |
6291 | ||
6292 | return found; | |
6293 | } | |
6294 | ||
04a773ad JB |
6295 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6296 | { | |
4c476991 JB |
6297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6298 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6299 | struct cfg80211_ibss_params ibss; |
6300 | struct wiphy *wiphy; | |
fffd0934 | 6301 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6302 | int err; |
6303 | ||
8e30bc55 JB |
6304 | memset(&ibss, 0, sizeof(ibss)); |
6305 | ||
04a773ad JB |
6306 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6307 | return -EINVAL; | |
6308 | ||
683b6d3b | 6309 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6310 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6311 | return -EINVAL; | |
6312 | ||
8e30bc55 JB |
6313 | ibss.beacon_interval = 100; |
6314 | ||
6315 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6316 | ibss.beacon_interval = | |
6317 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6318 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6319 | return -EINVAL; | |
6320 | } | |
6321 | ||
4c476991 JB |
6322 | if (!rdev->ops->join_ibss) |
6323 | return -EOPNOTSUPP; | |
04a773ad | 6324 | |
4c476991 JB |
6325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6326 | return -EOPNOTSUPP; | |
04a773ad | 6327 | |
79c97e97 | 6328 | wiphy = &rdev->wiphy; |
04a773ad | 6329 | |
39193498 | 6330 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6331 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6332 | |
6333 | if (!is_valid_ether_addr(ibss.bssid)) | |
6334 | return -EINVAL; | |
6335 | } | |
04a773ad JB |
6336 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6337 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6338 | ||
6339 | if (info->attrs[NL80211_ATTR_IE]) { | |
6340 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6341 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6342 | } | |
6343 | ||
683b6d3b JB |
6344 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6345 | if (err) | |
6346 | return err; | |
04a773ad | 6347 | |
683b6d3b | 6348 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6349 | return -EINVAL; |
6350 | ||
db9c64cf JB |
6351 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
6352 | return -EINVAL; | |
6353 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
6354 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
c04d6150 | 6355 | return -EINVAL; |
db9c64cf | 6356 | |
04a773ad | 6357 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6358 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6359 | ||
fbd2c8dc TP |
6360 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6361 | u8 *rates = | |
6362 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6363 | int n_rates = | |
6364 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6365 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6366 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6367 | |
34850ab2 JB |
6368 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6369 | &ibss.basic_rates); | |
6370 | if (err) | |
6371 | return err; | |
fbd2c8dc | 6372 | } |
dd5b4cc7 FF |
6373 | |
6374 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
6375 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6376 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6377 | return -EINVAL; | |
fbd2c8dc | 6378 | |
4c476991 | 6379 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6380 | bool no_ht = false; |
6381 | ||
4c476991 | 6382 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6383 | info->attrs[NL80211_ATTR_KEYS], |
6384 | &no_ht); | |
4c476991 JB |
6385 | if (IS_ERR(connkeys)) |
6386 | return PTR_ERR(connkeys); | |
de7044ee | 6387 | |
3d9d1d66 JB |
6388 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6389 | no_ht) { | |
de7044ee SM |
6390 | kfree(connkeys); |
6391 | return -EINVAL; | |
6392 | } | |
4c476991 | 6393 | } |
04a773ad | 6394 | |
267335d6 AQ |
6395 | ibss.control_port = |
6396 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6397 | ||
4c476991 | 6398 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6399 | if (err) |
6400 | kfree(connkeys); | |
04a773ad JB |
6401 | return err; |
6402 | } | |
6403 | ||
6404 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6405 | { | |
4c476991 JB |
6406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6407 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6408 | |
4c476991 JB |
6409 | if (!rdev->ops->leave_ibss) |
6410 | return -EOPNOTSUPP; | |
04a773ad | 6411 | |
4c476991 JB |
6412 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6413 | return -EOPNOTSUPP; | |
04a773ad | 6414 | |
4c476991 | 6415 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6416 | } |
6417 | ||
f4e583c8 AQ |
6418 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6419 | { | |
6420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6421 | struct net_device *dev = info->user_ptr[1]; | |
6422 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6423 | u32 nla_rate; | |
6424 | int err; | |
6425 | ||
6426 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6427 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6428 | return -EOPNOTSUPP; | |
6429 | ||
6430 | if (!rdev->ops->set_mcast_rate) | |
6431 | return -EOPNOTSUPP; | |
6432 | ||
6433 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6434 | ||
6435 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6436 | return -EINVAL; | |
6437 | ||
6438 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6439 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6440 | return -EINVAL; | |
6441 | ||
6442 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6443 | ||
6444 | return err; | |
6445 | } | |
6446 | ||
6fa3eb70 S |
6447 | static struct sk_buff * |
6448 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6449 | int approxlen, u32 portid, u32 seq, | |
6450 | enum nl80211_commands cmd, | |
6451 | enum nl80211_attrs attr, | |
6452 | const struct nl80211_vendor_cmd_info *info, | |
6453 | gfp_t gfp) | |
6454 | { | |
6455 | struct sk_buff *skb; | |
6456 | void *hdr; | |
6457 | struct nlattr *data; | |
6458 | ||
6459 | skb = nlmsg_new(approxlen + 100, gfp); | |
6460 | if (!skb) | |
6461 | return NULL; | |
6462 | ||
6463 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
6464 | if (!hdr) { | |
6465 | kfree_skb(skb); | |
6466 | return NULL; | |
6467 | } | |
6468 | ||
6469 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
6470 | goto nla_put_failure; | |
6471 | ||
6472 | if (info) { | |
6473 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
6474 | info->vendor_id)) | |
6475 | goto nla_put_failure; | |
6476 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
6477 | info->subcmd)) | |
6478 | goto nla_put_failure; | |
6479 | } | |
6480 | ||
6481 | data = nla_nest_start(skb, attr); | |
6482 | ||
6483 | ((void **)skb->cb)[0] = rdev; | |
6484 | ((void **)skb->cb)[1] = hdr; | |
6485 | ((void **)skb->cb)[2] = data; | |
6486 | ||
6487 | return skb; | |
6488 | ||
6489 | nla_put_failure: | |
6490 | kfree_skb(skb); | |
6491 | return NULL; | |
6492 | } | |
f4e583c8 | 6493 | |
aff89a9b JB |
6494 | #ifdef CONFIG_NL80211_TESTMODE |
6495 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6496 | .name = "testmode", | |
6497 | }; | |
6498 | ||
6fa3eb70 S |
6499 | static struct genl_multicast_group nl80211_vendor_mcgrp = { |
6500 | .name = "vendor", | |
6501 | }; | |
6502 | ||
aff89a9b JB |
6503 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
6504 | { | |
4c476991 | 6505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6506 | int err; |
6507 | ||
6508 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6509 | return -EINVAL; | |
6510 | ||
aff89a9b JB |
6511 | err = -EOPNOTSUPP; |
6512 | if (rdev->ops->testmode_cmd) { | |
6fa3eb70 | 6513 | rdev->cur_cmd_info = info; |
e35e4d28 | 6514 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6515 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6516 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6fa3eb70 | 6517 | rdev->cur_cmd_info = NULL; |
aff89a9b JB |
6518 | } |
6519 | ||
aff89a9b JB |
6520 | return err; |
6521 | } | |
6522 | ||
71063f0e WYG |
6523 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6524 | struct netlink_callback *cb) | |
6525 | { | |
00918d33 | 6526 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6527 | int err; |
6528 | long phy_idx; | |
6529 | void *data = NULL; | |
6530 | int data_len = 0; | |
6531 | ||
6532 | if (cb->args[0]) { | |
6533 | /* | |
6534 | * 0 is a valid index, but not valid for args[0], | |
6535 | * so we need to offset by 1. | |
6536 | */ | |
6537 | phy_idx = cb->args[0] - 1; | |
6538 | } else { | |
6539 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6540 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6541 | nl80211_policy); | |
6542 | if (err) | |
6543 | return err; | |
00918d33 | 6544 | |
2bd7e35d JB |
6545 | mutex_lock(&cfg80211_mutex); |
6546 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
6547 | nl80211_fam.attrbuf); | |
6548 | if (IS_ERR(rdev)) { | |
6549 | mutex_unlock(&cfg80211_mutex); | |
6550 | return PTR_ERR(rdev); | |
00918d33 | 6551 | } |
2bd7e35d JB |
6552 | phy_idx = rdev->wiphy_idx; |
6553 | rdev = NULL; | |
6554 | mutex_unlock(&cfg80211_mutex); | |
6555 | ||
71063f0e WYG |
6556 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6557 | cb->args[1] = | |
6558 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6559 | } | |
6560 | ||
6561 | if (cb->args[1]) { | |
6562 | data = nla_data((void *)cb->args[1]); | |
6563 | data_len = nla_len((void *)cb->args[1]); | |
6564 | } | |
6565 | ||
6566 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
6567 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6568 | if (!rdev) { | |
71063f0e WYG |
6569 | mutex_unlock(&cfg80211_mutex); |
6570 | return -ENOENT; | |
6571 | } | |
00918d33 | 6572 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
6573 | mutex_unlock(&cfg80211_mutex); |
6574 | ||
00918d33 | 6575 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6576 | err = -EOPNOTSUPP; |
6577 | goto out_err; | |
6578 | } | |
6579 | ||
6580 | while (1) { | |
15e47304 | 6581 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6582 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6583 | NL80211_CMD_TESTMODE); | |
6584 | struct nlattr *tmdata; | |
6585 | ||
6fa3eb70 S |
6586 | if (!hdr) |
6587 | break; | |
6588 | ||
9360ffd1 | 6589 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6590 | genlmsg_cancel(skb, hdr); |
6591 | break; | |
6592 | } | |
6593 | ||
6594 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6595 | if (!tmdata) { | |
6596 | genlmsg_cancel(skb, hdr); | |
6597 | break; | |
6598 | } | |
e35e4d28 | 6599 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6600 | nla_nest_end(skb, tmdata); |
6601 | ||
6602 | if (err == -ENOBUFS || err == -ENOENT) { | |
6603 | genlmsg_cancel(skb, hdr); | |
6604 | break; | |
6605 | } else if (err) { | |
6606 | genlmsg_cancel(skb, hdr); | |
6607 | goto out_err; | |
6608 | } | |
6609 | ||
6610 | genlmsg_end(skb, hdr); | |
6611 | } | |
6612 | ||
6613 | err = skb->len; | |
6614 | /* see above */ | |
6615 | cb->args[0] = phy_idx + 1; | |
6616 | out_err: | |
00918d33 | 6617 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
6618 | return err; |
6619 | } | |
6620 | ||
6fa3eb70 S |
6621 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6622 | enum nl80211_commands cmd, | |
6623 | enum nl80211_attrs attr, | |
6624 | int vendor_event_idx, | |
6625 | int approxlen, gfp_t gfp) | |
aff89a9b JB |
6626 | { |
6627 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6fa3eb70 | 6628 | const struct nl80211_vendor_cmd_info *info; |
aff89a9b | 6629 | |
6fa3eb70 S |
6630 | switch (cmd) { |
6631 | case NL80211_CMD_TESTMODE: | |
6632 | if (WARN_ON(vendor_event_idx != -1)) | |
6633 | return NULL; | |
6634 | info = NULL; | |
6635 | break; | |
6636 | case NL80211_CMD_VENDOR: | |
6637 | if (WARN_ON(vendor_event_idx < 0 || | |
6638 | vendor_event_idx >= wiphy->n_vendor_events)) | |
6639 | return NULL; | |
6640 | info = &wiphy->vendor_events[vendor_event_idx]; | |
6641 | break; | |
6642 | default: | |
6643 | WARN_ON(1); | |
aff89a9b | 6644 | return NULL; |
aff89a9b | 6645 | } |
6fa3eb70 S |
6646 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
6647 | cmd, attr, info, gfp); | |
aff89a9b | 6648 | } |
6fa3eb70 | 6649 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
aff89a9b | 6650 | |
6fa3eb70 | 6651 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
aff89a9b | 6652 | { |
c8942c6a | 6653 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
aff89a9b JB |
6654 | void *hdr = ((void **)skb->cb)[1]; |
6655 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6656 | ||
7dd31112 JB |
6657 | /* clear CB data for netlink core to own from now on */ |
6658 | memset(skb->cb, 0, sizeof(skb->cb)); | |
6659 | ||
aff89a9b JB |
6660 | nla_nest_end(skb, data); |
6661 | genlmsg_end(skb, hdr); | |
6fa3eb70 S |
6662 | |
6663 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
6664 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, | |
6665 | nl80211_vendor_mcgrp.id, gfp); | |
6666 | else | |
6667 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, | |
6668 | nl80211_testmode_mcgrp.id, gfp); | |
aff89a9b | 6669 | } |
6fa3eb70 | 6670 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
aff89a9b JB |
6671 | #endif |
6672 | ||
b23aa676 SO |
6673 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6674 | { | |
4c476991 JB |
6675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6676 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6677 | struct cfg80211_connect_params connect; |
6678 | struct wiphy *wiphy; | |
fffd0934 | 6679 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6680 | int err; |
6681 | ||
6682 | memset(&connect, 0, sizeof(connect)); | |
6683 | ||
6684 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6685 | return -EINVAL; | |
6686 | ||
6687 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6688 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6689 | return -EINVAL; | |
6690 | ||
6691 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6692 | connect.auth_type = | |
6693 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6694 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6695 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6696 | return -EINVAL; |
6697 | } else | |
6698 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6699 | ||
6700 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6701 | ||
c0692b8f | 6702 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6703 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6704 | if (err) |
6705 | return err; | |
b23aa676 | 6706 | |
074ac8df | 6707 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6708 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6709 | return -EOPNOTSUPP; | |
b23aa676 | 6710 | |
79c97e97 | 6711 | wiphy = &rdev->wiphy; |
b23aa676 | 6712 | |
4486ea98 BS |
6713 | connect.bg_scan_period = -1; |
6714 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6715 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6716 | connect.bg_scan_period = | |
6717 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6718 | } | |
6719 | ||
b23aa676 SO |
6720 | if (info->attrs[NL80211_ATTR_MAC]) |
6721 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6722 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6723 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6724 | ||
6725 | if (info->attrs[NL80211_ATTR_IE]) { | |
6726 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6727 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6728 | } | |
6729 | ||
cee00a95 JM |
6730 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6731 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6732 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6733 | connect.mfp != NL80211_MFP_NO) | |
6734 | return -EINVAL; | |
6735 | } else { | |
6736 | connect.mfp = NL80211_MFP_NO; | |
6737 | } | |
6738 | ||
b23aa676 SO |
6739 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6740 | connect.channel = | |
6741 | ieee80211_get_channel(wiphy, | |
6742 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6743 | if (!connect.channel || | |
4c476991 JB |
6744 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6745 | return -EINVAL; | |
b23aa676 SO |
6746 | } |
6747 | ||
fffd0934 JB |
6748 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6749 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6750 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6751 | if (IS_ERR(connkeys)) |
6752 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6753 | } |
6754 | ||
7e7c8926 BG |
6755 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6756 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6757 | ||
6758 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6759 | memcpy(&connect.ht_capa_mask, | |
6760 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6761 | sizeof(connect.ht_capa_mask)); | |
6762 | ||
6763 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6764 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6765 | kfree(connkeys); | |
7e7c8926 | 6766 | return -EINVAL; |
b4e4f47e | 6767 | } |
7e7c8926 BG |
6768 | memcpy(&connect.ht_capa, |
6769 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6770 | sizeof(connect.ht_capa)); | |
6771 | } | |
6772 | ||
ee2aca34 JB |
6773 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6774 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6775 | ||
6776 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6777 | memcpy(&connect.vht_capa_mask, | |
6778 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6779 | sizeof(connect.vht_capa_mask)); | |
6780 | ||
6781 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6782 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6783 | kfree(connkeys); | |
6784 | return -EINVAL; | |
6785 | } | |
6786 | memcpy(&connect.vht_capa, | |
6787 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6788 | sizeof(connect.vht_capa)); | |
6789 | } | |
6790 | ||
fffd0934 | 6791 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
6792 | if (err) |
6793 | kfree(connkeys); | |
b23aa676 SO |
6794 | return err; |
6795 | } | |
6796 | ||
6797 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6798 | { | |
4c476991 JB |
6799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6800 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6801 | u16 reason; |
6802 | ||
6803 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6804 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6805 | else | |
6806 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6807 | ||
6808 | if (reason == 0) | |
6809 | return -EINVAL; | |
6810 | ||
074ac8df | 6811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6813 | return -EOPNOTSUPP; | |
b23aa676 | 6814 | |
4c476991 | 6815 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
6816 | } |
6817 | ||
463d0183 JB |
6818 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6819 | { | |
4c476991 | 6820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6821 | struct net *net; |
6822 | int err; | |
6823 | u32 pid; | |
6824 | ||
6825 | if (!info->attrs[NL80211_ATTR_PID]) | |
6826 | return -EINVAL; | |
6827 | ||
6828 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6829 | ||
463d0183 | 6830 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6831 | if (IS_ERR(net)) |
6832 | return PTR_ERR(net); | |
463d0183 JB |
6833 | |
6834 | err = 0; | |
6835 | ||
6836 | /* check if anything to do */ | |
4c476991 JB |
6837 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6838 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6839 | |
463d0183 | 6840 | put_net(net); |
463d0183 JB |
6841 | return err; |
6842 | } | |
6843 | ||
67fbb16b SO |
6844 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6845 | { | |
4c476991 | 6846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6847 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6848 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6849 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6850 | struct cfg80211_pmksa pmksa; |
6851 | ||
6852 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6853 | ||
6854 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6855 | return -EINVAL; | |
6856 | ||
6857 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6858 | return -EINVAL; | |
6859 | ||
67fbb16b SO |
6860 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6861 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6862 | ||
074ac8df | 6863 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6864 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6865 | return -EOPNOTSUPP; | |
67fbb16b SO |
6866 | |
6867 | switch (info->genlhdr->cmd) { | |
6868 | case NL80211_CMD_SET_PMKSA: | |
6869 | rdev_ops = rdev->ops->set_pmksa; | |
6870 | break; | |
6871 | case NL80211_CMD_DEL_PMKSA: | |
6872 | rdev_ops = rdev->ops->del_pmksa; | |
6873 | break; | |
6874 | default: | |
6875 | WARN_ON(1); | |
6876 | break; | |
6877 | } | |
6878 | ||
4c476991 JB |
6879 | if (!rdev_ops) |
6880 | return -EOPNOTSUPP; | |
67fbb16b | 6881 | |
4c476991 | 6882 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6883 | } |
6884 | ||
6885 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6886 | { | |
4c476991 JB |
6887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6888 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6889 | |
074ac8df | 6890 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6891 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6892 | return -EOPNOTSUPP; | |
67fbb16b | 6893 | |
4c476991 JB |
6894 | if (!rdev->ops->flush_pmksa) |
6895 | return -EOPNOTSUPP; | |
67fbb16b | 6896 | |
e35e4d28 | 6897 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6898 | } |
6899 | ||
109086ce AN |
6900 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6901 | { | |
6902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6903 | struct net_device *dev = info->user_ptr[1]; | |
6904 | u8 action_code, dialog_token; | |
6905 | u16 status_code; | |
6906 | u8 *peer; | |
6907 | ||
6908 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6909 | !rdev->ops->tdls_mgmt) | |
6910 | return -EOPNOTSUPP; | |
6911 | ||
6912 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6913 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6914 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6915 | !info->attrs[NL80211_ATTR_IE] || | |
6916 | !info->attrs[NL80211_ATTR_MAC]) | |
6917 | return -EINVAL; | |
6918 | ||
6919 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6920 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6921 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6922 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6923 | ||
e35e4d28 HG |
6924 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6925 | dialog_token, status_code, | |
6926 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6927 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6928 | } |
6929 | ||
6930 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6931 | { | |
6932 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6933 | struct net_device *dev = info->user_ptr[1]; | |
6934 | enum nl80211_tdls_operation operation; | |
6935 | u8 *peer; | |
6936 | ||
6937 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6938 | !rdev->ops->tdls_oper) | |
6939 | return -EOPNOTSUPP; | |
6940 | ||
6941 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6942 | !info->attrs[NL80211_ATTR_MAC]) | |
6943 | return -EINVAL; | |
6944 | ||
6945 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6946 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6947 | ||
e35e4d28 | 6948 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6949 | } |
6950 | ||
9588bbd5 JM |
6951 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6952 | struct genl_info *info) | |
6953 | { | |
4c476991 | 6954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6955 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6956 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6957 | struct sk_buff *msg; |
6958 | void *hdr; | |
6959 | u64 cookie; | |
683b6d3b | 6960 | u32 duration; |
9588bbd5 JM |
6961 | int err; |
6962 | ||
6963 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6964 | !info->attrs[NL80211_ATTR_DURATION]) | |
6965 | return -EINVAL; | |
6966 | ||
6967 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6968 | ||
ebf348fc JB |
6969 | if (!rdev->ops->remain_on_channel || |
6970 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6971 | return -EOPNOTSUPP; | |
6972 | ||
9588bbd5 | 6973 | /* |
ebf348fc JB |
6974 | * We should be on that channel for at least a minimum amount of |
6975 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6976 | */ |
ebf348fc | 6977 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6978 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6979 | return -EINVAL; |
6980 | ||
683b6d3b JB |
6981 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6982 | if (err) | |
6983 | return err; | |
9588bbd5 JM |
6984 | |
6985 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6986 | if (!msg) |
6987 | return -ENOMEM; | |
9588bbd5 | 6988 | |
15e47304 | 6989 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 6990 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6fa3eb70 S |
6991 | if (!hdr) { |
6992 | err = -ENOBUFS; | |
9588bbd5 JM |
6993 | goto free_msg; |
6994 | } | |
6995 | ||
683b6d3b JB |
6996 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6997 | duration, &cookie); | |
9588bbd5 JM |
6998 | |
6999 | if (err) | |
7000 | goto free_msg; | |
7001 | ||
9360ffd1 DM |
7002 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7003 | goto nla_put_failure; | |
9588bbd5 JM |
7004 | |
7005 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7006 | |
7007 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7008 | |
7009 | nla_put_failure: | |
7010 | err = -ENOBUFS; | |
7011 | free_msg: | |
7012 | nlmsg_free(msg); | |
9588bbd5 JM |
7013 | return err; |
7014 | } | |
7015 | ||
7016 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7017 | struct genl_info *info) | |
7018 | { | |
4c476991 | 7019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7020 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7021 | u64 cookie; |
9588bbd5 JM |
7022 | |
7023 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7024 | return -EINVAL; | |
7025 | ||
4c476991 JB |
7026 | if (!rdev->ops->cancel_remain_on_channel) |
7027 | return -EOPNOTSUPP; | |
9588bbd5 | 7028 | |
9588bbd5 JM |
7029 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7030 | ||
e35e4d28 | 7031 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7032 | } |
7033 | ||
13ae75b1 JM |
7034 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7035 | u8 *rates, u8 rates_len) | |
7036 | { | |
7037 | u8 i; | |
7038 | u32 mask = 0; | |
7039 | ||
7040 | for (i = 0; i < rates_len; i++) { | |
7041 | int rate = (rates[i] & 0x7f) * 5; | |
7042 | int ridx; | |
7043 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7044 | struct ieee80211_rate *srate = | |
7045 | &sband->bitrates[ridx]; | |
7046 | if (rate == srate->bitrate) { | |
7047 | mask |= 1 << ridx; | |
7048 | break; | |
7049 | } | |
7050 | } | |
7051 | if (ridx == sband->n_bitrates) | |
7052 | return 0; /* rate not found */ | |
7053 | } | |
7054 | ||
7055 | return mask; | |
7056 | } | |
7057 | ||
24db78c0 SW |
7058 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7059 | u8 *rates, u8 rates_len, | |
7060 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7061 | { | |
7062 | u8 i; | |
7063 | ||
7064 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7065 | ||
7066 | for (i = 0; i < rates_len; i++) { | |
7067 | int ridx, rbit; | |
7068 | ||
7069 | ridx = rates[i] / 8; | |
7070 | rbit = BIT(rates[i] % 8); | |
7071 | ||
7072 | /* check validity */ | |
910570b5 | 7073 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7074 | return false; |
7075 | ||
7076 | /* check availability */ | |
7077 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7078 | mcs[ridx] |= rbit; | |
7079 | else | |
7080 | return false; | |
7081 | } | |
7082 | ||
7083 | return true; | |
7084 | } | |
7085 | ||
b54452b0 | 7086 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7087 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7088 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7089 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7090 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7091 | }; |
7092 | ||
7093 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7094 | struct genl_info *info) | |
7095 | { | |
7096 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7098 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7099 | int rem, i; |
7100 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7101 | struct nlattr *tx_rates; |
7102 | struct ieee80211_supported_band *sband; | |
7103 | ||
7104 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7105 | return -EINVAL; | |
7106 | ||
4c476991 JB |
7107 | if (!rdev->ops->set_bitrate_mask) |
7108 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7109 | |
7110 | memset(&mask, 0, sizeof(mask)); | |
7111 | /* Default to all rates enabled */ | |
7112 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7113 | sband = rdev->wiphy.bands[i]; | |
7114 | mask.control[i].legacy = | |
7115 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7116 | if (sband) |
7117 | memcpy(mask.control[i].mcs, | |
7118 | sband->ht_cap.mcs.rx_mask, | |
7119 | sizeof(mask.control[i].mcs)); | |
7120 | else | |
7121 | memset(mask.control[i].mcs, 0, | |
7122 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7123 | } |
7124 | ||
7125 | /* | |
7126 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7127 | * directly to the enum ieee80211_band values used in cfg80211. | |
7128 | */ | |
24db78c0 | 7129 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7130 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7131 | { | |
7132 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7133 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7134 | return -EINVAL; | |
13ae75b1 | 7135 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7136 | if (sband == NULL) |
7137 | return -EINVAL; | |
13ae75b1 JM |
7138 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7139 | nla_len(tx_rates), nl80211_txattr_policy); | |
7140 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7141 | mask.control[band].legacy = rateset_to_mask( | |
7142 | sband, | |
7143 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7144 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7145 | if ((mask.control[band].legacy == 0) && |
7146 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7147 | return -EINVAL; | |
24db78c0 SW |
7148 | } |
7149 | if (tb[NL80211_TXRATE_MCS]) { | |
7150 | if (!ht_rateset_to_mask( | |
7151 | sband, | |
7152 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7153 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7154 | mask.control[band].mcs)) | |
7155 | return -EINVAL; | |
7156 | } | |
7157 | ||
7158 | if (mask.control[band].legacy == 0) { | |
7159 | /* don't allow empty legacy rates if HT | |
7160 | * is not even supported. */ | |
7161 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7162 | return -EINVAL; | |
7163 | ||
7164 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7165 | if (mask.control[band].mcs[i]) | |
7166 | break; | |
7167 | ||
7168 | /* legacy and mcs rates may not be both empty */ | |
7169 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7170 | return -EINVAL; |
13ae75b1 JM |
7171 | } |
7172 | } | |
7173 | ||
e35e4d28 | 7174 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7175 | } |
7176 | ||
2e161f78 | 7177 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7178 | { |
4c476991 | 7179 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7180 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7181 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7182 | |
7183 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7184 | return -EINVAL; | |
7185 | ||
2e161f78 JB |
7186 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7187 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7188 | |
71bbc994 JB |
7189 | switch (wdev->iftype) { |
7190 | case NL80211_IFTYPE_STATION: | |
7191 | case NL80211_IFTYPE_ADHOC: | |
7192 | case NL80211_IFTYPE_P2P_CLIENT: | |
7193 | case NL80211_IFTYPE_AP: | |
7194 | case NL80211_IFTYPE_AP_VLAN: | |
7195 | case NL80211_IFTYPE_MESH_POINT: | |
7196 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7197 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7198 | break; |
7199 | default: | |
4c476991 | 7200 | return -EOPNOTSUPP; |
71bbc994 | 7201 | } |
026331c4 JM |
7202 | |
7203 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7204 | if (!rdev->ops->mgmt_tx) |
7205 | return -EOPNOTSUPP; | |
026331c4 | 7206 | |
15e47304 | 7207 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7208 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7209 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7210 | } |
7211 | ||
2e161f78 | 7212 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7213 | { |
4c476991 | 7214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7215 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7216 | struct cfg80211_chan_def chandef; |
026331c4 | 7217 | int err; |
d64d373f | 7218 | void *hdr = NULL; |
026331c4 | 7219 | u64 cookie; |
e247bd90 | 7220 | struct sk_buff *msg = NULL; |
f7ca38df | 7221 | unsigned int wait = 0; |
e247bd90 JB |
7222 | bool offchan, no_cck, dont_wait_for_ack; |
7223 | ||
7224 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7225 | |
683b6d3b | 7226 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7227 | return -EINVAL; |
7228 | ||
4c476991 JB |
7229 | if (!rdev->ops->mgmt_tx) |
7230 | return -EOPNOTSUPP; | |
026331c4 | 7231 | |
71bbc994 JB |
7232 | switch (wdev->iftype) { |
7233 | case NL80211_IFTYPE_STATION: | |
7234 | case NL80211_IFTYPE_ADHOC: | |
7235 | case NL80211_IFTYPE_P2P_CLIENT: | |
7236 | case NL80211_IFTYPE_AP: | |
7237 | case NL80211_IFTYPE_AP_VLAN: | |
7238 | case NL80211_IFTYPE_MESH_POINT: | |
7239 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7240 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7241 | break; |
7242 | default: | |
4c476991 | 7243 | return -EOPNOTSUPP; |
71bbc994 | 7244 | } |
026331c4 | 7245 | |
f7ca38df | 7246 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7247 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7248 | return -EINVAL; |
7249 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7250 | |
7251 | /* | |
7252 | * We should wait on the channel for at least a minimum amount | |
7253 | * of time (10ms) but no longer than the driver supports. | |
7254 | */ | |
7255 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7256 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7257 | return -EINVAL; | |
7258 | ||
f7ca38df JB |
7259 | } |
7260 | ||
f7ca38df JB |
7261 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7262 | ||
7c4ef712 JB |
7263 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7264 | return -EINVAL; | |
7265 | ||
e9f935e3 RM |
7266 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7267 | ||
683b6d3b JB |
7268 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7269 | if (err) | |
7270 | return err; | |
026331c4 | 7271 | |
e247bd90 JB |
7272 | if (!dont_wait_for_ack) { |
7273 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7274 | if (!msg) | |
7275 | return -ENOMEM; | |
026331c4 | 7276 | |
15e47304 | 7277 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7278 | NL80211_CMD_FRAME); |
6fa3eb70 S |
7279 | if (!hdr) { |
7280 | err = -ENOBUFS; | |
e247bd90 JB |
7281 | goto free_msg; |
7282 | } | |
026331c4 | 7283 | } |
e247bd90 | 7284 | |
683b6d3b | 7285 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7286 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7287 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7288 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7289 | if (err) |
7290 | goto free_msg; | |
7291 | ||
e247bd90 | 7292 | if (msg) { |
9360ffd1 DM |
7293 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7294 | goto nla_put_failure; | |
026331c4 | 7295 | |
e247bd90 JB |
7296 | genlmsg_end(msg, hdr); |
7297 | return genlmsg_reply(msg, info); | |
7298 | } | |
7299 | ||
7300 | return 0; | |
026331c4 JM |
7301 | |
7302 | nla_put_failure: | |
7303 | err = -ENOBUFS; | |
7304 | free_msg: | |
7305 | nlmsg_free(msg); | |
026331c4 JM |
7306 | return err; |
7307 | } | |
7308 | ||
f7ca38df JB |
7309 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7310 | { | |
7311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7312 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7313 | u64 cookie; |
7314 | ||
7315 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7316 | return -EINVAL; | |
7317 | ||
7318 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7319 | return -EOPNOTSUPP; | |
7320 | ||
71bbc994 JB |
7321 | switch (wdev->iftype) { |
7322 | case NL80211_IFTYPE_STATION: | |
7323 | case NL80211_IFTYPE_ADHOC: | |
7324 | case NL80211_IFTYPE_P2P_CLIENT: | |
7325 | case NL80211_IFTYPE_AP: | |
7326 | case NL80211_IFTYPE_AP_VLAN: | |
7327 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7328 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7329 | break; |
7330 | default: | |
f7ca38df | 7331 | return -EOPNOTSUPP; |
71bbc994 | 7332 | } |
f7ca38df JB |
7333 | |
7334 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7335 | ||
e35e4d28 | 7336 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7337 | } |
7338 | ||
ffb9eb3d KV |
7339 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7340 | { | |
4c476991 | 7341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7342 | struct wireless_dev *wdev; |
4c476991 | 7343 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7344 | u8 ps_state; |
7345 | bool state; | |
7346 | int err; | |
7347 | ||
4c476991 JB |
7348 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7349 | return -EINVAL; | |
ffb9eb3d KV |
7350 | |
7351 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7352 | ||
4c476991 JB |
7353 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7354 | return -EINVAL; | |
ffb9eb3d KV |
7355 | |
7356 | wdev = dev->ieee80211_ptr; | |
7357 | ||
4c476991 JB |
7358 | if (!rdev->ops->set_power_mgmt) |
7359 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7360 | |
7361 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7362 | ||
7363 | if (state == wdev->ps) | |
4c476991 | 7364 | return 0; |
ffb9eb3d | 7365 | |
e35e4d28 | 7366 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7367 | if (!err) |
7368 | wdev->ps = state; | |
ffb9eb3d KV |
7369 | return err; |
7370 | } | |
7371 | ||
7372 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7373 | { | |
4c476991 | 7374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7375 | enum nl80211_ps_state ps_state; |
7376 | struct wireless_dev *wdev; | |
4c476991 | 7377 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7378 | struct sk_buff *msg; |
7379 | void *hdr; | |
7380 | int err; | |
7381 | ||
ffb9eb3d KV |
7382 | wdev = dev->ieee80211_ptr; |
7383 | ||
4c476991 JB |
7384 | if (!rdev->ops->set_power_mgmt) |
7385 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7386 | |
7387 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7388 | if (!msg) |
7389 | return -ENOMEM; | |
ffb9eb3d | 7390 | |
15e47304 | 7391 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7392 | NL80211_CMD_GET_POWER_SAVE); |
7393 | if (!hdr) { | |
4c476991 | 7394 | err = -ENOBUFS; |
ffb9eb3d KV |
7395 | goto free_msg; |
7396 | } | |
7397 | ||
7398 | if (wdev->ps) | |
7399 | ps_state = NL80211_PS_ENABLED; | |
7400 | else | |
7401 | ps_state = NL80211_PS_DISABLED; | |
7402 | ||
9360ffd1 DM |
7403 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7404 | goto nla_put_failure; | |
ffb9eb3d KV |
7405 | |
7406 | genlmsg_end(msg, hdr); | |
4c476991 | 7407 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7408 | |
4c476991 | 7409 | nla_put_failure: |
ffb9eb3d | 7410 | err = -ENOBUFS; |
4c476991 | 7411 | free_msg: |
ffb9eb3d | 7412 | nlmsg_free(msg); |
ffb9eb3d KV |
7413 | return err; |
7414 | } | |
7415 | ||
d6dc1a38 JO |
7416 | static struct nla_policy |
7417 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7418 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7419 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7420 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7421 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7422 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7423 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7424 | }; |
7425 | ||
84f10708 | 7426 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7427 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7428 | { |
7429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7430 | struct wireless_dev *wdev; | |
7431 | struct net_device *dev = info->user_ptr[1]; | |
7432 | ||
d9d8b019 | 7433 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7434 | return -EINVAL; |
7435 | ||
7436 | wdev = dev->ieee80211_ptr; | |
7437 | ||
7438 | if (!rdev->ops->set_cqm_txe_config) | |
7439 | return -EOPNOTSUPP; | |
7440 | ||
7441 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7442 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7443 | return -EOPNOTSUPP; | |
7444 | ||
e35e4d28 | 7445 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7446 | } |
7447 | ||
d6dc1a38 JO |
7448 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7449 | s32 threshold, u32 hysteresis) | |
7450 | { | |
4c476991 | 7451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7452 | struct wireless_dev *wdev; |
4c476991 | 7453 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7454 | |
7455 | if (threshold > 0) | |
7456 | return -EINVAL; | |
7457 | ||
d6dc1a38 JO |
7458 | wdev = dev->ieee80211_ptr; |
7459 | ||
4c476991 JB |
7460 | if (!rdev->ops->set_cqm_rssi_config) |
7461 | return -EOPNOTSUPP; | |
d6dc1a38 | 7462 | |
074ac8df | 7463 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7464 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7465 | return -EOPNOTSUPP; | |
d6dc1a38 | 7466 | |
e35e4d28 | 7467 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7468 | } |
7469 | ||
7470 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7471 | { | |
7472 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7473 | struct nlattr *cqm; | |
7474 | int err; | |
7475 | ||
7476 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7477 | if (!cqm) { | |
7478 | err = -EINVAL; | |
7479 | goto out; | |
7480 | } | |
7481 | ||
7482 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7483 | nl80211_attr_cqm_policy); | |
7484 | if (err) | |
7485 | goto out; | |
7486 | ||
7487 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7488 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7489 | s32 threshold; | |
7490 | u32 hysteresis; | |
7491 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7492 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7493 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7494 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7495 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7496 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7497 | u32 rate, pkts, intvl; | |
7498 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7499 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7500 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7501 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7502 | } else |
7503 | err = -EINVAL; | |
7504 | ||
7505 | out: | |
7506 | return err; | |
7507 | } | |
7508 | ||
29cbe68c JB |
7509 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7510 | { | |
7511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7512 | struct net_device *dev = info->user_ptr[1]; | |
7513 | struct mesh_config cfg; | |
c80d545d | 7514 | struct mesh_setup setup; |
29cbe68c JB |
7515 | int err; |
7516 | ||
7517 | /* start with default */ | |
7518 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7519 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7520 | |
24bdd9f4 | 7521 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7522 | /* and parse parameters if given */ |
24bdd9f4 | 7523 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7524 | if (err) |
7525 | return err; | |
7526 | } | |
7527 | ||
7528 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7529 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7530 | return -EINVAL; | |
7531 | ||
c80d545d JC |
7532 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7533 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7534 | ||
4bb62344 CYY |
7535 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7536 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7537 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7538 | return -EINVAL; | |
7539 | ||
9bdbf04d MP |
7540 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7541 | setup.beacon_interval = | |
7542 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7543 | if (setup.beacon_interval < 10 || | |
7544 | setup.beacon_interval > 10000) | |
7545 | return -EINVAL; | |
7546 | } | |
7547 | ||
7548 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7549 | setup.dtim_period = | |
7550 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7551 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7552 | return -EINVAL; | |
7553 | } | |
7554 | ||
c80d545d JC |
7555 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7556 | /* parse additional setup parameters if given */ | |
7557 | err = nl80211_parse_mesh_setup(info, &setup); | |
7558 | if (err) | |
7559 | return err; | |
7560 | } | |
7561 | ||
d37bb18a TP |
7562 | if (setup.user_mpm) |
7563 | cfg.auto_open_plinks = false; | |
7564 | ||
cc1d2806 | 7565 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7566 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7567 | if (err) | |
7568 | return err; | |
cc1d2806 JB |
7569 | } else { |
7570 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7571 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7572 | } |
7573 | ||
c80d545d | 7574 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7575 | } |
7576 | ||
7577 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7578 | { | |
7579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7580 | struct net_device *dev = info->user_ptr[1]; | |
7581 | ||
7582 | return cfg80211_leave_mesh(rdev, dev); | |
7583 | } | |
7584 | ||
dfb89c56 | 7585 | #ifdef CONFIG_PM |
bb92d199 AK |
7586 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7587 | struct cfg80211_registered_device *rdev) | |
7588 | { | |
7589 | struct nlattr *nl_pats, *nl_pat; | |
7590 | int i, pat_len; | |
7591 | ||
7592 | if (!rdev->wowlan->n_patterns) | |
7593 | return 0; | |
7594 | ||
7595 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7596 | if (!nl_pats) | |
7597 | return -ENOBUFS; | |
7598 | ||
7599 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
7600 | nl_pat = nla_nest_start(msg, i + 1); | |
7601 | if (!nl_pat) | |
7602 | return -ENOBUFS; | |
7603 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
7604 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
7605 | DIV_ROUND_UP(pat_len, 8), | |
7606 | rdev->wowlan->patterns[i].mask) || | |
7607 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
7608 | pat_len, rdev->wowlan->patterns[i].pattern) || | |
7609 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, | |
7610 | rdev->wowlan->patterns[i].pkt_offset)) | |
7611 | return -ENOBUFS; | |
7612 | nla_nest_end(msg, nl_pat); | |
7613 | } | |
7614 | nla_nest_end(msg, nl_pats); | |
7615 | ||
7616 | return 0; | |
7617 | } | |
7618 | ||
2a0e047e JB |
7619 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7620 | struct cfg80211_wowlan_tcp *tcp) | |
7621 | { | |
7622 | struct nlattr *nl_tcp; | |
7623 | ||
7624 | if (!tcp) | |
7625 | return 0; | |
7626 | ||
7627 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7628 | if (!nl_tcp) | |
7629 | return -ENOBUFS; | |
7630 | ||
7631 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7632 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7633 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7634 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7635 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7636 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7637 | tcp->payload_len, tcp->payload) || | |
7638 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7639 | tcp->data_interval) || | |
7640 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7641 | tcp->wake_len, tcp->wake_data) || | |
7642 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7643 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7644 | return -ENOBUFS; | |
7645 | ||
7646 | if (tcp->payload_seq.len && | |
7647 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7648 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7649 | return -ENOBUFS; | |
7650 | ||
7651 | if (tcp->payload_tok.len && | |
7652 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7653 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7654 | &tcp->payload_tok)) | |
7655 | return -ENOBUFS; | |
7656 | ||
e248ad30 JB |
7657 | nla_nest_end(msg, nl_tcp); |
7658 | ||
2a0e047e JB |
7659 | return 0; |
7660 | } | |
7661 | ||
ff1b6e69 JB |
7662 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7663 | { | |
7664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7665 | struct sk_buff *msg; | |
7666 | void *hdr; | |
2a0e047e | 7667 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7668 | |
2a0e047e JB |
7669 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7670 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7671 | return -EOPNOTSUPP; |
7672 | ||
2a0e047e JB |
7673 | if (rdev->wowlan && rdev->wowlan->tcp) { |
7674 | /* adjust size to have room for all the data */ | |
7675 | size += rdev->wowlan->tcp->tokens_size + | |
7676 | rdev->wowlan->tcp->payload_len + | |
7677 | rdev->wowlan->tcp->wake_len + | |
7678 | rdev->wowlan->tcp->wake_len / 8; | |
7679 | } | |
7680 | ||
7681 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7682 | if (!msg) |
7683 | return -ENOMEM; | |
7684 | ||
15e47304 | 7685 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7686 | NL80211_CMD_GET_WOWLAN); |
7687 | if (!hdr) | |
7688 | goto nla_put_failure; | |
7689 | ||
7690 | if (rdev->wowlan) { | |
7691 | struct nlattr *nl_wowlan; | |
7692 | ||
7693 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7694 | if (!nl_wowlan) | |
7695 | goto nla_put_failure; | |
7696 | ||
9360ffd1 DM |
7697 | if ((rdev->wowlan->any && |
7698 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7699 | (rdev->wowlan->disconnect && | |
7700 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7701 | (rdev->wowlan->magic_pkt && | |
7702 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7703 | (rdev->wowlan->gtk_rekey_failure && | |
7704 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7705 | (rdev->wowlan->eap_identity_req && | |
7706 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7707 | (rdev->wowlan->four_way_handshake && | |
7708 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7709 | (rdev->wowlan->rfkill_release && | |
7710 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
7711 | goto nla_put_failure; | |
2a0e047e | 7712 | |
bb92d199 AK |
7713 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7714 | goto nla_put_failure; | |
2a0e047e JB |
7715 | |
7716 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) | |
7717 | goto nla_put_failure; | |
7718 | ||
ff1b6e69 JB |
7719 | nla_nest_end(msg, nl_wowlan); |
7720 | } | |
7721 | ||
7722 | genlmsg_end(msg, hdr); | |
7723 | return genlmsg_reply(msg, info); | |
7724 | ||
7725 | nla_put_failure: | |
7726 | nlmsg_free(msg); | |
7727 | return -ENOBUFS; | |
7728 | } | |
7729 | ||
2a0e047e JB |
7730 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7731 | struct nlattr *attr, | |
7732 | struct cfg80211_wowlan *trig) | |
7733 | { | |
7734 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7735 | struct cfg80211_wowlan_tcp *cfg; | |
7736 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7737 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7738 | u32 size; | |
7739 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7740 | int err, port; | |
7741 | ||
7742 | if (!rdev->wiphy.wowlan.tcp) | |
7743 | return -EINVAL; | |
7744 | ||
7745 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7746 | nla_data(attr), nla_len(attr), | |
7747 | nl80211_wowlan_tcp_policy); | |
7748 | if (err) | |
7749 | return err; | |
7750 | ||
7751 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7752 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7753 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7754 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7755 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7756 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7757 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7758 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7759 | return -EINVAL; | |
7760 | ||
7761 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
7762 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) | |
7763 | return -EINVAL; | |
7764 | ||
7765 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
723d568a JB |
7766 | rdev->wiphy.wowlan.tcp->data_interval_max || |
7767 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) | |
2a0e047e JB |
7768 | return -EINVAL; |
7769 | ||
7770 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
7771 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) | |
7772 | return -EINVAL; | |
7773 | ||
7774 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7775 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7776 | return -EINVAL; | |
7777 | ||
7778 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7779 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7780 | ||
7781 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7782 | tokens_size = tokln - sizeof(*tok); | |
7783 | ||
7784 | if (!tok->len || tokens_size % tok->len) | |
7785 | return -EINVAL; | |
7786 | if (!rdev->wiphy.wowlan.tcp->tok) | |
7787 | return -EINVAL; | |
7788 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) | |
7789 | return -EINVAL; | |
7790 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) | |
7791 | return -EINVAL; | |
7792 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) | |
7793 | return -EINVAL; | |
7794 | if (tok->offset + tok->len > data_size) | |
7795 | return -EINVAL; | |
7796 | } | |
7797 | ||
7798 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7799 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
7800 | if (!rdev->wiphy.wowlan.tcp->seq) | |
7801 | return -EINVAL; | |
7802 | if (seq->len == 0 || seq->len > 4) | |
7803 | return -EINVAL; | |
7804 | if (seq->len + seq->offset > data_size) | |
7805 | return -EINVAL; | |
7806 | } | |
7807 | ||
7808 | size = sizeof(*cfg); | |
7809 | size += data_size; | |
7810 | size += wake_size + wake_mask_size; | |
7811 | size += tokens_size; | |
7812 | ||
7813 | cfg = kzalloc(size, GFP_KERNEL); | |
7814 | if (!cfg) | |
7815 | return -ENOMEM; | |
7816 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7817 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7818 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7819 | ETH_ALEN); | |
7820 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7821 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7822 | else | |
7823 | port = 0; | |
7824 | #ifdef CONFIG_INET | |
7825 | /* allocate a socket and port for it and use it */ | |
7826 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7827 | IPPROTO_TCP, &cfg->sock, 1); | |
7828 | if (err) { | |
7829 | kfree(cfg); | |
7830 | return err; | |
7831 | } | |
7832 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7833 | sock_release(cfg->sock); | |
7834 | kfree(cfg); | |
7835 | return -EADDRINUSE; | |
7836 | } | |
7837 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7838 | #else | |
7839 | if (!port) { | |
7840 | kfree(cfg); | |
7841 | return -EINVAL; | |
7842 | } | |
7843 | cfg->src_port = port; | |
7844 | #endif | |
7845 | ||
7846 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7847 | cfg->payload_len = data_size; | |
7848 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7849 | memcpy((void *)cfg->payload, | |
7850 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7851 | data_size); | |
7852 | if (seq) | |
7853 | cfg->payload_seq = *seq; | |
7854 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7855 | cfg->wake_len = wake_size; | |
7856 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7857 | memcpy((void *)cfg->wake_data, | |
7858 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7859 | wake_size); | |
7860 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7861 | data_size + wake_size; | |
7862 | memcpy((void *)cfg->wake_mask, | |
7863 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7864 | wake_mask_size); | |
7865 | if (tok) { | |
7866 | cfg->tokens_size = tokens_size; | |
7867 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7868 | } | |
7869 | ||
7870 | trig->tcp = cfg; | |
7871 | ||
7872 | return 0; | |
7873 | } | |
7874 | ||
ff1b6e69 JB |
7875 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7876 | { | |
7877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7878 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7879 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7880 | struct cfg80211_wowlan *ntrig; |
ff1b6e69 JB |
7881 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
7882 | int err, i; | |
6d52563f | 7883 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 | 7884 | |
2a0e047e JB |
7885 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7886 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7887 | return -EOPNOTSUPP; |
7888 | ||
ae33bd81 JB |
7889 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7890 | cfg80211_rdev_free_wowlan(rdev); | |
7891 | rdev->wowlan = NULL; | |
7892 | goto set_wakeup; | |
7893 | } | |
ff1b6e69 JB |
7894 | |
7895 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7896 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7897 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7898 | nl80211_wowlan_policy); | |
7899 | if (err) | |
7900 | return err; | |
7901 | ||
7902 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7903 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7904 | return -EINVAL; | |
7905 | new_triggers.any = true; | |
7906 | } | |
7907 | ||
7908 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7909 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7910 | return -EINVAL; | |
7911 | new_triggers.disconnect = true; | |
7912 | } | |
7913 | ||
7914 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7915 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7916 | return -EINVAL; | |
7917 | new_triggers.magic_pkt = true; | |
7918 | } | |
7919 | ||
77dbbb13 JB |
7920 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7921 | return -EINVAL; | |
7922 | ||
7923 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7924 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7925 | return -EINVAL; | |
7926 | new_triggers.gtk_rekey_failure = true; | |
7927 | } | |
7928 | ||
7929 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7930 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7931 | return -EINVAL; | |
7932 | new_triggers.eap_identity_req = true; | |
7933 | } | |
7934 | ||
7935 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7936 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7937 | return -EINVAL; | |
7938 | new_triggers.four_way_handshake = true; | |
7939 | } | |
7940 | ||
7941 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7942 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7943 | return -EINVAL; | |
7944 | new_triggers.rfkill_release = true; | |
7945 | } | |
7946 | ||
ff1b6e69 JB |
7947 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7948 | struct nlattr *pat; | |
7949 | int n_patterns = 0; | |
bb92d199 | 7950 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7951 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7952 | ||
7953 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7954 | rem) | |
7955 | n_patterns++; | |
7956 | if (n_patterns > wowlan->n_patterns) | |
7957 | return -EINVAL; | |
7958 | ||
7959 | new_triggers.patterns = kcalloc(n_patterns, | |
7960 | sizeof(new_triggers.patterns[0]), | |
7961 | GFP_KERNEL); | |
7962 | if (!new_triggers.patterns) | |
7963 | return -ENOMEM; | |
7964 | ||
7965 | new_triggers.n_patterns = n_patterns; | |
7966 | i = 0; | |
7967 | ||
7968 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7969 | rem) { | |
7970 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7971 | nla_data(pat), nla_len(pat), NULL); | |
7972 | err = -EINVAL; | |
7973 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7974 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7975 | goto error; | |
7976 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7977 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7978 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7979 | mask_len) | |
7980 | goto error; | |
7981 | if (pat_len > wowlan->pattern_max_len || | |
7982 | pat_len < wowlan->pattern_min_len) | |
7983 | goto error; | |
7984 | ||
bb92d199 AK |
7985 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7986 | pkt_offset = 0; | |
7987 | else | |
7988 | pkt_offset = nla_get_u32( | |
7989 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7990 | if (pkt_offset > wowlan->max_pkt_offset) | |
7991 | goto error; | |
7992 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7993 | ||
ff1b6e69 JB |
7994 | new_triggers.patterns[i].mask = |
7995 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7996 | if (!new_triggers.patterns[i].mask) { | |
7997 | err = -ENOMEM; | |
7998 | goto error; | |
7999 | } | |
8000 | new_triggers.patterns[i].pattern = | |
8001 | new_triggers.patterns[i].mask + mask_len; | |
8002 | memcpy(new_triggers.patterns[i].mask, | |
8003 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
8004 | mask_len); | |
8005 | new_triggers.patterns[i].pattern_len = pat_len; | |
8006 | memcpy(new_triggers.patterns[i].pattern, | |
8007 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
8008 | pat_len); | |
8009 | i++; | |
8010 | } | |
8011 | } | |
8012 | ||
2a0e047e JB |
8013 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8014 | err = nl80211_parse_wowlan_tcp( | |
8015 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8016 | &new_triggers); | |
8017 | if (err) | |
8018 | goto error; | |
8019 | } | |
8020 | ||
ae33bd81 JB |
8021 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8022 | if (!ntrig) { | |
8023 | err = -ENOMEM; | |
8024 | goto error; | |
ff1b6e69 | 8025 | } |
ae33bd81 JB |
8026 | cfg80211_rdev_free_wowlan(rdev); |
8027 | rdev->wowlan = ntrig; | |
ff1b6e69 | 8028 | |
ae33bd81 | 8029 | set_wakeup: |
6d52563f | 8030 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
e35e4d28 | 8031 | rdev_set_wakeup(rdev, rdev->wowlan); |
6d52563f | 8032 | |
ff1b6e69 JB |
8033 | return 0; |
8034 | error: | |
8035 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8036 | kfree(new_triggers.patterns[i].mask); | |
8037 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8038 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8039 | sock_release(new_triggers.tcp->sock); | |
8040 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8041 | return err; |
8042 | } | |
dfb89c56 | 8043 | #endif |
ff1b6e69 | 8044 | |
e5497d76 JB |
8045 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8046 | { | |
8047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8048 | struct net_device *dev = info->user_ptr[1]; | |
8049 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8050 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8051 | struct cfg80211_gtk_rekey_data rekey_data; | |
8052 | int err; | |
8053 | ||
8054 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8055 | return -EINVAL; | |
8056 | ||
8057 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8058 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8059 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8060 | nl80211_rekey_policy); | |
8061 | if (err) | |
8062 | return err; | |
8063 | ||
44ec9689 VD |
8064 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
8065 | !tb[NL80211_REKEY_DATA_KCK]) | |
8066 | return -EINVAL; | |
e5497d76 JB |
8067 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
8068 | return -ERANGE; | |
8069 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8070 | return -ERANGE; | |
8071 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8072 | return -ERANGE; | |
8073 | ||
8074 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8075 | NL80211_KEK_LEN); | |
8076 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8077 | NL80211_KCK_LEN); | |
8078 | memcpy(rekey_data.replay_ctr, | |
8079 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8080 | NL80211_REPLAY_CTR_LEN); | |
8081 | ||
8082 | wdev_lock(wdev); | |
8083 | if (!wdev->current_bss) { | |
8084 | err = -ENOTCONN; | |
8085 | goto out; | |
8086 | } | |
8087 | ||
8088 | if (!rdev->ops->set_rekey_data) { | |
8089 | err = -EOPNOTSUPP; | |
8090 | goto out; | |
8091 | } | |
8092 | ||
e35e4d28 | 8093 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8094 | out: |
8095 | wdev_unlock(wdev); | |
8096 | return err; | |
8097 | } | |
8098 | ||
28946da7 JB |
8099 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8100 | struct genl_info *info) | |
8101 | { | |
8102 | struct net_device *dev = info->user_ptr[1]; | |
8103 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8104 | ||
8105 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8106 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8107 | return -EINVAL; | |
8108 | ||
15e47304 | 8109 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8110 | return -EBUSY; |
8111 | ||
15e47304 | 8112 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8113 | return 0; |
8114 | } | |
8115 | ||
7f6cf311 JB |
8116 | static int nl80211_probe_client(struct sk_buff *skb, |
8117 | struct genl_info *info) | |
8118 | { | |
8119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8120 | struct net_device *dev = info->user_ptr[1]; | |
8121 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8122 | struct sk_buff *msg; | |
8123 | void *hdr; | |
8124 | const u8 *addr; | |
8125 | u64 cookie; | |
8126 | int err; | |
8127 | ||
8128 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8129 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8130 | return -EOPNOTSUPP; | |
8131 | ||
8132 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8133 | return -EINVAL; | |
8134 | ||
8135 | if (!rdev->ops->probe_client) | |
8136 | return -EOPNOTSUPP; | |
8137 | ||
8138 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8139 | if (!msg) | |
8140 | return -ENOMEM; | |
8141 | ||
15e47304 | 8142 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 8143 | NL80211_CMD_PROBE_CLIENT); |
6fa3eb70 S |
8144 | if (!hdr) { |
8145 | err = -ENOBUFS; | |
7f6cf311 JB |
8146 | goto free_msg; |
8147 | } | |
8148 | ||
8149 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8150 | ||
e35e4d28 | 8151 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8152 | if (err) |
8153 | goto free_msg; | |
8154 | ||
9360ffd1 DM |
8155 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8156 | goto nla_put_failure; | |
7f6cf311 JB |
8157 | |
8158 | genlmsg_end(msg, hdr); | |
8159 | ||
8160 | return genlmsg_reply(msg, info); | |
8161 | ||
8162 | nla_put_failure: | |
8163 | err = -ENOBUFS; | |
8164 | free_msg: | |
8165 | nlmsg_free(msg); | |
8166 | return err; | |
8167 | } | |
8168 | ||
5e760230 JB |
8169 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8170 | { | |
8171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8172 | struct cfg80211_beacon_registration *reg, *nreg; |
8173 | int rv; | |
5e760230 JB |
8174 | |
8175 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8176 | return -EOPNOTSUPP; | |
8177 | ||
37c73b5f BG |
8178 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8179 | if (!nreg) | |
8180 | return -ENOMEM; | |
8181 | ||
8182 | /* First, check if already registered. */ | |
8183 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8184 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8185 | if (reg->nlportid == info->snd_portid) { | |
8186 | rv = -EALREADY; | |
8187 | goto out_err; | |
8188 | } | |
8189 | } | |
8190 | /* Add it to the list */ | |
8191 | nreg->nlportid = info->snd_portid; | |
8192 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8193 | |
37c73b5f | 8194 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8195 | |
8196 | return 0; | |
37c73b5f BG |
8197 | out_err: |
8198 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8199 | kfree(nreg); | |
8200 | return rv; | |
5e760230 JB |
8201 | } |
8202 | ||
98104fde JB |
8203 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8204 | { | |
8205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8206 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8207 | int err; | |
8208 | ||
8209 | if (!rdev->ops->start_p2p_device) | |
8210 | return -EOPNOTSUPP; | |
8211 | ||
8212 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8213 | return -EOPNOTSUPP; | |
8214 | ||
8215 | if (wdev->p2p_started) | |
8216 | return 0; | |
8217 | ||
8218 | mutex_lock(&rdev->devlist_mtx); | |
8219 | err = cfg80211_can_add_interface(rdev, wdev->iftype); | |
8220 | mutex_unlock(&rdev->devlist_mtx); | |
8221 | if (err) | |
8222 | return err; | |
8223 | ||
eeb126e9 | 8224 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8225 | if (err) |
8226 | return err; | |
8227 | ||
8228 | wdev->p2p_started = true; | |
8229 | mutex_lock(&rdev->devlist_mtx); | |
8230 | rdev->opencount++; | |
8231 | mutex_unlock(&rdev->devlist_mtx); | |
8232 | ||
8233 | return 0; | |
8234 | } | |
8235 | ||
8236 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8237 | { | |
8238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8239 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8240 | ||
8241 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8242 | return -EOPNOTSUPP; | |
8243 | ||
8244 | if (!rdev->ops->stop_p2p_device) | |
8245 | return -EOPNOTSUPP; | |
8246 | ||
65e8d5b8 | 8247 | mutex_lock(&rdev->devlist_mtx); |
f9f47529 JB |
8248 | mutex_lock(&rdev->sched_scan_mtx); |
8249 | cfg80211_stop_p2p_device(rdev, wdev); | |
8250 | mutex_unlock(&rdev->sched_scan_mtx); | |
65e8d5b8 | 8251 | mutex_unlock(&rdev->devlist_mtx); |
98104fde JB |
8252 | |
8253 | return 0; | |
8254 | } | |
8255 | ||
3713b4e3 JB |
8256 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8257 | struct genl_info *info) | |
8258 | { | |
8259 | void *hdr; | |
8260 | struct sk_buff *msg; | |
8261 | ||
8262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8263 | if (!msg) | |
8264 | return -ENOMEM; | |
8265 | ||
8266 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8267 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8268 | if (!hdr) | |
8269 | goto nla_put_failure; | |
8270 | ||
8271 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8272 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8273 | goto nla_put_failure; | |
8274 | ||
8275 | genlmsg_end(msg, hdr); | |
8276 | return genlmsg_reply(msg, info); | |
8277 | ||
8278 | nla_put_failure: | |
8279 | kfree_skb(msg); | |
8280 | return -ENOBUFS; | |
8281 | } | |
8282 | ||
355199e0 JM |
8283 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8284 | { | |
8285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8286 | struct cfg80211_update_ft_ies_params ft_params; | |
8287 | struct net_device *dev = info->user_ptr[1]; | |
8288 | ||
8289 | if (!rdev->ops->update_ft_ies) | |
8290 | return -EOPNOTSUPP; | |
8291 | ||
8292 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8293 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8294 | return -EINVAL; | |
8295 | ||
8296 | memset(&ft_params, 0, sizeof(ft_params)); | |
8297 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8298 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8299 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8300 | ||
8301 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8302 | } | |
8303 | ||
5de17984 AS |
8304 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8305 | struct genl_info *info) | |
8306 | { | |
8307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8308 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8309 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8310 | u16 duration; | |
8311 | int ret; | |
8312 | ||
8313 | if (!rdev->ops->crit_proto_start) | |
8314 | return -EOPNOTSUPP; | |
8315 | ||
8316 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8317 | return -EINVAL; | |
8318 | ||
8319 | if (rdev->crit_proto_nlportid) | |
8320 | return -EBUSY; | |
8321 | ||
8322 | /* determine protocol if provided */ | |
8323 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8324 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8325 | ||
8326 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8327 | return -EINVAL; | |
8328 | ||
8329 | /* timeout must be provided */ | |
8330 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8331 | return -EINVAL; | |
8332 | ||
8333 | duration = | |
8334 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8335 | ||
8336 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8337 | return -ERANGE; | |
8338 | ||
8339 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8340 | if (!ret) | |
8341 | rdev->crit_proto_nlportid = info->snd_portid; | |
8342 | ||
8343 | return ret; | |
8344 | } | |
8345 | ||
8346 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8347 | struct genl_info *info) | |
8348 | { | |
8349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8350 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8351 | ||
8352 | if (!rdev->ops->crit_proto_stop) | |
8353 | return -EOPNOTSUPP; | |
8354 | ||
8355 | if (rdev->crit_proto_nlportid) { | |
8356 | rdev->crit_proto_nlportid = 0; | |
8357 | rdev_crit_proto_stop(rdev, wdev); | |
8358 | } | |
8359 | return 0; | |
8360 | } | |
8361 | ||
6fa3eb70 S |
8362 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
8363 | { | |
8364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8365 | struct wireless_dev *wdev = | |
8366 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
8367 | int i, err; | |
8368 | u32 vid, subcmd; | |
8369 | ||
8370 | if (!rdev || !rdev->wiphy.vendor_commands) | |
8371 | return -EOPNOTSUPP; | |
8372 | ||
8373 | if (IS_ERR(wdev)) { | |
8374 | err = PTR_ERR(wdev); | |
8375 | if (err != -EINVAL) | |
8376 | return err; | |
8377 | wdev = NULL; | |
8378 | } else if (wdev->wiphy != &rdev->wiphy) { | |
8379 | return -EINVAL; | |
8380 | } | |
8381 | ||
8382 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
8383 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
8384 | return -EINVAL; | |
8385 | ||
8386 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
8387 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
8388 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
8389 | const struct wiphy_vendor_command *vcmd; | |
8390 | void *data = NULL; | |
8391 | int len = 0; | |
8392 | ||
8393 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
8394 | ||
8395 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
8396 | continue; | |
8397 | ||
8398 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
8399 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
8400 | if (!wdev) | |
8401 | return -EINVAL; | |
8402 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
8403 | !wdev->netdev) | |
8404 | return -EINVAL; | |
8405 | ||
8406 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
8407 | if (!wdev->netdev || | |
8408 | !netif_running(wdev->netdev)) | |
8409 | return -ENETDOWN; | |
8410 | } | |
8411 | } else { | |
8412 | wdev = NULL; | |
8413 | } | |
8414 | ||
8415 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
8416 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
8417 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
8418 | } | |
8419 | ||
8420 | rdev->cur_cmd_info = info; | |
8421 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
8422 | data, len); | |
8423 | rdev->cur_cmd_info = NULL; | |
8424 | return err; | |
8425 | } | |
8426 | ||
8427 | return -EOPNOTSUPP; | |
8428 | } | |
8429 | ||
8430 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
8431 | enum nl80211_commands cmd, | |
8432 | enum nl80211_attrs attr, | |
8433 | int approxlen) | |
8434 | { | |
8435 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
8436 | ||
8437 | if (WARN_ON(!rdev->cur_cmd_info)) | |
8438 | return NULL; | |
8439 | ||
8440 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
8441 | 0, | |
8442 | 0, | |
8443 | cmd, attr, NULL, GFP_KERNEL); | |
8444 | } | |
8445 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
8446 | ||
8447 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
8448 | { | |
8449 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
8450 | void *hdr = ((void **)skb->cb)[1]; | |
8451 | struct nlattr *data = ((void **)skb->cb)[2]; | |
8452 | ||
8453 | if (WARN_ON(!rdev->cur_cmd_info)) { | |
8454 | kfree_skb(skb); | |
8455 | return -EINVAL; | |
8456 | } | |
8457 | ||
8458 | nla_nest_end(skb, data); | |
8459 | genlmsg_end(skb, hdr); | |
8460 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
8461 | } | |
8462 | EXPORT_SYMBOL(cfg80211_vendor_cmd_reply); | |
8463 | ||
4c476991 JB |
8464 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8465 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8466 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8467 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8468 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8469 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8470 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8471 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8472 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8473 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8474 | |
8475 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8476 | struct genl_info *info) | |
8477 | { | |
8478 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8479 | struct wireless_dev *wdev; |
4c476991 | 8480 | struct net_device *dev; |
4c476991 JB |
8481 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8482 | ||
8483 | if (rtnl) | |
8484 | rtnl_lock(); | |
8485 | ||
8486 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8487 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8488 | if (IS_ERR(rdev)) { |
8489 | if (rtnl) | |
8490 | rtnl_unlock(); | |
8491 | return PTR_ERR(rdev); | |
8492 | } | |
8493 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8494 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8495 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
89a54e48 JB |
8496 | mutex_lock(&cfg80211_mutex); |
8497 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | |
8498 | info->attrs); | |
8499 | if (IS_ERR(wdev)) { | |
8500 | mutex_unlock(&cfg80211_mutex); | |
4c476991 JB |
8501 | if (rtnl) |
8502 | rtnl_unlock(); | |
89a54e48 | 8503 | return PTR_ERR(wdev); |
4c476991 | 8504 | } |
89a54e48 | 8505 | |
89a54e48 JB |
8506 | dev = wdev->netdev; |
8507 | rdev = wiphy_to_dev(wdev->wiphy); | |
8508 | ||
1bf614ef JB |
8509 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8510 | if (!dev) { | |
8511 | mutex_unlock(&cfg80211_mutex); | |
8512 | if (rtnl) | |
8513 | rtnl_unlock(); | |
8514 | return -EINVAL; | |
8515 | } | |
8516 | ||
8517 | info->user_ptr[1] = dev; | |
8518 | } else { | |
8519 | info->user_ptr[1] = wdev; | |
41265714 | 8520 | } |
1bf614ef JB |
8521 | |
8522 | if (dev) { | |
8523 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8524 | !netif_running(dev)) { | |
8525 | mutex_unlock(&cfg80211_mutex); | |
8526 | if (rtnl) | |
8527 | rtnl_unlock(); | |
8528 | return -ENETDOWN; | |
8529 | } | |
8530 | ||
8531 | dev_hold(dev); | |
98104fde JB |
8532 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8533 | if (!wdev->p2p_started) { | |
8534 | mutex_unlock(&cfg80211_mutex); | |
8535 | if (rtnl) | |
8536 | rtnl_unlock(); | |
8537 | return -ENETDOWN; | |
8538 | } | |
41265714 | 8539 | } |
89a54e48 | 8540 | |
89a54e48 JB |
8541 | cfg80211_lock_rdev(rdev); |
8542 | ||
8543 | mutex_unlock(&cfg80211_mutex); | |
8544 | ||
4c476991 | 8545 | info->user_ptr[0] = rdev; |
4c476991 JB |
8546 | } |
8547 | ||
8548 | return 0; | |
8549 | } | |
8550 | ||
8551 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8552 | struct genl_info *info) | |
8553 | { | |
8554 | if (info->user_ptr[0]) | |
8555 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
1bf614ef JB |
8556 | if (info->user_ptr[1]) { |
8557 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8558 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8559 | ||
8560 | if (wdev->netdev) | |
8561 | dev_put(wdev->netdev); | |
8562 | } else { | |
8563 | dev_put(info->user_ptr[1]); | |
8564 | } | |
8565 | } | |
4c476991 JB |
8566 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8567 | rtnl_unlock(); | |
8568 | } | |
8569 | ||
55682965 JB |
8570 | static struct genl_ops nl80211_ops[] = { |
8571 | { | |
8572 | .cmd = NL80211_CMD_GET_WIPHY, | |
8573 | .doit = nl80211_get_wiphy, | |
8574 | .dumpit = nl80211_dump_wiphy, | |
8575 | .policy = nl80211_policy, | |
8576 | /* can be retrieved by unprivileged users */ | |
4c476991 | 8577 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
8578 | }, |
8579 | { | |
8580 | .cmd = NL80211_CMD_SET_WIPHY, | |
8581 | .doit = nl80211_set_wiphy, | |
8582 | .policy = nl80211_policy, | |
8583 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8584 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8585 | }, |
8586 | { | |
8587 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8588 | .doit = nl80211_get_interface, | |
8589 | .dumpit = nl80211_dump_interface, | |
8590 | .policy = nl80211_policy, | |
8591 | /* can be retrieved by unprivileged users */ | |
72fb2abc | 8592 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
55682965 JB |
8593 | }, |
8594 | { | |
8595 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8596 | .doit = nl80211_set_interface, | |
8597 | .policy = nl80211_policy, | |
8598 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8599 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8600 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8601 | }, |
8602 | { | |
8603 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8604 | .doit = nl80211_new_interface, | |
8605 | .policy = nl80211_policy, | |
8606 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8607 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8608 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8609 | }, |
8610 | { | |
8611 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8612 | .doit = nl80211_del_interface, | |
8613 | .policy = nl80211_policy, | |
41ade00f | 8614 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8615 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8616 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8617 | }, |
8618 | { | |
8619 | .cmd = NL80211_CMD_GET_KEY, | |
8620 | .doit = nl80211_get_key, | |
8621 | .policy = nl80211_policy, | |
8622 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8624 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8625 | }, |
8626 | { | |
8627 | .cmd = NL80211_CMD_SET_KEY, | |
8628 | .doit = nl80211_set_key, | |
8629 | .policy = nl80211_policy, | |
8630 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8632 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8633 | }, |
8634 | { | |
8635 | .cmd = NL80211_CMD_NEW_KEY, | |
8636 | .doit = nl80211_new_key, | |
8637 | .policy = nl80211_policy, | |
8638 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8640 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8641 | }, |
8642 | { | |
8643 | .cmd = NL80211_CMD_DEL_KEY, | |
8644 | .doit = nl80211_del_key, | |
8645 | .policy = nl80211_policy, | |
55682965 | 8646 | .flags = GENL_ADMIN_PERM, |
41265714 | 8647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8648 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8649 | }, |
ed1b6cc7 JB |
8650 | { |
8651 | .cmd = NL80211_CMD_SET_BEACON, | |
8652 | .policy = nl80211_policy, | |
8653 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8654 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8656 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8657 | }, |
8658 | { | |
8860020e | 8659 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8660 | .policy = nl80211_policy, |
8661 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8662 | .doit = nl80211_start_ap, |
2b5f8b0b | 8663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8664 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8665 | }, |
8666 | { | |
8860020e | 8667 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8668 | .policy = nl80211_policy, |
8669 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8670 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8672 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8673 | }, |
5727ef1b JB |
8674 | { |
8675 | .cmd = NL80211_CMD_GET_STATION, | |
8676 | .doit = nl80211_get_station, | |
2ec600d6 | 8677 | .dumpit = nl80211_dump_station, |
5727ef1b | 8678 | .policy = nl80211_policy, |
4c476991 JB |
8679 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8680 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8681 | }, |
8682 | { | |
8683 | .cmd = NL80211_CMD_SET_STATION, | |
8684 | .doit = nl80211_set_station, | |
8685 | .policy = nl80211_policy, | |
8686 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8687 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8688 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8689 | }, |
8690 | { | |
8691 | .cmd = NL80211_CMD_NEW_STATION, | |
8692 | .doit = nl80211_new_station, | |
8693 | .policy = nl80211_policy, | |
8694 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8695 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8696 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8697 | }, |
8698 | { | |
8699 | .cmd = NL80211_CMD_DEL_STATION, | |
8700 | .doit = nl80211_del_station, | |
8701 | .policy = nl80211_policy, | |
2ec600d6 | 8702 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8703 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8704 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8705 | }, |
8706 | { | |
8707 | .cmd = NL80211_CMD_GET_MPATH, | |
8708 | .doit = nl80211_get_mpath, | |
8709 | .dumpit = nl80211_dump_mpath, | |
8710 | .policy = nl80211_policy, | |
8711 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8712 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8713 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8714 | }, |
8715 | { | |
8716 | .cmd = NL80211_CMD_SET_MPATH, | |
8717 | .doit = nl80211_set_mpath, | |
8718 | .policy = nl80211_policy, | |
8719 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8720 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8721 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8722 | }, |
8723 | { | |
8724 | .cmd = NL80211_CMD_NEW_MPATH, | |
8725 | .doit = nl80211_new_mpath, | |
8726 | .policy = nl80211_policy, | |
8727 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8728 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8729 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8730 | }, |
8731 | { | |
8732 | .cmd = NL80211_CMD_DEL_MPATH, | |
8733 | .doit = nl80211_del_mpath, | |
8734 | .policy = nl80211_policy, | |
9f1ba906 | 8735 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8737 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8738 | }, |
8739 | { | |
8740 | .cmd = NL80211_CMD_SET_BSS, | |
8741 | .doit = nl80211_set_bss, | |
8742 | .policy = nl80211_policy, | |
b2e1b302 | 8743 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8745 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8746 | }, |
f130347c LR |
8747 | { |
8748 | .cmd = NL80211_CMD_GET_REG, | |
8749 | .doit = nl80211_get_reg, | |
8750 | .policy = nl80211_policy, | |
8751 | /* can be retrieved by unprivileged users */ | |
8752 | }, | |
b2e1b302 LR |
8753 | { |
8754 | .cmd = NL80211_CMD_SET_REG, | |
8755 | .doit = nl80211_set_reg, | |
8756 | .policy = nl80211_policy, | |
8757 | .flags = GENL_ADMIN_PERM, | |
8758 | }, | |
8759 | { | |
8760 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8761 | .doit = nl80211_req_set_reg, | |
8762 | .policy = nl80211_policy, | |
93da9cc1 | 8763 | .flags = GENL_ADMIN_PERM, |
8764 | }, | |
8765 | { | |
24bdd9f4 JC |
8766 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8767 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8768 | .policy = nl80211_policy, |
8769 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8771 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8772 | }, |
8773 | { | |
24bdd9f4 JC |
8774 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8775 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8776 | .policy = nl80211_policy, |
9aed3cc1 | 8777 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8779 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8780 | }, |
2a519311 JB |
8781 | { |
8782 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8783 | .doit = nl80211_trigger_scan, | |
8784 | .policy = nl80211_policy, | |
8785 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8786 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8787 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8788 | }, |
8789 | { | |
8790 | .cmd = NL80211_CMD_GET_SCAN, | |
8791 | .policy = nl80211_policy, | |
8792 | .dumpit = nl80211_dump_scan, | |
8793 | }, | |
807f8a8c LC |
8794 | { |
8795 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8796 | .doit = nl80211_start_sched_scan, | |
8797 | .policy = nl80211_policy, | |
8798 | .flags = GENL_ADMIN_PERM, | |
8799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8800 | NL80211_FLAG_NEED_RTNL, | |
8801 | }, | |
8802 | { | |
8803 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8804 | .doit = nl80211_stop_sched_scan, | |
8805 | .policy = nl80211_policy, | |
8806 | .flags = GENL_ADMIN_PERM, | |
8807 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8808 | NL80211_FLAG_NEED_RTNL, | |
8809 | }, | |
636a5d36 JM |
8810 | { |
8811 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8812 | .doit = nl80211_authenticate, | |
8813 | .policy = nl80211_policy, | |
8814 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8815 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8816 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8817 | }, |
8818 | { | |
8819 | .cmd = NL80211_CMD_ASSOCIATE, | |
8820 | .doit = nl80211_associate, | |
8821 | .policy = nl80211_policy, | |
8822 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8824 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8825 | }, |
8826 | { | |
8827 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8828 | .doit = nl80211_deauthenticate, | |
8829 | .policy = nl80211_policy, | |
8830 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8832 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8833 | }, |
8834 | { | |
8835 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8836 | .doit = nl80211_disassociate, | |
8837 | .policy = nl80211_policy, | |
8838 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8840 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8841 | }, |
04a773ad JB |
8842 | { |
8843 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8844 | .doit = nl80211_join_ibss, | |
8845 | .policy = nl80211_policy, | |
8846 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8847 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8848 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8849 | }, |
8850 | { | |
8851 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8852 | .doit = nl80211_leave_ibss, | |
8853 | .policy = nl80211_policy, | |
8854 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8855 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8856 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8857 | }, |
aff89a9b JB |
8858 | #ifdef CONFIG_NL80211_TESTMODE |
8859 | { | |
8860 | .cmd = NL80211_CMD_TESTMODE, | |
8861 | .doit = nl80211_testmode_do, | |
71063f0e | 8862 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8863 | .policy = nl80211_policy, |
8864 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8865 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8866 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8867 | }, |
8868 | #endif | |
b23aa676 SO |
8869 | { |
8870 | .cmd = NL80211_CMD_CONNECT, | |
8871 | .doit = nl80211_connect, | |
8872 | .policy = nl80211_policy, | |
8873 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8875 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8876 | }, |
8877 | { | |
8878 | .cmd = NL80211_CMD_DISCONNECT, | |
8879 | .doit = nl80211_disconnect, | |
8880 | .policy = nl80211_policy, | |
8881 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8882 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8883 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8884 | }, |
463d0183 JB |
8885 | { |
8886 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8887 | .doit = nl80211_wiphy_netns, | |
8888 | .policy = nl80211_policy, | |
8889 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8890 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8891 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8892 | }, |
61fa713c HS |
8893 | { |
8894 | .cmd = NL80211_CMD_GET_SURVEY, | |
8895 | .policy = nl80211_policy, | |
8896 | .dumpit = nl80211_dump_survey, | |
8897 | }, | |
67fbb16b SO |
8898 | { |
8899 | .cmd = NL80211_CMD_SET_PMKSA, | |
8900 | .doit = nl80211_setdel_pmksa, | |
8901 | .policy = nl80211_policy, | |
8902 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8903 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8904 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8905 | }, |
8906 | { | |
8907 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8908 | .doit = nl80211_setdel_pmksa, | |
8909 | .policy = nl80211_policy, | |
8910 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8911 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8912 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8913 | }, |
8914 | { | |
8915 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8916 | .doit = nl80211_flush_pmksa, | |
8917 | .policy = nl80211_policy, | |
8918 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8919 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8920 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8921 | }, |
9588bbd5 JM |
8922 | { |
8923 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8924 | .doit = nl80211_remain_on_channel, | |
8925 | .policy = nl80211_policy, | |
8926 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8927 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8928 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8929 | }, |
8930 | { | |
8931 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8932 | .doit = nl80211_cancel_remain_on_channel, | |
8933 | .policy = nl80211_policy, | |
8934 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8935 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8936 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8937 | }, |
13ae75b1 JM |
8938 | { |
8939 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8940 | .doit = nl80211_set_tx_bitrate_mask, | |
8941 | .policy = nl80211_policy, | |
8942 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8943 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8944 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8945 | }, |
026331c4 | 8946 | { |
2e161f78 JB |
8947 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8948 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8949 | .policy = nl80211_policy, |
8950 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8951 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8952 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8953 | }, |
8954 | { | |
2e161f78 JB |
8955 | .cmd = NL80211_CMD_FRAME, |
8956 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8957 | .policy = nl80211_policy, |
f7ca38df | 8958 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8959 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8960 | NL80211_FLAG_NEED_RTNL, |
8961 | }, | |
8962 | { | |
8963 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8964 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8965 | .policy = nl80211_policy, | |
026331c4 | 8966 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8967 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8968 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8969 | }, |
ffb9eb3d KV |
8970 | { |
8971 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8972 | .doit = nl80211_set_power_save, | |
8973 | .policy = nl80211_policy, | |
8974 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8975 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8976 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8977 | }, |
8978 | { | |
8979 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8980 | .doit = nl80211_get_power_save, | |
8981 | .policy = nl80211_policy, | |
8982 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8983 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8984 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8985 | }, |
d6dc1a38 JO |
8986 | { |
8987 | .cmd = NL80211_CMD_SET_CQM, | |
8988 | .doit = nl80211_set_cqm, | |
8989 | .policy = nl80211_policy, | |
8990 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8991 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8992 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8993 | }, |
f444de05 JB |
8994 | { |
8995 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8996 | .doit = nl80211_set_channel, | |
8997 | .policy = nl80211_policy, | |
8998 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8999 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9000 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9001 | }, |
e8347eba BJ |
9002 | { |
9003 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9004 | .doit = nl80211_set_wds_peer, | |
9005 | .policy = nl80211_policy, | |
9006 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9007 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9008 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9009 | }, |
29cbe68c JB |
9010 | { |
9011 | .cmd = NL80211_CMD_JOIN_MESH, | |
9012 | .doit = nl80211_join_mesh, | |
9013 | .policy = nl80211_policy, | |
9014 | .flags = GENL_ADMIN_PERM, | |
9015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9016 | NL80211_FLAG_NEED_RTNL, | |
9017 | }, | |
9018 | { | |
9019 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9020 | .doit = nl80211_leave_mesh, | |
9021 | .policy = nl80211_policy, | |
9022 | .flags = GENL_ADMIN_PERM, | |
9023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9024 | NL80211_FLAG_NEED_RTNL, | |
9025 | }, | |
dfb89c56 | 9026 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9027 | { |
9028 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9029 | .doit = nl80211_get_wowlan, | |
9030 | .policy = nl80211_policy, | |
9031 | /* can be retrieved by unprivileged users */ | |
9032 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9033 | NL80211_FLAG_NEED_RTNL, | |
9034 | }, | |
9035 | { | |
9036 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9037 | .doit = nl80211_set_wowlan, | |
9038 | .policy = nl80211_policy, | |
9039 | .flags = GENL_ADMIN_PERM, | |
9040 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9041 | NL80211_FLAG_NEED_RTNL, | |
9042 | }, | |
dfb89c56 | 9043 | #endif |
e5497d76 JB |
9044 | { |
9045 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9046 | .doit = nl80211_set_rekey_data, | |
9047 | .policy = nl80211_policy, | |
9048 | .flags = GENL_ADMIN_PERM, | |
9049 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9050 | NL80211_FLAG_NEED_RTNL, | |
9051 | }, | |
109086ce AN |
9052 | { |
9053 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9054 | .doit = nl80211_tdls_mgmt, | |
9055 | .policy = nl80211_policy, | |
9056 | .flags = GENL_ADMIN_PERM, | |
9057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9058 | NL80211_FLAG_NEED_RTNL, | |
9059 | }, | |
9060 | { | |
9061 | .cmd = NL80211_CMD_TDLS_OPER, | |
9062 | .doit = nl80211_tdls_oper, | |
9063 | .policy = nl80211_policy, | |
9064 | .flags = GENL_ADMIN_PERM, | |
9065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9066 | NL80211_FLAG_NEED_RTNL, | |
9067 | }, | |
28946da7 JB |
9068 | { |
9069 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9070 | .doit = nl80211_register_unexpected_frame, | |
9071 | .policy = nl80211_policy, | |
9072 | .flags = GENL_ADMIN_PERM, | |
9073 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9074 | NL80211_FLAG_NEED_RTNL, | |
9075 | }, | |
7f6cf311 JB |
9076 | { |
9077 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9078 | .doit = nl80211_probe_client, | |
9079 | .policy = nl80211_policy, | |
9080 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9081 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9082 | NL80211_FLAG_NEED_RTNL, |
9083 | }, | |
5e760230 JB |
9084 | { |
9085 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9086 | .doit = nl80211_register_beacons, | |
9087 | .policy = nl80211_policy, | |
9088 | .flags = GENL_ADMIN_PERM, | |
9089 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9090 | NL80211_FLAG_NEED_RTNL, | |
9091 | }, | |
1d9d9213 SW |
9092 | { |
9093 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9094 | .doit = nl80211_set_noack_map, | |
9095 | .policy = nl80211_policy, | |
9096 | .flags = GENL_ADMIN_PERM, | |
9097 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9098 | NL80211_FLAG_NEED_RTNL, | |
9099 | }, | |
98104fde JB |
9100 | { |
9101 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9102 | .doit = nl80211_start_p2p_device, | |
9103 | .policy = nl80211_policy, | |
9104 | .flags = GENL_ADMIN_PERM, | |
9105 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9106 | NL80211_FLAG_NEED_RTNL, | |
9107 | }, | |
9108 | { | |
9109 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9110 | .doit = nl80211_stop_p2p_device, | |
9111 | .policy = nl80211_policy, | |
9112 | .flags = GENL_ADMIN_PERM, | |
9113 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9114 | NL80211_FLAG_NEED_RTNL, | |
9115 | }, | |
f4e583c8 AQ |
9116 | { |
9117 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9118 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9119 | .policy = nl80211_policy, |
9120 | .flags = GENL_ADMIN_PERM, | |
9121 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9122 | NL80211_FLAG_NEED_RTNL, | |
9123 | }, | |
9124 | { | |
9125 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9126 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9127 | .policy = nl80211_policy, |
9128 | .flags = GENL_ADMIN_PERM, | |
9129 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9130 | NL80211_FLAG_NEED_RTNL, | |
9131 | }, | |
04f39047 SW |
9132 | { |
9133 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9134 | .doit = nl80211_start_radar_detection, | |
9135 | .policy = nl80211_policy, | |
9136 | .flags = GENL_ADMIN_PERM, | |
9137 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9138 | NL80211_FLAG_NEED_RTNL, | |
9139 | }, | |
3713b4e3 JB |
9140 | { |
9141 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9142 | .doit = nl80211_get_protocol_features, | |
9143 | .policy = nl80211_policy, | |
9144 | }, | |
355199e0 JM |
9145 | { |
9146 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9147 | .doit = nl80211_update_ft_ies, | |
9148 | .policy = nl80211_policy, | |
9149 | .flags = GENL_ADMIN_PERM, | |
9150 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9151 | NL80211_FLAG_NEED_RTNL, | |
9152 | }, | |
5de17984 AS |
9153 | { |
9154 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9155 | .doit = nl80211_crit_protocol_start, | |
9156 | .policy = nl80211_policy, | |
9157 | .flags = GENL_ADMIN_PERM, | |
9158 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9159 | NL80211_FLAG_NEED_RTNL, | |
9160 | }, | |
9161 | { | |
9162 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9163 | .doit = nl80211_crit_protocol_stop, | |
9164 | .policy = nl80211_policy, | |
9165 | .flags = GENL_ADMIN_PERM, | |
9166 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9167 | NL80211_FLAG_NEED_RTNL, | |
6fa3eb70 S |
9168 | }, |
9169 | { | |
9170 | .cmd = NL80211_CMD_VENDOR, | |
9171 | .doit = nl80211_vendor_cmd, | |
9172 | .policy = nl80211_policy, | |
9173 | .flags = GENL_ADMIN_PERM, | |
9174 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9175 | NL80211_FLAG_NEED_RTNL, | |
9176 | }, | |
55682965 | 9177 | }; |
9588bbd5 | 9178 | |
6039f6d2 JM |
9179 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
9180 | .name = "mlme", | |
9181 | }; | |
55682965 JB |
9182 | |
9183 | /* multicast groups */ | |
9184 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
9185 | .name = "config", | |
9186 | }; | |
2a519311 JB |
9187 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
9188 | .name = "scan", | |
9189 | }; | |
73d54c9e LR |
9190 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
9191 | .name = "regulatory", | |
9192 | }; | |
55682965 JB |
9193 | |
9194 | /* notification functions */ | |
9195 | ||
9196 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9197 | { | |
9198 | struct sk_buff *msg; | |
9199 | ||
fd2120ca | 9200 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9201 | if (!msg) |
9202 | return; | |
9203 | ||
3713b4e3 JB |
9204 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
9205 | false, NULL, NULL, NULL) < 0) { | |
55682965 JB |
9206 | nlmsg_free(msg); |
9207 | return; | |
9208 | } | |
9209 | ||
463d0183 JB |
9210 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9211 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
9212 | } |
9213 | ||
362a415d JB |
9214 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9215 | struct cfg80211_registered_device *rdev) | |
9216 | { | |
9217 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9218 | struct nlattr *nest; | |
9219 | int i; | |
9220 | ||
f9f47529 | 9221 | lockdep_assert_held(&rdev->sched_scan_mtx); |
667503dd | 9222 | |
362a415d JB |
9223 | if (WARN_ON(!req)) |
9224 | return 0; | |
9225 | ||
9226 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9227 | if (!nest) | |
9228 | goto nla_put_failure; | |
9360ffd1 DM |
9229 | for (i = 0; i < req->n_ssids; i++) { |
9230 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9231 | goto nla_put_failure; | |
9232 | } | |
362a415d JB |
9233 | nla_nest_end(msg, nest); |
9234 | ||
9235 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9236 | if (!nest) | |
9237 | goto nla_put_failure; | |
9360ffd1 DM |
9238 | for (i = 0; i < req->n_channels; i++) { |
9239 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9240 | goto nla_put_failure; | |
9241 | } | |
362a415d JB |
9242 | nla_nest_end(msg, nest); |
9243 | ||
9360ffd1 DM |
9244 | if (req->ie && |
9245 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9246 | goto nla_put_failure; | |
362a415d | 9247 | |
ed473771 SL |
9248 | if (req->flags) |
9249 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9250 | ||
362a415d JB |
9251 | return 0; |
9252 | nla_put_failure: | |
9253 | return -ENOBUFS; | |
9254 | } | |
9255 | ||
a538e2d5 JB |
9256 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9257 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9258 | struct wireless_dev *wdev, |
15e47304 | 9259 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9260 | u32 cmd) |
2a519311 JB |
9261 | { |
9262 | void *hdr; | |
9263 | ||
15e47304 | 9264 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9265 | if (!hdr) |
9266 | return -1; | |
9267 | ||
9360ffd1 | 9268 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9269 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9270 | wdev->netdev->ifindex)) || | |
9271 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9272 | goto nla_put_failure; |
2a519311 | 9273 | |
362a415d JB |
9274 | /* ignore errors and send incomplete event anyway */ |
9275 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9276 | |
9277 | return genlmsg_end(msg, hdr); | |
9278 | ||
9279 | nla_put_failure: | |
9280 | genlmsg_cancel(msg, hdr); | |
9281 | return -EMSGSIZE; | |
9282 | } | |
9283 | ||
807f8a8c LC |
9284 | static int |
9285 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9286 | struct cfg80211_registered_device *rdev, | |
9287 | struct net_device *netdev, | |
15e47304 | 9288 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9289 | { |
9290 | void *hdr; | |
9291 | ||
15e47304 | 9292 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9293 | if (!hdr) |
9294 | return -1; | |
9295 | ||
9360ffd1 DM |
9296 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9297 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9298 | goto nla_put_failure; | |
807f8a8c LC |
9299 | |
9300 | return genlmsg_end(msg, hdr); | |
9301 | ||
9302 | nla_put_failure: | |
9303 | genlmsg_cancel(msg, hdr); | |
9304 | return -EMSGSIZE; | |
9305 | } | |
9306 | ||
a538e2d5 | 9307 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9308 | struct wireless_dev *wdev) |
a538e2d5 JB |
9309 | { |
9310 | struct sk_buff *msg; | |
9311 | ||
58050fce | 9312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9313 | if (!msg) |
9314 | return; | |
9315 | ||
fd014284 | 9316 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9317 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9318 | nlmsg_free(msg); | |
9319 | return; | |
9320 | } | |
9321 | ||
463d0183 JB |
9322 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9323 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9324 | } |
9325 | ||
2a519311 | 9326 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9327 | struct wireless_dev *wdev) |
2a519311 JB |
9328 | { |
9329 | struct sk_buff *msg; | |
9330 | ||
fd2120ca | 9331 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9332 | if (!msg) |
9333 | return; | |
9334 | ||
fd014284 | 9335 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9336 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9337 | nlmsg_free(msg); |
9338 | return; | |
9339 | } | |
9340 | ||
463d0183 JB |
9341 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9342 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9343 | } |
9344 | ||
9345 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9346 | struct wireless_dev *wdev) |
2a519311 JB |
9347 | { |
9348 | struct sk_buff *msg; | |
9349 | ||
fd2120ca | 9350 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9351 | if (!msg) |
9352 | return; | |
9353 | ||
fd014284 | 9354 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9355 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9356 | nlmsg_free(msg); |
9357 | return; | |
9358 | } | |
9359 | ||
463d0183 JB |
9360 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9361 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9362 | } |
9363 | ||
807f8a8c LC |
9364 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9365 | struct net_device *netdev) | |
9366 | { | |
9367 | struct sk_buff *msg; | |
9368 | ||
9369 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9370 | if (!msg) | |
9371 | return; | |
9372 | ||
9373 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9374 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9375 | nlmsg_free(msg); | |
9376 | return; | |
9377 | } | |
9378 | ||
9379 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9380 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9381 | } | |
9382 | ||
9383 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9384 | struct net_device *netdev, u32 cmd) | |
9385 | { | |
9386 | struct sk_buff *msg; | |
9387 | ||
58050fce | 9388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9389 | if (!msg) |
9390 | return; | |
9391 | ||
9392 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9393 | nlmsg_free(msg); | |
9394 | return; | |
9395 | } | |
9396 | ||
9397 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9398 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9399 | } | |
9400 | ||
73d54c9e LR |
9401 | /* |
9402 | * This can happen on global regulatory changes or device specific settings | |
9403 | * based on custom world regulatory domains. | |
9404 | */ | |
9405 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9406 | { | |
9407 | struct sk_buff *msg; | |
9408 | void *hdr; | |
9409 | ||
fd2120ca | 9410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9411 | if (!msg) |
9412 | return; | |
9413 | ||
9414 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9415 | if (!hdr) { | |
9416 | nlmsg_free(msg); | |
9417 | return; | |
9418 | } | |
9419 | ||
9420 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9421 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9422 | goto nla_put_failure; | |
9423 | ||
9424 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9425 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9426 | NL80211_REGDOM_TYPE_WORLD)) | |
9427 | goto nla_put_failure; | |
9428 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9429 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9430 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9431 | goto nla_put_failure; | |
9432 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9433 | request->intersect) { | |
9434 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9435 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9436 | goto nla_put_failure; | |
9437 | } else { | |
9438 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9439 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9440 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9441 | request->alpha2)) | |
9442 | goto nla_put_failure; | |
9443 | } | |
9444 | ||
f4173766 | 9445 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9446 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9447 | goto nla_put_failure; | |
73d54c9e | 9448 | |
3b7b72ee | 9449 | genlmsg_end(msg, hdr); |
73d54c9e | 9450 | |
bc43b28c | 9451 | rcu_read_lock(); |
463d0183 | 9452 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9453 | GFP_ATOMIC); |
9454 | rcu_read_unlock(); | |
73d54c9e LR |
9455 | |
9456 | return; | |
9457 | ||
9458 | nla_put_failure: | |
9459 | genlmsg_cancel(msg, hdr); | |
9460 | nlmsg_free(msg); | |
9461 | } | |
9462 | ||
6039f6d2 JM |
9463 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9464 | struct net_device *netdev, | |
9465 | const u8 *buf, size_t len, | |
e6d6e342 | 9466 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9467 | { |
9468 | struct sk_buff *msg; | |
9469 | void *hdr; | |
9470 | ||
e6d6e342 | 9471 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9472 | if (!msg) |
9473 | return; | |
9474 | ||
9475 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9476 | if (!hdr) { | |
9477 | nlmsg_free(msg); | |
9478 | return; | |
9479 | } | |
9480 | ||
9360ffd1 DM |
9481 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9482 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9483 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9484 | goto nla_put_failure; | |
6039f6d2 | 9485 | |
3b7b72ee | 9486 | genlmsg_end(msg, hdr); |
6039f6d2 | 9487 | |
463d0183 JB |
9488 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9489 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9490 | return; |
9491 | ||
9492 | nla_put_failure: | |
9493 | genlmsg_cancel(msg, hdr); | |
9494 | nlmsg_free(msg); | |
9495 | } | |
9496 | ||
9497 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9498 | struct net_device *netdev, const u8 *buf, |
9499 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9500 | { |
9501 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9502 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9503 | } |
9504 | ||
9505 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9506 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9507 | size_t len, gfp_t gfp) |
6039f6d2 | 9508 | { |
e6d6e342 JB |
9509 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9510 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9511 | } |
9512 | ||
53b46b84 | 9513 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9514 | struct net_device *netdev, const u8 *buf, |
9515 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9516 | { |
9517 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9518 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9519 | } |
9520 | ||
53b46b84 JM |
9521 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9522 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9523 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9524 | { |
9525 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9526 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9527 | } |
9528 | ||
947add36 JB |
9529 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
9530 | size_t len) | |
cf4e594e | 9531 | { |
947add36 JB |
9532 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9533 | struct wiphy *wiphy = wdev->wiphy; | |
9534 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9535 | ||
9536 | trace_cfg80211_send_unprot_deauth(dev); | |
9537 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9538 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); | |
cf4e594e | 9539 | } |
947add36 | 9540 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
cf4e594e | 9541 | |
947add36 JB |
9542 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
9543 | size_t len) | |
cf4e594e | 9544 | { |
947add36 JB |
9545 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9546 | struct wiphy *wiphy = wdev->wiphy; | |
9547 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9548 | ||
9549 | trace_cfg80211_send_unprot_disassoc(dev); | |
9550 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9551 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); | |
cf4e594e | 9552 | } |
947add36 | 9553 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
cf4e594e | 9554 | |
1b06bb40 LR |
9555 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9556 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9557 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9558 | { |
9559 | struct sk_buff *msg; | |
9560 | void *hdr; | |
9561 | ||
e6d6e342 | 9562 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9563 | if (!msg) |
9564 | return; | |
9565 | ||
9566 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9567 | if (!hdr) { | |
9568 | nlmsg_free(msg); | |
9569 | return; | |
9570 | } | |
9571 | ||
9360ffd1 DM |
9572 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9573 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9574 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9575 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9576 | goto nla_put_failure; | |
1965c853 | 9577 | |
3b7b72ee | 9578 | genlmsg_end(msg, hdr); |
1965c853 | 9579 | |
463d0183 JB |
9580 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9581 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9582 | return; |
9583 | ||
9584 | nla_put_failure: | |
9585 | genlmsg_cancel(msg, hdr); | |
9586 | nlmsg_free(msg); | |
9587 | } | |
9588 | ||
9589 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9590 | struct net_device *netdev, const u8 *addr, |
9591 | gfp_t gfp) | |
1965c853 JM |
9592 | { |
9593 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9594 | addr, gfp); |
1965c853 JM |
9595 | } |
9596 | ||
9597 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9598 | struct net_device *netdev, const u8 *addr, |
9599 | gfp_t gfp) | |
1965c853 | 9600 | { |
e6d6e342 JB |
9601 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9602 | addr, gfp); | |
1965c853 JM |
9603 | } |
9604 | ||
b23aa676 SO |
9605 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9606 | struct net_device *netdev, const u8 *bssid, | |
9607 | const u8 *req_ie, size_t req_ie_len, | |
9608 | const u8 *resp_ie, size_t resp_ie_len, | |
9609 | u16 status, gfp_t gfp) | |
9610 | { | |
9611 | struct sk_buff *msg; | |
9612 | void *hdr; | |
9613 | ||
58050fce | 9614 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9615 | if (!msg) |
9616 | return; | |
9617 | ||
9618 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9619 | if (!hdr) { | |
9620 | nlmsg_free(msg); | |
9621 | return; | |
9622 | } | |
9623 | ||
9360ffd1 DM |
9624 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9625 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9626 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9627 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9628 | (req_ie && | |
9629 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9630 | (resp_ie && | |
9631 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9632 | goto nla_put_failure; | |
b23aa676 | 9633 | |
3b7b72ee | 9634 | genlmsg_end(msg, hdr); |
b23aa676 | 9635 | |
463d0183 JB |
9636 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9637 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9638 | return; |
9639 | ||
9640 | nla_put_failure: | |
9641 | genlmsg_cancel(msg, hdr); | |
9642 | nlmsg_free(msg); | |
9643 | ||
9644 | } | |
9645 | ||
9646 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9647 | struct net_device *netdev, const u8 *bssid, | |
9648 | const u8 *req_ie, size_t req_ie_len, | |
9649 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9650 | { | |
9651 | struct sk_buff *msg; | |
9652 | void *hdr; | |
9653 | ||
58050fce | 9654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9655 | if (!msg) |
9656 | return; | |
9657 | ||
9658 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9659 | if (!hdr) { | |
9660 | nlmsg_free(msg); | |
9661 | return; | |
9662 | } | |
9663 | ||
9360ffd1 DM |
9664 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9665 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9666 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9667 | (req_ie && | |
9668 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9669 | (resp_ie && | |
9670 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9671 | goto nla_put_failure; | |
b23aa676 | 9672 | |
3b7b72ee | 9673 | genlmsg_end(msg, hdr); |
b23aa676 | 9674 | |
463d0183 JB |
9675 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9676 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9677 | return; |
9678 | ||
9679 | nla_put_failure: | |
9680 | genlmsg_cancel(msg, hdr); | |
9681 | nlmsg_free(msg); | |
9682 | ||
9683 | } | |
9684 | ||
9685 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9686 | struct net_device *netdev, u16 reason, | |
667503dd | 9687 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9688 | { |
9689 | struct sk_buff *msg; | |
9690 | void *hdr; | |
9691 | ||
58050fce | 9692 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9693 | if (!msg) |
9694 | return; | |
9695 | ||
9696 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9697 | if (!hdr) { | |
9698 | nlmsg_free(msg); | |
9699 | return; | |
9700 | } | |
9701 | ||
9360ffd1 DM |
9702 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9703 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9704 | (from_ap && reason && | |
9705 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9706 | (from_ap && | |
9707 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9708 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9709 | goto nla_put_failure; | |
b23aa676 | 9710 | |
3b7b72ee | 9711 | genlmsg_end(msg, hdr); |
b23aa676 | 9712 | |
463d0183 JB |
9713 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9714 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9715 | return; |
9716 | ||
9717 | nla_put_failure: | |
9718 | genlmsg_cancel(msg, hdr); | |
9719 | nlmsg_free(msg); | |
9720 | ||
9721 | } | |
9722 | ||
04a773ad JB |
9723 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9724 | struct net_device *netdev, const u8 *bssid, | |
9725 | gfp_t gfp) | |
9726 | { | |
9727 | struct sk_buff *msg; | |
9728 | void *hdr; | |
9729 | ||
fd2120ca | 9730 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9731 | if (!msg) |
9732 | return; | |
9733 | ||
9734 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9735 | if (!hdr) { | |
9736 | nlmsg_free(msg); | |
9737 | return; | |
9738 | } | |
9739 | ||
9360ffd1 DM |
9740 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9741 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9742 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9743 | goto nla_put_failure; | |
04a773ad | 9744 | |
3b7b72ee | 9745 | genlmsg_end(msg, hdr); |
04a773ad | 9746 | |
463d0183 JB |
9747 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9748 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9749 | return; |
9750 | ||
9751 | nla_put_failure: | |
9752 | genlmsg_cancel(msg, hdr); | |
9753 | nlmsg_free(msg); | |
9754 | } | |
9755 | ||
947add36 JB |
9756 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9757 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9758 | { |
947add36 JB |
9759 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9760 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9761 | struct sk_buff *msg; |
9762 | void *hdr; | |
9763 | ||
947add36 JB |
9764 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9765 | return; | |
9766 | ||
9767 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9768 | ||
c93b5e71 JC |
9769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9770 | if (!msg) | |
9771 | return; | |
9772 | ||
9773 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9774 | if (!hdr) { | |
9775 | nlmsg_free(msg); | |
9776 | return; | |
9777 | } | |
9778 | ||
9360ffd1 | 9779 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9780 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9781 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9782 | (ie_len && ie && |
9783 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9784 | goto nla_put_failure; | |
c93b5e71 | 9785 | |
3b7b72ee | 9786 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9787 | |
9788 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9789 | nl80211_mlme_mcgrp.id, gfp); | |
9790 | return; | |
9791 | ||
9792 | nla_put_failure: | |
9793 | genlmsg_cancel(msg, hdr); | |
9794 | nlmsg_free(msg); | |
9795 | } | |
947add36 | 9796 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9797 | |
a3b8b056 JM |
9798 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9799 | struct net_device *netdev, const u8 *addr, | |
9800 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9801 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9802 | { |
9803 | struct sk_buff *msg; | |
9804 | void *hdr; | |
9805 | ||
e6d6e342 | 9806 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9807 | if (!msg) |
9808 | return; | |
9809 | ||
9810 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9811 | if (!hdr) { | |
9812 | nlmsg_free(msg); | |
9813 | return; | |
9814 | } | |
9815 | ||
9360ffd1 DM |
9816 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9817 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9818 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9819 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9820 | (key_id != -1 && | |
9821 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9822 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9823 | goto nla_put_failure; | |
a3b8b056 | 9824 | |
3b7b72ee | 9825 | genlmsg_end(msg, hdr); |
a3b8b056 | 9826 | |
463d0183 JB |
9827 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9828 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9829 | return; |
9830 | ||
9831 | nla_put_failure: | |
9832 | genlmsg_cancel(msg, hdr); | |
9833 | nlmsg_free(msg); | |
9834 | } | |
9835 | ||
6bad8766 LR |
9836 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9837 | struct ieee80211_channel *channel_before, | |
9838 | struct ieee80211_channel *channel_after) | |
9839 | { | |
9840 | struct sk_buff *msg; | |
9841 | void *hdr; | |
9842 | struct nlattr *nl_freq; | |
9843 | ||
fd2120ca | 9844 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9845 | if (!msg) |
9846 | return; | |
9847 | ||
9848 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9849 | if (!hdr) { | |
9850 | nlmsg_free(msg); | |
9851 | return; | |
9852 | } | |
9853 | ||
9854 | /* | |
9855 | * Since we are applying the beacon hint to a wiphy we know its | |
9856 | * wiphy_idx is valid | |
9857 | */ | |
9360ffd1 DM |
9858 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9859 | goto nla_put_failure; | |
6bad8766 LR |
9860 | |
9861 | /* Before */ | |
9862 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9863 | if (!nl_freq) | |
9864 | goto nla_put_failure; | |
cdc89b97 | 9865 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
9866 | goto nla_put_failure; |
9867 | nla_nest_end(msg, nl_freq); | |
9868 | ||
9869 | /* After */ | |
9870 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9871 | if (!nl_freq) | |
9872 | goto nla_put_failure; | |
cdc89b97 | 9873 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
9874 | goto nla_put_failure; |
9875 | nla_nest_end(msg, nl_freq); | |
9876 | ||
3b7b72ee | 9877 | genlmsg_end(msg, hdr); |
6bad8766 | 9878 | |
463d0183 JB |
9879 | rcu_read_lock(); |
9880 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9881 | GFP_ATOMIC); | |
9882 | rcu_read_unlock(); | |
6bad8766 LR |
9883 | |
9884 | return; | |
9885 | ||
9886 | nla_put_failure: | |
9887 | genlmsg_cancel(msg, hdr); | |
9888 | nlmsg_free(msg); | |
9889 | } | |
9890 | ||
9588bbd5 JM |
9891 | static void nl80211_send_remain_on_chan_event( |
9892 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9893 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9894 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9895 | unsigned int duration, gfp_t gfp) |
9896 | { | |
9897 | struct sk_buff *msg; | |
9898 | void *hdr; | |
9899 | ||
9900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9901 | if (!msg) | |
9902 | return; | |
9903 | ||
9904 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9905 | if (!hdr) { | |
9906 | nlmsg_free(msg); | |
9907 | return; | |
9908 | } | |
9909 | ||
9360ffd1 | 9910 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9911 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9912 | wdev->netdev->ifindex)) || | |
00f53350 | 9913 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9914 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9915 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9916 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9917 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9918 | goto nla_put_failure; | |
9588bbd5 | 9919 | |
9360ffd1 DM |
9920 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9921 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9922 | goto nla_put_failure; | |
9588bbd5 | 9923 | |
3b7b72ee | 9924 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9925 | |
9926 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9927 | nl80211_mlme_mcgrp.id, gfp); | |
9928 | return; | |
9929 | ||
9930 | nla_put_failure: | |
9931 | genlmsg_cancel(msg, hdr); | |
9932 | nlmsg_free(msg); | |
9933 | } | |
9934 | ||
947add36 JB |
9935 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
9936 | struct ieee80211_channel *chan, | |
9937 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 9938 | { |
947add36 JB |
9939 | struct wiphy *wiphy = wdev->wiphy; |
9940 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9941 | ||
9942 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 9943 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 9944 | rdev, wdev, cookie, chan, |
42d97a59 | 9945 | duration, gfp); |
9588bbd5 | 9946 | } |
947add36 | 9947 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 9948 | |
947add36 JB |
9949 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
9950 | struct ieee80211_channel *chan, | |
9951 | gfp_t gfp) | |
9588bbd5 | 9952 | { |
947add36 JB |
9953 | struct wiphy *wiphy = wdev->wiphy; |
9954 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9955 | ||
9956 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 9957 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 9958 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 9959 | } |
947add36 | 9960 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 9961 | |
947add36 JB |
9962 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
9963 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 9964 | { |
947add36 JB |
9965 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9966 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
9967 | struct sk_buff *msg; |
9968 | ||
947add36 JB |
9969 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
9970 | ||
58050fce | 9971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9972 | if (!msg) |
9973 | return; | |
9974 | ||
66266b3a JL |
9975 | if (nl80211_send_station(msg, 0, 0, 0, |
9976 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9977 | nlmsg_free(msg); |
9978 | return; | |
9979 | } | |
9980 | ||
9981 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9982 | nl80211_mlme_mcgrp.id, gfp); | |
9983 | } | |
947add36 | 9984 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 9985 | |
947add36 | 9986 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 9987 | { |
947add36 JB |
9988 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9989 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
9990 | struct sk_buff *msg; |
9991 | void *hdr; | |
9992 | ||
947add36 JB |
9993 | trace_cfg80211_del_sta(dev, mac_addr); |
9994 | ||
58050fce | 9995 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9996 | if (!msg) |
9997 | return; | |
9998 | ||
9999 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10000 | if (!hdr) { | |
10001 | nlmsg_free(msg); | |
10002 | return; | |
10003 | } | |
10004 | ||
9360ffd1 DM |
10005 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10006 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10007 | goto nla_put_failure; | |
ec15e68b | 10008 | |
3b7b72ee | 10009 | genlmsg_end(msg, hdr); |
ec15e68b JM |
10010 | |
10011 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10012 | nl80211_mlme_mcgrp.id, gfp); | |
10013 | return; | |
10014 | ||
10015 | nla_put_failure: | |
10016 | genlmsg_cancel(msg, hdr); | |
10017 | nlmsg_free(msg); | |
10018 | } | |
947add36 | 10019 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10020 | |
947add36 JB |
10021 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10022 | enum nl80211_connect_failed_reason reason, | |
10023 | gfp_t gfp) | |
ed44a951 | 10024 | { |
947add36 JB |
10025 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10026 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10027 | struct sk_buff *msg; |
10028 | void *hdr; | |
10029 | ||
10030 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10031 | if (!msg) | |
10032 | return; | |
10033 | ||
10034 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10035 | if (!hdr) { | |
10036 | nlmsg_free(msg); | |
10037 | return; | |
10038 | } | |
10039 | ||
10040 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10041 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10042 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10043 | goto nla_put_failure; | |
10044 | ||
10045 | genlmsg_end(msg, hdr); | |
10046 | ||
10047 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10048 | nl80211_mlme_mcgrp.id, gfp); | |
10049 | return; | |
10050 | ||
10051 | nla_put_failure: | |
10052 | genlmsg_cancel(msg, hdr); | |
10053 | nlmsg_free(msg); | |
10054 | } | |
947add36 | 10055 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10056 | |
b92ab5d8 JB |
10057 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10058 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10059 | { |
10060 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10061 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10062 | struct sk_buff *msg; | |
10063 | void *hdr; | |
10064 | int err; | |
15e47304 | 10065 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10066 | |
15e47304 | 10067 | if (!nlportid) |
28946da7 JB |
10068 | return false; |
10069 | ||
10070 | msg = nlmsg_new(100, gfp); | |
10071 | if (!msg) | |
10072 | return true; | |
10073 | ||
b92ab5d8 | 10074 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10075 | if (!hdr) { |
10076 | nlmsg_free(msg); | |
10077 | return true; | |
10078 | } | |
10079 | ||
9360ffd1 DM |
10080 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10081 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10082 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10083 | goto nla_put_failure; | |
28946da7 JB |
10084 | |
10085 | err = genlmsg_end(msg, hdr); | |
10086 | if (err < 0) { | |
10087 | nlmsg_free(msg); | |
10088 | return true; | |
10089 | } | |
10090 | ||
15e47304 | 10091 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10092 | return true; |
10093 | ||
10094 | nla_put_failure: | |
10095 | genlmsg_cancel(msg, hdr); | |
10096 | nlmsg_free(msg); | |
10097 | return true; | |
10098 | } | |
10099 | ||
947add36 JB |
10100 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10101 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10102 | { |
947add36 JB |
10103 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10104 | bool ret; | |
10105 | ||
10106 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10107 | ||
10108 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10109 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10110 | trace_cfg80211_return_bool(false); | |
10111 | return false; | |
10112 | } | |
10113 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10114 | addr, gfp); | |
10115 | trace_cfg80211_return_bool(ret); | |
10116 | return ret; | |
b92ab5d8 | 10117 | } |
947add36 | 10118 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10119 | |
947add36 JB |
10120 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10121 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10122 | { |
947add36 JB |
10123 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10124 | bool ret; | |
10125 | ||
10126 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10127 | ||
10128 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10129 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10130 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10131 | trace_cfg80211_return_bool(false); | |
10132 | return false; | |
10133 | } | |
10134 | ret = __nl80211_unexpected_frame(dev, | |
10135 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10136 | addr, gfp); | |
10137 | trace_cfg80211_return_bool(ret); | |
10138 | return ret; | |
b92ab5d8 | 10139 | } |
947add36 | 10140 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10141 | |
2e161f78 | 10142 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10143 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
10144 | int freq, int sig_dbm, |
10145 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 10146 | { |
71bbc994 | 10147 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10148 | struct sk_buff *msg; |
10149 | void *hdr; | |
026331c4 JM |
10150 | |
10151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10152 | if (!msg) | |
10153 | return -ENOMEM; | |
10154 | ||
2e161f78 | 10155 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10156 | if (!hdr) { |
10157 | nlmsg_free(msg); | |
10158 | return -ENOMEM; | |
10159 | } | |
10160 | ||
9360ffd1 | 10161 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10162 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10163 | netdev->ifindex)) || | |
a838490b | 10164 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10165 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10166 | (sig_dbm && | |
10167 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10168 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10169 | goto nla_put_failure; | |
026331c4 | 10170 | |
3b7b72ee | 10171 | genlmsg_end(msg, hdr); |
026331c4 | 10172 | |
15e47304 | 10173 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10174 | |
10175 | nla_put_failure: | |
10176 | genlmsg_cancel(msg, hdr); | |
10177 | nlmsg_free(msg); | |
10178 | return -ENOBUFS; | |
10179 | } | |
10180 | ||
947add36 JB |
10181 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10182 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10183 | { |
947add36 JB |
10184 | struct wiphy *wiphy = wdev->wiphy; |
10185 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10186 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10187 | struct sk_buff *msg; |
10188 | void *hdr; | |
10189 | ||
947add36 JB |
10190 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10191 | ||
026331c4 JM |
10192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10193 | if (!msg) | |
10194 | return; | |
10195 | ||
2e161f78 | 10196 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10197 | if (!hdr) { |
10198 | nlmsg_free(msg); | |
10199 | return; | |
10200 | } | |
10201 | ||
9360ffd1 | 10202 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10203 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10204 | netdev->ifindex)) || | |
a838490b | 10205 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10206 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10207 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10208 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10209 | goto nla_put_failure; | |
026331c4 | 10210 | |
3b7b72ee | 10211 | genlmsg_end(msg, hdr); |
026331c4 | 10212 | |
c8942c6a MK |
10213 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10214 | nl80211_mlme_mcgrp.id, gfp); | |
026331c4 JM |
10215 | return; |
10216 | ||
10217 | nla_put_failure: | |
10218 | genlmsg_cancel(msg, hdr); | |
10219 | nlmsg_free(msg); | |
10220 | } | |
947add36 | 10221 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10222 | |
947add36 JB |
10223 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10224 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10225 | gfp_t gfp) | |
d6dc1a38 | 10226 | { |
947add36 JB |
10227 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10228 | struct wiphy *wiphy = wdev->wiphy; | |
10229 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10230 | struct sk_buff *msg; |
10231 | struct nlattr *pinfoattr; | |
10232 | void *hdr; | |
10233 | ||
947add36 JB |
10234 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10235 | ||
58050fce | 10236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10237 | if (!msg) |
10238 | return; | |
10239 | ||
10240 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10241 | if (!hdr) { | |
10242 | nlmsg_free(msg); | |
10243 | return; | |
10244 | } | |
10245 | ||
9360ffd1 | 10246 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10247 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10248 | goto nla_put_failure; |
d6dc1a38 JO |
10249 | |
10250 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10251 | if (!pinfoattr) | |
10252 | goto nla_put_failure; | |
10253 | ||
9360ffd1 DM |
10254 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10255 | rssi_event)) | |
10256 | goto nla_put_failure; | |
d6dc1a38 JO |
10257 | |
10258 | nla_nest_end(msg, pinfoattr); | |
10259 | ||
3b7b72ee | 10260 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10261 | |
10262 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10263 | nl80211_mlme_mcgrp.id, gfp); | |
10264 | return; | |
10265 | ||
10266 | nla_put_failure: | |
10267 | genlmsg_cancel(msg, hdr); | |
10268 | nlmsg_free(msg); | |
10269 | } | |
947add36 | 10270 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10271 | |
947add36 JB |
10272 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10273 | struct net_device *netdev, const u8 *bssid, | |
10274 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10275 | { |
10276 | struct sk_buff *msg; | |
10277 | struct nlattr *rekey_attr; | |
10278 | void *hdr; | |
10279 | ||
58050fce | 10280 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10281 | if (!msg) |
10282 | return; | |
10283 | ||
10284 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10285 | if (!hdr) { | |
10286 | nlmsg_free(msg); | |
10287 | return; | |
10288 | } | |
10289 | ||
9360ffd1 DM |
10290 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10291 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10292 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10293 | goto nla_put_failure; | |
e5497d76 JB |
10294 | |
10295 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10296 | if (!rekey_attr) | |
10297 | goto nla_put_failure; | |
10298 | ||
9360ffd1 DM |
10299 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10300 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10301 | goto nla_put_failure; | |
e5497d76 JB |
10302 | |
10303 | nla_nest_end(msg, rekey_attr); | |
10304 | ||
3b7b72ee | 10305 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10306 | |
10307 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10308 | nl80211_mlme_mcgrp.id, gfp); | |
10309 | return; | |
10310 | ||
10311 | nla_put_failure: | |
10312 | genlmsg_cancel(msg, hdr); | |
10313 | nlmsg_free(msg); | |
10314 | } | |
10315 | ||
947add36 JB |
10316 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10317 | const u8 *replay_ctr, gfp_t gfp) | |
10318 | { | |
10319 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10320 | struct wiphy *wiphy = wdev->wiphy; | |
10321 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10322 | ||
10323 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10324 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10325 | } | |
10326 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10327 | ||
10328 | static void | |
10329 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10330 | struct net_device *netdev, int index, | |
10331 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10332 | { |
10333 | struct sk_buff *msg; | |
10334 | struct nlattr *attr; | |
10335 | void *hdr; | |
10336 | ||
58050fce | 10337 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10338 | if (!msg) |
10339 | return; | |
10340 | ||
10341 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10342 | if (!hdr) { | |
10343 | nlmsg_free(msg); | |
10344 | return; | |
10345 | } | |
10346 | ||
9360ffd1 DM |
10347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10348 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10349 | goto nla_put_failure; | |
c9df56b4 JM |
10350 | |
10351 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10352 | if (!attr) | |
10353 | goto nla_put_failure; | |
10354 | ||
9360ffd1 DM |
10355 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10356 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10357 | (preauth && | |
10358 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10359 | goto nla_put_failure; | |
c9df56b4 JM |
10360 | |
10361 | nla_nest_end(msg, attr); | |
10362 | ||
3b7b72ee | 10363 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10364 | |
10365 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10366 | nl80211_mlme_mcgrp.id, gfp); | |
10367 | return; | |
10368 | ||
10369 | nla_put_failure: | |
10370 | genlmsg_cancel(msg, hdr); | |
10371 | nlmsg_free(msg); | |
10372 | } | |
10373 | ||
947add36 JB |
10374 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10375 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10376 | { | |
10377 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10378 | struct wiphy *wiphy = wdev->wiphy; | |
10379 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10380 | ||
10381 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10382 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10383 | } | |
10384 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10385 | ||
10386 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10387 | struct net_device *netdev, | |
10388 | struct cfg80211_chan_def *chandef, | |
10389 | gfp_t gfp) | |
5314526b TP |
10390 | { |
10391 | struct sk_buff *msg; | |
10392 | void *hdr; | |
10393 | ||
58050fce | 10394 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10395 | if (!msg) |
10396 | return; | |
10397 | ||
10398 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10399 | if (!hdr) { | |
10400 | nlmsg_free(msg); | |
10401 | return; | |
10402 | } | |
10403 | ||
683b6d3b JB |
10404 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10405 | goto nla_put_failure; | |
10406 | ||
10407 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10408 | goto nla_put_failure; |
5314526b TP |
10409 | |
10410 | genlmsg_end(msg, hdr); | |
10411 | ||
10412 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10413 | nl80211_mlme_mcgrp.id, gfp); | |
10414 | return; | |
10415 | ||
10416 | nla_put_failure: | |
10417 | genlmsg_cancel(msg, hdr); | |
10418 | nlmsg_free(msg); | |
10419 | } | |
10420 | ||
947add36 JB |
10421 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10422 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10423 | { |
947add36 JB |
10424 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10425 | struct wiphy *wiphy = wdev->wiphy; | |
10426 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10427 | ||
10428 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10429 | ||
10430 | wdev_lock(wdev); | |
10431 | ||
10432 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10433 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10434 | goto out; | |
10435 | ||
10436 | wdev->channel = chandef->chan; | |
10437 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10438 | out: | |
10439 | wdev_unlock(wdev); | |
10440 | return; | |
10441 | } | |
10442 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10443 | ||
10444 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10445 | const u8 *peer, u32 num_packets, | |
10446 | u32 rate, u32 intvl, gfp_t gfp) | |
10447 | { | |
10448 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10449 | struct wiphy *wiphy = wdev->wiphy; | |
10450 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10451 | struct sk_buff *msg; |
10452 | struct nlattr *pinfoattr; | |
10453 | void *hdr; | |
10454 | ||
10455 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10456 | if (!msg) | |
10457 | return; | |
10458 | ||
10459 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10460 | if (!hdr) { | |
10461 | nlmsg_free(msg); | |
10462 | return; | |
10463 | } | |
10464 | ||
10465 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10466 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10467 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10468 | goto nla_put_failure; | |
10469 | ||
10470 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10471 | if (!pinfoattr) | |
10472 | goto nla_put_failure; | |
10473 | ||
10474 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10475 | goto nla_put_failure; | |
10476 | ||
10477 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10478 | goto nla_put_failure; | |
10479 | ||
10480 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10481 | goto nla_put_failure; | |
10482 | ||
10483 | nla_nest_end(msg, pinfoattr); | |
10484 | ||
10485 | genlmsg_end(msg, hdr); | |
10486 | ||
10487 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10488 | nl80211_mlme_mcgrp.id, gfp); | |
10489 | return; | |
10490 | ||
10491 | nla_put_failure: | |
10492 | genlmsg_cancel(msg, hdr); | |
10493 | nlmsg_free(msg); | |
10494 | } | |
947add36 | 10495 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10496 | |
04f39047 SW |
10497 | void |
10498 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10499 | struct cfg80211_chan_def *chandef, | |
10500 | enum nl80211_radar_event event, | |
10501 | struct net_device *netdev, gfp_t gfp) | |
10502 | { | |
10503 | struct sk_buff *msg; | |
10504 | void *hdr; | |
10505 | ||
10506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10507 | if (!msg) | |
10508 | return; | |
10509 | ||
10510 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10511 | if (!hdr) { | |
10512 | nlmsg_free(msg); | |
10513 | return; | |
10514 | } | |
10515 | ||
10516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10517 | goto nla_put_failure; | |
10518 | ||
10519 | /* NOP and radar events don't need a netdev parameter */ | |
10520 | if (netdev) { | |
10521 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10522 | ||
10523 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10524 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10525 | goto nla_put_failure; | |
10526 | } | |
10527 | ||
10528 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10529 | goto nla_put_failure; | |
10530 | ||
10531 | if (nl80211_send_chandef(msg, chandef)) | |
10532 | goto nla_put_failure; | |
10533 | ||
10534 | if (genlmsg_end(msg, hdr) < 0) { | |
10535 | nlmsg_free(msg); | |
10536 | return; | |
10537 | } | |
10538 | ||
10539 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10540 | nl80211_mlme_mcgrp.id, gfp); | |
10541 | return; | |
10542 | ||
10543 | nla_put_failure: | |
10544 | genlmsg_cancel(msg, hdr); | |
10545 | nlmsg_free(msg); | |
10546 | } | |
10547 | ||
947add36 JB |
10548 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10549 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10550 | { |
947add36 JB |
10551 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10552 | struct wiphy *wiphy = wdev->wiphy; | |
10553 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10554 | struct sk_buff *msg; |
10555 | struct nlattr *pinfoattr; | |
10556 | void *hdr; | |
10557 | ||
947add36 JB |
10558 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10559 | ||
58050fce | 10560 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10561 | if (!msg) |
10562 | return; | |
10563 | ||
10564 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10565 | if (!hdr) { | |
10566 | nlmsg_free(msg); | |
10567 | return; | |
10568 | } | |
10569 | ||
9360ffd1 | 10570 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10571 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10572 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10573 | goto nla_put_failure; | |
c063dbf5 JB |
10574 | |
10575 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10576 | if (!pinfoattr) | |
10577 | goto nla_put_failure; | |
10578 | ||
9360ffd1 DM |
10579 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10580 | goto nla_put_failure; | |
c063dbf5 JB |
10581 | |
10582 | nla_nest_end(msg, pinfoattr); | |
10583 | ||
3b7b72ee | 10584 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10585 | |
10586 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10587 | nl80211_mlme_mcgrp.id, gfp); | |
10588 | return; | |
10589 | ||
10590 | nla_put_failure: | |
10591 | genlmsg_cancel(msg, hdr); | |
10592 | nlmsg_free(msg); | |
10593 | } | |
947add36 | 10594 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10595 | |
7f6cf311 JB |
10596 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10597 | u64 cookie, bool acked, gfp_t gfp) | |
10598 | { | |
10599 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10600 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10601 | struct sk_buff *msg; | |
10602 | void *hdr; | |
10603 | int err; | |
10604 | ||
4ee3e063 BL |
10605 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10606 | ||
58050fce | 10607 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10608 | |
7f6cf311 JB |
10609 | if (!msg) |
10610 | return; | |
10611 | ||
10612 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10613 | if (!hdr) { | |
10614 | nlmsg_free(msg); | |
10615 | return; | |
10616 | } | |
10617 | ||
9360ffd1 DM |
10618 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10619 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10620 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10621 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10622 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10623 | goto nla_put_failure; | |
7f6cf311 JB |
10624 | |
10625 | err = genlmsg_end(msg, hdr); | |
10626 | if (err < 0) { | |
10627 | nlmsg_free(msg); | |
10628 | return; | |
10629 | } | |
10630 | ||
10631 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10632 | nl80211_mlme_mcgrp.id, gfp); | |
10633 | return; | |
10634 | ||
10635 | nla_put_failure: | |
10636 | genlmsg_cancel(msg, hdr); | |
10637 | nlmsg_free(msg); | |
10638 | } | |
10639 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10640 | ||
5e760230 JB |
10641 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10642 | const u8 *frame, size_t len, | |
37c73b5f | 10643 | int freq, int sig_dbm) |
5e760230 JB |
10644 | { |
10645 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10646 | struct sk_buff *msg; | |
10647 | void *hdr; | |
37c73b5f | 10648 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10649 | |
4ee3e063 BL |
10650 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10651 | ||
37c73b5f BG |
10652 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10653 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10654 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10655 | if (!msg) { | |
10656 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10657 | return; | |
10658 | } | |
5e760230 | 10659 | |
37c73b5f BG |
10660 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10661 | if (!hdr) | |
10662 | goto nla_put_failure; | |
5e760230 | 10663 | |
37c73b5f BG |
10664 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10665 | (freq && | |
10666 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10667 | (sig_dbm && | |
10668 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10669 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10670 | goto nla_put_failure; | |
5e760230 | 10671 | |
37c73b5f | 10672 | genlmsg_end(msg, hdr); |
5e760230 | 10673 | |
37c73b5f BG |
10674 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10675 | } | |
10676 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10677 | return; |
10678 | ||
10679 | nla_put_failure: | |
37c73b5f BG |
10680 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10681 | if (hdr) | |
10682 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10683 | nlmsg_free(msg); |
10684 | } | |
10685 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10686 | ||
cd8f7cb4 JB |
10687 | #ifdef CONFIG_PM |
10688 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10689 | struct cfg80211_wowlan_wakeup *wakeup, | |
10690 | gfp_t gfp) | |
10691 | { | |
10692 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10693 | struct sk_buff *msg; | |
10694 | void *hdr; | |
10695 | int err, size = 200; | |
10696 | ||
10697 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10698 | ||
10699 | if (wakeup) | |
10700 | size += wakeup->packet_present_len; | |
10701 | ||
10702 | msg = nlmsg_new(size, gfp); | |
10703 | if (!msg) | |
10704 | return; | |
10705 | ||
10706 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10707 | if (!hdr) | |
10708 | goto free_msg; | |
10709 | ||
10710 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10711 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10712 | goto free_msg; | |
10713 | ||
10714 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10715 | wdev->netdev->ifindex)) | |
10716 | goto free_msg; | |
10717 | ||
10718 | if (wakeup) { | |
10719 | struct nlattr *reasons; | |
10720 | ||
10721 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10722 | ||
10723 | if (wakeup->disconnect && | |
10724 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10725 | goto free_msg; | |
10726 | if (wakeup->magic_pkt && | |
10727 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10728 | goto free_msg; | |
10729 | if (wakeup->gtk_rekey_failure && | |
10730 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10731 | goto free_msg; | |
10732 | if (wakeup->eap_identity_req && | |
10733 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10734 | goto free_msg; | |
10735 | if (wakeup->four_way_handshake && | |
10736 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10737 | goto free_msg; | |
10738 | if (wakeup->rfkill_release && | |
10739 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10740 | goto free_msg; | |
10741 | ||
10742 | if (wakeup->pattern_idx >= 0 && | |
10743 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10744 | wakeup->pattern_idx)) | |
10745 | goto free_msg; | |
10746 | ||
2a0e047e JB |
10747 | if (wakeup->tcp_match) |
10748 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10749 | ||
10750 | if (wakeup->tcp_connlost) | |
10751 | nla_put_flag(msg, | |
10752 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10753 | ||
10754 | if (wakeup->tcp_nomoretokens) | |
10755 | nla_put_flag(msg, | |
10756 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10757 | ||
cd8f7cb4 JB |
10758 | if (wakeup->packet) { |
10759 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10760 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10761 | ||
10762 | if (!wakeup->packet_80211) { | |
10763 | pkt_attr = | |
10764 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10765 | len_attr = | |
10766 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10767 | } | |
10768 | ||
10769 | if (wakeup->packet_len && | |
10770 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10771 | goto free_msg; | |
10772 | ||
10773 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10774 | wakeup->packet)) | |
10775 | goto free_msg; | |
10776 | } | |
10777 | ||
10778 | nla_nest_end(msg, reasons); | |
10779 | } | |
10780 | ||
10781 | err = genlmsg_end(msg, hdr); | |
10782 | if (err < 0) | |
10783 | goto free_msg; | |
10784 | ||
10785 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10786 | nl80211_mlme_mcgrp.id, gfp); | |
10787 | return; | |
10788 | ||
10789 | free_msg: | |
10790 | nlmsg_free(msg); | |
10791 | } | |
10792 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10793 | #endif | |
10794 | ||
3475b094 JM |
10795 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10796 | enum nl80211_tdls_operation oper, | |
10797 | u16 reason_code, gfp_t gfp) | |
10798 | { | |
10799 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10800 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10801 | struct sk_buff *msg; | |
10802 | void *hdr; | |
10803 | int err; | |
10804 | ||
10805 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10806 | reason_code); | |
10807 | ||
10808 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10809 | if (!msg) | |
10810 | return; | |
10811 | ||
10812 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10813 | if (!hdr) { | |
10814 | nlmsg_free(msg); | |
10815 | return; | |
10816 | } | |
10817 | ||
10818 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10819 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10820 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10821 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10822 | (reason_code > 0 && | |
10823 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10824 | goto nla_put_failure; | |
10825 | ||
10826 | err = genlmsg_end(msg, hdr); | |
10827 | if (err < 0) { | |
10828 | nlmsg_free(msg); | |
10829 | return; | |
10830 | } | |
10831 | ||
10832 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10833 | nl80211_mlme_mcgrp.id, gfp); | |
10834 | return; | |
10835 | ||
10836 | nla_put_failure: | |
10837 | genlmsg_cancel(msg, hdr); | |
10838 | nlmsg_free(msg); | |
10839 | } | |
10840 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10841 | ||
026331c4 JM |
10842 | static int nl80211_netlink_notify(struct notifier_block * nb, |
10843 | unsigned long state, | |
10844 | void *_notify) | |
10845 | { | |
10846 | struct netlink_notify *notify = _notify; | |
10847 | struct cfg80211_registered_device *rdev; | |
10848 | struct wireless_dev *wdev; | |
37c73b5f | 10849 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 10850 | |
3af67b1b | 10851 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
10852 | return NOTIFY_DONE; |
10853 | ||
10854 | rcu_read_lock(); | |
10855 | ||
5e760230 | 10856 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 10857 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 10858 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
10859 | |
10860 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10861 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
10862 | list) { | |
10863 | if (reg->nlportid == notify->portid) { | |
10864 | list_del(®->list); | |
10865 | kfree(reg); | |
10866 | break; | |
10867 | } | |
10868 | } | |
10869 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 10870 | } |
026331c4 JM |
10871 | |
10872 | rcu_read_unlock(); | |
10873 | ||
10874 | return NOTIFY_DONE; | |
10875 | } | |
10876 | ||
10877 | static struct notifier_block nl80211_netlink_notifier = { | |
10878 | .notifier_call = nl80211_netlink_notify, | |
10879 | }; | |
10880 | ||
355199e0 JM |
10881 | void cfg80211_ft_event(struct net_device *netdev, |
10882 | struct cfg80211_ft_event_params *ft_event) | |
10883 | { | |
10884 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
10885 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10886 | struct sk_buff *msg; | |
10887 | void *hdr; | |
10888 | int err; | |
10889 | ||
10890 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
10891 | ||
10892 | if (!ft_event->target_ap) | |
10893 | return; | |
10894 | ||
10895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10896 | if (!msg) | |
10897 | return; | |
10898 | ||
10899 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
10900 | if (!hdr) { | |
10901 | nlmsg_free(msg); | |
10902 | return; | |
10903 | } | |
10904 | ||
10905 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
10906 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
10907 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
10908 | if (ft_event->ies) | |
10909 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
10910 | if (ft_event->ric_ies) | |
10911 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
10912 | ft_event->ric_ies); | |
10913 | ||
10914 | err = genlmsg_end(msg, hdr); | |
10915 | if (err < 0) { | |
10916 | nlmsg_free(msg); | |
10917 | return; | |
10918 | } | |
10919 | ||
10920 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10921 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
10922 | } | |
10923 | EXPORT_SYMBOL(cfg80211_ft_event); | |
10924 | ||
5de17984 AS |
10925 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
10926 | { | |
10927 | struct cfg80211_registered_device *rdev; | |
10928 | struct sk_buff *msg; | |
10929 | void *hdr; | |
10930 | u32 nlportid; | |
10931 | ||
10932 | rdev = wiphy_to_dev(wdev->wiphy); | |
10933 | if (!rdev->crit_proto_nlportid) | |
10934 | return; | |
10935 | ||
10936 | nlportid = rdev->crit_proto_nlportid; | |
10937 | rdev->crit_proto_nlportid = 0; | |
10938 | ||
10939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10940 | if (!msg) | |
10941 | return; | |
10942 | ||
10943 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
10944 | if (!hdr) | |
10945 | goto nla_put_failure; | |
10946 | ||
10947 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10948 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10949 | goto nla_put_failure; | |
10950 | ||
10951 | genlmsg_end(msg, hdr); | |
10952 | ||
10953 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
10954 | return; | |
10955 | ||
10956 | nla_put_failure: | |
10957 | if (hdr) | |
10958 | genlmsg_cancel(msg, hdr); | |
10959 | nlmsg_free(msg); | |
10960 | ||
10961 | } | |
10962 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
10963 | ||
55682965 JB |
10964 | /* initialisation/exit functions */ |
10965 | ||
10966 | int nl80211_init(void) | |
10967 | { | |
0d63cbb5 | 10968 | int err; |
55682965 | 10969 | |
0d63cbb5 MM |
10970 | err = genl_register_family_with_ops(&nl80211_fam, |
10971 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10972 | if (err) |
10973 | return err; | |
10974 | ||
55682965 JB |
10975 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10976 | if (err) | |
10977 | goto err_out; | |
10978 | ||
2a519311 JB |
10979 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10980 | if (err) | |
10981 | goto err_out; | |
10982 | ||
73d54c9e LR |
10983 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10984 | if (err) | |
10985 | goto err_out; | |
10986 | ||
6039f6d2 JM |
10987 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10988 | if (err) | |
10989 | goto err_out; | |
10990 | ||
aff89a9b JB |
10991 | #ifdef CONFIG_NL80211_TESTMODE |
10992 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10993 | if (err) | |
10994 | goto err_out; | |
6fa3eb70 S |
10995 | |
10996 | err = genl_register_mc_group(&nl80211_fam, &nl80211_vendor_mcgrp); | |
10997 | if (err) | |
10998 | goto err_out; | |
aff89a9b JB |
10999 | #endif |
11000 | ||
026331c4 JM |
11001 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11002 | if (err) | |
11003 | goto err_out; | |
11004 | ||
55682965 JB |
11005 | return 0; |
11006 | err_out: | |
11007 | genl_unregister_family(&nl80211_fam); | |
11008 | return err; | |
11009 | } | |
11010 | ||
11011 | void nl80211_exit(void) | |
11012 | { | |
026331c4 | 11013 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11014 | genl_unregister_family(&nl80211_fam); |
11015 | } |