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