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