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