]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
11 | #include <linux/list.h> |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/ieee80211.h> | |
14 | #include <linux/nl80211.h> | |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/netlink.h> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
2a0e047e | 22 | #include <net/inet_connection_sock.h> |
55682965 JB |
23 | #include "core.h" |
24 | #include "nl80211.h" | |
b2e1b302 | 25 | #include "reg.h" |
e35e4d28 | 26 | #include "rdev-ops.h" |
55682965 | 27 | |
5fb628e9 JM |
28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
29 | struct genl_info *info, | |
30 | struct cfg80211_crypto_settings *settings, | |
31 | int cipher_limit); | |
32 | ||
4c476991 JB |
33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
34 | struct genl_info *info); | |
35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
36 | struct genl_info *info); | |
37 | ||
55682965 JB |
38 | /* the netlink family */ |
39 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
42 | .hdrsize = 0, /* no private header */ | |
43 | .version = 1, /* no particular meaning now */ | |
55682965 | 44 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 45 | .netnsok = true, |
4c476991 JB |
46 | .pre_doit = nl80211_pre_doit, |
47 | .post_doit = nl80211_post_doit, | |
55682965 JB |
48 | }; |
49 | ||
89a54e48 JB |
50 | /* returns ERR_PTR values */ |
51 | static struct wireless_dev * | |
52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 53 | { |
89a54e48 JB |
54 | struct cfg80211_registered_device *rdev; |
55 | struct wireless_dev *result = NULL; | |
56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
58 | u64 wdev_id; | |
59 | int wiphy_idx = -1; | |
60 | int ifidx = -1; | |
55682965 | 61 | |
5fe231e8 | 62 | ASSERT_RTNL(); |
55682965 | 63 | |
89a54e48 JB |
64 | if (!have_ifidx && !have_wdev_id) |
65 | return ERR_PTR(-EINVAL); | |
55682965 | 66 | |
89a54e48 JB |
67 | if (have_ifidx) |
68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
69 | if (have_wdev_id) { | |
70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
71 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
72 | } |
73 | ||
89a54e48 JB |
74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
75 | struct wireless_dev *wdev; | |
76 | ||
77 | if (wiphy_net(&rdev->wiphy) != netns) | |
78 | continue; | |
79 | ||
80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
81 | continue; | |
82 | ||
89a54e48 JB |
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 | } | |
89a54e48 JB |
94 | |
95 | if (result) | |
96 | break; | |
97 | } | |
98 | ||
99 | if (result) | |
100 | return result; | |
101 | return ERR_PTR(-ENODEV); | |
55682965 JB |
102 | } |
103 | ||
a9455408 | 104 | static struct cfg80211_registered_device * |
878d9ec7 | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 106 | { |
7fee4778 JB |
107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
108 | struct net_device *netdev; | |
a9455408 | 109 | |
5fe231e8 | 110 | ASSERT_RTNL(); |
a9455408 | 111 | |
878d9ec7 | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
113 | !attrs[NL80211_ATTR_IFINDEX] && |
114 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
115 | return ERR_PTR(-EINVAL); |
116 | ||
878d9ec7 | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 120 | |
89a54e48 JB |
121 | if (attrs[NL80211_ATTR_WDEV]) { |
122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
123 | struct wireless_dev *wdev; | |
124 | bool found = false; | |
125 | ||
126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
127 | if (tmp) { | |
128 | /* make sure wdev exists */ | |
89a54e48 JB |
129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
130 | if (wdev->identifier != (u32)wdev_id) | |
131 | continue; | |
132 | found = true; | |
133 | break; | |
134 | } | |
89a54e48 JB |
135 | |
136 | if (!found) | |
137 | tmp = NULL; | |
138 | ||
139 | if (rdev && tmp != rdev) | |
140 | return ERR_PTR(-EINVAL); | |
141 | rdev = tmp; | |
142 | } | |
143 | } | |
144 | ||
878d9ec7 JB |
145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
4f7eff10 | 147 | netdev = dev_get_by_index(netns, ifindex); |
7fee4778 JB |
148 | if (netdev) { |
149 | if (netdev->ieee80211_ptr) | |
150 | tmp = wiphy_to_dev( | |
151 | netdev->ieee80211_ptr->wiphy); | |
152 | else | |
153 | tmp = NULL; | |
154 | ||
155 | dev_put(netdev); | |
156 | ||
157 | /* not wireless device -- return error */ | |
158 | if (!tmp) | |
159 | return ERR_PTR(-EINVAL); | |
160 | ||
161 | /* mismatch -- return error */ | |
162 | if (rdev && tmp != rdev) | |
163 | return ERR_PTR(-EINVAL); | |
164 | ||
165 | rdev = tmp; | |
a9455408 | 166 | } |
a9455408 | 167 | } |
a9455408 | 168 | |
4f7eff10 JB |
169 | if (!rdev) |
170 | return ERR_PTR(-ENODEV); | |
a9455408 | 171 | |
4f7eff10 JB |
172 | if (netns != wiphy_net(&rdev->wiphy)) |
173 | return ERR_PTR(-ENODEV); | |
174 | ||
175 | return rdev; | |
a9455408 JB |
176 | } |
177 | ||
178 | /* | |
179 | * This function returns a pointer to the driver | |
180 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
181 | * |
182 | * The result of this can be a PTR_ERR and hence must | |
183 | * be checked with IS_ERR() for errors. | |
184 | */ | |
185 | static struct cfg80211_registered_device * | |
4f7eff10 | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 187 | { |
5fe231e8 | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
189 | } |
190 | ||
55682965 | 191 | /* policy for the attributes */ |
b54452b0 | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 195 | .len = 20-1 }, |
31888487 | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 197 | |
72bdcf34 | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
203 | ||
b9a5f8ca JM |
204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
209 | |
210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 213 | |
e007b857 EP |
214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 216 | |
b9454e83 | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
219 | .len = WLAN_MAX_KEY_LEN }, | |
220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
225 | |
226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
229 | .len = IEEE80211_MAX_DATA_LEN }, | |
230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
231 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
236 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 243 | |
b2e1b302 LR |
244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
246 | ||
9f1ba906 JM |
247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
251 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 253 | |
24bdd9f4 | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 256 | |
6c739419 | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
258 | |
259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
261 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
264 | |
265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
266 | .len = IEEE80211_MAX_SSID_LEN }, | |
267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
272 | [NL80211_ATTR_STA_FLAGS2] = { |
273 | .len = sizeof(struct nl80211_sta_flag_update), | |
274 | }, | |
3f77316c | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
284 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
289 | .len = IEEE80211_MAX_DATA_LEN }, | |
290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
312 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
323 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
327 | .len = NL80211_HT_CAPABILITY_LEN | |
328 | }, | |
1d9d9213 | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
346 | .len = NL80211_VHT_CAPABILITY_LEN, | |
347 | }, | |
355199e0 JM |
348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
350 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
352 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
353 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
354 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
355 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, | |
356 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, | |
c01fc9ad SD |
357 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
358 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 359 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 360 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
55682965 JB |
361 | }; |
362 | ||
e31b8213 | 363 | /* policy for the key attributes */ |
b54452b0 | 364 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 365 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
366 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
367 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 368 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
369 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
370 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 371 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
372 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
373 | }; | |
374 | ||
375 | /* policy for the key default flags */ | |
376 | static const struct nla_policy | |
377 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
378 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
379 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
380 | }; |
381 | ||
ff1b6e69 JB |
382 | /* policy for WoWLAN attributes */ |
383 | static const struct nla_policy | |
384 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
385 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
386 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
387 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
388 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
389 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
390 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
391 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
392 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
393 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
394 | }; | |
395 | ||
396 | static const struct nla_policy | |
397 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
398 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
399 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
400 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
401 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
402 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
403 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
404 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
405 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
406 | }, | |
407 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
408 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
409 | }, | |
410 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
411 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
412 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
413 | }; |
414 | ||
be29b99a AK |
415 | /* policy for coalesce rule attributes */ |
416 | static const struct nla_policy | |
417 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
418 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
419 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
420 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
421 | }; | |
422 | ||
e5497d76 JB |
423 | /* policy for GTK rekey offload attributes */ |
424 | static const struct nla_policy | |
425 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
426 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
427 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
428 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
429 | }; | |
430 | ||
a1f1c21c LC |
431 | static const struct nla_policy |
432 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 433 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 434 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 435 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
436 | }; |
437 | ||
97990a06 JB |
438 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
439 | struct netlink_callback *cb, | |
440 | struct cfg80211_registered_device **rdev, | |
441 | struct wireless_dev **wdev) | |
a043897a | 442 | { |
97990a06 | 443 | int err; |
a043897a | 444 | |
97990a06 | 445 | rtnl_lock(); |
a043897a | 446 | |
97990a06 JB |
447 | if (!cb->args[0]) { |
448 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
449 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
450 | nl80211_policy); | |
451 | if (err) | |
452 | goto out_unlock; | |
67748893 | 453 | |
97990a06 JB |
454 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
455 | nl80211_fam.attrbuf); | |
456 | if (IS_ERR(*wdev)) { | |
457 | err = PTR_ERR(*wdev); | |
458 | goto out_unlock; | |
459 | } | |
460 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
c319d50b JB |
461 | /* 0 is the first index - add 1 to parse only once */ |
462 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
463 | cb->args[1] = (*wdev)->identifier; |
464 | } else { | |
c319d50b JB |
465 | /* subtract the 1 again here */ |
466 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 467 | struct wireless_dev *tmp; |
67748893 | 468 | |
97990a06 JB |
469 | if (!wiphy) { |
470 | err = -ENODEV; | |
471 | goto out_unlock; | |
472 | } | |
473 | *rdev = wiphy_to_dev(wiphy); | |
474 | *wdev = NULL; | |
67748893 | 475 | |
97990a06 JB |
476 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
477 | if (tmp->identifier == cb->args[1]) { | |
478 | *wdev = tmp; | |
479 | break; | |
480 | } | |
481 | } | |
67748893 | 482 | |
97990a06 JB |
483 | if (!*wdev) { |
484 | err = -ENODEV; | |
485 | goto out_unlock; | |
486 | } | |
67748893 JB |
487 | } |
488 | ||
67748893 | 489 | return 0; |
97990a06 | 490 | out_unlock: |
67748893 JB |
491 | rtnl_unlock(); |
492 | return err; | |
493 | } | |
494 | ||
97990a06 | 495 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 496 | { |
67748893 JB |
497 | rtnl_unlock(); |
498 | } | |
499 | ||
f4a11bb0 JB |
500 | /* IE validation */ |
501 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
502 | { | |
503 | const u8 *pos; | |
504 | int len; | |
505 | ||
506 | if (!attr) | |
507 | return true; | |
508 | ||
509 | pos = nla_data(attr); | |
510 | len = nla_len(attr); | |
511 | ||
512 | while (len) { | |
513 | u8 elemlen; | |
514 | ||
515 | if (len < 2) | |
516 | return false; | |
517 | len -= 2; | |
518 | ||
519 | elemlen = pos[1]; | |
520 | if (elemlen > len) | |
521 | return false; | |
522 | ||
523 | len -= elemlen; | |
524 | pos += 2 + elemlen; | |
525 | } | |
526 | ||
527 | return true; | |
528 | } | |
529 | ||
55682965 | 530 | /* message building helper */ |
15e47304 | 531 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
532 | int flags, u8 cmd) |
533 | { | |
534 | /* since there is no private header just add the generic one */ | |
15e47304 | 535 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
536 | } |
537 | ||
5dab3b8a | 538 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
539 | struct ieee80211_channel *chan, |
540 | bool large) | |
5dab3b8a | 541 | { |
9360ffd1 DM |
542 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
543 | chan->center_freq)) | |
544 | goto nla_put_failure; | |
5dab3b8a | 545 | |
9360ffd1 DM |
546 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
547 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
548 | goto nla_put_failure; | |
8fe02e16 LR |
549 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
550 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
551 | goto nla_put_failure; | |
552 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
553 | goto nla_put_failure; | |
554 | } | |
cdc89b97 JB |
555 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
556 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
557 | goto nla_put_failure; | |
558 | if (large) { | |
559 | u32 time; | |
560 | ||
561 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
562 | ||
563 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
564 | chan->dfs_state)) | |
565 | goto nla_put_failure; | |
566 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
567 | time)) | |
568 | goto nla_put_failure; | |
569 | } | |
570 | } | |
5dab3b8a | 571 | |
fe1abafd JB |
572 | if (large) { |
573 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
574 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
575 | goto nla_put_failure; | |
576 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
578 | goto nla_put_failure; | |
579 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
580 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
581 | goto nla_put_failure; | |
582 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
583 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
584 | goto nla_put_failure; | |
585 | } | |
586 | ||
9360ffd1 DM |
587 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
588 | DBM_TO_MBM(chan->max_power))) | |
589 | goto nla_put_failure; | |
5dab3b8a LR |
590 | |
591 | return 0; | |
592 | ||
593 | nla_put_failure: | |
594 | return -ENOBUFS; | |
595 | } | |
596 | ||
55682965 JB |
597 | /* netlink command implementations */ |
598 | ||
b9454e83 JB |
599 | struct key_parse { |
600 | struct key_params p; | |
601 | int idx; | |
e31b8213 | 602 | int type; |
b9454e83 | 603 | bool def, defmgmt; |
dbd2fd65 | 604 | bool def_uni, def_multi; |
b9454e83 JB |
605 | }; |
606 | ||
607 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
608 | { | |
609 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
610 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
611 | nl80211_key_policy); | |
612 | if (err) | |
613 | return err; | |
614 | ||
615 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
616 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
617 | ||
dbd2fd65 JB |
618 | if (k->def) { |
619 | k->def_uni = true; | |
620 | k->def_multi = true; | |
621 | } | |
622 | if (k->defmgmt) | |
623 | k->def_multi = true; | |
624 | ||
b9454e83 JB |
625 | if (tb[NL80211_KEY_IDX]) |
626 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
627 | ||
628 | if (tb[NL80211_KEY_DATA]) { | |
629 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
630 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
631 | } | |
632 | ||
633 | if (tb[NL80211_KEY_SEQ]) { | |
634 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
635 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
636 | } | |
637 | ||
638 | if (tb[NL80211_KEY_CIPHER]) | |
639 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
640 | ||
e31b8213 JB |
641 | if (tb[NL80211_KEY_TYPE]) { |
642 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
643 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
644 | return -EINVAL; | |
645 | } | |
646 | ||
dbd2fd65 JB |
647 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
648 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
649 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
650 | tb[NL80211_KEY_DEFAULT_TYPES], | |
651 | nl80211_key_default_policy); | |
dbd2fd65 JB |
652 | if (err) |
653 | return err; | |
654 | ||
655 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
656 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
657 | } | |
658 | ||
b9454e83 JB |
659 | return 0; |
660 | } | |
661 | ||
662 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
663 | { | |
664 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
665 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
666 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
667 | } | |
668 | ||
669 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
670 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
671 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
672 | } | |
673 | ||
674 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
675 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
676 | ||
677 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
678 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
679 | ||
680 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
681 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
682 | ||
dbd2fd65 JB |
683 | if (k->def) { |
684 | k->def_uni = true; | |
685 | k->def_multi = true; | |
686 | } | |
687 | if (k->defmgmt) | |
688 | k->def_multi = true; | |
689 | ||
e31b8213 JB |
690 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
691 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
692 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
693 | return -EINVAL; | |
694 | } | |
695 | ||
dbd2fd65 JB |
696 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
697 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
698 | int err = nla_parse_nested( | |
699 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
700 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
701 | nl80211_key_default_policy); | |
702 | if (err) | |
703 | return err; | |
704 | ||
705 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
706 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
707 | } | |
708 | ||
b9454e83 JB |
709 | return 0; |
710 | } | |
711 | ||
712 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
713 | { | |
714 | int err; | |
715 | ||
716 | memset(k, 0, sizeof(*k)); | |
717 | k->idx = -1; | |
e31b8213 | 718 | k->type = -1; |
b9454e83 JB |
719 | |
720 | if (info->attrs[NL80211_ATTR_KEY]) | |
721 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
722 | else | |
723 | err = nl80211_parse_key_old(info, k); | |
724 | ||
725 | if (err) | |
726 | return err; | |
727 | ||
728 | if (k->def && k->defmgmt) | |
729 | return -EINVAL; | |
730 | ||
dbd2fd65 JB |
731 | if (k->defmgmt) { |
732 | if (k->def_uni || !k->def_multi) | |
733 | return -EINVAL; | |
734 | } | |
735 | ||
b9454e83 JB |
736 | if (k->idx != -1) { |
737 | if (k->defmgmt) { | |
738 | if (k->idx < 4 || k->idx > 5) | |
739 | return -EINVAL; | |
740 | } else if (k->def) { | |
741 | if (k->idx < 0 || k->idx > 3) | |
742 | return -EINVAL; | |
743 | } else { | |
744 | if (k->idx < 0 || k->idx > 5) | |
745 | return -EINVAL; | |
746 | } | |
747 | } | |
748 | ||
749 | return 0; | |
750 | } | |
751 | ||
fffd0934 JB |
752 | static struct cfg80211_cached_keys * |
753 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 754 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
755 | { |
756 | struct key_parse parse; | |
757 | struct nlattr *key; | |
758 | struct cfg80211_cached_keys *result; | |
759 | int rem, err, def = 0; | |
760 | ||
761 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
762 | if (!result) | |
763 | return ERR_PTR(-ENOMEM); | |
764 | ||
765 | result->def = -1; | |
766 | result->defmgmt = -1; | |
767 | ||
768 | nla_for_each_nested(key, keys, rem) { | |
769 | memset(&parse, 0, sizeof(parse)); | |
770 | parse.idx = -1; | |
771 | ||
772 | err = nl80211_parse_key_new(key, &parse); | |
773 | if (err) | |
774 | goto error; | |
775 | err = -EINVAL; | |
776 | if (!parse.p.key) | |
777 | goto error; | |
778 | if (parse.idx < 0 || parse.idx > 4) | |
779 | goto error; | |
780 | if (parse.def) { | |
781 | if (def) | |
782 | goto error; | |
783 | def = 1; | |
784 | result->def = parse.idx; | |
dbd2fd65 JB |
785 | if (!parse.def_uni || !parse.def_multi) |
786 | goto error; | |
fffd0934 JB |
787 | } else if (parse.defmgmt) |
788 | goto error; | |
789 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 790 | parse.idx, false, NULL); |
fffd0934 JB |
791 | if (err) |
792 | goto error; | |
793 | result->params[parse.idx].cipher = parse.p.cipher; | |
794 | result->params[parse.idx].key_len = parse.p.key_len; | |
795 | result->params[parse.idx].key = result->data[parse.idx]; | |
796 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
797 | |
798 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
799 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
800 | if (no_ht) | |
801 | *no_ht = true; | |
802 | } | |
fffd0934 JB |
803 | } |
804 | ||
805 | return result; | |
806 | error: | |
807 | kfree(result); | |
808 | return ERR_PTR(err); | |
809 | } | |
810 | ||
811 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
812 | { | |
813 | ASSERT_WDEV_LOCK(wdev); | |
814 | ||
fffd0934 JB |
815 | switch (wdev->iftype) { |
816 | case NL80211_IFTYPE_AP: | |
817 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 818 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 819 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
820 | break; |
821 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 822 | case NL80211_IFTYPE_STATION: |
074ac8df | 823 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 824 | if (!wdev->current_bss) |
fffd0934 JB |
825 | return -ENOLINK; |
826 | break; | |
827 | default: | |
828 | return -EINVAL; | |
829 | } | |
830 | ||
831 | return 0; | |
832 | } | |
833 | ||
7527a782 JB |
834 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
835 | { | |
836 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
837 | int i; | |
838 | ||
839 | if (!nl_modes) | |
840 | goto nla_put_failure; | |
841 | ||
842 | i = 0; | |
843 | while (ifmodes) { | |
9360ffd1 DM |
844 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
845 | goto nla_put_failure; | |
7527a782 JB |
846 | ifmodes >>= 1; |
847 | i++; | |
848 | } | |
849 | ||
850 | nla_nest_end(msg, nl_modes); | |
851 | return 0; | |
852 | ||
853 | nla_put_failure: | |
854 | return -ENOBUFS; | |
855 | } | |
856 | ||
857 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
858 | struct sk_buff *msg, |
859 | bool large) | |
7527a782 JB |
860 | { |
861 | struct nlattr *nl_combis; | |
862 | int i, j; | |
863 | ||
864 | nl_combis = nla_nest_start(msg, | |
865 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
866 | if (!nl_combis) | |
867 | goto nla_put_failure; | |
868 | ||
869 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
870 | const struct ieee80211_iface_combination *c; | |
871 | struct nlattr *nl_combi, *nl_limits; | |
872 | ||
873 | c = &wiphy->iface_combinations[i]; | |
874 | ||
875 | nl_combi = nla_nest_start(msg, i + 1); | |
876 | if (!nl_combi) | |
877 | goto nla_put_failure; | |
878 | ||
879 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
880 | if (!nl_limits) | |
881 | goto nla_put_failure; | |
882 | ||
883 | for (j = 0; j < c->n_limits; j++) { | |
884 | struct nlattr *nl_limit; | |
885 | ||
886 | nl_limit = nla_nest_start(msg, j + 1); | |
887 | if (!nl_limit) | |
888 | goto nla_put_failure; | |
9360ffd1 DM |
889 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
890 | c->limits[j].max)) | |
891 | goto nla_put_failure; | |
7527a782 JB |
892 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
893 | c->limits[j].types)) | |
894 | goto nla_put_failure; | |
895 | nla_nest_end(msg, nl_limit); | |
896 | } | |
897 | ||
898 | nla_nest_end(msg, nl_limits); | |
899 | ||
9360ffd1 DM |
900 | if (c->beacon_int_infra_match && |
901 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
902 | goto nla_put_failure; | |
903 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
904 | c->num_different_channels) || | |
905 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
906 | c->max_interfaces)) | |
907 | goto nla_put_failure; | |
cdc89b97 JB |
908 | if (large && |
909 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
910 | c->radar_detect_widths)) | |
911 | goto nla_put_failure; | |
7527a782 JB |
912 | |
913 | nla_nest_end(msg, nl_combi); | |
914 | } | |
915 | ||
916 | nla_nest_end(msg, nl_combis); | |
917 | ||
918 | return 0; | |
919 | nla_put_failure: | |
920 | return -ENOBUFS; | |
921 | } | |
922 | ||
3713b4e3 | 923 | #ifdef CONFIG_PM |
b56cf720 JB |
924 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
925 | struct sk_buff *msg) | |
926 | { | |
964dc9e2 | 927 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
928 | struct nlattr *nl_tcp; |
929 | ||
930 | if (!tcp) | |
931 | return 0; | |
932 | ||
933 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
934 | if (!nl_tcp) | |
935 | return -ENOBUFS; | |
936 | ||
937 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
938 | tcp->data_payload_max)) | |
939 | return -ENOBUFS; | |
940 | ||
941 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
942 | tcp->data_payload_max)) | |
943 | return -ENOBUFS; | |
944 | ||
945 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
946 | return -ENOBUFS; | |
947 | ||
948 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
949 | sizeof(*tcp->tok), tcp->tok)) | |
950 | return -ENOBUFS; | |
951 | ||
952 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
953 | tcp->data_interval_max)) | |
954 | return -ENOBUFS; | |
955 | ||
956 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
957 | tcp->wake_payload_max)) | |
958 | return -ENOBUFS; | |
959 | ||
960 | nla_nest_end(msg, nl_tcp); | |
961 | return 0; | |
962 | } | |
963 | ||
3713b4e3 | 964 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
965 | struct cfg80211_registered_device *dev, |
966 | bool large) | |
55682965 | 967 | { |
3713b4e3 | 968 | struct nlattr *nl_wowlan; |
55682965 | 969 | |
964dc9e2 | 970 | if (!dev->wiphy.wowlan) |
3713b4e3 | 971 | return 0; |
55682965 | 972 | |
3713b4e3 JB |
973 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
974 | if (!nl_wowlan) | |
975 | return -ENOBUFS; | |
9360ffd1 | 976 | |
964dc9e2 | 977 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
964dc9e2 | 979 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
964dc9e2 | 981 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
964dc9e2 | 983 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
964dc9e2 | 985 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
964dc9e2 | 987 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 988 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
964dc9e2 | 989 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 990 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
964dc9e2 | 991 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
992 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
993 | return -ENOBUFS; | |
9360ffd1 | 994 | |
964dc9e2 | 995 | if (dev->wiphy.wowlan->n_patterns) { |
50ac6607 | 996 | struct nl80211_pattern_support pat = { |
964dc9e2 JB |
997 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
998 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, | |
999 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, | |
1000 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1001 | }; |
9360ffd1 | 1002 | |
3713b4e3 JB |
1003 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1004 | sizeof(pat), &pat)) | |
1005 | return -ENOBUFS; | |
1006 | } | |
9360ffd1 | 1007 | |
b56cf720 JB |
1008 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1009 | return -ENOBUFS; | |
1010 | ||
3713b4e3 | 1011 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1012 | |
3713b4e3 JB |
1013 | return 0; |
1014 | } | |
1015 | #endif | |
9360ffd1 | 1016 | |
be29b99a AK |
1017 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1018 | struct cfg80211_registered_device *dev) | |
1019 | { | |
1020 | struct nl80211_coalesce_rule_support rule; | |
1021 | ||
1022 | if (!dev->wiphy.coalesce) | |
1023 | return 0; | |
1024 | ||
1025 | rule.max_rules = dev->wiphy.coalesce->n_rules; | |
1026 | rule.max_delay = dev->wiphy.coalesce->max_delay; | |
1027 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; | |
1028 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; | |
1029 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; | |
1030 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; | |
1031 | ||
1032 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1033 | return -ENOBUFS; | |
1034 | ||
1035 | return 0; | |
1036 | } | |
1037 | ||
3713b4e3 JB |
1038 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1039 | struct ieee80211_supported_band *sband) | |
1040 | { | |
1041 | struct nlattr *nl_rates, *nl_rate; | |
1042 | struct ieee80211_rate *rate; | |
1043 | int i; | |
87bbbe22 | 1044 | |
3713b4e3 JB |
1045 | /* add HT info */ |
1046 | if (sband->ht_cap.ht_supported && | |
1047 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1048 | sizeof(sband->ht_cap.mcs), | |
1049 | &sband->ht_cap.mcs) || | |
1050 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1051 | sband->ht_cap.cap) || | |
1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1053 | sband->ht_cap.ampdu_factor) || | |
1054 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1055 | sband->ht_cap.ampdu_density))) | |
1056 | return -ENOBUFS; | |
afe0cbf8 | 1057 | |
3713b4e3 JB |
1058 | /* add VHT info */ |
1059 | if (sband->vht_cap.vht_supported && | |
1060 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1061 | sizeof(sband->vht_cap.vht_mcs), | |
1062 | &sband->vht_cap.vht_mcs) || | |
1063 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1064 | sband->vht_cap.cap))) | |
1065 | return -ENOBUFS; | |
f59ac048 | 1066 | |
3713b4e3 JB |
1067 | /* add bitrates */ |
1068 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1069 | if (!nl_rates) | |
1070 | return -ENOBUFS; | |
ee688b00 | 1071 | |
3713b4e3 JB |
1072 | for (i = 0; i < sband->n_bitrates; i++) { |
1073 | nl_rate = nla_nest_start(msg, i); | |
1074 | if (!nl_rate) | |
1075 | return -ENOBUFS; | |
ee688b00 | 1076 | |
3713b4e3 JB |
1077 | rate = &sband->bitrates[i]; |
1078 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1079 | rate->bitrate)) | |
1080 | return -ENOBUFS; | |
1081 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1082 | nla_put_flag(msg, | |
1083 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1084 | return -ENOBUFS; | |
ee688b00 | 1085 | |
3713b4e3 JB |
1086 | nla_nest_end(msg, nl_rate); |
1087 | } | |
d51626df | 1088 | |
3713b4e3 | 1089 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1090 | |
3713b4e3 JB |
1091 | return 0; |
1092 | } | |
ee688b00 | 1093 | |
3713b4e3 JB |
1094 | static int |
1095 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1096 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1097 | { | |
1098 | u16 stypes; | |
1099 | struct nlattr *nl_ftypes, *nl_ifs; | |
1100 | enum nl80211_iftype ift; | |
1101 | int i; | |
ee688b00 | 1102 | |
3713b4e3 JB |
1103 | if (!mgmt_stypes) |
1104 | return 0; | |
5dab3b8a | 1105 | |
3713b4e3 JB |
1106 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1107 | if (!nl_ifs) | |
1108 | return -ENOBUFS; | |
e2f367f2 | 1109 | |
3713b4e3 JB |
1110 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1111 | nl_ftypes = nla_nest_start(msg, ift); | |
1112 | if (!nl_ftypes) | |
1113 | return -ENOBUFS; | |
1114 | i = 0; | |
1115 | stypes = mgmt_stypes[ift].tx; | |
1116 | while (stypes) { | |
1117 | if ((stypes & 1) && | |
1118 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1119 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1120 | return -ENOBUFS; | |
1121 | stypes >>= 1; | |
1122 | i++; | |
ee688b00 | 1123 | } |
3713b4e3 JB |
1124 | nla_nest_end(msg, nl_ftypes); |
1125 | } | |
ee688b00 | 1126 | |
3713b4e3 | 1127 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1128 | |
3713b4e3 JB |
1129 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1130 | if (!nl_ifs) | |
1131 | return -ENOBUFS; | |
ee688b00 | 1132 | |
3713b4e3 JB |
1133 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1134 | nl_ftypes = nla_nest_start(msg, ift); | |
1135 | if (!nl_ftypes) | |
1136 | return -ENOBUFS; | |
1137 | i = 0; | |
1138 | stypes = mgmt_stypes[ift].rx; | |
1139 | while (stypes) { | |
1140 | if ((stypes & 1) && | |
1141 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1142 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1143 | return -ENOBUFS; | |
1144 | stypes >>= 1; | |
1145 | i++; | |
1146 | } | |
1147 | nla_nest_end(msg, nl_ftypes); | |
1148 | } | |
1149 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1150 | |
3713b4e3 JB |
1151 | return 0; |
1152 | } | |
ee688b00 | 1153 | |
86e8cf98 JB |
1154 | struct nl80211_dump_wiphy_state { |
1155 | s64 filter_wiphy; | |
1156 | long start; | |
1157 | long split_start, band_start, chan_start; | |
1158 | bool split; | |
1159 | }; | |
1160 | ||
3713b4e3 JB |
1161 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1162 | struct sk_buff *msg, u32 portid, u32 seq, | |
86e8cf98 | 1163 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1164 | { |
1165 | void *hdr; | |
1166 | struct nlattr *nl_bands, *nl_band; | |
1167 | struct nlattr *nl_freqs, *nl_freq; | |
1168 | struct nlattr *nl_cmds; | |
1169 | enum ieee80211_band band; | |
1170 | struct ieee80211_channel *chan; | |
1171 | int i; | |
1172 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1173 | dev->wiphy.mgmt_stypes; | |
fe1abafd | 1174 | u32 features; |
ee688b00 | 1175 | |
3713b4e3 JB |
1176 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1177 | if (!hdr) | |
1178 | return -ENOBUFS; | |
ee688b00 | 1179 | |
86e8cf98 JB |
1180 | if (WARN_ON(!state)) |
1181 | return -EINVAL; | |
ee688b00 | 1182 | |
3713b4e3 JB |
1183 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1184 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1185 | wiphy_name(&dev->wiphy)) || | |
1186 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1187 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1188 | goto nla_put_failure; |
1189 | ||
86e8cf98 | 1190 | switch (state->split_start) { |
3713b4e3 JB |
1191 | case 0: |
1192 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1193 | dev->wiphy.retry_short) || | |
1194 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1195 | dev->wiphy.retry_long) || | |
1196 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1197 | dev->wiphy.frag_threshold) || | |
1198 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1199 | dev->wiphy.rts_threshold) || | |
1200 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1201 | dev->wiphy.coverage_class) || | |
1202 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1203 | dev->wiphy.max_scan_ssids) || | |
1204 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1205 | dev->wiphy.max_sched_scan_ssids) || | |
1206 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1207 | dev->wiphy.max_scan_ie_len) || | |
1208 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1209 | dev->wiphy.max_sched_scan_ie_len) || | |
1210 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1211 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1212 | goto nla_put_failure; |
3713b4e3 JB |
1213 | |
1214 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1215 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1216 | goto nla_put_failure; |
3713b4e3 JB |
1217 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1218 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1219 | goto nla_put_failure; | |
1220 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1221 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1222 | goto nla_put_failure; | |
1223 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1224 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1225 | goto nla_put_failure; | |
1226 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1227 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1228 | goto nla_put_failure; | |
1229 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1230 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1231 | goto nla_put_failure; |
86e8cf98 JB |
1232 | state->split_start++; |
1233 | if (state->split) | |
3713b4e3 JB |
1234 | break; |
1235 | case 1: | |
1236 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1237 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1238 | dev->wiphy.cipher_suites)) | |
1239 | goto nla_put_failure; | |
4745fc09 | 1240 | |
3713b4e3 JB |
1241 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1242 | dev->wiphy.max_num_pmkids)) | |
1243 | goto nla_put_failure; | |
b23aa676 | 1244 | |
3713b4e3 JB |
1245 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1246 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1247 | goto nla_put_failure; |
b23aa676 | 1248 | |
3713b4e3 JB |
1249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1250 | dev->wiphy.available_antennas_tx) || | |
1251 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1252 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1253 | goto nla_put_failure; |
b23aa676 | 1254 | |
3713b4e3 JB |
1255 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1256 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1257 | dev->wiphy.probe_resp_offload)) | |
1258 | goto nla_put_failure; | |
8fdc621d | 1259 | |
3713b4e3 JB |
1260 | if ((dev->wiphy.available_antennas_tx || |
1261 | dev->wiphy.available_antennas_rx) && | |
1262 | dev->ops->get_antenna) { | |
1263 | u32 tx_ant = 0, rx_ant = 0; | |
1264 | int res; | |
1265 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1266 | if (!res) { | |
1267 | if (nla_put_u32(msg, | |
1268 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1269 | tx_ant) || | |
1270 | nla_put_u32(msg, | |
1271 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1272 | rx_ant)) | |
1273 | goto nla_put_failure; | |
1274 | } | |
1275 | } | |
a293911d | 1276 | |
86e8cf98 JB |
1277 | state->split_start++; |
1278 | if (state->split) | |
3713b4e3 JB |
1279 | break; |
1280 | case 2: | |
1281 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1282 | dev->wiphy.interface_modes)) | |
1283 | goto nla_put_failure; | |
86e8cf98 JB |
1284 | state->split_start++; |
1285 | if (state->split) | |
3713b4e3 JB |
1286 | break; |
1287 | case 3: | |
1288 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1289 | if (!nl_bands) | |
1290 | goto nla_put_failure; | |
f7ca38df | 1291 | |
86e8cf98 JB |
1292 | for (band = state->band_start; |
1293 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1294 | struct ieee80211_supported_band *sband; |
2e161f78 | 1295 | |
3713b4e3 | 1296 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1297 | |
3713b4e3 JB |
1298 | if (!sband) |
1299 | continue; | |
1300 | ||
1301 | nl_band = nla_nest_start(msg, band); | |
1302 | if (!nl_band) | |
2e161f78 | 1303 | goto nla_put_failure; |
3713b4e3 | 1304 | |
86e8cf98 | 1305 | switch (state->chan_start) { |
3713b4e3 JB |
1306 | case 0: |
1307 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1308 | goto nla_put_failure; |
86e8cf98 JB |
1309 | state->chan_start++; |
1310 | if (state->split) | |
3713b4e3 JB |
1311 | break; |
1312 | default: | |
1313 | /* add frequencies */ | |
1314 | nl_freqs = nla_nest_start( | |
1315 | msg, NL80211_BAND_ATTR_FREQS); | |
1316 | if (!nl_freqs) | |
1317 | goto nla_put_failure; | |
1318 | ||
86e8cf98 | 1319 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1320 | i < sband->n_channels; |
1321 | i++) { | |
1322 | nl_freq = nla_nest_start(msg, i); | |
1323 | if (!nl_freq) | |
1324 | goto nla_put_failure; | |
1325 | ||
1326 | chan = &sband->channels[i]; | |
1327 | ||
86e8cf98 JB |
1328 | if (nl80211_msg_put_channel( |
1329 | msg, chan, | |
1330 | state->split)) | |
3713b4e3 JB |
1331 | goto nla_put_failure; |
1332 | ||
1333 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1334 | if (state->split) |
3713b4e3 JB |
1335 | break; |
1336 | } | |
1337 | if (i < sband->n_channels) | |
86e8cf98 | 1338 | state->chan_start = i + 2; |
3713b4e3 | 1339 | else |
86e8cf98 | 1340 | state->chan_start = 0; |
3713b4e3 JB |
1341 | nla_nest_end(msg, nl_freqs); |
1342 | } | |
1343 | ||
1344 | nla_nest_end(msg, nl_band); | |
1345 | ||
86e8cf98 | 1346 | if (state->split) { |
3713b4e3 | 1347 | /* start again here */ |
86e8cf98 | 1348 | if (state->chan_start) |
3713b4e3 JB |
1349 | band--; |
1350 | break; | |
2e161f78 | 1351 | } |
2e161f78 | 1352 | } |
3713b4e3 | 1353 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1354 | |
3713b4e3 | 1355 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1356 | state->band_start = band + 1; |
3713b4e3 | 1357 | else |
86e8cf98 | 1358 | state->band_start = 0; |
74b70a4e | 1359 | |
3713b4e3 | 1360 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1361 | if (state->band_start == 0 && state->chan_start == 0) |
1362 | state->split_start++; | |
1363 | if (state->split) | |
3713b4e3 JB |
1364 | break; |
1365 | case 4: | |
1366 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1367 | if (!nl_cmds) | |
2e161f78 JB |
1368 | goto nla_put_failure; |
1369 | ||
3713b4e3 JB |
1370 | i = 0; |
1371 | #define CMD(op, n) \ | |
1372 | do { \ | |
1373 | if (dev->ops->op) { \ | |
1374 | i++; \ | |
1375 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1376 | goto nla_put_failure; \ | |
1377 | } \ | |
1378 | } while (0) | |
1379 | ||
1380 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1381 | CMD(change_virtual_intf, SET_INTERFACE); | |
1382 | CMD(add_key, NEW_KEY); | |
1383 | CMD(start_ap, START_AP); | |
1384 | CMD(add_station, NEW_STATION); | |
1385 | CMD(add_mpath, NEW_MPATH); | |
1386 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1387 | CMD(change_bss, SET_BSS); | |
1388 | CMD(auth, AUTHENTICATE); | |
1389 | CMD(assoc, ASSOCIATE); | |
1390 | CMD(deauth, DEAUTHENTICATE); | |
1391 | CMD(disassoc, DISASSOCIATE); | |
1392 | CMD(join_ibss, JOIN_IBSS); | |
1393 | CMD(join_mesh, JOIN_MESH); | |
1394 | CMD(set_pmksa, SET_PMKSA); | |
1395 | CMD(del_pmksa, DEL_PMKSA); | |
1396 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1397 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1398 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1399 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1400 | CMD(mgmt_tx, FRAME); | |
1401 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1402 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1403 | i++; | |
1404 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1405 | goto nla_put_failure; |
2e161f78 | 1406 | } |
3713b4e3 JB |
1407 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1408 | dev->ops->join_mesh) { | |
1409 | i++; | |
1410 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1411 | goto nla_put_failure; | |
1412 | } | |
1413 | CMD(set_wds_peer, SET_WDS_PEER); | |
1414 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1415 | CMD(tdls_mgmt, TDLS_MGMT); | |
1416 | CMD(tdls_oper, TDLS_OPER); | |
1417 | } | |
1418 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1419 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1420 | CMD(probe_client, PROBE_CLIENT); | |
1421 | CMD(set_noack_map, SET_NOACK_MAP); | |
1422 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1423 | i++; | |
1424 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1425 | goto nla_put_failure; | |
1426 | } | |
1427 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1428 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
86e8cf98 | 1429 | if (state->split) { |
5de17984 AS |
1430 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1431 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
16ef1fe2 SW |
1432 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
1433 | CMD(channel_switch, CHANNEL_SWITCH); | |
5de17984 | 1434 | } |
2e161f78 | 1435 | |
3713b4e3 JB |
1436 | #ifdef CONFIG_NL80211_TESTMODE |
1437 | CMD(testmode_cmd, TESTMODE); | |
1438 | #endif | |
ff1b6e69 | 1439 | |
3713b4e3 | 1440 | #undef CMD |
ff1b6e69 | 1441 | |
3713b4e3 JB |
1442 | if (dev->ops->connect || dev->ops->auth) { |
1443 | i++; | |
1444 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1445 | goto nla_put_failure; |
ff1b6e69 JB |
1446 | } |
1447 | ||
3713b4e3 JB |
1448 | if (dev->ops->disconnect || dev->ops->deauth) { |
1449 | i++; | |
1450 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1451 | goto nla_put_failure; | |
1452 | } | |
1453 | ||
1454 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1455 | state->split_start++; |
1456 | if (state->split) | |
3713b4e3 JB |
1457 | break; |
1458 | case 5: | |
1459 | if (dev->ops->remain_on_channel && | |
1460 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1461 | nla_put_u32(msg, | |
1462 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1463 | dev->wiphy.max_remain_on_channel_duration)) | |
1464 | goto nla_put_failure; | |
1465 | ||
1466 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1467 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1468 | goto nla_put_failure; | |
1469 | ||
1470 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1471 | goto nla_put_failure; | |
86e8cf98 JB |
1472 | state->split_start++; |
1473 | if (state->split) | |
3713b4e3 JB |
1474 | break; |
1475 | case 6: | |
1476 | #ifdef CONFIG_PM | |
86e8cf98 | 1477 | if (nl80211_send_wowlan(msg, dev, state->split)) |
3713b4e3 | 1478 | goto nla_put_failure; |
86e8cf98 JB |
1479 | state->split_start++; |
1480 | if (state->split) | |
3713b4e3 JB |
1481 | break; |
1482 | #else | |
86e8cf98 | 1483 | state->split_start++; |
dfb89c56 | 1484 | #endif |
3713b4e3 JB |
1485 | case 7: |
1486 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1487 | dev->wiphy.software_iftypes)) | |
1488 | goto nla_put_failure; | |
ff1b6e69 | 1489 | |
86e8cf98 JB |
1490 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
1491 | state->split)) | |
3713b4e3 | 1492 | goto nla_put_failure; |
7527a782 | 1493 | |
86e8cf98 JB |
1494 | state->split_start++; |
1495 | if (state->split) | |
3713b4e3 JB |
1496 | break; |
1497 | case 8: | |
1498 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1499 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1500 | dev->wiphy.ap_sme_capa)) | |
1501 | goto nla_put_failure; | |
7527a782 | 1502 | |
fe1abafd JB |
1503 | features = dev->wiphy.features; |
1504 | /* | |
1505 | * We can only add the per-channel limit information if the | |
1506 | * dump is split, otherwise it makes it too big. Therefore | |
1507 | * only advertise it in that case. | |
1508 | */ | |
86e8cf98 | 1509 | if (state->split) |
fe1abafd JB |
1510 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1511 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1512 | goto nla_put_failure; |
562a7480 | 1513 | |
3713b4e3 JB |
1514 | if (dev->wiphy.ht_capa_mod_mask && |
1515 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1516 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1517 | dev->wiphy.ht_capa_mod_mask)) | |
1518 | goto nla_put_failure; | |
1f074bd8 | 1519 | |
3713b4e3 JB |
1520 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1521 | dev->wiphy.max_acl_mac_addrs && | |
1522 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1523 | dev->wiphy.max_acl_mac_addrs)) | |
1524 | goto nla_put_failure; | |
7e7c8926 | 1525 | |
3713b4e3 JB |
1526 | /* |
1527 | * Any information below this point is only available to | |
1528 | * applications that can deal with it being split. This | |
1529 | * helps ensure that newly added capabilities don't break | |
1530 | * older tools by overrunning their buffers. | |
1531 | * | |
1532 | * We still increment split_start so that in the split | |
1533 | * case we'll continue with more data in the next round, | |
1534 | * but break unconditionally so unsplit data stops here. | |
1535 | */ | |
86e8cf98 | 1536 | state->split_start++; |
3713b4e3 JB |
1537 | break; |
1538 | case 9: | |
fe1abafd JB |
1539 | if (dev->wiphy.extended_capabilities && |
1540 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1541 | dev->wiphy.extended_capabilities_len, | |
1542 | dev->wiphy.extended_capabilities) || | |
1543 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1544 | dev->wiphy.extended_capabilities_len, | |
1545 | dev->wiphy.extended_capabilities_mask))) | |
1546 | goto nla_put_failure; | |
a50df0c4 | 1547 | |
ee2aca34 JB |
1548 | if (dev->wiphy.vht_capa_mod_mask && |
1549 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1550 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1551 | dev->wiphy.vht_capa_mod_mask)) | |
1552 | goto nla_put_failure; | |
1553 | ||
be29b99a AK |
1554 | state->split_start++; |
1555 | break; | |
1556 | case 10: | |
1557 | if (nl80211_send_coalesce(msg, dev)) | |
1558 | goto nla_put_failure; | |
1559 | ||
01e0daa4 FF |
1560 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
1561 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || | |
1562 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1563 | goto nla_put_failure; | |
1564 | ||
3713b4e3 | 1565 | /* done */ |
86e8cf98 | 1566 | state->split_start = 0; |
3713b4e3 JB |
1567 | break; |
1568 | } | |
55682965 JB |
1569 | return genlmsg_end(msg, hdr); |
1570 | ||
1571 | nla_put_failure: | |
bc3ed28c TG |
1572 | genlmsg_cancel(msg, hdr); |
1573 | return -EMSGSIZE; | |
55682965 JB |
1574 | } |
1575 | ||
86e8cf98 JB |
1576 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1577 | struct netlink_callback *cb, | |
1578 | struct nl80211_dump_wiphy_state *state) | |
1579 | { | |
1580 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1581 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1582 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1583 | /* ignore parse errors for backward compatibility */ | |
1584 | if (ret) | |
1585 | return 0; | |
1586 | ||
1587 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1588 | if (tb[NL80211_ATTR_WIPHY]) | |
1589 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1590 | if (tb[NL80211_ATTR_WDEV]) | |
1591 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1592 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1593 | struct net_device *netdev; | |
1594 | struct cfg80211_registered_device *rdev; | |
1595 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1596 | ||
1597 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1598 | if (!netdev) | |
1599 | return -ENODEV; | |
1600 | if (netdev->ieee80211_ptr) { | |
1601 | rdev = wiphy_to_dev( | |
1602 | netdev->ieee80211_ptr->wiphy); | |
1603 | state->filter_wiphy = rdev->wiphy_idx; | |
1604 | } | |
1605 | dev_put(netdev); | |
1606 | } | |
1607 | ||
1608 | return 0; | |
1609 | } | |
1610 | ||
55682965 JB |
1611 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1612 | { | |
645e77de | 1613 | int idx = 0, ret; |
86e8cf98 | 1614 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
55682965 | 1615 | struct cfg80211_registered_device *dev; |
3a5a423b | 1616 | |
5fe231e8 | 1617 | rtnl_lock(); |
86e8cf98 JB |
1618 | if (!state) { |
1619 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1620 | if (!state) { |
1621 | rtnl_unlock(); | |
86e8cf98 | 1622 | return -ENOMEM; |
3713b4e3 | 1623 | } |
86e8cf98 JB |
1624 | state->filter_wiphy = -1; |
1625 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1626 | if (ret) { | |
1627 | kfree(state); | |
1628 | rtnl_unlock(); | |
1629 | return ret; | |
3713b4e3 | 1630 | } |
86e8cf98 | 1631 | cb->args[0] = (long)state; |
3713b4e3 JB |
1632 | } |
1633 | ||
79c97e97 | 1634 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1635 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1636 | continue; | |
86e8cf98 | 1637 | if (++idx <= state->start) |
55682965 | 1638 | continue; |
86e8cf98 JB |
1639 | if (state->filter_wiphy != -1 && |
1640 | state->filter_wiphy != dev->wiphy_idx) | |
3713b4e3 JB |
1641 | continue; |
1642 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1643 | do { | |
1644 | ret = nl80211_send_wiphy(dev, skb, | |
1645 | NETLINK_CB(cb->skb).portid, | |
1646 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1647 | NLM_F_MULTI, state); |
3713b4e3 JB |
1648 | if (ret < 0) { |
1649 | /* | |
1650 | * If sending the wiphy data didn't fit (ENOBUFS | |
1651 | * or EMSGSIZE returned), this SKB is still | |
1652 | * empty (so it's not too big because another | |
1653 | * wiphy dataset is already in the skb) and | |
1654 | * we've not tried to adjust the dump allocation | |
1655 | * yet ... then adjust the alloc size to be | |
1656 | * bigger, and return 1 but with the empty skb. | |
1657 | * This results in an empty message being RX'ed | |
1658 | * in userspace, but that is ignored. | |
1659 | * | |
1660 | * We can then retry with the larger buffer. | |
1661 | */ | |
1662 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1663 | !skb->len && | |
1664 | cb->min_dump_alloc < 4096) { | |
1665 | cb->min_dump_alloc = 4096; | |
d98cae64 | 1666 | rtnl_unlock(); |
3713b4e3 JB |
1667 | return 1; |
1668 | } | |
1669 | idx--; | |
1670 | break; | |
645e77de | 1671 | } |
86e8cf98 | 1672 | } while (state->split_start > 0); |
3713b4e3 | 1673 | break; |
55682965 | 1674 | } |
5fe231e8 | 1675 | rtnl_unlock(); |
55682965 | 1676 | |
86e8cf98 | 1677 | state->start = idx; |
55682965 JB |
1678 | |
1679 | return skb->len; | |
1680 | } | |
1681 | ||
86e8cf98 JB |
1682 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1683 | { | |
1684 | kfree((void *)cb->args[0]); | |
1685 | return 0; | |
1686 | } | |
1687 | ||
55682965 JB |
1688 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1689 | { | |
1690 | struct sk_buff *msg; | |
4c476991 | 1691 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
86e8cf98 | 1692 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1693 | |
645e77de | 1694 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1695 | if (!msg) |
4c476991 | 1696 | return -ENOMEM; |
55682965 | 1697 | |
3713b4e3 | 1698 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
86e8cf98 | 1699 | &state) < 0) { |
4c476991 JB |
1700 | nlmsg_free(msg); |
1701 | return -ENOBUFS; | |
1702 | } | |
55682965 | 1703 | |
134e6375 | 1704 | return genlmsg_reply(msg, info); |
55682965 JB |
1705 | } |
1706 | ||
31888487 JM |
1707 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1708 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1709 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1710 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1711 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1712 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1713 | }; | |
1714 | ||
1715 | static int parse_txq_params(struct nlattr *tb[], | |
1716 | struct ieee80211_txq_params *txq_params) | |
1717 | { | |
a3304b0a | 1718 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1719 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1720 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1721 | return -EINVAL; | |
1722 | ||
a3304b0a | 1723 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1724 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1725 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1726 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1727 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1728 | ||
a3304b0a JB |
1729 | if (txq_params->ac >= NL80211_NUM_ACS) |
1730 | return -EINVAL; | |
1731 | ||
31888487 JM |
1732 | return 0; |
1733 | } | |
1734 | ||
f444de05 JB |
1735 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1736 | { | |
1737 | /* | |
cc1d2806 JB |
1738 | * You can only set the channel explicitly for WDS interfaces, |
1739 | * all others have their channel managed via their respective | |
1740 | * "establish a connection" command (connect, join, ...) | |
1741 | * | |
1742 | * For AP/GO and mesh mode, the channel can be set with the | |
1743 | * channel userspace API, but is only stored and passed to the | |
1744 | * low-level driver when the AP starts or the mesh is joined. | |
1745 | * This is for backward compatibility, userspace can also give | |
1746 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1747 | * |
1748 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1749 | * whatever else is going on, so they have their own special |
1750 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1751 | */ |
1752 | return !wdev || | |
1753 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1754 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1755 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1756 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1757 | } |
1758 | ||
683b6d3b JB |
1759 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1760 | struct genl_info *info, | |
1761 | struct cfg80211_chan_def *chandef) | |
1762 | { | |
dbeca2ea | 1763 | u32 control_freq; |
683b6d3b JB |
1764 | |
1765 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1766 | return -EINVAL; | |
1767 | ||
1768 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1769 | ||
1770 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1771 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1772 | chandef->center_freq1 = control_freq; | |
1773 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1774 | |
1775 | /* Primary channel not allowed */ | |
1776 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1777 | return -EINVAL; | |
1778 | ||
3d9d1d66 JB |
1779 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1780 | enum nl80211_channel_type chantype; | |
1781 | ||
1782 | chantype = nla_get_u32( | |
1783 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1784 | ||
1785 | switch (chantype) { | |
1786 | case NL80211_CHAN_NO_HT: | |
1787 | case NL80211_CHAN_HT20: | |
1788 | case NL80211_CHAN_HT40PLUS: | |
1789 | case NL80211_CHAN_HT40MINUS: | |
1790 | cfg80211_chandef_create(chandef, chandef->chan, | |
1791 | chantype); | |
1792 | break; | |
1793 | default: | |
1794 | return -EINVAL; | |
1795 | } | |
1796 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1797 | chandef->width = | |
1798 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1799 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1800 | chandef->center_freq1 = | |
1801 | nla_get_u32( | |
1802 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1803 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1804 | chandef->center_freq2 = | |
1805 | nla_get_u32( | |
1806 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1807 | } | |
1808 | ||
9f5e8f6e | 1809 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1810 | return -EINVAL; |
1811 | ||
9f5e8f6e JB |
1812 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1813 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1814 | return -EINVAL; |
1815 | ||
2f301ab2 SW |
1816 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1817 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1818 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1819 | return -EINVAL; | |
1820 | ||
683b6d3b JB |
1821 | return 0; |
1822 | } | |
1823 | ||
f444de05 JB |
1824 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1825 | struct wireless_dev *wdev, | |
1826 | struct genl_info *info) | |
1827 | { | |
683b6d3b | 1828 | struct cfg80211_chan_def chandef; |
f444de05 | 1829 | int result; |
e8c9bd5b JB |
1830 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1831 | ||
1832 | if (wdev) | |
1833 | iftype = wdev->iftype; | |
f444de05 | 1834 | |
f444de05 JB |
1835 | if (!nl80211_can_set_dev_channel(wdev)) |
1836 | return -EOPNOTSUPP; | |
1837 | ||
683b6d3b JB |
1838 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1839 | if (result) | |
1840 | return result; | |
f444de05 | 1841 | |
e8c9bd5b | 1842 | switch (iftype) { |
aa430da4 JB |
1843 | case NL80211_IFTYPE_AP: |
1844 | case NL80211_IFTYPE_P2P_GO: | |
1845 | if (wdev->beacon_interval) { | |
1846 | result = -EBUSY; | |
1847 | break; | |
1848 | } | |
683b6d3b | 1849 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1850 | result = -EINVAL; |
1851 | break; | |
1852 | } | |
683b6d3b | 1853 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1854 | result = 0; |
1855 | break; | |
cc1d2806 | 1856 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1857 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1858 | break; |
e8c9bd5b | 1859 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1860 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1861 | break; |
aa430da4 | 1862 | default: |
e8c9bd5b | 1863 | result = -EINVAL; |
f444de05 | 1864 | } |
f444de05 JB |
1865 | |
1866 | return result; | |
1867 | } | |
1868 | ||
1869 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1870 | { | |
4c476991 JB |
1871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1872 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1873 | |
4c476991 | 1874 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1875 | } |
1876 | ||
e8347eba BJ |
1877 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1878 | { | |
43b19952 JB |
1879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1880 | struct net_device *dev = info->user_ptr[1]; | |
1881 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1882 | const u8 *bssid; |
e8347eba BJ |
1883 | |
1884 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1885 | return -EINVAL; | |
1886 | ||
43b19952 JB |
1887 | if (netif_running(dev)) |
1888 | return -EBUSY; | |
e8347eba | 1889 | |
43b19952 JB |
1890 | if (!rdev->ops->set_wds_peer) |
1891 | return -EOPNOTSUPP; | |
e8347eba | 1892 | |
43b19952 JB |
1893 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1894 | return -EOPNOTSUPP; | |
e8347eba BJ |
1895 | |
1896 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1897 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1898 | } |
1899 | ||
1900 | ||
55682965 JB |
1901 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1902 | { | |
1903 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1904 | struct net_device *netdev = NULL; |
1905 | struct wireless_dev *wdev; | |
a1e567c8 | 1906 | int result = 0, rem_txq_params = 0; |
31888487 | 1907 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1908 | u32 changed; |
1909 | u8 retry_short = 0, retry_long = 0; | |
1910 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1911 | u8 coverage_class = 0; |
55682965 | 1912 | |
5fe231e8 JB |
1913 | ASSERT_RTNL(); |
1914 | ||
f444de05 JB |
1915 | /* |
1916 | * Try to find the wiphy and netdev. Normally this | |
1917 | * function shouldn't need the netdev, but this is | |
1918 | * done for backward compatibility -- previously | |
1919 | * setting the channel was done per wiphy, but now | |
1920 | * it is per netdev. Previous userland like hostapd | |
1921 | * also passed a netdev to set_wiphy, so that it is | |
1922 | * possible to let that go to the right netdev! | |
1923 | */ | |
4bbf4d56 | 1924 | |
f444de05 JB |
1925 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1926 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1927 | ||
1928 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
5fe231e8 | 1929 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 1930 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 1931 | else |
f444de05 | 1932 | netdev = NULL; |
4bbf4d56 JB |
1933 | } |
1934 | ||
f444de05 | 1935 | if (!netdev) { |
878d9ec7 JB |
1936 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1937 | info->attrs); | |
5fe231e8 | 1938 | if (IS_ERR(rdev)) |
4c476991 | 1939 | return PTR_ERR(rdev); |
f444de05 JB |
1940 | wdev = NULL; |
1941 | netdev = NULL; | |
1942 | result = 0; | |
71fe96bf | 1943 | } else |
f444de05 | 1944 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1945 | |
1946 | /* | |
1947 | * end workaround code, by now the rdev is available | |
1948 | * and locked, and wdev may or may not be NULL. | |
1949 | */ | |
4bbf4d56 JB |
1950 | |
1951 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1952 | result = cfg80211_dev_rename( |
1953 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 1954 | |
4bbf4d56 JB |
1955 | if (result) |
1956 | goto bad_res; | |
31888487 JM |
1957 | |
1958 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1959 | struct ieee80211_txq_params txq_params; | |
1960 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1961 | ||
1962 | if (!rdev->ops->set_txq_params) { | |
1963 | result = -EOPNOTSUPP; | |
1964 | goto bad_res; | |
1965 | } | |
1966 | ||
f70f01c2 EP |
1967 | if (!netdev) { |
1968 | result = -EINVAL; | |
1969 | goto bad_res; | |
1970 | } | |
1971 | ||
133a3ff2 JB |
1972 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1973 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1974 | result = -EINVAL; | |
1975 | goto bad_res; | |
1976 | } | |
1977 | ||
2b5f8b0b JB |
1978 | if (!netif_running(netdev)) { |
1979 | result = -ENETDOWN; | |
1980 | goto bad_res; | |
1981 | } | |
1982 | ||
31888487 JM |
1983 | nla_for_each_nested(nl_txq_params, |
1984 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1985 | rem_txq_params) { | |
1986 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1987 | nla_data(nl_txq_params), | |
1988 | nla_len(nl_txq_params), | |
1989 | txq_params_policy); | |
1990 | result = parse_txq_params(tb, &txq_params); | |
1991 | if (result) | |
1992 | goto bad_res; | |
1993 | ||
e35e4d28 HG |
1994 | result = rdev_set_txq_params(rdev, netdev, |
1995 | &txq_params); | |
31888487 JM |
1996 | if (result) |
1997 | goto bad_res; | |
1998 | } | |
1999 | } | |
55682965 | 2000 | |
72bdcf34 | 2001 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
2002 | result = __nl80211_set_channel(rdev, |
2003 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
2004 | info); | |
72bdcf34 JM |
2005 | if (result) |
2006 | goto bad_res; | |
2007 | } | |
2008 | ||
98d2ff8b | 2009 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2010 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2011 | enum nl80211_tx_power_setting type; |
2012 | int idx, mbm = 0; | |
2013 | ||
c8442118 JB |
2014 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2015 | txp_wdev = NULL; | |
2016 | ||
98d2ff8b | 2017 | if (!rdev->ops->set_tx_power) { |
60ea385f | 2018 | result = -EOPNOTSUPP; |
98d2ff8b JO |
2019 | goto bad_res; |
2020 | } | |
2021 | ||
2022 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2023 | type = nla_get_u32(info->attrs[idx]); | |
2024 | ||
2025 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
2026 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
2027 | result = -EINVAL; | |
2028 | goto bad_res; | |
2029 | } | |
2030 | ||
2031 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2032 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2033 | mbm = nla_get_u32(info->attrs[idx]); | |
2034 | } | |
2035 | ||
c8442118 | 2036 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
2037 | if (result) |
2038 | goto bad_res; | |
2039 | } | |
2040 | ||
afe0cbf8 BR |
2041 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2042 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2043 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2044 | if ((!rdev->wiphy.available_antennas_tx && |
2045 | !rdev->wiphy.available_antennas_rx) || | |
2046 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
2047 | result = -EOPNOTSUPP; |
2048 | goto bad_res; | |
2049 | } | |
2050 | ||
2051 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2052 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2053 | ||
a7ffac95 | 2054 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2055 | * available antenna masks, except for the "all" mask */ |
2056 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2057 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2058 | result = -EINVAL; |
2059 | goto bad_res; | |
2060 | } | |
2061 | ||
7f531e03 BR |
2062 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2063 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2064 | |
e35e4d28 | 2065 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2066 | if (result) |
2067 | goto bad_res; | |
2068 | } | |
2069 | ||
b9a5f8ca JM |
2070 | changed = 0; |
2071 | ||
2072 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2073 | retry_short = nla_get_u8( | |
2074 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2075 | if (retry_short == 0) { | |
2076 | result = -EINVAL; | |
2077 | goto bad_res; | |
2078 | } | |
2079 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2080 | } | |
2081 | ||
2082 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2083 | retry_long = nla_get_u8( | |
2084 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2085 | if (retry_long == 0) { | |
2086 | result = -EINVAL; | |
2087 | goto bad_res; | |
2088 | } | |
2089 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2090 | } | |
2091 | ||
2092 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2093 | frag_threshold = nla_get_u32( | |
2094 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2095 | if (frag_threshold < 256) { | |
2096 | result = -EINVAL; | |
2097 | goto bad_res; | |
2098 | } | |
2099 | if (frag_threshold != (u32) -1) { | |
2100 | /* | |
2101 | * Fragments (apart from the last one) are required to | |
2102 | * have even length. Make the fragmentation code | |
2103 | * simpler by stripping LSB should someone try to use | |
2104 | * odd threshold value. | |
2105 | */ | |
2106 | frag_threshold &= ~0x1; | |
2107 | } | |
2108 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2109 | } | |
2110 | ||
2111 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2112 | rts_threshold = nla_get_u32( | |
2113 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2114 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2115 | } | |
2116 | ||
81077e82 LT |
2117 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2118 | coverage_class = nla_get_u8( | |
2119 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2120 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2121 | } | |
2122 | ||
b9a5f8ca JM |
2123 | if (changed) { |
2124 | u8 old_retry_short, old_retry_long; | |
2125 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2126 | u8 old_coverage_class; |
b9a5f8ca JM |
2127 | |
2128 | if (!rdev->ops->set_wiphy_params) { | |
2129 | result = -EOPNOTSUPP; | |
2130 | goto bad_res; | |
2131 | } | |
2132 | ||
2133 | old_retry_short = rdev->wiphy.retry_short; | |
2134 | old_retry_long = rdev->wiphy.retry_long; | |
2135 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2136 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2137 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2138 | |
2139 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2140 | rdev->wiphy.retry_short = retry_short; | |
2141 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2142 | rdev->wiphy.retry_long = retry_long; | |
2143 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2144 | rdev->wiphy.frag_threshold = frag_threshold; | |
2145 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2146 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2147 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2148 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2149 | |
e35e4d28 | 2150 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2151 | if (result) { |
2152 | rdev->wiphy.retry_short = old_retry_short; | |
2153 | rdev->wiphy.retry_long = old_retry_long; | |
2154 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2155 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2156 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2157 | } |
2158 | } | |
72bdcf34 | 2159 | |
306d6112 | 2160 | bad_res: |
f444de05 JB |
2161 | if (netdev) |
2162 | dev_put(netdev); | |
55682965 JB |
2163 | return result; |
2164 | } | |
2165 | ||
71bbc994 JB |
2166 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2167 | { | |
2168 | return (u64)wdev->identifier | | |
2169 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2170 | } | |
55682965 | 2171 | |
683b6d3b | 2172 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2173 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2174 | { |
9f5e8f6e | 2175 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2176 | |
683b6d3b JB |
2177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2178 | chandef->chan->center_freq)) | |
2179 | return -ENOBUFS; | |
3d9d1d66 JB |
2180 | switch (chandef->width) { |
2181 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2182 | case NL80211_CHAN_WIDTH_20: | |
2183 | case NL80211_CHAN_WIDTH_40: | |
2184 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2185 | cfg80211_get_chandef_type(chandef))) | |
2186 | return -ENOBUFS; | |
2187 | break; | |
2188 | default: | |
2189 | break; | |
2190 | } | |
2191 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2192 | return -ENOBUFS; | |
2193 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2194 | return -ENOBUFS; | |
2195 | if (chandef->center_freq2 && | |
2196 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2197 | return -ENOBUFS; |
2198 | return 0; | |
2199 | } | |
2200 | ||
15e47304 | 2201 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2202 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2203 | struct wireless_dev *wdev) |
55682965 | 2204 | { |
72fb2abc | 2205 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2206 | void *hdr; |
2207 | ||
15e47304 | 2208 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2209 | if (!hdr) |
2210 | return -1; | |
2211 | ||
72fb2abc JB |
2212 | if (dev && |
2213 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2214 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2215 | goto nla_put_failure; |
2216 | ||
2217 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2218 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2219 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2220 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2221 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2222 | rdev->devlist_generation ^ | |
2223 | (cfg80211_rdev_list_generation << 2))) | |
2224 | goto nla_put_failure; | |
f5ea9120 | 2225 | |
5b7ccaf3 | 2226 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2227 | int ret; |
2228 | struct cfg80211_chan_def chandef; | |
2229 | ||
2230 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2231 | if (ret == 0) { | |
2232 | if (nl80211_send_chandef(msg, &chandef)) | |
2233 | goto nla_put_failure; | |
2234 | } | |
d91df0e3 PF |
2235 | } |
2236 | ||
b84e7a05 AQ |
2237 | if (wdev->ssid_len) { |
2238 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2239 | goto nla_put_failure; | |
2240 | } | |
2241 | ||
55682965 JB |
2242 | return genlmsg_end(msg, hdr); |
2243 | ||
2244 | nla_put_failure: | |
bc3ed28c TG |
2245 | genlmsg_cancel(msg, hdr); |
2246 | return -EMSGSIZE; | |
55682965 JB |
2247 | } |
2248 | ||
2249 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2250 | { | |
2251 | int wp_idx = 0; | |
2252 | int if_idx = 0; | |
2253 | int wp_start = cb->args[0]; | |
2254 | int if_start = cb->args[1]; | |
f5ea9120 | 2255 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2256 | struct wireless_dev *wdev; |
2257 | ||
5fe231e8 | 2258 | rtnl_lock(); |
f5ea9120 JB |
2259 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2260 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2261 | continue; |
bba95fef JB |
2262 | if (wp_idx < wp_start) { |
2263 | wp_idx++; | |
55682965 | 2264 | continue; |
bba95fef | 2265 | } |
55682965 JB |
2266 | if_idx = 0; |
2267 | ||
89a54e48 | 2268 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2269 | if (if_idx < if_start) { |
2270 | if_idx++; | |
55682965 | 2271 | continue; |
bba95fef | 2272 | } |
15e47304 | 2273 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2274 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2275 | rdev, wdev) < 0) { |
bba95fef JB |
2276 | goto out; |
2277 | } | |
2278 | if_idx++; | |
55682965 | 2279 | } |
bba95fef JB |
2280 | |
2281 | wp_idx++; | |
55682965 | 2282 | } |
bba95fef | 2283 | out: |
5fe231e8 | 2284 | rtnl_unlock(); |
55682965 JB |
2285 | |
2286 | cb->args[0] = wp_idx; | |
2287 | cb->args[1] = if_idx; | |
2288 | ||
2289 | return skb->len; | |
2290 | } | |
2291 | ||
2292 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2293 | { | |
2294 | struct sk_buff *msg; | |
4c476991 | 2295 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2296 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2297 | |
fd2120ca | 2298 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2299 | if (!msg) |
4c476991 | 2300 | return -ENOMEM; |
55682965 | 2301 | |
15e47304 | 2302 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2303 | dev, wdev) < 0) { |
4c476991 JB |
2304 | nlmsg_free(msg); |
2305 | return -ENOBUFS; | |
2306 | } | |
55682965 | 2307 | |
134e6375 | 2308 | return genlmsg_reply(msg, info); |
55682965 JB |
2309 | } |
2310 | ||
66f7ac50 MW |
2311 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2312 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2313 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2314 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2315 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2316 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2317 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2318 | }; |
2319 | ||
2320 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2321 | { | |
2322 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2323 | int flag; | |
2324 | ||
2325 | *mntrflags = 0; | |
2326 | ||
2327 | if (!nla) | |
2328 | return -EINVAL; | |
2329 | ||
2330 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2331 | nla, mntr_flags_policy)) | |
2332 | return -EINVAL; | |
2333 | ||
2334 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2335 | if (flags[flag]) | |
2336 | *mntrflags |= (1<<flag); | |
2337 | ||
2338 | return 0; | |
2339 | } | |
2340 | ||
9bc383de | 2341 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2342 | struct net_device *netdev, u8 use_4addr, |
2343 | enum nl80211_iftype iftype) | |
9bc383de | 2344 | { |
ad4bb6f8 | 2345 | if (!use_4addr) { |
f350a0a8 | 2346 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2347 | return -EBUSY; |
9bc383de | 2348 | return 0; |
ad4bb6f8 | 2349 | } |
9bc383de JB |
2350 | |
2351 | switch (iftype) { | |
2352 | case NL80211_IFTYPE_AP_VLAN: | |
2353 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2354 | return 0; | |
2355 | break; | |
2356 | case NL80211_IFTYPE_STATION: | |
2357 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2358 | return 0; | |
2359 | break; | |
2360 | default: | |
2361 | break; | |
2362 | } | |
2363 | ||
2364 | return -EOPNOTSUPP; | |
2365 | } | |
2366 | ||
55682965 JB |
2367 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2368 | { | |
4c476991 | 2369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2370 | struct vif_params params; |
e36d56b6 | 2371 | int err; |
04a773ad | 2372 | enum nl80211_iftype otype, ntype; |
4c476991 | 2373 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2374 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2375 | bool change = false; |
55682965 | 2376 | |
2ec600d6 LCC |
2377 | memset(¶ms, 0, sizeof(params)); |
2378 | ||
04a773ad | 2379 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2380 | |
723b038d | 2381 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2382 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2383 | if (otype != ntype) |
ac7f9cfa | 2384 | change = true; |
4c476991 JB |
2385 | if (ntype > NL80211_IFTYPE_MAX) |
2386 | return -EINVAL; | |
723b038d JB |
2387 | } |
2388 | ||
92ffe055 | 2389 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2390 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2391 | ||
4c476991 JB |
2392 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2393 | return -EINVAL; | |
29cbe68c JB |
2394 | if (netif_running(dev)) |
2395 | return -EBUSY; | |
2396 | ||
2397 | wdev_lock(wdev); | |
2398 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2399 | IEEE80211_MAX_MESH_ID_LEN); | |
2400 | wdev->mesh_id_up_len = | |
2401 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2402 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2403 | wdev->mesh_id_up_len); | |
2404 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2405 | } |
2406 | ||
8b787643 FF |
2407 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2408 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2409 | change = true; | |
ad4bb6f8 | 2410 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2411 | if (err) |
4c476991 | 2412 | return err; |
8b787643 FF |
2413 | } else { |
2414 | params.use_4addr = -1; | |
2415 | } | |
2416 | ||
92ffe055 | 2417 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2418 | if (ntype != NL80211_IFTYPE_MONITOR) |
2419 | return -EINVAL; | |
92ffe055 JB |
2420 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2421 | &_flags); | |
ac7f9cfa | 2422 | if (err) |
4c476991 | 2423 | return err; |
ac7f9cfa JB |
2424 | |
2425 | flags = &_flags; | |
2426 | change = true; | |
92ffe055 | 2427 | } |
3b85875a | 2428 | |
18003297 | 2429 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2430 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2431 | return -EOPNOTSUPP; | |
2432 | ||
ac7f9cfa | 2433 | if (change) |
3d54d255 | 2434 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2435 | else |
2436 | err = 0; | |
60719ffd | 2437 | |
9bc383de JB |
2438 | if (!err && params.use_4addr != -1) |
2439 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2440 | ||
55682965 JB |
2441 | return err; |
2442 | } | |
2443 | ||
2444 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2445 | { | |
4c476991 | 2446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2447 | struct vif_params params; |
84efbb84 | 2448 | struct wireless_dev *wdev; |
1c90f9d4 | 2449 | struct sk_buff *msg; |
55682965 JB |
2450 | int err; |
2451 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2452 | u32 flags; |
55682965 | 2453 | |
2ec600d6 LCC |
2454 | memset(¶ms, 0, sizeof(params)); |
2455 | ||
55682965 JB |
2456 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2457 | return -EINVAL; | |
2458 | ||
2459 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2460 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2461 | if (type > NL80211_IFTYPE_MAX) | |
2462 | return -EINVAL; | |
2463 | } | |
2464 | ||
79c97e97 | 2465 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2466 | !(rdev->wiphy.interface_modes & (1 << type))) |
2467 | return -EOPNOTSUPP; | |
55682965 | 2468 | |
1c18f145 AS |
2469 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2470 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2471 | ETH_ALEN); | |
2472 | if (!is_valid_ether_addr(params.macaddr)) | |
2473 | return -EADDRNOTAVAIL; | |
2474 | } | |
2475 | ||
9bc383de | 2476 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2477 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2478 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2479 | if (err) |
4c476991 | 2480 | return err; |
9bc383de | 2481 | } |
8b787643 | 2482 | |
1c90f9d4 JB |
2483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2484 | if (!msg) | |
2485 | return -ENOMEM; | |
2486 | ||
66f7ac50 MW |
2487 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2488 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2489 | &flags); | |
e057d3c3 | 2490 | |
18003297 | 2491 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2492 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2493 | return -EOPNOTSUPP; | |
2494 | ||
e35e4d28 HG |
2495 | wdev = rdev_add_virtual_intf(rdev, |
2496 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2497 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2498 | if (IS_ERR(wdev)) { |
2499 | nlmsg_free(msg); | |
84efbb84 | 2500 | return PTR_ERR(wdev); |
1c90f9d4 | 2501 | } |
2ec600d6 | 2502 | |
98104fde JB |
2503 | switch (type) { |
2504 | case NL80211_IFTYPE_MESH_POINT: | |
2505 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2506 | break; | |
29cbe68c JB |
2507 | wdev_lock(wdev); |
2508 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2509 | IEEE80211_MAX_MESH_ID_LEN); | |
2510 | wdev->mesh_id_up_len = | |
2511 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2512 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2513 | wdev->mesh_id_up_len); | |
2514 | wdev_unlock(wdev); | |
98104fde JB |
2515 | break; |
2516 | case NL80211_IFTYPE_P2P_DEVICE: | |
2517 | /* | |
2518 | * P2P Device doesn't have a netdev, so doesn't go | |
2519 | * through the netdev notifier and must be added here | |
2520 | */ | |
2521 | mutex_init(&wdev->mtx); | |
2522 | INIT_LIST_HEAD(&wdev->event_list); | |
2523 | spin_lock_init(&wdev->event_lock); | |
2524 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2525 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2526 | ||
98104fde JB |
2527 | wdev->identifier = ++rdev->wdev_id; |
2528 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2529 | rdev->devlist_generation++; | |
98104fde JB |
2530 | break; |
2531 | default: | |
2532 | break; | |
29cbe68c JB |
2533 | } |
2534 | ||
15e47304 | 2535 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2536 | rdev, wdev) < 0) { |
2537 | nlmsg_free(msg); | |
2538 | return -ENOBUFS; | |
2539 | } | |
2540 | ||
2541 | return genlmsg_reply(msg, info); | |
55682965 JB |
2542 | } |
2543 | ||
2544 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2545 | { | |
4c476991 | 2546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2547 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2548 | |
4c476991 JB |
2549 | if (!rdev->ops->del_virtual_intf) |
2550 | return -EOPNOTSUPP; | |
55682965 | 2551 | |
84efbb84 JB |
2552 | /* |
2553 | * If we remove a wireless device without a netdev then clear | |
2554 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2555 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2556 | * since the wdev has been freed, unlike with a netdev where | |
2557 | * we need the dev_put() for the netdev to really be freed. | |
2558 | */ | |
2559 | if (!wdev->netdev) | |
2560 | info->user_ptr[1] = NULL; | |
2561 | ||
e35e4d28 | 2562 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2563 | } |
2564 | ||
1d9d9213 SW |
2565 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2566 | { | |
2567 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2568 | struct net_device *dev = info->user_ptr[1]; | |
2569 | u16 noack_map; | |
2570 | ||
2571 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2572 | return -EINVAL; | |
2573 | ||
2574 | if (!rdev->ops->set_noack_map) | |
2575 | return -EOPNOTSUPP; | |
2576 | ||
2577 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2578 | ||
e35e4d28 | 2579 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2580 | } |
2581 | ||
41ade00f JB |
2582 | struct get_key_cookie { |
2583 | struct sk_buff *msg; | |
2584 | int error; | |
b9454e83 | 2585 | int idx; |
41ade00f JB |
2586 | }; |
2587 | ||
2588 | static void get_key_callback(void *c, struct key_params *params) | |
2589 | { | |
b9454e83 | 2590 | struct nlattr *key; |
41ade00f JB |
2591 | struct get_key_cookie *cookie = c; |
2592 | ||
9360ffd1 DM |
2593 | if ((params->key && |
2594 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2595 | params->key_len, params->key)) || | |
2596 | (params->seq && | |
2597 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2598 | params->seq_len, params->seq)) || | |
2599 | (params->cipher && | |
2600 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2601 | params->cipher))) | |
2602 | goto nla_put_failure; | |
41ade00f | 2603 | |
b9454e83 JB |
2604 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2605 | if (!key) | |
2606 | goto nla_put_failure; | |
2607 | ||
9360ffd1 DM |
2608 | if ((params->key && |
2609 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2610 | params->key_len, params->key)) || | |
2611 | (params->seq && | |
2612 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2613 | params->seq_len, params->seq)) || | |
2614 | (params->cipher && | |
2615 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2616 | params->cipher))) | |
2617 | goto nla_put_failure; | |
b9454e83 | 2618 | |
9360ffd1 DM |
2619 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2620 | goto nla_put_failure; | |
b9454e83 JB |
2621 | |
2622 | nla_nest_end(cookie->msg, key); | |
2623 | ||
41ade00f JB |
2624 | return; |
2625 | nla_put_failure: | |
2626 | cookie->error = 1; | |
2627 | } | |
2628 | ||
2629 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2630 | { | |
4c476991 | 2631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2632 | int err; |
4c476991 | 2633 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2634 | u8 key_idx = 0; |
e31b8213 JB |
2635 | const u8 *mac_addr = NULL; |
2636 | bool pairwise; | |
41ade00f JB |
2637 | struct get_key_cookie cookie = { |
2638 | .error = 0, | |
2639 | }; | |
2640 | void *hdr; | |
2641 | struct sk_buff *msg; | |
2642 | ||
2643 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2644 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2645 | ||
3cfcf6ac | 2646 | if (key_idx > 5) |
41ade00f JB |
2647 | return -EINVAL; |
2648 | ||
2649 | if (info->attrs[NL80211_ATTR_MAC]) | |
2650 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2651 | ||
e31b8213 JB |
2652 | pairwise = !!mac_addr; |
2653 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2654 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2655 | if (kt >= NUM_NL80211_KEYTYPES) | |
2656 | return -EINVAL; | |
2657 | if (kt != NL80211_KEYTYPE_GROUP && | |
2658 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2659 | return -EINVAL; | |
2660 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2661 | } | |
2662 | ||
4c476991 JB |
2663 | if (!rdev->ops->get_key) |
2664 | return -EOPNOTSUPP; | |
41ade00f | 2665 | |
fd2120ca | 2666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2667 | if (!msg) |
2668 | return -ENOMEM; | |
41ade00f | 2669 | |
15e47304 | 2670 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2671 | NL80211_CMD_NEW_KEY); |
cb35fba3 DC |
2672 | if (!hdr) |
2673 | return -ENOBUFS; | |
41ade00f JB |
2674 | |
2675 | cookie.msg = msg; | |
b9454e83 | 2676 | cookie.idx = key_idx; |
41ade00f | 2677 | |
9360ffd1 DM |
2678 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2679 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2680 | goto nla_put_failure; | |
2681 | if (mac_addr && | |
2682 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2683 | goto nla_put_failure; | |
41ade00f | 2684 | |
e31b8213 JB |
2685 | if (pairwise && mac_addr && |
2686 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2687 | return -ENOENT; | |
2688 | ||
e35e4d28 HG |
2689 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2690 | get_key_callback); | |
41ade00f JB |
2691 | |
2692 | if (err) | |
6c95e2a2 | 2693 | goto free_msg; |
41ade00f JB |
2694 | |
2695 | if (cookie.error) | |
2696 | goto nla_put_failure; | |
2697 | ||
2698 | genlmsg_end(msg, hdr); | |
4c476991 | 2699 | return genlmsg_reply(msg, info); |
41ade00f JB |
2700 | |
2701 | nla_put_failure: | |
2702 | err = -ENOBUFS; | |
6c95e2a2 | 2703 | free_msg: |
41ade00f | 2704 | nlmsg_free(msg); |
41ade00f JB |
2705 | return err; |
2706 | } | |
2707 | ||
2708 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2709 | { | |
4c476991 | 2710 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2711 | struct key_parse key; |
41ade00f | 2712 | int err; |
4c476991 | 2713 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2714 | |
b9454e83 JB |
2715 | err = nl80211_parse_key(info, &key); |
2716 | if (err) | |
2717 | return err; | |
41ade00f | 2718 | |
b9454e83 | 2719 | if (key.idx < 0) |
41ade00f JB |
2720 | return -EINVAL; |
2721 | ||
b9454e83 JB |
2722 | /* only support setting default key */ |
2723 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2724 | return -EINVAL; |
2725 | ||
dbd2fd65 | 2726 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2727 | |
dbd2fd65 JB |
2728 | if (key.def) { |
2729 | if (!rdev->ops->set_default_key) { | |
2730 | err = -EOPNOTSUPP; | |
2731 | goto out; | |
2732 | } | |
41ade00f | 2733 | |
dbd2fd65 JB |
2734 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2735 | if (err) | |
2736 | goto out; | |
2737 | ||
e35e4d28 | 2738 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2739 | key.def_uni, key.def_multi); |
2740 | ||
2741 | if (err) | |
2742 | goto out; | |
fffd0934 | 2743 | |
3d23e349 | 2744 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2745 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2746 | #endif | |
2747 | } else { | |
2748 | if (key.def_uni || !key.def_multi) { | |
2749 | err = -EINVAL; | |
2750 | goto out; | |
2751 | } | |
2752 | ||
2753 | if (!rdev->ops->set_default_mgmt_key) { | |
2754 | err = -EOPNOTSUPP; | |
2755 | goto out; | |
2756 | } | |
2757 | ||
2758 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2759 | if (err) | |
2760 | goto out; | |
2761 | ||
e35e4d28 | 2762 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2763 | if (err) |
2764 | goto out; | |
2765 | ||
2766 | #ifdef CONFIG_CFG80211_WEXT | |
2767 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2768 | #endif |
dbd2fd65 JB |
2769 | } |
2770 | ||
2771 | out: | |
fffd0934 | 2772 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2773 | |
41ade00f JB |
2774 | return err; |
2775 | } | |
2776 | ||
2777 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2778 | { | |
4c476991 | 2779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2780 | int err; |
4c476991 | 2781 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2782 | struct key_parse key; |
e31b8213 | 2783 | const u8 *mac_addr = NULL; |
41ade00f | 2784 | |
b9454e83 JB |
2785 | err = nl80211_parse_key(info, &key); |
2786 | if (err) | |
2787 | return err; | |
41ade00f | 2788 | |
b9454e83 | 2789 | if (!key.p.key) |
41ade00f JB |
2790 | return -EINVAL; |
2791 | ||
41ade00f JB |
2792 | if (info->attrs[NL80211_ATTR_MAC]) |
2793 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2794 | ||
e31b8213 JB |
2795 | if (key.type == -1) { |
2796 | if (mac_addr) | |
2797 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2798 | else | |
2799 | key.type = NL80211_KEYTYPE_GROUP; | |
2800 | } | |
2801 | ||
2802 | /* for now */ | |
2803 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2804 | key.type != NL80211_KEYTYPE_GROUP) | |
2805 | return -EINVAL; | |
2806 | ||
4c476991 JB |
2807 | if (!rdev->ops->add_key) |
2808 | return -EOPNOTSUPP; | |
25e47c18 | 2809 | |
e31b8213 JB |
2810 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2811 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2812 | mac_addr)) | |
4c476991 | 2813 | return -EINVAL; |
41ade00f | 2814 | |
fffd0934 JB |
2815 | wdev_lock(dev->ieee80211_ptr); |
2816 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2817 | if (!err) | |
e35e4d28 HG |
2818 | err = rdev_add_key(rdev, dev, key.idx, |
2819 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2820 | mac_addr, &key.p); | |
fffd0934 | 2821 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2822 | |
41ade00f JB |
2823 | return err; |
2824 | } | |
2825 | ||
2826 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2827 | { | |
4c476991 | 2828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2829 | int err; |
4c476991 | 2830 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2831 | u8 *mac_addr = NULL; |
b9454e83 | 2832 | struct key_parse key; |
41ade00f | 2833 | |
b9454e83 JB |
2834 | err = nl80211_parse_key(info, &key); |
2835 | if (err) | |
2836 | return err; | |
41ade00f JB |
2837 | |
2838 | if (info->attrs[NL80211_ATTR_MAC]) | |
2839 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2840 | ||
e31b8213 JB |
2841 | if (key.type == -1) { |
2842 | if (mac_addr) | |
2843 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2844 | else | |
2845 | key.type = NL80211_KEYTYPE_GROUP; | |
2846 | } | |
2847 | ||
2848 | /* for now */ | |
2849 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2850 | key.type != NL80211_KEYTYPE_GROUP) | |
2851 | return -EINVAL; | |
2852 | ||
4c476991 JB |
2853 | if (!rdev->ops->del_key) |
2854 | return -EOPNOTSUPP; | |
41ade00f | 2855 | |
fffd0934 JB |
2856 | wdev_lock(dev->ieee80211_ptr); |
2857 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2858 | |
2859 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2860 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2861 | err = -ENOENT; | |
2862 | ||
fffd0934 | 2863 | if (!err) |
e35e4d28 HG |
2864 | err = rdev_del_key(rdev, dev, key.idx, |
2865 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2866 | mac_addr); | |
41ade00f | 2867 | |
3d23e349 | 2868 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2869 | if (!err) { |
b9454e83 | 2870 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2871 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2872 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2873 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2874 | } | |
2875 | #endif | |
fffd0934 | 2876 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2877 | |
41ade00f JB |
2878 | return err; |
2879 | } | |
2880 | ||
77765eaf VT |
2881 | /* This function returns an error or the number of nested attributes */ |
2882 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2883 | { | |
2884 | struct nlattr *attr; | |
2885 | int n_entries = 0, tmp; | |
2886 | ||
2887 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2888 | if (nla_len(attr) != ETH_ALEN) | |
2889 | return -EINVAL; | |
2890 | ||
2891 | n_entries++; | |
2892 | } | |
2893 | ||
2894 | return n_entries; | |
2895 | } | |
2896 | ||
2897 | /* | |
2898 | * This function parses ACL information and allocates memory for ACL data. | |
2899 | * On successful return, the calling function is responsible to free the | |
2900 | * ACL buffer returned by this function. | |
2901 | */ | |
2902 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2903 | struct genl_info *info) | |
2904 | { | |
2905 | enum nl80211_acl_policy acl_policy; | |
2906 | struct nlattr *attr; | |
2907 | struct cfg80211_acl_data *acl; | |
2908 | int i = 0, n_entries, tmp; | |
2909 | ||
2910 | if (!wiphy->max_acl_mac_addrs) | |
2911 | return ERR_PTR(-EOPNOTSUPP); | |
2912 | ||
2913 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2914 | return ERR_PTR(-EINVAL); | |
2915 | ||
2916 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2917 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2918 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2919 | return ERR_PTR(-EINVAL); | |
2920 | ||
2921 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2922 | return ERR_PTR(-EINVAL); | |
2923 | ||
2924 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2925 | if (n_entries < 0) | |
2926 | return ERR_PTR(n_entries); | |
2927 | ||
2928 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2929 | return ERR_PTR(-ENOTSUPP); | |
2930 | ||
2931 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2932 | GFP_KERNEL); | |
2933 | if (!acl) | |
2934 | return ERR_PTR(-ENOMEM); | |
2935 | ||
2936 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2937 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2938 | i++; | |
2939 | } | |
2940 | ||
2941 | acl->n_acl_entries = n_entries; | |
2942 | acl->acl_policy = acl_policy; | |
2943 | ||
2944 | return acl; | |
2945 | } | |
2946 | ||
2947 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2948 | { | |
2949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2950 | struct net_device *dev = info->user_ptr[1]; | |
2951 | struct cfg80211_acl_data *acl; | |
2952 | int err; | |
2953 | ||
2954 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2956 | return -EOPNOTSUPP; | |
2957 | ||
2958 | if (!dev->ieee80211_ptr->beacon_interval) | |
2959 | return -EINVAL; | |
2960 | ||
2961 | acl = parse_acl_data(&rdev->wiphy, info); | |
2962 | if (IS_ERR(acl)) | |
2963 | return PTR_ERR(acl); | |
2964 | ||
2965 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2966 | ||
2967 | kfree(acl); | |
2968 | ||
2969 | return err; | |
2970 | } | |
2971 | ||
a1193be8 | 2972 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 2973 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 2974 | { |
8860020e | 2975 | bool haveinfo = false; |
ed1b6cc7 | 2976 | |
a1193be8 SW |
2977 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
2978 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
2979 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2980 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2981 | return -EINVAL; |
2982 | ||
8860020e | 2983 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2984 | |
a1193be8 SW |
2985 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
2986 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
2987 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
2988 | if (!bcn->head_len) |
2989 | return -EINVAL; | |
2990 | haveinfo = true; | |
ed1b6cc7 JB |
2991 | } |
2992 | ||
a1193be8 SW |
2993 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
2994 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
2995 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 2996 | haveinfo = true; |
ed1b6cc7 JB |
2997 | } |
2998 | ||
4c476991 JB |
2999 | if (!haveinfo) |
3000 | return -EINVAL; | |
3b85875a | 3001 | |
a1193be8 SW |
3002 | if (attrs[NL80211_ATTR_IE]) { |
3003 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3004 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3005 | } |
3006 | ||
a1193be8 | 3007 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3008 | bcn->proberesp_ies = |
a1193be8 | 3009 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3010 | bcn->proberesp_ies_len = |
a1193be8 | 3011 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3012 | } |
3013 | ||
a1193be8 | 3014 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3015 | bcn->assocresp_ies = |
a1193be8 | 3016 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3017 | bcn->assocresp_ies_len = |
a1193be8 | 3018 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3019 | } |
3020 | ||
a1193be8 SW |
3021 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3022 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3023 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3024 | } |
3025 | ||
8860020e JB |
3026 | return 0; |
3027 | } | |
3028 | ||
46c1dd0c FF |
3029 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3030 | struct cfg80211_ap_settings *params) | |
3031 | { | |
3032 | struct wireless_dev *wdev; | |
3033 | bool ret = false; | |
3034 | ||
89a54e48 | 3035 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3036 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3037 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3038 | continue; | |
3039 | ||
683b6d3b | 3040 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3041 | continue; |
3042 | ||
683b6d3b | 3043 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3044 | ret = true; |
3045 | break; | |
3046 | } | |
3047 | ||
46c1dd0c FF |
3048 | return ret; |
3049 | } | |
3050 | ||
e39e5b5e JM |
3051 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3052 | enum nl80211_auth_type auth_type, | |
3053 | enum nl80211_commands cmd) | |
3054 | { | |
3055 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3056 | return false; | |
3057 | ||
3058 | switch (cmd) { | |
3059 | case NL80211_CMD_AUTHENTICATE: | |
3060 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3061 | auth_type == NL80211_AUTHTYPE_SAE) | |
3062 | return false; | |
3063 | return true; | |
3064 | case NL80211_CMD_CONNECT: | |
3065 | case NL80211_CMD_START_AP: | |
3066 | /* SAE not supported yet */ | |
3067 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3068 | return false; | |
3069 | return true; | |
3070 | default: | |
3071 | return false; | |
3072 | } | |
3073 | } | |
3074 | ||
8860020e JB |
3075 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3076 | { | |
3077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3078 | struct net_device *dev = info->user_ptr[1]; | |
3079 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3080 | struct cfg80211_ap_settings params; | |
3081 | int err; | |
04f39047 | 3082 | u8 radar_detect_width = 0; |
8860020e JB |
3083 | |
3084 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3085 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3086 | return -EOPNOTSUPP; | |
3087 | ||
3088 | if (!rdev->ops->start_ap) | |
3089 | return -EOPNOTSUPP; | |
3090 | ||
3091 | if (wdev->beacon_interval) | |
3092 | return -EALREADY; | |
3093 | ||
3094 | memset(¶ms, 0, sizeof(params)); | |
3095 | ||
3096 | /* these are required for START_AP */ | |
3097 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3098 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3099 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3100 | return -EINVAL; | |
3101 | ||
a1193be8 | 3102 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3103 | if (err) |
3104 | return err; | |
3105 | ||
3106 | params.beacon_interval = | |
3107 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3108 | params.dtim_period = | |
3109 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3110 | ||
3111 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3112 | if (err) | |
3113 | return err; | |
3114 | ||
3115 | /* | |
3116 | * In theory, some of these attributes should be required here | |
3117 | * but since they were not used when the command was originally | |
3118 | * added, keep them optional for old user space programs to let | |
3119 | * them continue to work with drivers that do not need the | |
3120 | * additional information -- drivers must check! | |
3121 | */ | |
3122 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3123 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3124 | params.ssid_len = | |
3125 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3126 | if (params.ssid_len == 0 || | |
3127 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3128 | return -EINVAL; | |
3129 | } | |
3130 | ||
3131 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3132 | params.hidden_ssid = nla_get_u32( | |
3133 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3134 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3135 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3136 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3137 | return -EINVAL; | |
3138 | } | |
3139 | ||
3140 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3141 | ||
3142 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3143 | params.auth_type = nla_get_u32( | |
3144 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3145 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3146 | NL80211_CMD_START_AP)) | |
8860020e JB |
3147 | return -EINVAL; |
3148 | } else | |
3149 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3150 | ||
3151 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3152 | NL80211_MAX_NR_CIPHER_SUITES); | |
3153 | if (err) | |
3154 | return err; | |
3155 | ||
1b658f11 VT |
3156 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3157 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3158 | return -EOPNOTSUPP; | |
3159 | params.inactivity_timeout = nla_get_u16( | |
3160 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3161 | } | |
3162 | ||
53cabad7 JB |
3163 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3164 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3165 | return -EINVAL; | |
3166 | params.p2p_ctwindow = | |
3167 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3168 | if (params.p2p_ctwindow > 127) | |
3169 | return -EINVAL; | |
3170 | if (params.p2p_ctwindow != 0 && | |
3171 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3172 | return -EINVAL; | |
3173 | } | |
3174 | ||
3175 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3176 | u8 tmp; | |
3177 | ||
3178 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3179 | return -EINVAL; | |
3180 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3181 | if (tmp > 1) | |
3182 | return -EINVAL; | |
3183 | params.p2p_opp_ps = tmp; | |
3184 | if (params.p2p_opp_ps != 0 && | |
3185 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3186 | return -EINVAL; | |
3187 | } | |
3188 | ||
aa430da4 | 3189 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3190 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3191 | if (err) | |
3192 | return err; | |
3193 | } else if (wdev->preset_chandef.chan) { | |
3194 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3195 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3196 | return -EINVAL; |
3197 | ||
683b6d3b | 3198 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3199 | return -EINVAL; |
3200 | ||
04f39047 SW |
3201 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3202 | if (err < 0) | |
3203 | return err; | |
3204 | if (err) { | |
3205 | radar_detect_width = BIT(params.chandef.width); | |
3206 | params.radar_required = true; | |
3207 | } | |
3208 | ||
04f39047 SW |
3209 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3210 | params.chandef.chan, | |
3211 | CHAN_MODE_SHARED, | |
3212 | radar_detect_width); | |
e4e32459 MK |
3213 | if (err) |
3214 | return err; | |
3215 | ||
77765eaf VT |
3216 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3217 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3218 | if (IS_ERR(params.acl)) | |
3219 | return PTR_ERR(params.acl); | |
3220 | } | |
3221 | ||
c56589ed | 3222 | wdev_lock(wdev); |
e35e4d28 | 3223 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3224 | if (!err) { |
683b6d3b | 3225 | wdev->preset_chandef = params.chandef; |
8860020e | 3226 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3227 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3228 | wdev->ssid_len = params.ssid_len; |
3229 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3230 | } |
c56589ed | 3231 | wdev_unlock(wdev); |
77765eaf VT |
3232 | |
3233 | kfree(params.acl); | |
3234 | ||
56d1893d | 3235 | return err; |
ed1b6cc7 JB |
3236 | } |
3237 | ||
8860020e JB |
3238 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3239 | { | |
3240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3241 | struct net_device *dev = info->user_ptr[1]; | |
3242 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3243 | struct cfg80211_beacon_data params; | |
3244 | int err; | |
3245 | ||
3246 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3247 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3248 | return -EOPNOTSUPP; | |
3249 | ||
3250 | if (!rdev->ops->change_beacon) | |
3251 | return -EOPNOTSUPP; | |
3252 | ||
3253 | if (!wdev->beacon_interval) | |
3254 | return -EINVAL; | |
3255 | ||
a1193be8 | 3256 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3257 | if (err) |
3258 | return err; | |
3259 | ||
c56589ed SW |
3260 | wdev_lock(wdev); |
3261 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3262 | wdev_unlock(wdev); | |
3263 | ||
3264 | return err; | |
8860020e JB |
3265 | } |
3266 | ||
3267 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3268 | { |
4c476991 JB |
3269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3270 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3271 | |
60771780 | 3272 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3273 | } |
3274 | ||
5727ef1b JB |
3275 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3276 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3277 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3278 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3279 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3280 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3281 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3282 | }; |
3283 | ||
eccb8e8f | 3284 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3285 | enum nl80211_iftype iftype, |
eccb8e8f | 3286 | struct station_parameters *params) |
5727ef1b JB |
3287 | { |
3288 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3289 | struct nlattr *nla; |
5727ef1b JB |
3290 | int flag; |
3291 | ||
eccb8e8f JB |
3292 | /* |
3293 | * Try parsing the new attribute first so userspace | |
3294 | * can specify both for older kernels. | |
3295 | */ | |
3296 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3297 | if (nla) { | |
3298 | struct nl80211_sta_flag_update *sta_flags; | |
3299 | ||
3300 | sta_flags = nla_data(nla); | |
3301 | params->sta_flags_mask = sta_flags->mask; | |
3302 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3303 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3304 | if ((params->sta_flags_mask | |
3305 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3306 | return -EINVAL; | |
3307 | return 0; | |
3308 | } | |
3309 | ||
3310 | /* if present, parse the old attribute */ | |
5727ef1b | 3311 | |
eccb8e8f | 3312 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3313 | if (!nla) |
3314 | return 0; | |
3315 | ||
3316 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3317 | nla, sta_flags_policy)) | |
3318 | return -EINVAL; | |
3319 | ||
bdd3ae3d JB |
3320 | /* |
3321 | * Only allow certain flags for interface types so that | |
3322 | * other attributes are silently ignored. Remember that | |
3323 | * this is backward compatibility code with old userspace | |
3324 | * and shouldn't be hit in other cases anyway. | |
3325 | */ | |
3326 | switch (iftype) { | |
3327 | case NL80211_IFTYPE_AP: | |
3328 | case NL80211_IFTYPE_AP_VLAN: | |
3329 | case NL80211_IFTYPE_P2P_GO: | |
3330 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3331 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3332 | BIT(NL80211_STA_FLAG_WME) | | |
3333 | BIT(NL80211_STA_FLAG_MFP); | |
3334 | break; | |
3335 | case NL80211_IFTYPE_P2P_CLIENT: | |
3336 | case NL80211_IFTYPE_STATION: | |
3337 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3338 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3339 | break; | |
3340 | case NL80211_IFTYPE_MESH_POINT: | |
3341 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3342 | BIT(NL80211_STA_FLAG_MFP) | | |
3343 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3344 | default: | |
3345 | return -EINVAL; | |
3346 | } | |
5727ef1b | 3347 | |
3383b5a6 JB |
3348 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3349 | if (flags[flag]) { | |
eccb8e8f | 3350 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3351 | |
3383b5a6 JB |
3352 | /* no longer support new API additions in old API */ |
3353 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3354 | return -EINVAL; | |
3355 | } | |
3356 | } | |
3357 | ||
5727ef1b JB |
3358 | return 0; |
3359 | } | |
3360 | ||
c8dcfd8a FF |
3361 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3362 | int attr) | |
3363 | { | |
3364 | struct nlattr *rate; | |
8eb41c8d VK |
3365 | u32 bitrate; |
3366 | u16 bitrate_compat; | |
c8dcfd8a FF |
3367 | |
3368 | rate = nla_nest_start(msg, attr); | |
3369 | if (!rate) | |
db9c64cf | 3370 | return false; |
c8dcfd8a FF |
3371 | |
3372 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3373 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3374 | /* report 16-bit bitrate only if we can */ |
3375 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3376 | if (bitrate > 0 && |
3377 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3378 | return false; | |
3379 | if (bitrate_compat > 0 && | |
3380 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3381 | return false; | |
3382 | ||
3383 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3384 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3385 | return false; | |
3386 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3387 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3388 | return false; | |
3389 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3390 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3391 | return false; | |
3392 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3393 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3394 | return false; | |
3395 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3396 | return false; | |
3397 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3398 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3399 | return false; | |
3400 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3401 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3402 | return false; | |
3403 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3404 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3405 | return false; | |
3406 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3407 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3408 | return false; | |
3409 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3410 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3411 | return false; | |
3412 | } | |
c8dcfd8a FF |
3413 | |
3414 | nla_nest_end(msg, rate); | |
3415 | return true; | |
c8dcfd8a FF |
3416 | } |
3417 | ||
119363c7 FF |
3418 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3419 | int id) | |
3420 | { | |
3421 | void *attr; | |
3422 | int i = 0; | |
3423 | ||
3424 | if (!mask) | |
3425 | return true; | |
3426 | ||
3427 | attr = nla_nest_start(msg, id); | |
3428 | if (!attr) | |
3429 | return false; | |
3430 | ||
3431 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3432 | if (!(mask & BIT(i))) | |
3433 | continue; | |
3434 | ||
3435 | if (nla_put_u8(msg, i, signal[i])) | |
3436 | return false; | |
3437 | } | |
3438 | ||
3439 | nla_nest_end(msg, attr); | |
3440 | ||
3441 | return true; | |
3442 | } | |
3443 | ||
15e47304 | 3444 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3445 | int flags, |
3446 | struct cfg80211_registered_device *rdev, | |
3447 | struct net_device *dev, | |
98b62183 | 3448 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3449 | { |
3450 | void *hdr; | |
f4263c98 | 3451 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3452 | |
15e47304 | 3453 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3454 | if (!hdr) |
3455 | return -1; | |
3456 | ||
9360ffd1 DM |
3457 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3458 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3459 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3460 | goto nla_put_failure; | |
f5ea9120 | 3461 | |
2ec600d6 LCC |
3462 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3463 | if (!sinfoattr) | |
fd5b74dc | 3464 | goto nla_put_failure; |
9360ffd1 DM |
3465 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3466 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3467 | sinfo->connected_time)) | |
3468 | goto nla_put_failure; | |
3469 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3470 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3471 | sinfo->inactive_time)) | |
3472 | goto nla_put_failure; | |
42745e03 VK |
3473 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3474 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3475 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3476 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3477 | goto nla_put_failure; |
42745e03 | 3478 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3479 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3480 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3481 | (u32)sinfo->tx_bytes)) |
3482 | goto nla_put_failure; | |
3483 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3484 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3485 | sinfo->rx_bytes)) | |
3486 | goto nla_put_failure; | |
3487 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3488 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3489 | sinfo->tx_bytes)) |
3490 | goto nla_put_failure; | |
3491 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3492 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3493 | goto nla_put_failure; | |
3494 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3495 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3496 | goto nla_put_failure; | |
3497 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3498 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3499 | sinfo->plink_state)) | |
3500 | goto nla_put_failure; | |
66266b3a JL |
3501 | switch (rdev->wiphy.signal_type) { |
3502 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3503 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3504 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3505 | sinfo->signal)) | |
3506 | goto nla_put_failure; | |
3507 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3508 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3509 | sinfo->signal_avg)) | |
3510 | goto nla_put_failure; | |
66266b3a JL |
3511 | break; |
3512 | default: | |
3513 | break; | |
3514 | } | |
119363c7 FF |
3515 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3516 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3517 | sinfo->chain_signal, | |
3518 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3519 | goto nla_put_failure; | |
3520 | } | |
3521 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3522 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3523 | sinfo->chain_signal_avg, | |
3524 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3525 | goto nla_put_failure; | |
3526 | } | |
420e7fab | 3527 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3528 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3529 | NL80211_STA_INFO_TX_BITRATE)) | |
3530 | goto nla_put_failure; | |
3531 | } | |
3532 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3533 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3534 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3535 | goto nla_put_failure; |
420e7fab | 3536 | } |
9360ffd1 DM |
3537 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3538 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3539 | sinfo->rx_packets)) | |
3540 | goto nla_put_failure; | |
3541 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3542 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3543 | sinfo->tx_packets)) | |
3544 | goto nla_put_failure; | |
3545 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3546 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3547 | sinfo->tx_retries)) | |
3548 | goto nla_put_failure; | |
3549 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3550 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3551 | sinfo->tx_failed)) | |
3552 | goto nla_put_failure; | |
3553 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3554 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3555 | sinfo->beacon_loss_count)) | |
3556 | goto nla_put_failure; | |
3b1c5a53 MP |
3557 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3558 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3559 | sinfo->local_pm)) | |
3560 | goto nla_put_failure; | |
3561 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3562 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3563 | sinfo->peer_pm)) | |
3564 | goto nla_put_failure; | |
3565 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3566 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3567 | sinfo->nonpeer_pm)) | |
3568 | goto nla_put_failure; | |
f4263c98 PS |
3569 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3570 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3571 | if (!bss_param) | |
3572 | goto nla_put_failure; | |
3573 | ||
9360ffd1 DM |
3574 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3575 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3576 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3577 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3578 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3579 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3580 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3581 | sinfo->bss_param.dtim_period) || | |
3582 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3583 | sinfo->bss_param.beacon_interval)) | |
3584 | goto nla_put_failure; | |
f4263c98 PS |
3585 | |
3586 | nla_nest_end(msg, bss_param); | |
3587 | } | |
9360ffd1 DM |
3588 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3589 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3590 | sizeof(struct nl80211_sta_flag_update), | |
3591 | &sinfo->sta_flags)) | |
3592 | goto nla_put_failure; | |
7eab0f64 JL |
3593 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3594 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3595 | sinfo->t_offset)) | |
3596 | goto nla_put_failure; | |
2ec600d6 | 3597 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3598 | |
9360ffd1 DM |
3599 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3600 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3601 | sinfo->assoc_req_ies)) | |
3602 | goto nla_put_failure; | |
50d3dfb7 | 3603 | |
fd5b74dc JB |
3604 | return genlmsg_end(msg, hdr); |
3605 | ||
3606 | nla_put_failure: | |
bc3ed28c TG |
3607 | genlmsg_cancel(msg, hdr); |
3608 | return -EMSGSIZE; | |
fd5b74dc JB |
3609 | } |
3610 | ||
2ec600d6 | 3611 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3612 | struct netlink_callback *cb) |
2ec600d6 | 3613 | { |
2ec600d6 LCC |
3614 | struct station_info sinfo; |
3615 | struct cfg80211_registered_device *dev; | |
97990a06 | 3616 | struct wireless_dev *wdev; |
2ec600d6 | 3617 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3618 | int sta_idx = cb->args[2]; |
2ec600d6 | 3619 | int err; |
2ec600d6 | 3620 | |
97990a06 | 3621 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3622 | if (err) |
3623 | return err; | |
bba95fef | 3624 | |
97990a06 JB |
3625 | if (!wdev->netdev) { |
3626 | err = -EINVAL; | |
3627 | goto out_err; | |
3628 | } | |
3629 | ||
bba95fef | 3630 | if (!dev->ops->dump_station) { |
eec60b03 | 3631 | err = -EOPNOTSUPP; |
bba95fef JB |
3632 | goto out_err; |
3633 | } | |
3634 | ||
bba95fef | 3635 | while (1) { |
f612cedf | 3636 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3637 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3638 | mac_addr, &sinfo); |
bba95fef JB |
3639 | if (err == -ENOENT) |
3640 | break; | |
3641 | if (err) | |
3b85875a | 3642 | goto out_err; |
bba95fef JB |
3643 | |
3644 | if (nl80211_send_station(skb, | |
15e47304 | 3645 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3646 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3647 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3648 | &sinfo) < 0) |
3649 | goto out; | |
3650 | ||
3651 | sta_idx++; | |
3652 | } | |
3653 | ||
3654 | ||
3655 | out: | |
97990a06 | 3656 | cb->args[2] = sta_idx; |
bba95fef | 3657 | err = skb->len; |
bba95fef | 3658 | out_err: |
97990a06 | 3659 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3660 | |
3661 | return err; | |
2ec600d6 | 3662 | } |
fd5b74dc | 3663 | |
5727ef1b JB |
3664 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3665 | { | |
4c476991 JB |
3666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3667 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3668 | struct station_info sinfo; |
fd5b74dc JB |
3669 | struct sk_buff *msg; |
3670 | u8 *mac_addr = NULL; | |
4c476991 | 3671 | int err; |
fd5b74dc | 3672 | |
2ec600d6 | 3673 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3674 | |
3675 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3676 | return -EINVAL; | |
3677 | ||
3678 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3679 | ||
4c476991 JB |
3680 | if (!rdev->ops->get_station) |
3681 | return -EOPNOTSUPP; | |
3b85875a | 3682 | |
e35e4d28 | 3683 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3684 | if (err) |
4c476991 | 3685 | return err; |
2ec600d6 | 3686 | |
fd2120ca | 3687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3688 | if (!msg) |
4c476991 | 3689 | return -ENOMEM; |
fd5b74dc | 3690 | |
15e47304 | 3691 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3692 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3693 | nlmsg_free(msg); |
3694 | return -ENOBUFS; | |
3695 | } | |
3b85875a | 3696 | |
4c476991 | 3697 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3698 | } |
3699 | ||
77ee7c89 JB |
3700 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3701 | struct station_parameters *params, | |
3702 | enum cfg80211_station_type statype) | |
3703 | { | |
3704 | if (params->listen_interval != -1) | |
3705 | return -EINVAL; | |
3706 | if (params->aid) | |
3707 | return -EINVAL; | |
3708 | ||
3709 | /* When you run into this, adjust the code below for the new flag */ | |
3710 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3711 | ||
3712 | switch (statype) { | |
eef941e6 TP |
3713 | case CFG80211_STA_MESH_PEER_KERNEL: |
3714 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3715 | /* |
3716 | * No ignoring the TDLS flag here -- the userspace mesh | |
3717 | * code doesn't have the bug of including TDLS in the | |
3718 | * mask everywhere. | |
3719 | */ | |
3720 | if (params->sta_flags_mask & | |
3721 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3722 | BIT(NL80211_STA_FLAG_MFP) | | |
3723 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3724 | return -EINVAL; | |
3725 | break; | |
3726 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3727 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3728 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3729 | return -EINVAL; | |
3730 | /* ignore since it can't change */ | |
3731 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3732 | break; | |
3733 | default: | |
3734 | /* disallow mesh-specific things */ | |
3735 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3736 | return -EINVAL; | |
3737 | if (params->local_pm) | |
3738 | return -EINVAL; | |
3739 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3740 | return -EINVAL; | |
3741 | } | |
3742 | ||
3743 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3744 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3745 | /* TDLS can't be set, ... */ | |
3746 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3747 | return -EINVAL; | |
3748 | /* | |
3749 | * ... but don't bother the driver with it. This works around | |
3750 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3751 | * TLDS_PEER flag in the mask even for AP mode. | |
3752 | */ | |
3753 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3754 | } | |
3755 | ||
3756 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3757 | /* reject other things that can't change */ | |
3758 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3759 | return -EINVAL; | |
3760 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3761 | return -EINVAL; | |
3762 | if (params->supported_rates) | |
3763 | return -EINVAL; | |
3764 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3765 | return -EINVAL; | |
3766 | } | |
3767 | ||
3768 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3769 | if (params->vlan) | |
3770 | return -EINVAL; | |
3771 | } | |
3772 | ||
3773 | switch (statype) { | |
3774 | case CFG80211_STA_AP_MLME_CLIENT: | |
3775 | /* Use this only for authorizing/unauthorizing a station */ | |
3776 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3777 | return -EOPNOTSUPP; | |
3778 | break; | |
3779 | case CFG80211_STA_AP_CLIENT: | |
3780 | /* accept only the listed bits */ | |
3781 | if (params->sta_flags_mask & | |
3782 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3783 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3784 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3785 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3786 | BIT(NL80211_STA_FLAG_WME) | | |
3787 | BIT(NL80211_STA_FLAG_MFP))) | |
3788 | return -EINVAL; | |
3789 | ||
3790 | /* but authenticated/associated only if driver handles it */ | |
3791 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3792 | params->sta_flags_mask & | |
3793 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3794 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3795 | return -EINVAL; | |
3796 | break; | |
3797 | case CFG80211_STA_IBSS: | |
3798 | case CFG80211_STA_AP_STA: | |
3799 | /* reject any changes other than AUTHORIZED */ | |
3800 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3801 | return -EINVAL; | |
3802 | break; | |
3803 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3804 | /* reject any changes other than AUTHORIZED or WME */ | |
3805 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3806 | BIT(NL80211_STA_FLAG_WME))) | |
3807 | return -EINVAL; | |
3808 | /* force (at least) rates when authorizing */ | |
3809 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3810 | !params->supported_rates) | |
3811 | return -EINVAL; | |
3812 | break; | |
3813 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3814 | /* reject any changes */ | |
3815 | return -EINVAL; | |
eef941e6 | 3816 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3817 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3818 | return -EINVAL; | |
3819 | break; | |
eef941e6 | 3820 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3821 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3822 | return -EINVAL; | |
3823 | break; | |
3824 | } | |
3825 | ||
3826 | return 0; | |
3827 | } | |
3828 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3829 | ||
5727ef1b | 3830 | /* |
c258d2de | 3831 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3832 | */ |
80b99899 JB |
3833 | static struct net_device *get_vlan(struct genl_info *info, |
3834 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3835 | { |
463d0183 | 3836 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3837 | struct net_device *v; |
3838 | int ret; | |
3839 | ||
3840 | if (!vlanattr) | |
3841 | return NULL; | |
3842 | ||
3843 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3844 | if (!v) | |
3845 | return ERR_PTR(-ENODEV); | |
3846 | ||
3847 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3848 | ret = -EINVAL; | |
3849 | goto error; | |
5727ef1b | 3850 | } |
80b99899 | 3851 | |
77ee7c89 JB |
3852 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3853 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3854 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3855 | ret = -EINVAL; | |
3856 | goto error; | |
3857 | } | |
3858 | ||
80b99899 JB |
3859 | if (!netif_running(v)) { |
3860 | ret = -ENETDOWN; | |
3861 | goto error; | |
3862 | } | |
3863 | ||
3864 | return v; | |
3865 | error: | |
3866 | dev_put(v); | |
3867 | return ERR_PTR(ret); | |
5727ef1b JB |
3868 | } |
3869 | ||
df881293 JM |
3870 | static struct nla_policy |
3871 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3872 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3873 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3874 | }; | |
3875 | ||
ff276691 JB |
3876 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3877 | struct station_parameters *params) | |
df881293 | 3878 | { |
df881293 JM |
3879 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3880 | struct nlattr *nla; | |
3881 | int err; | |
3882 | ||
df881293 JM |
3883 | /* parse WME attributes if present */ |
3884 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3885 | return 0; | |
3886 | ||
3887 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3888 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3889 | nl80211_sta_wme_policy); | |
3890 | if (err) | |
3891 | return err; | |
3892 | ||
3893 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3894 | params->uapsd_queues = nla_get_u8( | |
3895 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3896 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3897 | return -EINVAL; | |
3898 | ||
3899 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3900 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3901 | ||
3902 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3903 | return -EINVAL; | |
3904 | ||
3905 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3906 | ||
3907 | return 0; | |
3908 | } | |
3909 | ||
c01fc9ad SD |
3910 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
3911 | struct station_parameters *params) | |
3912 | { | |
3913 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
3914 | params->supported_channels = | |
3915 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
3916 | params->supported_channels_len = | |
3917 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
3918 | /* | |
3919 | * Need to include at least one (first channel, number of | |
3920 | * channels) tuple for each subband, and must have proper | |
3921 | * tuples for the rest of the data as well. | |
3922 | */ | |
3923 | if (params->supported_channels_len < 2) | |
3924 | return -EINVAL; | |
3925 | if (params->supported_channels_len % 2) | |
3926 | return -EINVAL; | |
3927 | } | |
3928 | ||
3929 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
3930 | params->supported_oper_classes = | |
3931 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
3932 | params->supported_oper_classes_len = | |
3933 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
3934 | /* | |
3935 | * The value of the Length field of the Supported Operating | |
3936 | * Classes element is between 2 and 253. | |
3937 | */ | |
3938 | if (params->supported_oper_classes_len < 2 || | |
3939 | params->supported_oper_classes_len > 253) | |
3940 | return -EINVAL; | |
3941 | } | |
3942 | return 0; | |
3943 | } | |
3944 | ||
ff276691 JB |
3945 | static int nl80211_set_station_tdls(struct genl_info *info, |
3946 | struct station_parameters *params) | |
3947 | { | |
c01fc9ad | 3948 | int err; |
ff276691 | 3949 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
3950 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
3951 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
3952 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3953 | params->ht_capa = | |
3954 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3955 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3956 | params->vht_capa = | |
3957 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3958 | ||
c01fc9ad SD |
3959 | err = nl80211_parse_sta_channel_info(info, params); |
3960 | if (err) | |
3961 | return err; | |
3962 | ||
ff276691 JB |
3963 | return nl80211_parse_sta_wme(info, params); |
3964 | } | |
3965 | ||
5727ef1b JB |
3966 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3967 | { | |
4c476991 | 3968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3969 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3970 | struct station_parameters params; |
77ee7c89 JB |
3971 | u8 *mac_addr; |
3972 | int err; | |
5727ef1b JB |
3973 | |
3974 | memset(¶ms, 0, sizeof(params)); | |
3975 | ||
3976 | params.listen_interval = -1; | |
3977 | ||
77ee7c89 JB |
3978 | if (!rdev->ops->change_station) |
3979 | return -EOPNOTSUPP; | |
3980 | ||
5727ef1b JB |
3981 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3982 | return -EINVAL; | |
3983 | ||
3984 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3985 | return -EINVAL; | |
3986 | ||
3987 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3988 | ||
3989 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3990 | params.supported_rates = | |
3991 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3992 | params.supported_rates_len = | |
3993 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3994 | } | |
3995 | ||
9d62a986 JM |
3996 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3997 | params.capability = | |
3998 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3999 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4000 | } | |
4001 | ||
4002 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4003 | params.ext_capab = | |
4004 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4005 | params.ext_capab_len = | |
4006 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4007 | } | |
4008 | ||
df881293 | 4009 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4010 | return -EINVAL; |
36aedc90 | 4011 | |
bdd3ae3d | 4012 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4013 | return -EINVAL; |
4014 | ||
f8bacc21 | 4015 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4016 | params.plink_action = |
f8bacc21 JB |
4017 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4018 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4019 | return -EINVAL; | |
4020 | } | |
2ec600d6 | 4021 | |
f8bacc21 | 4022 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4023 | params.plink_state = |
f8bacc21 JB |
4024 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4025 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4026 | return -EINVAL; | |
4027 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4028 | } | |
9c3990aa | 4029 | |
3b1c5a53 MP |
4030 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4031 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4032 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4033 | ||
4034 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4035 | pm > NL80211_MESH_POWER_MAX) | |
4036 | return -EINVAL; | |
4037 | ||
4038 | params.local_pm = pm; | |
4039 | } | |
4040 | ||
77ee7c89 JB |
4041 | /* Include parameters for TDLS peer (will check later) */ |
4042 | err = nl80211_set_station_tdls(info, ¶ms); | |
4043 | if (err) | |
4044 | return err; | |
4045 | ||
4046 | params.vlan = get_vlan(info, rdev); | |
4047 | if (IS_ERR(params.vlan)) | |
4048 | return PTR_ERR(params.vlan); | |
4049 | ||
a97f4424 JB |
4050 | switch (dev->ieee80211_ptr->iftype) { |
4051 | case NL80211_IFTYPE_AP: | |
4052 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4053 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4054 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4055 | case NL80211_IFTYPE_STATION: |
267335d6 | 4056 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4057 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4058 | break; |
4059 | default: | |
77ee7c89 JB |
4060 | err = -EOPNOTSUPP; |
4061 | goto out_put_vlan; | |
034d655e JB |
4062 | } |
4063 | ||
77ee7c89 | 4064 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4065 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4066 | |
77ee7c89 | 4067 | out_put_vlan: |
5727ef1b JB |
4068 | if (params.vlan) |
4069 | dev_put(params.vlan); | |
3b85875a | 4070 | |
5727ef1b JB |
4071 | return err; |
4072 | } | |
4073 | ||
4074 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4075 | { | |
4c476991 | 4076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4077 | int err; |
4c476991 | 4078 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4079 | struct station_parameters params; |
4080 | u8 *mac_addr = NULL; | |
4081 | ||
4082 | memset(¶ms, 0, sizeof(params)); | |
4083 | ||
984c311b JB |
4084 | if (!rdev->ops->add_station) |
4085 | return -EOPNOTSUPP; | |
4086 | ||
5727ef1b JB |
4087 | if (!info->attrs[NL80211_ATTR_MAC]) |
4088 | return -EINVAL; | |
4089 | ||
5727ef1b JB |
4090 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4091 | return -EINVAL; | |
4092 | ||
4093 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4094 | return -EINVAL; | |
4095 | ||
5e4b6f56 JM |
4096 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4097 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4098 | return -EINVAL; |
4099 | ||
5727ef1b JB |
4100 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4101 | params.supported_rates = | |
4102 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4103 | params.supported_rates_len = | |
4104 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4105 | params.listen_interval = | |
4106 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4107 | |
3d124ea2 | 4108 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4109 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4110 | else |
4111 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4112 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4113 | return -EINVAL; | |
51b50fbe | 4114 | |
9d62a986 JM |
4115 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4116 | params.capability = | |
4117 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4118 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4119 | } | |
4120 | ||
4121 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4122 | params.ext_capab = | |
4123 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4124 | params.ext_capab_len = | |
4125 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4126 | } | |
4127 | ||
36aedc90 JM |
4128 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4129 | params.ht_capa = | |
4130 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4131 | |
f461be3e MP |
4132 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4133 | params.vht_capa = | |
4134 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4135 | ||
60f4a7b1 MK |
4136 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4137 | params.opmode_notif_used = true; | |
4138 | params.opmode_notif = | |
4139 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4140 | } | |
4141 | ||
f8bacc21 | 4142 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4143 | params.plink_action = |
f8bacc21 JB |
4144 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4145 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4146 | return -EINVAL; | |
4147 | } | |
96b78dff | 4148 | |
c01fc9ad SD |
4149 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4150 | if (err) | |
4151 | return err; | |
4152 | ||
ff276691 JB |
4153 | err = nl80211_parse_sta_wme(info, ¶ms); |
4154 | if (err) | |
4155 | return err; | |
bdd90d5e | 4156 | |
bdd3ae3d | 4157 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4158 | return -EINVAL; |
4159 | ||
77ee7c89 JB |
4160 | /* When you run into this, adjust the code below for the new flag */ |
4161 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4162 | ||
bdd90d5e JB |
4163 | switch (dev->ieee80211_ptr->iftype) { |
4164 | case NL80211_IFTYPE_AP: | |
4165 | case NL80211_IFTYPE_AP_VLAN: | |
4166 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4167 | /* ignore WME attributes if iface/sta is not capable */ |
4168 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4169 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4170 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4171 | |
bdd90d5e | 4172 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4173 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4174 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4175 | return -EINVAL; |
bdd90d5e JB |
4176 | /* but don't bother the driver with it */ |
4177 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4178 | |
d582cffb JB |
4179 | /* allow authenticated/associated only if driver handles it */ |
4180 | if (!(rdev->wiphy.features & | |
4181 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4182 | params.sta_flags_mask & | |
4183 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4184 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4185 | return -EINVAL; | |
4186 | ||
bdd90d5e JB |
4187 | /* must be last in here for error handling */ |
4188 | params.vlan = get_vlan(info, rdev); | |
4189 | if (IS_ERR(params.vlan)) | |
4190 | return PTR_ERR(params.vlan); | |
4191 | break; | |
4192 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4193 | /* ignore uAPSD data */ |
4194 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4195 | ||
d582cffb JB |
4196 | /* associated is disallowed */ |
4197 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4198 | return -EINVAL; | |
bdd90d5e | 4199 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4200 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4201 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4202 | return -EINVAL; |
4203 | break; | |
4204 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4205 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4206 | /* ignore uAPSD data */ |
4207 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4208 | ||
77ee7c89 JB |
4209 | /* these are disallowed */ |
4210 | if (params.sta_flags_mask & | |
4211 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4212 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4213 | return -EINVAL; |
bdd90d5e JB |
4214 | /* Only TDLS peers can be added */ |
4215 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4216 | return -EINVAL; | |
4217 | /* Can only add if TDLS ... */ | |
4218 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4219 | return -EOPNOTSUPP; | |
4220 | /* ... with external setup is supported */ | |
4221 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4222 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4223 | /* |
4224 | * Older wpa_supplicant versions always mark the TDLS peer | |
4225 | * as authorized, but it shouldn't yet be. | |
4226 | */ | |
4227 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4228 | break; |
4229 | default: | |
4230 | return -EOPNOTSUPP; | |
c75786c9 EP |
4231 | } |
4232 | ||
bdd90d5e | 4233 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4234 | |
e35e4d28 | 4235 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4236 | |
5727ef1b JB |
4237 | if (params.vlan) |
4238 | dev_put(params.vlan); | |
5727ef1b JB |
4239 | return err; |
4240 | } | |
4241 | ||
4242 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4243 | { | |
4c476991 JB |
4244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4245 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4246 | u8 *mac_addr = NULL; |
4247 | ||
4248 | if (info->attrs[NL80211_ATTR_MAC]) | |
4249 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4250 | ||
e80cf853 | 4251 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4252 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4253 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4254 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4255 | return -EINVAL; | |
5727ef1b | 4256 | |
4c476991 JB |
4257 | if (!rdev->ops->del_station) |
4258 | return -EOPNOTSUPP; | |
3b85875a | 4259 | |
e35e4d28 | 4260 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4261 | } |
4262 | ||
15e47304 | 4263 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4264 | int flags, struct net_device *dev, |
4265 | u8 *dst, u8 *next_hop, | |
4266 | struct mpath_info *pinfo) | |
4267 | { | |
4268 | void *hdr; | |
4269 | struct nlattr *pinfoattr; | |
4270 | ||
15e47304 | 4271 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4272 | if (!hdr) |
4273 | return -1; | |
4274 | ||
9360ffd1 DM |
4275 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4276 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4277 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4278 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4279 | goto nla_put_failure; | |
f5ea9120 | 4280 | |
2ec600d6 LCC |
4281 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4282 | if (!pinfoattr) | |
4283 | goto nla_put_failure; | |
9360ffd1 DM |
4284 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4285 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4286 | pinfo->frame_qlen)) | |
4287 | goto nla_put_failure; | |
4288 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4289 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4290 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4291 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4292 | pinfo->metric)) || | |
4293 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4294 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4295 | pinfo->exptime)) || | |
4296 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4297 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4298 | pinfo->flags)) || | |
4299 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4300 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4301 | pinfo->discovery_timeout)) || | |
4302 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4303 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4304 | pinfo->discovery_retries))) | |
4305 | goto nla_put_failure; | |
2ec600d6 LCC |
4306 | |
4307 | nla_nest_end(msg, pinfoattr); | |
4308 | ||
4309 | return genlmsg_end(msg, hdr); | |
4310 | ||
4311 | nla_put_failure: | |
bc3ed28c TG |
4312 | genlmsg_cancel(msg, hdr); |
4313 | return -EMSGSIZE; | |
2ec600d6 LCC |
4314 | } |
4315 | ||
4316 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4317 | struct netlink_callback *cb) |
2ec600d6 | 4318 | { |
2ec600d6 LCC |
4319 | struct mpath_info pinfo; |
4320 | struct cfg80211_registered_device *dev; | |
97990a06 | 4321 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4322 | u8 dst[ETH_ALEN]; |
4323 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4324 | int path_idx = cb->args[2]; |
2ec600d6 | 4325 | int err; |
2ec600d6 | 4326 | |
97990a06 | 4327 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4328 | if (err) |
4329 | return err; | |
bba95fef JB |
4330 | |
4331 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4332 | err = -EOPNOTSUPP; |
bba95fef JB |
4333 | goto out_err; |
4334 | } | |
4335 | ||
97990a06 | 4336 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4337 | err = -EOPNOTSUPP; |
0448b5fc | 4338 | goto out_err; |
eec60b03 JM |
4339 | } |
4340 | ||
bba95fef | 4341 | while (1) { |
97990a06 JB |
4342 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4343 | next_hop, &pinfo); | |
bba95fef | 4344 | if (err == -ENOENT) |
2ec600d6 | 4345 | break; |
bba95fef | 4346 | if (err) |
3b85875a | 4347 | goto out_err; |
2ec600d6 | 4348 | |
15e47304 | 4349 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4350 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4351 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4352 | &pinfo) < 0) |
4353 | goto out; | |
2ec600d6 | 4354 | |
bba95fef | 4355 | path_idx++; |
2ec600d6 | 4356 | } |
2ec600d6 | 4357 | |
2ec600d6 | 4358 | |
bba95fef | 4359 | out: |
97990a06 | 4360 | cb->args[2] = path_idx; |
bba95fef | 4361 | err = skb->len; |
bba95fef | 4362 | out_err: |
97990a06 | 4363 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4364 | return err; |
2ec600d6 LCC |
4365 | } |
4366 | ||
4367 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4368 | { | |
4c476991 | 4369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4370 | int err; |
4c476991 | 4371 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4372 | struct mpath_info pinfo; |
4373 | struct sk_buff *msg; | |
4374 | u8 *dst = NULL; | |
4375 | u8 next_hop[ETH_ALEN]; | |
4376 | ||
4377 | memset(&pinfo, 0, sizeof(pinfo)); | |
4378 | ||
4379 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4380 | return -EINVAL; | |
4381 | ||
4382 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4383 | ||
4c476991 JB |
4384 | if (!rdev->ops->get_mpath) |
4385 | return -EOPNOTSUPP; | |
2ec600d6 | 4386 | |
4c476991 JB |
4387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4388 | return -EOPNOTSUPP; | |
eec60b03 | 4389 | |
e35e4d28 | 4390 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4391 | if (err) |
4c476991 | 4392 | return err; |
2ec600d6 | 4393 | |
fd2120ca | 4394 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4395 | if (!msg) |
4c476991 | 4396 | return -ENOMEM; |
2ec600d6 | 4397 | |
15e47304 | 4398 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4399 | dev, dst, next_hop, &pinfo) < 0) { |
4400 | nlmsg_free(msg); | |
4401 | return -ENOBUFS; | |
4402 | } | |
3b85875a | 4403 | |
4c476991 | 4404 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4405 | } |
4406 | ||
4407 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4408 | { | |
4c476991 JB |
4409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4410 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4411 | u8 *dst = NULL; |
4412 | u8 *next_hop = NULL; | |
4413 | ||
4414 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4415 | return -EINVAL; | |
4416 | ||
4417 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4418 | return -EINVAL; | |
4419 | ||
4420 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4421 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4422 | ||
4c476991 JB |
4423 | if (!rdev->ops->change_mpath) |
4424 | return -EOPNOTSUPP; | |
35a8efe1 | 4425 | |
4c476991 JB |
4426 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4427 | return -EOPNOTSUPP; | |
2ec600d6 | 4428 | |
e35e4d28 | 4429 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4430 | } |
4c476991 | 4431 | |
2ec600d6 LCC |
4432 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4433 | { | |
4c476991 JB |
4434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4435 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4436 | u8 *dst = NULL; |
4437 | u8 *next_hop = NULL; | |
4438 | ||
4439 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4440 | return -EINVAL; | |
4441 | ||
4442 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4443 | return -EINVAL; | |
4444 | ||
4445 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4446 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4447 | ||
4c476991 JB |
4448 | if (!rdev->ops->add_mpath) |
4449 | return -EOPNOTSUPP; | |
35a8efe1 | 4450 | |
4c476991 JB |
4451 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4452 | return -EOPNOTSUPP; | |
2ec600d6 | 4453 | |
e35e4d28 | 4454 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4455 | } |
4456 | ||
4457 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4458 | { | |
4c476991 JB |
4459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4460 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4461 | u8 *dst = NULL; |
4462 | ||
4463 | if (info->attrs[NL80211_ATTR_MAC]) | |
4464 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4465 | ||
4c476991 JB |
4466 | if (!rdev->ops->del_mpath) |
4467 | return -EOPNOTSUPP; | |
3b85875a | 4468 | |
e35e4d28 | 4469 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4470 | } |
4471 | ||
9f1ba906 JM |
4472 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4473 | { | |
4c476991 JB |
4474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4475 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4476 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4477 | struct bss_parameters params; |
c56589ed | 4478 | int err; |
9f1ba906 JM |
4479 | |
4480 | memset(¶ms, 0, sizeof(params)); | |
4481 | /* default to not changing parameters */ | |
4482 | params.use_cts_prot = -1; | |
4483 | params.use_short_preamble = -1; | |
4484 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4485 | params.ap_isolate = -1; |
50b12f59 | 4486 | params.ht_opmode = -1; |
53cabad7 JB |
4487 | params.p2p_ctwindow = -1; |
4488 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4489 | |
4490 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4491 | params.use_cts_prot = | |
4492 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4493 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4494 | params.use_short_preamble = | |
4495 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4496 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4497 | params.use_short_slot_time = | |
4498 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4499 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4500 | params.basic_rates = | |
4501 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4502 | params.basic_rates_len = | |
4503 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4504 | } | |
fd8aaaf3 FF |
4505 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4506 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4507 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4508 | params.ht_opmode = | |
4509 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4510 | |
53cabad7 JB |
4511 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4512 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4513 | return -EINVAL; | |
4514 | params.p2p_ctwindow = | |
4515 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4516 | if (params.p2p_ctwindow < 0) | |
4517 | return -EINVAL; | |
4518 | if (params.p2p_ctwindow != 0 && | |
4519 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4520 | return -EINVAL; | |
4521 | } | |
4522 | ||
4523 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4524 | u8 tmp; | |
4525 | ||
4526 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4527 | return -EINVAL; | |
4528 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4529 | if (tmp > 1) | |
4530 | return -EINVAL; | |
4531 | params.p2p_opp_ps = tmp; | |
4532 | if (params.p2p_opp_ps && | |
4533 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4534 | return -EINVAL; | |
4535 | } | |
4536 | ||
4c476991 JB |
4537 | if (!rdev->ops->change_bss) |
4538 | return -EOPNOTSUPP; | |
9f1ba906 | 4539 | |
074ac8df | 4540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4541 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4542 | return -EOPNOTSUPP; | |
3b85875a | 4543 | |
c56589ed SW |
4544 | wdev_lock(wdev); |
4545 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4546 | wdev_unlock(wdev); | |
4547 | ||
4548 | return err; | |
9f1ba906 JM |
4549 | } |
4550 | ||
b54452b0 | 4551 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4552 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4553 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4554 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4555 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4556 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4557 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4558 | }; | |
4559 | ||
4560 | static int parse_reg_rule(struct nlattr *tb[], | |
4561 | struct ieee80211_reg_rule *reg_rule) | |
4562 | { | |
4563 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4564 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4565 | ||
4566 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4567 | return -EINVAL; | |
4568 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4569 | return -EINVAL; | |
4570 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4571 | return -EINVAL; | |
4572 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4573 | return -EINVAL; | |
4574 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4575 | return -EINVAL; | |
4576 | ||
4577 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4578 | ||
4579 | freq_range->start_freq_khz = | |
4580 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4581 | freq_range->end_freq_khz = | |
4582 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4583 | freq_range->max_bandwidth_khz = | |
4584 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4585 | ||
4586 | power_rule->max_eirp = | |
4587 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4588 | ||
4589 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4590 | power_rule->max_antenna_gain = | |
4591 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4592 | ||
4593 | return 0; | |
4594 | } | |
4595 | ||
4596 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4597 | { | |
4598 | int r; | |
4599 | char *data = NULL; | |
57b5ce07 | 4600 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4601 | |
80778f18 LR |
4602 | /* |
4603 | * You should only get this when cfg80211 hasn't yet initialized | |
4604 | * completely when built-in to the kernel right between the time | |
4605 | * window between nl80211_init() and regulatory_init(), if that is | |
4606 | * even possible. | |
4607 | */ | |
458f4f9e | 4608 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4609 | return -EINPROGRESS; |
80778f18 | 4610 | |
fe33eb39 LR |
4611 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4612 | return -EINVAL; | |
b2e1b302 LR |
4613 | |
4614 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4615 | ||
57b5ce07 LR |
4616 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4617 | user_reg_hint_type = | |
4618 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4619 | else | |
4620 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4621 | ||
4622 | switch (user_reg_hint_type) { | |
4623 | case NL80211_USER_REG_HINT_USER: | |
4624 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4625 | break; | |
4626 | default: | |
4627 | return -EINVAL; | |
4628 | } | |
4629 | ||
4630 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4631 | |
b2e1b302 LR |
4632 | return r; |
4633 | } | |
4634 | ||
24bdd9f4 | 4635 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4636 | struct genl_info *info) |
93da9cc1 | 4637 | { |
4c476991 | 4638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4639 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4640 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4641 | struct mesh_config cur_params; | |
4642 | int err = 0; | |
93da9cc1 | 4643 | void *hdr; |
4644 | struct nlattr *pinfoattr; | |
4645 | struct sk_buff *msg; | |
4646 | ||
29cbe68c JB |
4647 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4648 | return -EOPNOTSUPP; | |
4649 | ||
24bdd9f4 | 4650 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4651 | return -EOPNOTSUPP; |
f3f92586 | 4652 | |
29cbe68c JB |
4653 | wdev_lock(wdev); |
4654 | /* If not connected, get default parameters */ | |
4655 | if (!wdev->mesh_id_len) | |
4656 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4657 | else | |
e35e4d28 | 4658 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4659 | wdev_unlock(wdev); |
4660 | ||
93da9cc1 | 4661 | if (err) |
4c476991 | 4662 | return err; |
93da9cc1 | 4663 | |
4664 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4665 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4666 | if (!msg) |
4667 | return -ENOMEM; | |
15e47304 | 4668 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4669 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4670 | if (!hdr) |
efe1cf0c | 4671 | goto out; |
24bdd9f4 | 4672 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4673 | if (!pinfoattr) |
4674 | goto nla_put_failure; | |
9360ffd1 DM |
4675 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4676 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4677 | cur_params.dot11MeshRetryTimeout) || | |
4678 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4679 | cur_params.dot11MeshConfirmTimeout) || | |
4680 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4681 | cur_params.dot11MeshHoldingTimeout) || | |
4682 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4683 | cur_params.dot11MeshMaxPeerLinks) || | |
4684 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4685 | cur_params.dot11MeshMaxRetries) || | |
4686 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4687 | cur_params.dot11MeshTTL) || | |
4688 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4689 | cur_params.element_ttl) || | |
4690 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4691 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4692 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4693 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4694 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4695 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4696 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4697 | cur_params.path_refresh_time) || | |
4698 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4699 | cur_params.min_discovery_timeout) || | |
4700 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4701 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4702 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4703 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4704 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4705 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4706 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4707 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4708 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4709 | cur_params.dot11MeshHWMPRootMode) || | |
4710 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4711 | cur_params.dot11MeshHWMPRannInterval) || | |
4712 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4713 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4714 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4715 | cur_params.dot11MeshForwarding) || | |
4716 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4717 | cur_params.rssi_threshold) || |
4718 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4719 | cur_params.ht_opmode) || |
4720 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4721 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4722 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4723 | cur_params.dot11MeshHWMProotInterval) || |
4724 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4725 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4726 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4727 | cur_params.power_mode) || | |
4728 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4729 | cur_params.dot11MeshAwakeWindowDuration) || |
4730 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4731 | cur_params.plink_timeout)) | |
9360ffd1 | 4732 | goto nla_put_failure; |
93da9cc1 | 4733 | nla_nest_end(msg, pinfoattr); |
4734 | genlmsg_end(msg, hdr); | |
4c476991 | 4735 | return genlmsg_reply(msg, info); |
93da9cc1 | 4736 | |
3b85875a | 4737 | nla_put_failure: |
93da9cc1 | 4738 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4739 | out: |
d080e275 | 4740 | nlmsg_free(msg); |
4c476991 | 4741 | return -ENOBUFS; |
93da9cc1 | 4742 | } |
4743 | ||
b54452b0 | 4744 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4745 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4746 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4747 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4748 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4749 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4750 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4751 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4752 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4753 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4754 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4755 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4756 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4757 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4758 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4759 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4760 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4761 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4762 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4763 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4764 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4765 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4766 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4767 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4768 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4769 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4770 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4771 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4772 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4773 | }; |
4774 | ||
c80d545d JC |
4775 | static const struct nla_policy |
4776 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4777 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4778 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4779 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4780 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4781 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4782 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4783 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4784 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4785 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4786 | }; |
4787 | ||
24bdd9f4 | 4788 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4789 | struct mesh_config *cfg, |
4790 | u32 *mask_out) | |
93da9cc1 | 4791 | { |
93da9cc1 | 4792 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4793 | u32 mask = 0; |
93da9cc1 | 4794 | |
ea54fba2 MP |
4795 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4796 | do { \ | |
4797 | if (tb[attr]) { \ | |
4798 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4799 | return -EINVAL; \ | |
4800 | cfg->param = fn(tb[attr]); \ | |
4801 | mask |= (1 << (attr - 1)); \ | |
4802 | } \ | |
4803 | } while (0) | |
bd90fdcc JB |
4804 | |
4805 | ||
24bdd9f4 | 4806 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4807 | return -EINVAL; |
4808 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4809 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4810 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4811 | return -EINVAL; |
4812 | ||
93da9cc1 | 4813 | /* This makes sure that there aren't more than 32 mesh config |
4814 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4815 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4816 | ||
4817 | /* Fill in the params struct */ | |
ea54fba2 | 4818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4819 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4820 | nla_get_u16); | |
ea54fba2 | 4821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4822 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4823 | nla_get_u16); | |
ea54fba2 | 4824 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4825 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4826 | nla_get_u16); | |
ea54fba2 | 4827 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4828 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4829 | nla_get_u16); | |
ea54fba2 | 4830 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4831 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4832 | nla_get_u8); | |
ea54fba2 | 4833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4834 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4835 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4836 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4837 | nla_get_u8); | |
ea54fba2 | 4838 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4839 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4840 | nla_get_u8); | |
ea54fba2 MP |
4841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4842 | 1, 255, mask, | |
a4f606ea CYY |
4843 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4844 | nla_get_u32); | |
ea54fba2 | 4845 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4846 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4847 | nla_get_u8); | |
ea54fba2 | 4848 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4849 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4850 | nla_get_u32); | |
ea54fba2 | 4851 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4852 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4853 | nla_get_u16); | |
ea54fba2 MP |
4854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4855 | 1, 65535, mask, | |
a4f606ea CYY |
4856 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4857 | nla_get_u32); | |
93da9cc1 | 4858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4859 | 1, 65535, mask, |
4860 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4861 | nla_get_u16); |
dca7e943 | 4862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4863 | 1, 65535, mask, |
4864 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4865 | nla_get_u16); |
93da9cc1 | 4866 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4867 | dot11MeshHWMPnetDiameterTraversalTime, |
4868 | 1, 65535, mask, | |
a4f606ea CYY |
4869 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4870 | nla_get_u16); | |
ea54fba2 MP |
4871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4872 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4873 | nla_get_u8); | |
4874 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4875 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4876 | nla_get_u16); |
63c5723b | 4877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4878 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4879 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4880 | nla_get_u8); |
ea54fba2 | 4881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4882 | mask, NL80211_MESHCONF_FORWARDING, |
4883 | nla_get_u8); | |
83374fe9 | 4884 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 4885 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 4886 | nla_get_s32); |
ea54fba2 | 4887 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4888 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4889 | nla_get_u16); |
4890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4891 | 1, 65535, mask, |
ac1073a6 CYY |
4892 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4893 | nla_get_u32); | |
ea54fba2 | 4894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4895 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4896 | nla_get_u16); |
4897 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4898 | dot11MeshHWMPconfirmationInterval, |
4899 | 1, 65535, mask, | |
728b19e5 | 4900 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4901 | nla_get_u16); |
3b1c5a53 MP |
4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4903 | NL80211_MESH_POWER_ACTIVE, | |
4904 | NL80211_MESH_POWER_MAX, | |
4905 | mask, NL80211_MESHCONF_POWER_MODE, | |
4906 | nla_get_u32); | |
4907 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4908 | 0, 65535, mask, | |
4909 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
4910 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
4911 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4912 | nla_get_u32); | |
bd90fdcc JB |
4913 | if (mask_out) |
4914 | *mask_out = mask; | |
c80d545d | 4915 | |
bd90fdcc JB |
4916 | return 0; |
4917 | ||
4918 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4919 | } | |
4920 | ||
c80d545d JC |
4921 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4922 | struct mesh_setup *setup) | |
4923 | { | |
bb2798d4 | 4924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4925 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4926 | ||
4927 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4928 | return -EINVAL; | |
4929 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4930 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4931 | nl80211_mesh_setup_params_policy)) | |
4932 | return -EINVAL; | |
4933 | ||
d299a1f2 JC |
4934 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4935 | setup->sync_method = | |
4936 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4937 | IEEE80211_SYNC_METHOD_VENDOR : | |
4938 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4939 | ||
c80d545d JC |
4940 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4941 | setup->path_sel_proto = | |
4942 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4943 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4944 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4945 | ||
4946 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4947 | setup->path_metric = | |
4948 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4949 | IEEE80211_PATH_METRIC_VENDOR : | |
4950 | IEEE80211_PATH_METRIC_AIRTIME; | |
4951 | ||
581a8b0f JC |
4952 | |
4953 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4954 | struct nlattr *ieattr = |
581a8b0f | 4955 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4956 | if (!is_valid_ie_attr(ieattr)) |
4957 | return -EINVAL; | |
581a8b0f JC |
4958 | setup->ie = nla_data(ieattr); |
4959 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4960 | } |
bb2798d4 TP |
4961 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4962 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4963 | return -EINVAL; | |
4964 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4965 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4966 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4967 | if (setup->is_secure) |
4968 | setup->user_mpm = true; | |
c80d545d | 4969 | |
6e16d90b CT |
4970 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
4971 | if (!setup->user_mpm) | |
4972 | return -EINVAL; | |
4973 | setup->auth_id = | |
4974 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
4975 | } | |
4976 | ||
c80d545d JC |
4977 | return 0; |
4978 | } | |
4979 | ||
24bdd9f4 | 4980 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4981 | struct genl_info *info) |
bd90fdcc JB |
4982 | { |
4983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4984 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4985 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4986 | struct mesh_config cfg; |
4987 | u32 mask; | |
4988 | int err; | |
4989 | ||
29cbe68c JB |
4990 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4991 | return -EOPNOTSUPP; | |
4992 | ||
24bdd9f4 | 4993 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4994 | return -EOPNOTSUPP; |
4995 | ||
24bdd9f4 | 4996 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4997 | if (err) |
4998 | return err; | |
4999 | ||
29cbe68c JB |
5000 | wdev_lock(wdev); |
5001 | if (!wdev->mesh_id_len) | |
5002 | err = -ENOLINK; | |
5003 | ||
5004 | if (!err) | |
e35e4d28 | 5005 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5006 | |
5007 | wdev_unlock(wdev); | |
5008 | ||
5009 | return err; | |
93da9cc1 | 5010 | } |
5011 | ||
f130347c LR |
5012 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5013 | { | |
458f4f9e | 5014 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5015 | struct sk_buff *msg; |
5016 | void *hdr = NULL; | |
5017 | struct nlattr *nl_reg_rules; | |
5018 | unsigned int i; | |
f130347c LR |
5019 | |
5020 | if (!cfg80211_regdomain) | |
5fe231e8 | 5021 | return -EINVAL; |
f130347c | 5022 | |
fd2120ca | 5023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5024 | if (!msg) |
5025 | return -ENOBUFS; | |
f130347c | 5026 | |
15e47304 | 5027 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5028 | NL80211_CMD_GET_REG); |
5029 | if (!hdr) | |
efe1cf0c | 5030 | goto put_failure; |
f130347c | 5031 | |
57b5ce07 LR |
5032 | if (reg_last_request_cell_base() && |
5033 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5034 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5035 | goto nla_put_failure; | |
5036 | ||
458f4f9e JB |
5037 | rcu_read_lock(); |
5038 | regdom = rcu_dereference(cfg80211_regdomain); | |
5039 | ||
5040 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5041 | (regdom->dfs_region && | |
5042 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5043 | goto nla_put_failure_rcu; | |
5044 | ||
f130347c LR |
5045 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5046 | if (!nl_reg_rules) | |
458f4f9e | 5047 | goto nla_put_failure_rcu; |
f130347c | 5048 | |
458f4f9e | 5049 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5050 | struct nlattr *nl_reg_rule; |
5051 | const struct ieee80211_reg_rule *reg_rule; | |
5052 | const struct ieee80211_freq_range *freq_range; | |
5053 | const struct ieee80211_power_rule *power_rule; | |
5054 | ||
458f4f9e | 5055 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5056 | freq_range = ®_rule->freq_range; |
5057 | power_rule = ®_rule->power_rule; | |
5058 | ||
5059 | nl_reg_rule = nla_nest_start(msg, i); | |
5060 | if (!nl_reg_rule) | |
458f4f9e | 5061 | goto nla_put_failure_rcu; |
f130347c | 5062 | |
9360ffd1 DM |
5063 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5064 | reg_rule->flags) || | |
5065 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5066 | freq_range->start_freq_khz) || | |
5067 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5068 | freq_range->end_freq_khz) || | |
5069 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
5070 | freq_range->max_bandwidth_khz) || | |
5071 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
5072 | power_rule->max_antenna_gain) || | |
5073 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
5074 | power_rule->max_eirp)) | |
458f4f9e | 5075 | goto nla_put_failure_rcu; |
f130347c LR |
5076 | |
5077 | nla_nest_end(msg, nl_reg_rule); | |
5078 | } | |
458f4f9e | 5079 | rcu_read_unlock(); |
f130347c LR |
5080 | |
5081 | nla_nest_end(msg, nl_reg_rules); | |
5082 | ||
5083 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5084 | return genlmsg_reply(msg, info); |
f130347c | 5085 | |
458f4f9e JB |
5086 | nla_put_failure_rcu: |
5087 | rcu_read_unlock(); | |
f130347c LR |
5088 | nla_put_failure: |
5089 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5090 | put_failure: |
d080e275 | 5091 | nlmsg_free(msg); |
5fe231e8 | 5092 | return -EMSGSIZE; |
f130347c LR |
5093 | } |
5094 | ||
b2e1b302 LR |
5095 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5096 | { | |
5097 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5098 | struct nlattr *nl_reg_rule; | |
5099 | char *alpha2 = NULL; | |
5100 | int rem_reg_rules = 0, r = 0; | |
5101 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5102 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5103 | struct ieee80211_regdomain *rd = NULL; |
5104 | ||
5105 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5106 | return -EINVAL; | |
5107 | ||
5108 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5109 | return -EINVAL; | |
5110 | ||
5111 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5112 | ||
8b60b078 LR |
5113 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5114 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5115 | ||
b2e1b302 | 5116 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5117 | rem_reg_rules) { |
b2e1b302 LR |
5118 | num_rules++; |
5119 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5120 | return -EINVAL; |
b2e1b302 LR |
5121 | } |
5122 | ||
e438768f LR |
5123 | if (!reg_is_valid_request(alpha2)) |
5124 | return -EINVAL; | |
5125 | ||
b2e1b302 | 5126 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5127 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5128 | |
5129 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5130 | if (!rd) |
5131 | return -ENOMEM; | |
b2e1b302 LR |
5132 | |
5133 | rd->n_reg_rules = num_rules; | |
5134 | rd->alpha2[0] = alpha2[0]; | |
5135 | rd->alpha2[1] = alpha2[1]; | |
5136 | ||
8b60b078 LR |
5137 | /* |
5138 | * Disable DFS master mode if the DFS region was | |
5139 | * not supported or known on this kernel. | |
5140 | */ | |
5141 | if (reg_supported_dfs_region(dfs_region)) | |
5142 | rd->dfs_region = dfs_region; | |
5143 | ||
b2e1b302 | 5144 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5145 | rem_reg_rules) { |
b2e1b302 | 5146 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
5147 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
5148 | reg_rule_policy); | |
b2e1b302 LR |
5149 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5150 | if (r) | |
5151 | goto bad_reg; | |
5152 | ||
5153 | rule_idx++; | |
5154 | ||
d0e18f83 LR |
5155 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5156 | r = -EINVAL; | |
b2e1b302 | 5157 | goto bad_reg; |
d0e18f83 | 5158 | } |
b2e1b302 LR |
5159 | } |
5160 | ||
b2e1b302 | 5161 | r = set_regdom(rd); |
6913b49a | 5162 | /* set_regdom took ownership */ |
1a919318 | 5163 | rd = NULL; |
b2e1b302 | 5164 | |
d2372b31 | 5165 | bad_reg: |
b2e1b302 | 5166 | kfree(rd); |
d0e18f83 | 5167 | return r; |
b2e1b302 LR |
5168 | } |
5169 | ||
83f5e2cf JB |
5170 | static int validate_scan_freqs(struct nlattr *freqs) |
5171 | { | |
5172 | struct nlattr *attr1, *attr2; | |
5173 | int n_channels = 0, tmp1, tmp2; | |
5174 | ||
5175 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5176 | n_channels++; | |
5177 | /* | |
5178 | * Some hardware has a limited channel list for | |
5179 | * scanning, and it is pretty much nonsensical | |
5180 | * to scan for a channel twice, so disallow that | |
5181 | * and don't require drivers to check that the | |
5182 | * channel list they get isn't longer than what | |
5183 | * they can scan, as long as they can scan all | |
5184 | * the channels they registered at once. | |
5185 | */ | |
5186 | nla_for_each_nested(attr2, freqs, tmp2) | |
5187 | if (attr1 != attr2 && | |
5188 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5189 | return 0; | |
5190 | } | |
5191 | ||
5192 | return n_channels; | |
5193 | } | |
5194 | ||
2a519311 JB |
5195 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5196 | { | |
4c476991 | 5197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5198 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5199 | struct cfg80211_scan_request *request; |
2a519311 JB |
5200 | struct nlattr *attr; |
5201 | struct wiphy *wiphy; | |
83f5e2cf | 5202 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5203 | size_t ie_len; |
2a519311 | 5204 | |
f4a11bb0 JB |
5205 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5206 | return -EINVAL; | |
5207 | ||
79c97e97 | 5208 | wiphy = &rdev->wiphy; |
2a519311 | 5209 | |
4c476991 JB |
5210 | if (!rdev->ops->scan) |
5211 | return -EOPNOTSUPP; | |
2a519311 | 5212 | |
f9f47529 JB |
5213 | if (rdev->scan_req) { |
5214 | err = -EBUSY; | |
5215 | goto unlock; | |
5216 | } | |
2a519311 JB |
5217 | |
5218 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5219 | n_channels = validate_scan_freqs( |
5220 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5221 | if (!n_channels) { |
5222 | err = -EINVAL; | |
5223 | goto unlock; | |
5224 | } | |
2a519311 | 5225 | } else { |
34850ab2 | 5226 | enum ieee80211_band band; |
83f5e2cf JB |
5227 | n_channels = 0; |
5228 | ||
2a519311 JB |
5229 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5230 | if (wiphy->bands[band]) | |
5231 | n_channels += wiphy->bands[band]->n_channels; | |
5232 | } | |
5233 | ||
5234 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5235 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5236 | n_ssids++; | |
5237 | ||
f9f47529 JB |
5238 | if (n_ssids > wiphy->max_scan_ssids) { |
5239 | err = -EINVAL; | |
5240 | goto unlock; | |
5241 | } | |
2a519311 | 5242 | |
70692ad2 JM |
5243 | if (info->attrs[NL80211_ATTR_IE]) |
5244 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5245 | else | |
5246 | ie_len = 0; | |
5247 | ||
f9f47529 JB |
5248 | if (ie_len > wiphy->max_scan_ie_len) { |
5249 | err = -EINVAL; | |
5250 | goto unlock; | |
5251 | } | |
18a83659 | 5252 | |
2a519311 | 5253 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5254 | + sizeof(*request->ssids) * n_ssids |
5255 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5256 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5257 | if (!request) { |
5258 | err = -ENOMEM; | |
5259 | goto unlock; | |
5260 | } | |
2a519311 | 5261 | |
2a519311 | 5262 | if (n_ssids) |
5ba63533 | 5263 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5264 | request->n_ssids = n_ssids; |
70692ad2 JM |
5265 | if (ie_len) { |
5266 | if (request->ssids) | |
5267 | request->ie = (void *)(request->ssids + n_ssids); | |
5268 | else | |
5269 | request->ie = (void *)(request->channels + n_channels); | |
5270 | } | |
2a519311 | 5271 | |
584991dc | 5272 | i = 0; |
2a519311 JB |
5273 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5274 | /* user specified, bail out if channel not found */ | |
2a519311 | 5275 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5276 | struct ieee80211_channel *chan; |
5277 | ||
5278 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5279 | ||
5280 | if (!chan) { | |
2a519311 JB |
5281 | err = -EINVAL; |
5282 | goto out_free; | |
5283 | } | |
584991dc JB |
5284 | |
5285 | /* ignore disabled channels */ | |
5286 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5287 | continue; | |
5288 | ||
5289 | request->channels[i] = chan; | |
2a519311 JB |
5290 | i++; |
5291 | } | |
5292 | } else { | |
34850ab2 JB |
5293 | enum ieee80211_band band; |
5294 | ||
2a519311 | 5295 | /* all channels */ |
2a519311 JB |
5296 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5297 | int j; | |
5298 | if (!wiphy->bands[band]) | |
5299 | continue; | |
5300 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5301 | struct ieee80211_channel *chan; |
5302 | ||
5303 | chan = &wiphy->bands[band]->channels[j]; | |
5304 | ||
5305 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5306 | continue; | |
5307 | ||
5308 | request->channels[i] = chan; | |
2a519311 JB |
5309 | i++; |
5310 | } | |
5311 | } | |
5312 | } | |
5313 | ||
584991dc JB |
5314 | if (!i) { |
5315 | err = -EINVAL; | |
5316 | goto out_free; | |
5317 | } | |
5318 | ||
5319 | request->n_channels = i; | |
5320 | ||
2a519311 JB |
5321 | i = 0; |
5322 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5323 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5324 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5325 | err = -EINVAL; |
5326 | goto out_free; | |
5327 | } | |
57a27e1d | 5328 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5329 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5330 | i++; |
5331 | } | |
5332 | } | |
5333 | ||
70692ad2 JM |
5334 | if (info->attrs[NL80211_ATTR_IE]) { |
5335 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5336 | memcpy((void *)request->ie, |
5337 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5338 | request->ie_len); |
5339 | } | |
5340 | ||
34850ab2 | 5341 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5342 | if (wiphy->bands[i]) |
5343 | request->rates[i] = | |
5344 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5345 | |
5346 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5347 | nla_for_each_nested(attr, | |
5348 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5349 | tmp) { | |
5350 | enum ieee80211_band band = nla_type(attr); | |
5351 | ||
84404623 | 5352 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5353 | err = -EINVAL; |
5354 | goto out_free; | |
5355 | } | |
5356 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5357 | nla_data(attr), | |
5358 | nla_len(attr), | |
5359 | &request->rates[band]); | |
5360 | if (err) | |
5361 | goto out_free; | |
5362 | } | |
5363 | } | |
5364 | ||
46856bbf | 5365 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5366 | request->flags = nla_get_u32( |
5367 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5368 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5369 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5370 | err = -EOPNOTSUPP; |
5371 | goto out_free; | |
5372 | } | |
5373 | } | |
ed473771 | 5374 | |
e9f935e3 RM |
5375 | request->no_cck = |
5376 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5377 | ||
fd014284 | 5378 | request->wdev = wdev; |
79c97e97 | 5379 | request->wiphy = &rdev->wiphy; |
15d6030b | 5380 | request->scan_start = jiffies; |
2a519311 | 5381 | |
79c97e97 | 5382 | rdev->scan_req = request; |
e35e4d28 | 5383 | err = rdev_scan(rdev, request); |
2a519311 | 5384 | |
463d0183 | 5385 | if (!err) { |
fd014284 JB |
5386 | nl80211_send_scan_start(rdev, wdev); |
5387 | if (wdev->netdev) | |
5388 | dev_hold(wdev->netdev); | |
4c476991 | 5389 | } else { |
2a519311 | 5390 | out_free: |
79c97e97 | 5391 | rdev->scan_req = NULL; |
2a519311 JB |
5392 | kfree(request); |
5393 | } | |
3b85875a | 5394 | |
f9f47529 | 5395 | unlock: |
2a519311 JB |
5396 | return err; |
5397 | } | |
5398 | ||
807f8a8c LC |
5399 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5400 | struct genl_info *info) | |
5401 | { | |
5402 | struct cfg80211_sched_scan_request *request; | |
5403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5404 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5405 | struct nlattr *attr; |
5406 | struct wiphy *wiphy; | |
a1f1c21c | 5407 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5408 | u32 interval; |
807f8a8c LC |
5409 | enum ieee80211_band band; |
5410 | size_t ie_len; | |
a1f1c21c | 5411 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5412 | |
5413 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5414 | !rdev->ops->sched_scan_start) | |
5415 | return -EOPNOTSUPP; | |
5416 | ||
5417 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5418 | return -EINVAL; | |
5419 | ||
bbe6ad6d LC |
5420 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5421 | return -EINVAL; | |
5422 | ||
5423 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5424 | if (interval == 0) | |
5425 | return -EINVAL; | |
5426 | ||
807f8a8c LC |
5427 | wiphy = &rdev->wiphy; |
5428 | ||
5429 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5430 | n_channels = validate_scan_freqs( | |
5431 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5432 | if (!n_channels) | |
5433 | return -EINVAL; | |
5434 | } else { | |
5435 | n_channels = 0; | |
5436 | ||
5437 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5438 | if (wiphy->bands[band]) | |
5439 | n_channels += wiphy->bands[band]->n_channels; | |
5440 | } | |
5441 | ||
5442 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5443 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5444 | tmp) | |
5445 | n_ssids++; | |
5446 | ||
93b6aa69 | 5447 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5448 | return -EINVAL; |
5449 | ||
a1f1c21c LC |
5450 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5451 | nla_for_each_nested(attr, | |
5452 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5453 | tmp) | |
5454 | n_match_sets++; | |
5455 | ||
5456 | if (n_match_sets > wiphy->max_match_sets) | |
5457 | return -EINVAL; | |
5458 | ||
807f8a8c LC |
5459 | if (info->attrs[NL80211_ATTR_IE]) |
5460 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5461 | else | |
5462 | ie_len = 0; | |
5463 | ||
5a865bad | 5464 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5465 | return -EINVAL; |
5466 | ||
c10841ca LC |
5467 | if (rdev->sched_scan_req) { |
5468 | err = -EINPROGRESS; | |
5469 | goto out; | |
5470 | } | |
5471 | ||
807f8a8c | 5472 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5473 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5474 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5475 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5476 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5477 | if (!request) { |
5478 | err = -ENOMEM; | |
5479 | goto out; | |
5480 | } | |
807f8a8c LC |
5481 | |
5482 | if (n_ssids) | |
5483 | request->ssids = (void *)&request->channels[n_channels]; | |
5484 | request->n_ssids = n_ssids; | |
5485 | if (ie_len) { | |
5486 | if (request->ssids) | |
5487 | request->ie = (void *)(request->ssids + n_ssids); | |
5488 | else | |
5489 | request->ie = (void *)(request->channels + n_channels); | |
5490 | } | |
5491 | ||
a1f1c21c LC |
5492 | if (n_match_sets) { |
5493 | if (request->ie) | |
5494 | request->match_sets = (void *)(request->ie + ie_len); | |
5495 | else if (request->ssids) | |
5496 | request->match_sets = | |
5497 | (void *)(request->ssids + n_ssids); | |
5498 | else | |
5499 | request->match_sets = | |
5500 | (void *)(request->channels + n_channels); | |
5501 | } | |
5502 | request->n_match_sets = n_match_sets; | |
5503 | ||
807f8a8c LC |
5504 | i = 0; |
5505 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5506 | /* user specified, bail out if channel not found */ | |
5507 | nla_for_each_nested(attr, | |
5508 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5509 | tmp) { | |
5510 | struct ieee80211_channel *chan; | |
5511 | ||
5512 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5513 | ||
5514 | if (!chan) { | |
5515 | err = -EINVAL; | |
5516 | goto out_free; | |
5517 | } | |
5518 | ||
5519 | /* ignore disabled channels */ | |
5520 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5521 | continue; | |
5522 | ||
5523 | request->channels[i] = chan; | |
5524 | i++; | |
5525 | } | |
5526 | } else { | |
5527 | /* all channels */ | |
5528 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5529 | int j; | |
5530 | if (!wiphy->bands[band]) | |
5531 | continue; | |
5532 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5533 | struct ieee80211_channel *chan; | |
5534 | ||
5535 | chan = &wiphy->bands[band]->channels[j]; | |
5536 | ||
5537 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5538 | continue; | |
5539 | ||
5540 | request->channels[i] = chan; | |
5541 | i++; | |
5542 | } | |
5543 | } | |
5544 | } | |
5545 | ||
5546 | if (!i) { | |
5547 | err = -EINVAL; | |
5548 | goto out_free; | |
5549 | } | |
5550 | ||
5551 | request->n_channels = i; | |
5552 | ||
5553 | i = 0; | |
5554 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5555 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5556 | tmp) { | |
57a27e1d | 5557 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5558 | err = -EINVAL; |
5559 | goto out_free; | |
5560 | } | |
57a27e1d | 5561 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5562 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5563 | nla_len(attr)); | |
807f8a8c LC |
5564 | i++; |
5565 | } | |
5566 | } | |
5567 | ||
a1f1c21c LC |
5568 | i = 0; |
5569 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5570 | nla_for_each_nested(attr, | |
5571 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5572 | tmp) { | |
88e920b4 | 5573 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5574 | |
5575 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5576 | nla_data(attr), nla_len(attr), | |
5577 | nl80211_match_policy); | |
4a4ab0d7 | 5578 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5579 | if (ssid) { |
5580 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5581 | err = -EINVAL; | |
5582 | goto out_free; | |
5583 | } | |
5584 | memcpy(request->match_sets[i].ssid.ssid, | |
5585 | nla_data(ssid), nla_len(ssid)); | |
5586 | request->match_sets[i].ssid.ssid_len = | |
5587 | nla_len(ssid); | |
5588 | } | |
88e920b4 TP |
5589 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5590 | if (rssi) | |
5591 | request->rssi_thold = nla_get_u32(rssi); | |
5592 | else | |
5593 | request->rssi_thold = | |
5594 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5595 | i++; |
5596 | } | |
5597 | } | |
5598 | ||
807f8a8c LC |
5599 | if (info->attrs[NL80211_ATTR_IE]) { |
5600 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5601 | memcpy((void *)request->ie, | |
5602 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5603 | request->ie_len); | |
5604 | } | |
5605 | ||
46856bbf | 5606 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5607 | request->flags = nla_get_u32( |
5608 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5609 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5610 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5611 | err = -EOPNOTSUPP; |
5612 | goto out_free; | |
5613 | } | |
5614 | } | |
ed473771 | 5615 | |
807f8a8c LC |
5616 | request->dev = dev; |
5617 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5618 | request->interval = interval; |
15d6030b | 5619 | request->scan_start = jiffies; |
807f8a8c | 5620 | |
e35e4d28 | 5621 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5622 | if (!err) { |
5623 | rdev->sched_scan_req = request; | |
5624 | nl80211_send_sched_scan(rdev, dev, | |
5625 | NL80211_CMD_START_SCHED_SCAN); | |
5626 | goto out; | |
5627 | } | |
5628 | ||
5629 | out_free: | |
5630 | kfree(request); | |
5631 | out: | |
5632 | return err; | |
5633 | } | |
5634 | ||
5635 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5636 | struct genl_info *info) | |
5637 | { | |
5638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5639 | ||
5640 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5641 | !rdev->ops->sched_scan_stop) | |
5642 | return -EOPNOTSUPP; | |
5643 | ||
5fe231e8 | 5644 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5645 | } |
5646 | ||
04f39047 SW |
5647 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5648 | struct genl_info *info) | |
5649 | { | |
5650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5651 | struct net_device *dev = info->user_ptr[1]; | |
5652 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5653 | struct cfg80211_chan_def chandef; | |
55f7435c | 5654 | enum nl80211_dfs_regions dfs_region; |
04f39047 SW |
5655 | int err; |
5656 | ||
55f7435c LR |
5657 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5658 | if (dfs_region == NL80211_DFS_UNSET) | |
5659 | return -EINVAL; | |
5660 | ||
04f39047 SW |
5661 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5662 | if (err) | |
5663 | return err; | |
5664 | ||
ff311bc1 SW |
5665 | if (netif_carrier_ok(dev)) |
5666 | return -EBUSY; | |
5667 | ||
04f39047 SW |
5668 | if (wdev->cac_started) |
5669 | return -EBUSY; | |
5670 | ||
5671 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5672 | if (err < 0) | |
5673 | return err; | |
5674 | ||
5675 | if (err == 0) | |
5676 | return -EINVAL; | |
5677 | ||
fe7c3a1f | 5678 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
5679 | return -EINVAL; |
5680 | ||
5681 | if (!rdev->ops->start_radar_detection) | |
5682 | return -EOPNOTSUPP; | |
5683 | ||
04f39047 SW |
5684 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5685 | chandef.chan, CHAN_MODE_SHARED, | |
5686 | BIT(chandef.width)); | |
5687 | if (err) | |
5fe231e8 | 5688 | return err; |
04f39047 SW |
5689 | |
5690 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5691 | if (!err) { | |
5692 | wdev->channel = chandef.chan; | |
5693 | wdev->cac_started = true; | |
5694 | wdev->cac_start_time = jiffies; | |
5695 | } | |
04f39047 SW |
5696 | return err; |
5697 | } | |
5698 | ||
16ef1fe2 SW |
5699 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5700 | { | |
5701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5702 | struct net_device *dev = info->user_ptr[1]; | |
5703 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5704 | struct cfg80211_csa_settings params; | |
5705 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5706 | * function is called under RTNL lock, so this should not be a problem. | |
5707 | */ | |
5708 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5709 | u8 radar_detect_width = 0; | |
5710 | int err; | |
ee4bc9e7 | 5711 | bool need_new_beacon = false; |
16ef1fe2 SW |
5712 | |
5713 | if (!rdev->ops->channel_switch || | |
5714 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5715 | return -EOPNOTSUPP; | |
5716 | ||
ee4bc9e7 SW |
5717 | switch (dev->ieee80211_ptr->iftype) { |
5718 | case NL80211_IFTYPE_AP: | |
5719 | case NL80211_IFTYPE_P2P_GO: | |
5720 | need_new_beacon = true; | |
5721 | ||
5722 | /* useless if AP is not running */ | |
5723 | if (!wdev->beacon_interval) | |
5724 | return -EINVAL; | |
5725 | break; | |
5726 | case NL80211_IFTYPE_ADHOC: | |
c6da674a | 5727 | case NL80211_IFTYPE_MESH_POINT: |
ee4bc9e7 SW |
5728 | break; |
5729 | default: | |
16ef1fe2 | 5730 | return -EOPNOTSUPP; |
ee4bc9e7 | 5731 | } |
16ef1fe2 SW |
5732 | |
5733 | memset(¶ms, 0, sizeof(params)); | |
5734 | ||
5735 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5736 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5737 | return -EINVAL; | |
5738 | ||
5739 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 5740 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
5741 | return -EINVAL; |
5742 | ||
5743 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5744 | ||
ee4bc9e7 SW |
5745 | if (!need_new_beacon) |
5746 | goto skip_beacons; | |
5747 | ||
16ef1fe2 SW |
5748 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
5749 | if (err) | |
5750 | return err; | |
5751 | ||
5752 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5753 | info->attrs[NL80211_ATTR_CSA_IES], | |
5754 | nl80211_policy); | |
5755 | if (err) | |
5756 | return err; | |
5757 | ||
5758 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5759 | if (err) | |
5760 | return err; | |
5761 | ||
5762 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5763 | return -EINVAL; | |
5764 | ||
5765 | params.counter_offset_beacon = | |
5766 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5767 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) | |
5768 | return -EINVAL; | |
5769 | ||
5770 | /* sanity check - counters should be the same */ | |
5771 | if (params.beacon_csa.tail[params.counter_offset_beacon] != | |
5772 | params.count) | |
5773 | return -EINVAL; | |
5774 | ||
5775 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | |
5776 | params.counter_offset_presp = | |
5777 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5778 | if (params.counter_offset_presp >= | |
5779 | params.beacon_csa.probe_resp_len) | |
5780 | return -EINVAL; | |
5781 | ||
5782 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != | |
5783 | params.count) | |
5784 | return -EINVAL; | |
5785 | } | |
5786 | ||
ee4bc9e7 | 5787 | skip_beacons: |
16ef1fe2 SW |
5788 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
5789 | if (err) | |
5790 | return err; | |
5791 | ||
5792 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) | |
5793 | return -EINVAL; | |
5794 | ||
ee4bc9e7 | 5795 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
5336fa88 SW |
5796 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
5797 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { | |
ee4bc9e7 SW |
5798 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
5799 | ¶ms.chandef); | |
5800 | if (err < 0) { | |
5801 | return err; | |
5802 | } else if (err) { | |
5803 | radar_detect_width = BIT(params.chandef.width); | |
5804 | params.radar_required = true; | |
5805 | } | |
16ef1fe2 SW |
5806 | } |
5807 | ||
5808 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5809 | params.chandef.chan, | |
5810 | CHAN_MODE_SHARED, | |
5811 | radar_detect_width); | |
5812 | if (err) | |
5813 | return err; | |
5814 | ||
5815 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | |
5816 | params.block_tx = true; | |
5817 | ||
c56589ed SW |
5818 | wdev_lock(wdev); |
5819 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
5820 | wdev_unlock(wdev); | |
5821 | ||
5822 | return err; | |
16ef1fe2 SW |
5823 | } |
5824 | ||
9720bb3a JB |
5825 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5826 | u32 seq, int flags, | |
2a519311 | 5827 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5828 | struct wireless_dev *wdev, |
5829 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5830 | { |
48ab905d | 5831 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5832 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5833 | void *hdr; |
5834 | struct nlattr *bss; | |
8cef2c9d | 5835 | bool tsf = false; |
48ab905d JB |
5836 | |
5837 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5838 | |
15e47304 | 5839 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5840 | NL80211_CMD_NEW_SCAN_RESULTS); |
5841 | if (!hdr) | |
5842 | return -1; | |
5843 | ||
9720bb3a JB |
5844 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5845 | ||
97990a06 JB |
5846 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5847 | goto nla_put_failure; | |
5848 | if (wdev->netdev && | |
9360ffd1 DM |
5849 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5850 | goto nla_put_failure; | |
97990a06 JB |
5851 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5852 | goto nla_put_failure; | |
2a519311 JB |
5853 | |
5854 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5855 | if (!bss) | |
5856 | goto nla_put_failure; | |
9360ffd1 | 5857 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5858 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5859 | goto nla_put_failure; |
9caf0364 JB |
5860 | |
5861 | rcu_read_lock(); | |
5862 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5863 | if (ies) { |
5864 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5865 | goto fail_unlock_rcu; | |
5866 | tsf = true; | |
5867 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5868 | ies->len, ies->data)) | |
5869 | goto fail_unlock_rcu; | |
9caf0364 JB |
5870 | } |
5871 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5872 | if (ies) { |
5873 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5874 | goto fail_unlock_rcu; | |
5875 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5876 | ies->len, ies->data)) | |
5877 | goto fail_unlock_rcu; | |
9caf0364 JB |
5878 | } |
5879 | rcu_read_unlock(); | |
5880 | ||
9360ffd1 DM |
5881 | if (res->beacon_interval && |
5882 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5883 | goto nla_put_failure; | |
5884 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5885 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 5886 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
5887 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
5888 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5889 | goto nla_put_failure; | |
2a519311 | 5890 | |
77965c97 | 5891 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5892 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5893 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5894 | goto nla_put_failure; | |
2a519311 JB |
5895 | break; |
5896 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5897 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5898 | goto nla_put_failure; | |
2a519311 JB |
5899 | break; |
5900 | default: | |
5901 | break; | |
5902 | } | |
5903 | ||
48ab905d | 5904 | switch (wdev->iftype) { |
074ac8df | 5905 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5906 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5907 | if (intbss == wdev->current_bss && |
5908 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5909 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5910 | goto nla_put_failure; | |
48ab905d JB |
5911 | break; |
5912 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5913 | if (intbss == wdev->current_bss && |
5914 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5915 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5916 | goto nla_put_failure; | |
48ab905d JB |
5917 | break; |
5918 | default: | |
5919 | break; | |
5920 | } | |
5921 | ||
2a519311 JB |
5922 | nla_nest_end(msg, bss); |
5923 | ||
5924 | return genlmsg_end(msg, hdr); | |
5925 | ||
8cef2c9d JB |
5926 | fail_unlock_rcu: |
5927 | rcu_read_unlock(); | |
2a519311 JB |
5928 | nla_put_failure: |
5929 | genlmsg_cancel(msg, hdr); | |
5930 | return -EMSGSIZE; | |
5931 | } | |
5932 | ||
97990a06 | 5933 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5934 | { |
48ab905d | 5935 | struct cfg80211_registered_device *rdev; |
2a519311 | 5936 | struct cfg80211_internal_bss *scan; |
48ab905d | 5937 | struct wireless_dev *wdev; |
97990a06 | 5938 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5939 | int err; |
5940 | ||
97990a06 | 5941 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5942 | if (err) |
5943 | return err; | |
2a519311 | 5944 | |
48ab905d JB |
5945 | wdev_lock(wdev); |
5946 | spin_lock_bh(&rdev->bss_lock); | |
5947 | cfg80211_bss_expire(rdev); | |
5948 | ||
9720bb3a JB |
5949 | cb->seq = rdev->bss_generation; |
5950 | ||
48ab905d | 5951 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5952 | if (++idx <= start) |
5953 | continue; | |
9720bb3a | 5954 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5955 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5956 | rdev, wdev, scan) < 0) { |
2a519311 | 5957 | idx--; |
67748893 | 5958 | break; |
2a519311 JB |
5959 | } |
5960 | } | |
5961 | ||
48ab905d JB |
5962 | spin_unlock_bh(&rdev->bss_lock); |
5963 | wdev_unlock(wdev); | |
2a519311 | 5964 | |
97990a06 JB |
5965 | cb->args[2] = idx; |
5966 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5967 | |
67748893 | 5968 | return skb->len; |
2a519311 JB |
5969 | } |
5970 | ||
15e47304 | 5971 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5972 | int flags, struct net_device *dev, |
5973 | struct survey_info *survey) | |
5974 | { | |
5975 | void *hdr; | |
5976 | struct nlattr *infoattr; | |
5977 | ||
15e47304 | 5978 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5979 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5980 | if (!hdr) | |
5981 | return -ENOMEM; | |
5982 | ||
9360ffd1 DM |
5983 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5984 | goto nla_put_failure; | |
61fa713c HS |
5985 | |
5986 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5987 | if (!infoattr) | |
5988 | goto nla_put_failure; | |
5989 | ||
9360ffd1 DM |
5990 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5991 | survey->channel->center_freq)) | |
5992 | goto nla_put_failure; | |
5993 | ||
5994 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5995 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5996 | goto nla_put_failure; | |
5997 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5998 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5999 | goto nla_put_failure; | |
6000 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6001 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6002 | survey->channel_time)) | |
6003 | goto nla_put_failure; | |
6004 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6005 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6006 | survey->channel_time_busy)) | |
6007 | goto nla_put_failure; | |
6008 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6009 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6010 | survey->channel_time_ext_busy)) | |
6011 | goto nla_put_failure; | |
6012 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6013 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6014 | survey->channel_time_rx)) | |
6015 | goto nla_put_failure; | |
6016 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6017 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6018 | survey->channel_time_tx)) | |
6019 | goto nla_put_failure; | |
61fa713c HS |
6020 | |
6021 | nla_nest_end(msg, infoattr); | |
6022 | ||
6023 | return genlmsg_end(msg, hdr); | |
6024 | ||
6025 | nla_put_failure: | |
6026 | genlmsg_cancel(msg, hdr); | |
6027 | return -EMSGSIZE; | |
6028 | } | |
6029 | ||
6030 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6031 | struct netlink_callback *cb) | |
6032 | { | |
6033 | struct survey_info survey; | |
6034 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
6035 | struct wireless_dev *wdev; |
6036 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6037 | int res; |
6038 | ||
97990a06 | 6039 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
6040 | if (res) |
6041 | return res; | |
61fa713c | 6042 | |
97990a06 JB |
6043 | if (!wdev->netdev) { |
6044 | res = -EINVAL; | |
6045 | goto out_err; | |
6046 | } | |
6047 | ||
61fa713c HS |
6048 | if (!dev->ops->dump_survey) { |
6049 | res = -EOPNOTSUPP; | |
6050 | goto out_err; | |
6051 | } | |
6052 | ||
6053 | while (1) { | |
180cdc79 LR |
6054 | struct ieee80211_channel *chan; |
6055 | ||
97990a06 | 6056 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6057 | if (res == -ENOENT) |
6058 | break; | |
6059 | if (res) | |
6060 | goto out_err; | |
6061 | ||
180cdc79 LR |
6062 | /* Survey without a channel doesn't make sense */ |
6063 | if (!survey.channel) { | |
6064 | res = -EINVAL; | |
6065 | goto out; | |
6066 | } | |
6067 | ||
6068 | chan = ieee80211_get_channel(&dev->wiphy, | |
6069 | survey.channel->center_freq); | |
6070 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6071 | survey_idx++; | |
6072 | continue; | |
6073 | } | |
6074 | ||
61fa713c | 6075 | if (nl80211_send_survey(skb, |
15e47304 | 6076 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6077 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6078 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6079 | goto out; |
6080 | survey_idx++; | |
6081 | } | |
6082 | ||
6083 | out: | |
97990a06 | 6084 | cb->args[2] = survey_idx; |
61fa713c HS |
6085 | res = skb->len; |
6086 | out_err: | |
97990a06 | 6087 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
6088 | return res; |
6089 | } | |
6090 | ||
b23aa676 SO |
6091 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6092 | { | |
6093 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6094 | NL80211_WPA_VERSION_2)); | |
6095 | } | |
6096 | ||
636a5d36 JM |
6097 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6098 | { | |
4c476991 JB |
6099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6100 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6101 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6102 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6103 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6104 | enum nl80211_auth_type auth_type; |
fffd0934 | 6105 | struct key_parse key; |
d5cdfacb | 6106 | bool local_state_change; |
636a5d36 | 6107 | |
f4a11bb0 JB |
6108 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6109 | return -EINVAL; | |
6110 | ||
6111 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6112 | return -EINVAL; | |
6113 | ||
1778092e JM |
6114 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6115 | return -EINVAL; | |
6116 | ||
19957bb3 JB |
6117 | if (!info->attrs[NL80211_ATTR_SSID]) |
6118 | return -EINVAL; | |
6119 | ||
6120 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6121 | return -EINVAL; | |
6122 | ||
fffd0934 JB |
6123 | err = nl80211_parse_key(info, &key); |
6124 | if (err) | |
6125 | return err; | |
6126 | ||
6127 | if (key.idx >= 0) { | |
e31b8213 JB |
6128 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6129 | return -EINVAL; | |
fffd0934 JB |
6130 | if (!key.p.key || !key.p.key_len) |
6131 | return -EINVAL; | |
6132 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6133 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6134 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6135 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6136 | return -EINVAL; | |
6137 | if (key.idx > 4) | |
6138 | return -EINVAL; | |
6139 | } else { | |
6140 | key.p.key_len = 0; | |
6141 | key.p.key = NULL; | |
6142 | } | |
6143 | ||
afea0b7a JB |
6144 | if (key.idx >= 0) { |
6145 | int i; | |
6146 | bool ok = false; | |
6147 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6148 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6149 | ok = true; | |
6150 | break; | |
6151 | } | |
6152 | } | |
4c476991 JB |
6153 | if (!ok) |
6154 | return -EINVAL; | |
afea0b7a JB |
6155 | } |
6156 | ||
4c476991 JB |
6157 | if (!rdev->ops->auth) |
6158 | return -EOPNOTSUPP; | |
636a5d36 | 6159 | |
074ac8df | 6160 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6162 | return -EOPNOTSUPP; | |
eec60b03 | 6163 | |
19957bb3 | 6164 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 6165 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 6166 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
6167 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6168 | return -EINVAL; | |
636a5d36 | 6169 | |
19957bb3 JB |
6170 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6171 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6172 | |
6173 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6174 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6175 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6176 | } |
6177 | ||
19957bb3 | 6178 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6179 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6180 | return -EINVAL; |
636a5d36 | 6181 | |
e39e5b5e JM |
6182 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6183 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6184 | return -EINVAL; | |
6185 | ||
6186 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6187 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6188 | return -EINVAL; | |
6189 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6190 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6191 | /* need to include at least Auth Transaction and Status Code */ | |
6192 | if (sae_data_len < 4) | |
6193 | return -EINVAL; | |
6194 | } | |
6195 | ||
d5cdfacb JM |
6196 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6197 | ||
95de817b JB |
6198 | /* |
6199 | * Since we no longer track auth state, ignore | |
6200 | * requests to only change local state. | |
6201 | */ | |
6202 | if (local_state_change) | |
6203 | return 0; | |
6204 | ||
91bf9b26 JB |
6205 | wdev_lock(dev->ieee80211_ptr); |
6206 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6207 | ssid, ssid_len, ie, ie_len, | |
6208 | key.p.key, key.p.key_len, key.idx, | |
6209 | sae_data, sae_data_len); | |
6210 | wdev_unlock(dev->ieee80211_ptr); | |
6211 | return err; | |
636a5d36 JM |
6212 | } |
6213 | ||
c0692b8f JB |
6214 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6215 | struct genl_info *info, | |
3dc27d25 JB |
6216 | struct cfg80211_crypto_settings *settings, |
6217 | int cipher_limit) | |
b23aa676 | 6218 | { |
c0b2bbd8 JB |
6219 | memset(settings, 0, sizeof(*settings)); |
6220 | ||
b23aa676 SO |
6221 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6222 | ||
c0692b8f JB |
6223 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6224 | u16 proto; | |
6225 | proto = nla_get_u16( | |
6226 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6227 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6228 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6229 | proto != ETH_P_PAE) | |
6230 | return -EINVAL; | |
6231 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6232 | settings->control_port_no_encrypt = true; | |
6233 | } else | |
6234 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6235 | ||
b23aa676 SO |
6236 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6237 | void *data; | |
6238 | int len, i; | |
6239 | ||
6240 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6241 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6242 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6243 | ||
6244 | if (len % sizeof(u32)) | |
6245 | return -EINVAL; | |
6246 | ||
3dc27d25 | 6247 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6248 | return -EINVAL; |
6249 | ||
6250 | memcpy(settings->ciphers_pairwise, data, len); | |
6251 | ||
6252 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6253 | if (!cfg80211_supported_cipher_suite( |
6254 | &rdev->wiphy, | |
b23aa676 SO |
6255 | settings->ciphers_pairwise[i])) |
6256 | return -EINVAL; | |
6257 | } | |
6258 | ||
6259 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6260 | settings->cipher_group = | |
6261 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6262 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6263 | settings->cipher_group)) | |
b23aa676 SO |
6264 | return -EINVAL; |
6265 | } | |
6266 | ||
6267 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6268 | settings->wpa_versions = | |
6269 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6270 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6271 | return -EINVAL; | |
6272 | } | |
6273 | ||
6274 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6275 | void *data; | |
6d30240e | 6276 | int len; |
b23aa676 SO |
6277 | |
6278 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6279 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6280 | settings->n_akm_suites = len / sizeof(u32); | |
6281 | ||
6282 | if (len % sizeof(u32)) | |
6283 | return -EINVAL; | |
6284 | ||
1b9ca027 JM |
6285 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6286 | return -EINVAL; | |
6287 | ||
b23aa676 | 6288 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6289 | } |
6290 | ||
6291 | return 0; | |
6292 | } | |
6293 | ||
636a5d36 JM |
6294 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6295 | { | |
4c476991 JB |
6296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6297 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6298 | struct ieee80211_channel *chan; |
f62fab73 JB |
6299 | struct cfg80211_assoc_request req = {}; |
6300 | const u8 *bssid, *ssid; | |
6301 | int err, ssid_len = 0; | |
636a5d36 | 6302 | |
f4a11bb0 JB |
6303 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6304 | return -EINVAL; | |
6305 | ||
6306 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6307 | !info->attrs[NL80211_ATTR_SSID] || |
6308 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6309 | return -EINVAL; |
6310 | ||
4c476991 JB |
6311 | if (!rdev->ops->assoc) |
6312 | return -EOPNOTSUPP; | |
636a5d36 | 6313 | |
074ac8df | 6314 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6315 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6316 | return -EOPNOTSUPP; | |
eec60b03 | 6317 | |
19957bb3 | 6318 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6319 | |
19957bb3 JB |
6320 | chan = ieee80211_get_channel(&rdev->wiphy, |
6321 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6322 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6323 | return -EINVAL; | |
636a5d36 | 6324 | |
19957bb3 JB |
6325 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6326 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6327 | |
6328 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6329 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6330 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6331 | } |
6332 | ||
dc6382ce | 6333 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6334 | enum nl80211_mfp mfp = |
dc6382ce | 6335 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6336 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6337 | req.use_mfp = true; |
4c476991 JB |
6338 | else if (mfp != NL80211_MFP_NO) |
6339 | return -EINVAL; | |
dc6382ce JM |
6340 | } |
6341 | ||
3e5d7649 | 6342 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6343 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6344 | |
7e7c8926 | 6345 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6346 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6347 | |
6348 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6349 | memcpy(&req.ht_capa_mask, |
6350 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6351 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6352 | |
6353 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6354 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6355 | return -EINVAL; |
f62fab73 JB |
6356 | memcpy(&req.ht_capa, |
6357 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6358 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6359 | } |
6360 | ||
ee2aca34 | 6361 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6362 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6363 | |
6364 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6365 | memcpy(&req.vht_capa_mask, |
6366 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6367 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6368 | |
6369 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6370 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6371 | return -EINVAL; |
f62fab73 JB |
6372 | memcpy(&req.vht_capa, |
6373 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6374 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6375 | } |
6376 | ||
f62fab73 | 6377 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6378 | if (!err) { |
6379 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6380 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6381 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6382 | wdev_unlock(dev->ieee80211_ptr); |
6383 | } | |
636a5d36 | 6384 | |
636a5d36 JM |
6385 | return err; |
6386 | } | |
6387 | ||
6388 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6389 | { | |
4c476991 JB |
6390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6391 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6392 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6393 | int ie_len = 0, err; |
19957bb3 | 6394 | u16 reason_code; |
d5cdfacb | 6395 | bool local_state_change; |
636a5d36 | 6396 | |
f4a11bb0 JB |
6397 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6398 | return -EINVAL; | |
6399 | ||
6400 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6401 | return -EINVAL; | |
6402 | ||
6403 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6404 | return -EINVAL; | |
6405 | ||
4c476991 JB |
6406 | if (!rdev->ops->deauth) |
6407 | return -EOPNOTSUPP; | |
636a5d36 | 6408 | |
074ac8df | 6409 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6410 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6411 | return -EOPNOTSUPP; | |
eec60b03 | 6412 | |
19957bb3 | 6413 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6414 | |
19957bb3 JB |
6415 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6416 | if (reason_code == 0) { | |
f4a11bb0 | 6417 | /* Reason Code 0 is reserved */ |
4c476991 | 6418 | return -EINVAL; |
255e737e | 6419 | } |
636a5d36 JM |
6420 | |
6421 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6422 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6423 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6424 | } |
6425 | ||
d5cdfacb JM |
6426 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6427 | ||
91bf9b26 JB |
6428 | wdev_lock(dev->ieee80211_ptr); |
6429 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6430 | local_state_change); | |
6431 | wdev_unlock(dev->ieee80211_ptr); | |
6432 | return err; | |
636a5d36 JM |
6433 | } |
6434 | ||
6435 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6436 | { | |
4c476991 JB |
6437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6438 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6439 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6440 | int ie_len = 0, err; |
19957bb3 | 6441 | u16 reason_code; |
d5cdfacb | 6442 | bool local_state_change; |
636a5d36 | 6443 | |
f4a11bb0 JB |
6444 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6445 | return -EINVAL; | |
6446 | ||
6447 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6448 | return -EINVAL; | |
6449 | ||
6450 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6451 | return -EINVAL; | |
6452 | ||
4c476991 JB |
6453 | if (!rdev->ops->disassoc) |
6454 | return -EOPNOTSUPP; | |
636a5d36 | 6455 | |
074ac8df | 6456 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6457 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6458 | return -EOPNOTSUPP; | |
eec60b03 | 6459 | |
19957bb3 | 6460 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6461 | |
19957bb3 JB |
6462 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6463 | if (reason_code == 0) { | |
f4a11bb0 | 6464 | /* Reason Code 0 is reserved */ |
4c476991 | 6465 | return -EINVAL; |
255e737e | 6466 | } |
636a5d36 JM |
6467 | |
6468 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6469 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6470 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6471 | } |
6472 | ||
d5cdfacb JM |
6473 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6474 | ||
91bf9b26 JB |
6475 | wdev_lock(dev->ieee80211_ptr); |
6476 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6477 | local_state_change); | |
6478 | wdev_unlock(dev->ieee80211_ptr); | |
6479 | return err; | |
636a5d36 JM |
6480 | } |
6481 | ||
dd5b4cc7 FF |
6482 | static bool |
6483 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6484 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6485 | int rateval) | |
6486 | { | |
6487 | struct wiphy *wiphy = &rdev->wiphy; | |
6488 | bool found = false; | |
6489 | int band, i; | |
6490 | ||
6491 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6492 | struct ieee80211_supported_band *sband; | |
6493 | ||
6494 | sband = wiphy->bands[band]; | |
6495 | if (!sband) | |
6496 | continue; | |
6497 | ||
6498 | for (i = 0; i < sband->n_bitrates; i++) { | |
6499 | if (sband->bitrates[i].bitrate == rateval) { | |
6500 | mcast_rate[band] = i + 1; | |
6501 | found = true; | |
6502 | break; | |
6503 | } | |
6504 | } | |
6505 | } | |
6506 | ||
6507 | return found; | |
6508 | } | |
6509 | ||
04a773ad JB |
6510 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6511 | { | |
4c476991 JB |
6512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6513 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6514 | struct cfg80211_ibss_params ibss; |
6515 | struct wiphy *wiphy; | |
fffd0934 | 6516 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6517 | int err; |
6518 | ||
8e30bc55 JB |
6519 | memset(&ibss, 0, sizeof(ibss)); |
6520 | ||
04a773ad JB |
6521 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6522 | return -EINVAL; | |
6523 | ||
683b6d3b | 6524 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6525 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6526 | return -EINVAL; | |
6527 | ||
8e30bc55 JB |
6528 | ibss.beacon_interval = 100; |
6529 | ||
6530 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6531 | ibss.beacon_interval = | |
6532 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6533 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6534 | return -EINVAL; | |
6535 | } | |
6536 | ||
4c476991 JB |
6537 | if (!rdev->ops->join_ibss) |
6538 | return -EOPNOTSUPP; | |
04a773ad | 6539 | |
4c476991 JB |
6540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6541 | return -EOPNOTSUPP; | |
04a773ad | 6542 | |
79c97e97 | 6543 | wiphy = &rdev->wiphy; |
04a773ad | 6544 | |
39193498 | 6545 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6546 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6547 | |
6548 | if (!is_valid_ether_addr(ibss.bssid)) | |
6549 | return -EINVAL; | |
6550 | } | |
04a773ad JB |
6551 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6552 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6553 | ||
6554 | if (info->attrs[NL80211_ATTR_IE]) { | |
6555 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6556 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6557 | } | |
6558 | ||
683b6d3b JB |
6559 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6560 | if (err) | |
6561 | return err; | |
04a773ad | 6562 | |
683b6d3b | 6563 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6564 | return -EINVAL; |
6565 | ||
2f301ab2 | 6566 | switch (ibss.chandef.width) { |
bf372645 SW |
6567 | case NL80211_CHAN_WIDTH_5: |
6568 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6569 | case NL80211_CHAN_WIDTH_20_NOHT: |
6570 | break; | |
6571 | case NL80211_CHAN_WIDTH_20: | |
6572 | case NL80211_CHAN_WIDTH_40: | |
6573 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6574 | break; | |
6575 | default: | |
c04d6150 | 6576 | return -EINVAL; |
2f301ab2 | 6577 | } |
db9c64cf | 6578 | |
04a773ad | 6579 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6580 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6581 | ||
fbd2c8dc TP |
6582 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6583 | u8 *rates = | |
6584 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6585 | int n_rates = | |
6586 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6587 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6588 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6589 | |
34850ab2 JB |
6590 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6591 | &ibss.basic_rates); | |
6592 | if (err) | |
6593 | return err; | |
fbd2c8dc | 6594 | } |
dd5b4cc7 | 6595 | |
803768f5 SW |
6596 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6597 | memcpy(&ibss.ht_capa_mask, | |
6598 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6599 | sizeof(ibss.ht_capa_mask)); | |
6600 | ||
6601 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6602 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6603 | return -EINVAL; | |
6604 | memcpy(&ibss.ht_capa, | |
6605 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6606 | sizeof(ibss.ht_capa)); | |
6607 | } | |
6608 | ||
dd5b4cc7 FF |
6609 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6610 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6611 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6612 | return -EINVAL; | |
fbd2c8dc | 6613 | |
4c476991 | 6614 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6615 | bool no_ht = false; |
6616 | ||
4c476991 | 6617 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6618 | info->attrs[NL80211_ATTR_KEYS], |
6619 | &no_ht); | |
4c476991 JB |
6620 | if (IS_ERR(connkeys)) |
6621 | return PTR_ERR(connkeys); | |
de7044ee | 6622 | |
3d9d1d66 JB |
6623 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6624 | no_ht) { | |
de7044ee SM |
6625 | kfree(connkeys); |
6626 | return -EINVAL; | |
6627 | } | |
4c476991 | 6628 | } |
04a773ad | 6629 | |
267335d6 AQ |
6630 | ibss.control_port = |
6631 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6632 | ||
5336fa88 SW |
6633 | ibss.userspace_handles_dfs = |
6634 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
6635 | ||
4c476991 | 6636 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6637 | if (err) |
6638 | kfree(connkeys); | |
04a773ad JB |
6639 | return err; |
6640 | } | |
6641 | ||
6642 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6643 | { | |
4c476991 JB |
6644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6645 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6646 | |
4c476991 JB |
6647 | if (!rdev->ops->leave_ibss) |
6648 | return -EOPNOTSUPP; | |
04a773ad | 6649 | |
4c476991 JB |
6650 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6651 | return -EOPNOTSUPP; | |
04a773ad | 6652 | |
4c476991 | 6653 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6654 | } |
6655 | ||
f4e583c8 AQ |
6656 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6657 | { | |
6658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6659 | struct net_device *dev = info->user_ptr[1]; | |
6660 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6661 | u32 nla_rate; | |
6662 | int err; | |
6663 | ||
6664 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6665 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6666 | return -EOPNOTSUPP; | |
6667 | ||
6668 | if (!rdev->ops->set_mcast_rate) | |
6669 | return -EOPNOTSUPP; | |
6670 | ||
6671 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6672 | ||
6673 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6674 | return -EINVAL; | |
6675 | ||
6676 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6677 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6678 | return -EINVAL; | |
6679 | ||
6680 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6681 | ||
6682 | return err; | |
6683 | } | |
6684 | ||
6685 | ||
aff89a9b JB |
6686 | #ifdef CONFIG_NL80211_TESTMODE |
6687 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6688 | .name = "testmode", | |
6689 | }; | |
6690 | ||
6691 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6692 | { | |
4c476991 | 6693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
6694 | struct wireless_dev *wdev = |
6695 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
6696 | int err; |
6697 | ||
fc73f11f DS |
6698 | if (!rdev->ops->testmode_cmd) |
6699 | return -EOPNOTSUPP; | |
6700 | ||
6701 | if (IS_ERR(wdev)) { | |
6702 | err = PTR_ERR(wdev); | |
6703 | if (err != -EINVAL) | |
6704 | return err; | |
6705 | wdev = NULL; | |
6706 | } else if (wdev->wiphy != &rdev->wiphy) { | |
6707 | return -EINVAL; | |
6708 | } | |
6709 | ||
aff89a9b JB |
6710 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
6711 | return -EINVAL; | |
6712 | ||
fc73f11f DS |
6713 | rdev->testmode_info = info; |
6714 | err = rdev_testmode_cmd(rdev, wdev, | |
aff89a9b JB |
6715 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6716 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
fc73f11f | 6717 | rdev->testmode_info = NULL; |
aff89a9b | 6718 | |
aff89a9b JB |
6719 | return err; |
6720 | } | |
6721 | ||
71063f0e WYG |
6722 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6723 | struct netlink_callback *cb) | |
6724 | { | |
00918d33 | 6725 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6726 | int err; |
6727 | long phy_idx; | |
6728 | void *data = NULL; | |
6729 | int data_len = 0; | |
6730 | ||
5fe231e8 JB |
6731 | rtnl_lock(); |
6732 | ||
71063f0e WYG |
6733 | if (cb->args[0]) { |
6734 | /* | |
6735 | * 0 is a valid index, but not valid for args[0], | |
6736 | * so we need to offset by 1. | |
6737 | */ | |
6738 | phy_idx = cb->args[0] - 1; | |
6739 | } else { | |
6740 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6741 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6742 | nl80211_policy); | |
6743 | if (err) | |
5fe231e8 | 6744 | goto out_err; |
00918d33 | 6745 | |
2bd7e35d JB |
6746 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6747 | nl80211_fam.attrbuf); | |
6748 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6749 | err = PTR_ERR(rdev); |
6750 | goto out_err; | |
00918d33 | 6751 | } |
2bd7e35d JB |
6752 | phy_idx = rdev->wiphy_idx; |
6753 | rdev = NULL; | |
2bd7e35d | 6754 | |
71063f0e WYG |
6755 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6756 | cb->args[1] = | |
6757 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6758 | } | |
6759 | ||
6760 | if (cb->args[1]) { | |
6761 | data = nla_data((void *)cb->args[1]); | |
6762 | data_len = nla_len((void *)cb->args[1]); | |
6763 | } | |
6764 | ||
00918d33 JB |
6765 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6766 | if (!rdev) { | |
5fe231e8 JB |
6767 | err = -ENOENT; |
6768 | goto out_err; | |
71063f0e | 6769 | } |
71063f0e | 6770 | |
00918d33 | 6771 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6772 | err = -EOPNOTSUPP; |
6773 | goto out_err; | |
6774 | } | |
6775 | ||
6776 | while (1) { | |
15e47304 | 6777 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6778 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6779 | NL80211_CMD_TESTMODE); | |
6780 | struct nlattr *tmdata; | |
6781 | ||
cb35fba3 DC |
6782 | if (!hdr) |
6783 | break; | |
6784 | ||
9360ffd1 | 6785 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6786 | genlmsg_cancel(skb, hdr); |
6787 | break; | |
6788 | } | |
6789 | ||
6790 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6791 | if (!tmdata) { | |
6792 | genlmsg_cancel(skb, hdr); | |
6793 | break; | |
6794 | } | |
e35e4d28 | 6795 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6796 | nla_nest_end(skb, tmdata); |
6797 | ||
6798 | if (err == -ENOBUFS || err == -ENOENT) { | |
6799 | genlmsg_cancel(skb, hdr); | |
6800 | break; | |
6801 | } else if (err) { | |
6802 | genlmsg_cancel(skb, hdr); | |
6803 | goto out_err; | |
6804 | } | |
6805 | ||
6806 | genlmsg_end(skb, hdr); | |
6807 | } | |
6808 | ||
6809 | err = skb->len; | |
6810 | /* see above */ | |
6811 | cb->args[0] = phy_idx + 1; | |
6812 | out_err: | |
5fe231e8 | 6813 | rtnl_unlock(); |
71063f0e WYG |
6814 | return err; |
6815 | } | |
6816 | ||
aff89a9b JB |
6817 | static struct sk_buff * |
6818 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6819 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6820 | { |
6821 | struct sk_buff *skb; | |
6822 | void *hdr; | |
6823 | struct nlattr *data; | |
6824 | ||
6825 | skb = nlmsg_new(approxlen + 100, gfp); | |
6826 | if (!skb) | |
6827 | return NULL; | |
6828 | ||
15e47304 | 6829 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6830 | if (!hdr) { |
6831 | kfree_skb(skb); | |
6832 | return NULL; | |
6833 | } | |
6834 | ||
9360ffd1 DM |
6835 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6836 | goto nla_put_failure; | |
aff89a9b JB |
6837 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6838 | ||
6839 | ((void **)skb->cb)[0] = rdev; | |
6840 | ((void **)skb->cb)[1] = hdr; | |
6841 | ((void **)skb->cb)[2] = data; | |
6842 | ||
6843 | return skb; | |
6844 | ||
6845 | nla_put_failure: | |
6846 | kfree_skb(skb); | |
6847 | return NULL; | |
6848 | } | |
6849 | ||
6850 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6851 | int approxlen) | |
6852 | { | |
6853 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6854 | ||
6855 | if (WARN_ON(!rdev->testmode_info)) | |
6856 | return NULL; | |
6857 | ||
6858 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6859 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6860 | rdev->testmode_info->snd_seq, |
6861 | GFP_KERNEL); | |
6862 | } | |
6863 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6864 | ||
6865 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6866 | { | |
6867 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6868 | void *hdr = ((void **)skb->cb)[1]; | |
6869 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6870 | ||
6871 | if (WARN_ON(!rdev->testmode_info)) { | |
6872 | kfree_skb(skb); | |
6873 | return -EINVAL; | |
6874 | } | |
6875 | ||
6876 | nla_nest_end(skb, data); | |
6877 | genlmsg_end(skb, hdr); | |
6878 | return genlmsg_reply(skb, rdev->testmode_info); | |
6879 | } | |
6880 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6881 | ||
6882 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6883 | int approxlen, gfp_t gfp) | |
6884 | { | |
6885 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6886 | ||
6887 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6888 | } | |
6889 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6890 | ||
6891 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6892 | { | |
a0ec570f | 6893 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
aff89a9b JB |
6894 | void *hdr = ((void **)skb->cb)[1]; |
6895 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6896 | ||
6897 | nla_nest_end(skb, data); | |
6898 | genlmsg_end(skb, hdr); | |
a0ec570f MK |
6899 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
6900 | nl80211_testmode_mcgrp.id, gfp); | |
aff89a9b JB |
6901 | } |
6902 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6903 | #endif | |
6904 | ||
b23aa676 SO |
6905 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6906 | { | |
4c476991 JB |
6907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6908 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6909 | struct cfg80211_connect_params connect; |
6910 | struct wiphy *wiphy; | |
fffd0934 | 6911 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6912 | int err; |
6913 | ||
6914 | memset(&connect, 0, sizeof(connect)); | |
6915 | ||
6916 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6917 | return -EINVAL; | |
6918 | ||
6919 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6920 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6921 | return -EINVAL; | |
6922 | ||
6923 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6924 | connect.auth_type = | |
6925 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6926 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6927 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6928 | return -EINVAL; |
6929 | } else | |
6930 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6931 | ||
6932 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6933 | ||
c0692b8f | 6934 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6935 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6936 | if (err) |
6937 | return err; | |
b23aa676 | 6938 | |
074ac8df | 6939 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6940 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6941 | return -EOPNOTSUPP; | |
b23aa676 | 6942 | |
79c97e97 | 6943 | wiphy = &rdev->wiphy; |
b23aa676 | 6944 | |
4486ea98 BS |
6945 | connect.bg_scan_period = -1; |
6946 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6947 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6948 | connect.bg_scan_period = | |
6949 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6950 | } | |
6951 | ||
b23aa676 SO |
6952 | if (info->attrs[NL80211_ATTR_MAC]) |
6953 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6954 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6955 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6956 | ||
6957 | if (info->attrs[NL80211_ATTR_IE]) { | |
6958 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6959 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6960 | } | |
6961 | ||
cee00a95 JM |
6962 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6963 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6964 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6965 | connect.mfp != NL80211_MFP_NO) | |
6966 | return -EINVAL; | |
6967 | } else { | |
6968 | connect.mfp = NL80211_MFP_NO; | |
6969 | } | |
6970 | ||
b23aa676 SO |
6971 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6972 | connect.channel = | |
6973 | ieee80211_get_channel(wiphy, | |
6974 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6975 | if (!connect.channel || | |
4c476991 JB |
6976 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6977 | return -EINVAL; | |
b23aa676 SO |
6978 | } |
6979 | ||
fffd0934 JB |
6980 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6981 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6982 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6983 | if (IS_ERR(connkeys)) |
6984 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6985 | } |
6986 | ||
7e7c8926 BG |
6987 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6988 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6989 | ||
6990 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6991 | memcpy(&connect.ht_capa_mask, | |
6992 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6993 | sizeof(connect.ht_capa_mask)); | |
6994 | ||
6995 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6996 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6997 | kfree(connkeys); | |
7e7c8926 | 6998 | return -EINVAL; |
b4e4f47e | 6999 | } |
7e7c8926 BG |
7000 | memcpy(&connect.ht_capa, |
7001 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7002 | sizeof(connect.ht_capa)); | |
7003 | } | |
7004 | ||
ee2aca34 JB |
7005 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7006 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7007 | ||
7008 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7009 | memcpy(&connect.vht_capa_mask, | |
7010 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7011 | sizeof(connect.vht_capa_mask)); | |
7012 | ||
7013 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7014 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
7015 | kfree(connkeys); | |
7016 | return -EINVAL; | |
7017 | } | |
7018 | memcpy(&connect.vht_capa, | |
7019 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7020 | sizeof(connect.vht_capa)); | |
7021 | } | |
7022 | ||
83739b03 JB |
7023 | wdev_lock(dev->ieee80211_ptr); |
7024 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7025 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
7026 | if (err) |
7027 | kfree(connkeys); | |
b23aa676 SO |
7028 | return err; |
7029 | } | |
7030 | ||
7031 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7032 | { | |
4c476991 JB |
7033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7034 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7035 | u16 reason; |
83739b03 | 7036 | int ret; |
b23aa676 SO |
7037 | |
7038 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7039 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7040 | else | |
7041 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7042 | ||
7043 | if (reason == 0) | |
7044 | return -EINVAL; | |
7045 | ||
074ac8df | 7046 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7047 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7048 | return -EOPNOTSUPP; | |
b23aa676 | 7049 | |
83739b03 JB |
7050 | wdev_lock(dev->ieee80211_ptr); |
7051 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7052 | wdev_unlock(dev->ieee80211_ptr); | |
7053 | return ret; | |
b23aa676 SO |
7054 | } |
7055 | ||
463d0183 JB |
7056 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7057 | { | |
4c476991 | 7058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7059 | struct net *net; |
7060 | int err; | |
7061 | u32 pid; | |
7062 | ||
7063 | if (!info->attrs[NL80211_ATTR_PID]) | |
7064 | return -EINVAL; | |
7065 | ||
7066 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7067 | ||
463d0183 | 7068 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7069 | if (IS_ERR(net)) |
7070 | return PTR_ERR(net); | |
463d0183 JB |
7071 | |
7072 | err = 0; | |
7073 | ||
7074 | /* check if anything to do */ | |
4c476991 JB |
7075 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7076 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7077 | |
463d0183 | 7078 | put_net(net); |
463d0183 JB |
7079 | return err; |
7080 | } | |
7081 | ||
67fbb16b SO |
7082 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7083 | { | |
4c476991 | 7084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7085 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7086 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7087 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7088 | struct cfg80211_pmksa pmksa; |
7089 | ||
7090 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7091 | ||
7092 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7093 | return -EINVAL; | |
7094 | ||
7095 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7096 | return -EINVAL; | |
7097 | ||
67fbb16b SO |
7098 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7099 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7100 | ||
074ac8df | 7101 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7103 | return -EOPNOTSUPP; | |
67fbb16b SO |
7104 | |
7105 | switch (info->genlhdr->cmd) { | |
7106 | case NL80211_CMD_SET_PMKSA: | |
7107 | rdev_ops = rdev->ops->set_pmksa; | |
7108 | break; | |
7109 | case NL80211_CMD_DEL_PMKSA: | |
7110 | rdev_ops = rdev->ops->del_pmksa; | |
7111 | break; | |
7112 | default: | |
7113 | WARN_ON(1); | |
7114 | break; | |
7115 | } | |
7116 | ||
4c476991 JB |
7117 | if (!rdev_ops) |
7118 | return -EOPNOTSUPP; | |
67fbb16b | 7119 | |
4c476991 | 7120 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7121 | } |
7122 | ||
7123 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7124 | { | |
4c476991 JB |
7125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7126 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7127 | |
074ac8df | 7128 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7129 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7130 | return -EOPNOTSUPP; | |
67fbb16b | 7131 | |
4c476991 JB |
7132 | if (!rdev->ops->flush_pmksa) |
7133 | return -EOPNOTSUPP; | |
67fbb16b | 7134 | |
e35e4d28 | 7135 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7136 | } |
7137 | ||
109086ce AN |
7138 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7139 | { | |
7140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7141 | struct net_device *dev = info->user_ptr[1]; | |
7142 | u8 action_code, dialog_token; | |
7143 | u16 status_code; | |
7144 | u8 *peer; | |
7145 | ||
7146 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7147 | !rdev->ops->tdls_mgmt) | |
7148 | return -EOPNOTSUPP; | |
7149 | ||
7150 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7151 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7152 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7153 | !info->attrs[NL80211_ATTR_IE] || | |
7154 | !info->attrs[NL80211_ATTR_MAC]) | |
7155 | return -EINVAL; | |
7156 | ||
7157 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7158 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7159 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7160 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
7161 | ||
e35e4d28 HG |
7162 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
7163 | dialog_token, status_code, | |
7164 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
7165 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7166 | } |
7167 | ||
7168 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7169 | { | |
7170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7171 | struct net_device *dev = info->user_ptr[1]; | |
7172 | enum nl80211_tdls_operation operation; | |
7173 | u8 *peer; | |
7174 | ||
7175 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7176 | !rdev->ops->tdls_oper) | |
7177 | return -EOPNOTSUPP; | |
7178 | ||
7179 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7180 | !info->attrs[NL80211_ATTR_MAC]) | |
7181 | return -EINVAL; | |
7182 | ||
7183 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7184 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7185 | ||
e35e4d28 | 7186 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7187 | } |
7188 | ||
9588bbd5 JM |
7189 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7190 | struct genl_info *info) | |
7191 | { | |
4c476991 | 7192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7193 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7194 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7195 | struct sk_buff *msg; |
7196 | void *hdr; | |
7197 | u64 cookie; | |
683b6d3b | 7198 | u32 duration; |
9588bbd5 JM |
7199 | int err; |
7200 | ||
7201 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7202 | !info->attrs[NL80211_ATTR_DURATION]) | |
7203 | return -EINVAL; | |
7204 | ||
7205 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7206 | ||
ebf348fc JB |
7207 | if (!rdev->ops->remain_on_channel || |
7208 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7209 | return -EOPNOTSUPP; | |
7210 | ||
9588bbd5 | 7211 | /* |
ebf348fc JB |
7212 | * We should be on that channel for at least a minimum amount of |
7213 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7214 | */ |
ebf348fc | 7215 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7216 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7217 | return -EINVAL; |
7218 | ||
683b6d3b JB |
7219 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7220 | if (err) | |
7221 | return err; | |
9588bbd5 JM |
7222 | |
7223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7224 | if (!msg) |
7225 | return -ENOMEM; | |
9588bbd5 | 7226 | |
15e47304 | 7227 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7228 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7229 | if (!hdr) { |
7230 | err = -ENOBUFS; | |
9588bbd5 JM |
7231 | goto free_msg; |
7232 | } | |
7233 | ||
683b6d3b JB |
7234 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7235 | duration, &cookie); | |
9588bbd5 JM |
7236 | |
7237 | if (err) | |
7238 | goto free_msg; | |
7239 | ||
9360ffd1 DM |
7240 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7241 | goto nla_put_failure; | |
9588bbd5 JM |
7242 | |
7243 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7244 | |
7245 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7246 | |
7247 | nla_put_failure: | |
7248 | err = -ENOBUFS; | |
7249 | free_msg: | |
7250 | nlmsg_free(msg); | |
9588bbd5 JM |
7251 | return err; |
7252 | } | |
7253 | ||
7254 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7255 | struct genl_info *info) | |
7256 | { | |
4c476991 | 7257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7258 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7259 | u64 cookie; |
9588bbd5 JM |
7260 | |
7261 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7262 | return -EINVAL; | |
7263 | ||
4c476991 JB |
7264 | if (!rdev->ops->cancel_remain_on_channel) |
7265 | return -EOPNOTSUPP; | |
9588bbd5 | 7266 | |
9588bbd5 JM |
7267 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7268 | ||
e35e4d28 | 7269 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7270 | } |
7271 | ||
13ae75b1 JM |
7272 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7273 | u8 *rates, u8 rates_len) | |
7274 | { | |
7275 | u8 i; | |
7276 | u32 mask = 0; | |
7277 | ||
7278 | for (i = 0; i < rates_len; i++) { | |
7279 | int rate = (rates[i] & 0x7f) * 5; | |
7280 | int ridx; | |
7281 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7282 | struct ieee80211_rate *srate = | |
7283 | &sband->bitrates[ridx]; | |
7284 | if (rate == srate->bitrate) { | |
7285 | mask |= 1 << ridx; | |
7286 | break; | |
7287 | } | |
7288 | } | |
7289 | if (ridx == sband->n_bitrates) | |
7290 | return 0; /* rate not found */ | |
7291 | } | |
7292 | ||
7293 | return mask; | |
7294 | } | |
7295 | ||
24db78c0 SW |
7296 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7297 | u8 *rates, u8 rates_len, | |
7298 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7299 | { | |
7300 | u8 i; | |
7301 | ||
7302 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7303 | ||
7304 | for (i = 0; i < rates_len; i++) { | |
7305 | int ridx, rbit; | |
7306 | ||
7307 | ridx = rates[i] / 8; | |
7308 | rbit = BIT(rates[i] % 8); | |
7309 | ||
7310 | /* check validity */ | |
910570b5 | 7311 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7312 | return false; |
7313 | ||
7314 | /* check availability */ | |
7315 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7316 | mcs[ridx] |= rbit; | |
7317 | else | |
7318 | return false; | |
7319 | } | |
7320 | ||
7321 | return true; | |
7322 | } | |
7323 | ||
b54452b0 | 7324 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7325 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7326 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7327 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7328 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7329 | }; |
7330 | ||
7331 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7332 | struct genl_info *info) | |
7333 | { | |
7334 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7336 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7337 | int rem, i; |
7338 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7339 | struct nlattr *tx_rates; |
7340 | struct ieee80211_supported_band *sband; | |
7341 | ||
7342 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7343 | return -EINVAL; | |
7344 | ||
4c476991 JB |
7345 | if (!rdev->ops->set_bitrate_mask) |
7346 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7347 | |
7348 | memset(&mask, 0, sizeof(mask)); | |
7349 | /* Default to all rates enabled */ | |
7350 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7351 | sband = rdev->wiphy.bands[i]; | |
7352 | mask.control[i].legacy = | |
7353 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7354 | if (sband) |
7355 | memcpy(mask.control[i].mcs, | |
7356 | sband->ht_cap.mcs.rx_mask, | |
7357 | sizeof(mask.control[i].mcs)); | |
7358 | else | |
7359 | memset(mask.control[i].mcs, 0, | |
7360 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7361 | } |
7362 | ||
7363 | /* | |
7364 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7365 | * directly to the enum ieee80211_band values used in cfg80211. | |
7366 | */ | |
24db78c0 | 7367 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7368 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7369 | { | |
7370 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7371 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7372 | return -EINVAL; | |
13ae75b1 | 7373 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7374 | if (sband == NULL) |
7375 | return -EINVAL; | |
13ae75b1 JM |
7376 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7377 | nla_len(tx_rates), nl80211_txattr_policy); | |
7378 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7379 | mask.control[band].legacy = rateset_to_mask( | |
7380 | sband, | |
7381 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7382 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7383 | if ((mask.control[band].legacy == 0) && |
7384 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7385 | return -EINVAL; | |
24db78c0 SW |
7386 | } |
7387 | if (tb[NL80211_TXRATE_MCS]) { | |
7388 | if (!ht_rateset_to_mask( | |
7389 | sband, | |
7390 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7391 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7392 | mask.control[band].mcs)) | |
7393 | return -EINVAL; | |
7394 | } | |
7395 | ||
7396 | if (mask.control[band].legacy == 0) { | |
7397 | /* don't allow empty legacy rates if HT | |
7398 | * is not even supported. */ | |
7399 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7400 | return -EINVAL; | |
7401 | ||
7402 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7403 | if (mask.control[band].mcs[i]) | |
7404 | break; | |
7405 | ||
7406 | /* legacy and mcs rates may not be both empty */ | |
7407 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7408 | return -EINVAL; |
13ae75b1 JM |
7409 | } |
7410 | } | |
7411 | ||
e35e4d28 | 7412 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7413 | } |
7414 | ||
2e161f78 | 7415 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7416 | { |
4c476991 | 7417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7418 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7419 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7420 | |
7421 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7422 | return -EINVAL; | |
7423 | ||
2e161f78 JB |
7424 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7425 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7426 | |
71bbc994 JB |
7427 | switch (wdev->iftype) { |
7428 | case NL80211_IFTYPE_STATION: | |
7429 | case NL80211_IFTYPE_ADHOC: | |
7430 | case NL80211_IFTYPE_P2P_CLIENT: | |
7431 | case NL80211_IFTYPE_AP: | |
7432 | case NL80211_IFTYPE_AP_VLAN: | |
7433 | case NL80211_IFTYPE_MESH_POINT: | |
7434 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7435 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7436 | break; |
7437 | default: | |
4c476991 | 7438 | return -EOPNOTSUPP; |
71bbc994 | 7439 | } |
026331c4 JM |
7440 | |
7441 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7442 | if (!rdev->ops->mgmt_tx) |
7443 | return -EOPNOTSUPP; | |
026331c4 | 7444 | |
15e47304 | 7445 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7446 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7447 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7448 | } |
7449 | ||
2e161f78 | 7450 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7451 | { |
4c476991 | 7452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7453 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7454 | struct cfg80211_chan_def chandef; |
026331c4 | 7455 | int err; |
d64d373f | 7456 | void *hdr = NULL; |
026331c4 | 7457 | u64 cookie; |
e247bd90 | 7458 | struct sk_buff *msg = NULL; |
b176e629 AO |
7459 | struct cfg80211_mgmt_tx_params params = { |
7460 | .dont_wait_for_ack = | |
7461 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7462 | }; | |
026331c4 | 7463 | |
683b6d3b | 7464 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7465 | return -EINVAL; |
7466 | ||
4c476991 JB |
7467 | if (!rdev->ops->mgmt_tx) |
7468 | return -EOPNOTSUPP; | |
026331c4 | 7469 | |
71bbc994 | 7470 | switch (wdev->iftype) { |
ea141b75 AQ |
7471 | case NL80211_IFTYPE_P2P_DEVICE: |
7472 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7473 | return -EINVAL; | |
71bbc994 JB |
7474 | case NL80211_IFTYPE_STATION: |
7475 | case NL80211_IFTYPE_ADHOC: | |
7476 | case NL80211_IFTYPE_P2P_CLIENT: | |
7477 | case NL80211_IFTYPE_AP: | |
7478 | case NL80211_IFTYPE_AP_VLAN: | |
7479 | case NL80211_IFTYPE_MESH_POINT: | |
7480 | case NL80211_IFTYPE_P2P_GO: | |
7481 | break; | |
7482 | default: | |
4c476991 | 7483 | return -EOPNOTSUPP; |
71bbc994 | 7484 | } |
026331c4 | 7485 | |
f7ca38df | 7486 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7487 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7488 | return -EINVAL; |
b176e629 | 7489 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7490 | |
7491 | /* | |
7492 | * We should wait on the channel for at least a minimum amount | |
7493 | * of time (10ms) but no longer than the driver supports. | |
7494 | */ | |
b176e629 AO |
7495 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7496 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7497 | return -EINVAL; |
7498 | ||
f7ca38df JB |
7499 | } |
7500 | ||
b176e629 | 7501 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 7502 | |
b176e629 | 7503 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
7504 | return -EINVAL; |
7505 | ||
b176e629 | 7506 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 7507 | |
ea141b75 AQ |
7508 | /* get the channel if any has been specified, otherwise pass NULL to |
7509 | * the driver. The latter will use the current one | |
7510 | */ | |
7511 | chandef.chan = NULL; | |
7512 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7513 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7514 | if (err) | |
7515 | return err; | |
7516 | } | |
7517 | ||
b176e629 | 7518 | if (!chandef.chan && params.offchan) |
ea141b75 | 7519 | return -EINVAL; |
026331c4 | 7520 | |
b176e629 | 7521 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
7522 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7523 | if (!msg) | |
7524 | return -ENOMEM; | |
026331c4 | 7525 | |
15e47304 | 7526 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7527 | NL80211_CMD_FRAME); |
cb35fba3 DC |
7528 | if (!hdr) { |
7529 | err = -ENOBUFS; | |
e247bd90 JB |
7530 | goto free_msg; |
7531 | } | |
026331c4 | 7532 | } |
e247bd90 | 7533 | |
b176e629 AO |
7534 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
7535 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
7536 | params.chan = chandef.chan; | |
7537 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
7538 | if (err) |
7539 | goto free_msg; | |
7540 | ||
e247bd90 | 7541 | if (msg) { |
9360ffd1 DM |
7542 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7543 | goto nla_put_failure; | |
026331c4 | 7544 | |
e247bd90 JB |
7545 | genlmsg_end(msg, hdr); |
7546 | return genlmsg_reply(msg, info); | |
7547 | } | |
7548 | ||
7549 | return 0; | |
026331c4 JM |
7550 | |
7551 | nla_put_failure: | |
7552 | err = -ENOBUFS; | |
7553 | free_msg: | |
7554 | nlmsg_free(msg); | |
026331c4 JM |
7555 | return err; |
7556 | } | |
7557 | ||
f7ca38df JB |
7558 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7559 | { | |
7560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7561 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7562 | u64 cookie; |
7563 | ||
7564 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7565 | return -EINVAL; | |
7566 | ||
7567 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7568 | return -EOPNOTSUPP; | |
7569 | ||
71bbc994 JB |
7570 | switch (wdev->iftype) { |
7571 | case NL80211_IFTYPE_STATION: | |
7572 | case NL80211_IFTYPE_ADHOC: | |
7573 | case NL80211_IFTYPE_P2P_CLIENT: | |
7574 | case NL80211_IFTYPE_AP: | |
7575 | case NL80211_IFTYPE_AP_VLAN: | |
7576 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7577 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7578 | break; |
7579 | default: | |
f7ca38df | 7580 | return -EOPNOTSUPP; |
71bbc994 | 7581 | } |
f7ca38df JB |
7582 | |
7583 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7584 | ||
e35e4d28 | 7585 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7586 | } |
7587 | ||
ffb9eb3d KV |
7588 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7589 | { | |
4c476991 | 7590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7591 | struct wireless_dev *wdev; |
4c476991 | 7592 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7593 | u8 ps_state; |
7594 | bool state; | |
7595 | int err; | |
7596 | ||
4c476991 JB |
7597 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7598 | return -EINVAL; | |
ffb9eb3d KV |
7599 | |
7600 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7601 | ||
4c476991 JB |
7602 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7603 | return -EINVAL; | |
ffb9eb3d KV |
7604 | |
7605 | wdev = dev->ieee80211_ptr; | |
7606 | ||
4c476991 JB |
7607 | if (!rdev->ops->set_power_mgmt) |
7608 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7609 | |
7610 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7611 | ||
7612 | if (state == wdev->ps) | |
4c476991 | 7613 | return 0; |
ffb9eb3d | 7614 | |
e35e4d28 | 7615 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7616 | if (!err) |
7617 | wdev->ps = state; | |
ffb9eb3d KV |
7618 | return err; |
7619 | } | |
7620 | ||
7621 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7622 | { | |
4c476991 | 7623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7624 | enum nl80211_ps_state ps_state; |
7625 | struct wireless_dev *wdev; | |
4c476991 | 7626 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7627 | struct sk_buff *msg; |
7628 | void *hdr; | |
7629 | int err; | |
7630 | ||
ffb9eb3d KV |
7631 | wdev = dev->ieee80211_ptr; |
7632 | ||
4c476991 JB |
7633 | if (!rdev->ops->set_power_mgmt) |
7634 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7635 | |
7636 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7637 | if (!msg) |
7638 | return -ENOMEM; | |
ffb9eb3d | 7639 | |
15e47304 | 7640 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7641 | NL80211_CMD_GET_POWER_SAVE); |
7642 | if (!hdr) { | |
4c476991 | 7643 | err = -ENOBUFS; |
ffb9eb3d KV |
7644 | goto free_msg; |
7645 | } | |
7646 | ||
7647 | if (wdev->ps) | |
7648 | ps_state = NL80211_PS_ENABLED; | |
7649 | else | |
7650 | ps_state = NL80211_PS_DISABLED; | |
7651 | ||
9360ffd1 DM |
7652 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7653 | goto nla_put_failure; | |
ffb9eb3d KV |
7654 | |
7655 | genlmsg_end(msg, hdr); | |
4c476991 | 7656 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7657 | |
4c476991 | 7658 | nla_put_failure: |
ffb9eb3d | 7659 | err = -ENOBUFS; |
4c476991 | 7660 | free_msg: |
ffb9eb3d | 7661 | nlmsg_free(msg); |
ffb9eb3d KV |
7662 | return err; |
7663 | } | |
7664 | ||
d6dc1a38 JO |
7665 | static struct nla_policy |
7666 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7667 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7668 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7669 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7670 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7671 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7672 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7673 | }; |
7674 | ||
84f10708 | 7675 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7676 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7677 | { |
7678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 7679 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7680 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 7681 | |
d9d8b019 | 7682 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7683 | return -EINVAL; |
7684 | ||
84f10708 TP |
7685 | if (!rdev->ops->set_cqm_txe_config) |
7686 | return -EOPNOTSUPP; | |
7687 | ||
7688 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7689 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7690 | return -EOPNOTSUPP; | |
7691 | ||
e35e4d28 | 7692 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7693 | } |
7694 | ||
d6dc1a38 JO |
7695 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7696 | s32 threshold, u32 hysteresis) | |
7697 | { | |
4c476991 | 7698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 7699 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7700 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
7701 | |
7702 | if (threshold > 0) | |
7703 | return -EINVAL; | |
7704 | ||
1da5fcc8 JB |
7705 | /* disabling - hysteresis should also be zero then */ |
7706 | if (threshold == 0) | |
7707 | hysteresis = 0; | |
d6dc1a38 | 7708 | |
4c476991 JB |
7709 | if (!rdev->ops->set_cqm_rssi_config) |
7710 | return -EOPNOTSUPP; | |
d6dc1a38 | 7711 | |
074ac8df | 7712 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7713 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7714 | return -EOPNOTSUPP; | |
d6dc1a38 | 7715 | |
e35e4d28 | 7716 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7717 | } |
7718 | ||
7719 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7720 | { | |
7721 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7722 | struct nlattr *cqm; | |
7723 | int err; | |
7724 | ||
7725 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
7726 | if (!cqm) |
7727 | return -EINVAL; | |
d6dc1a38 JO |
7728 | |
7729 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7730 | nl80211_attr_cqm_policy); | |
7731 | if (err) | |
1da5fcc8 | 7732 | return err; |
d6dc1a38 JO |
7733 | |
7734 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7735 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
7736 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
7737 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 7738 | |
1da5fcc8 JB |
7739 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
7740 | } | |
7741 | ||
7742 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
7743 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7744 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7745 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7746 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7747 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7748 | ||
7749 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
7750 | } | |
7751 | ||
7752 | return -EINVAL; | |
d6dc1a38 JO |
7753 | } |
7754 | ||
29cbe68c JB |
7755 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7756 | { | |
7757 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7758 | struct net_device *dev = info->user_ptr[1]; | |
7759 | struct mesh_config cfg; | |
c80d545d | 7760 | struct mesh_setup setup; |
29cbe68c JB |
7761 | int err; |
7762 | ||
7763 | /* start with default */ | |
7764 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7765 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7766 | |
24bdd9f4 | 7767 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7768 | /* and parse parameters if given */ |
24bdd9f4 | 7769 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7770 | if (err) |
7771 | return err; | |
7772 | } | |
7773 | ||
7774 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7775 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7776 | return -EINVAL; | |
7777 | ||
c80d545d JC |
7778 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7779 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7780 | ||
4bb62344 CYY |
7781 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7782 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7783 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7784 | return -EINVAL; | |
7785 | ||
9bdbf04d MP |
7786 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7787 | setup.beacon_interval = | |
7788 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7789 | if (setup.beacon_interval < 10 || | |
7790 | setup.beacon_interval > 10000) | |
7791 | return -EINVAL; | |
7792 | } | |
7793 | ||
7794 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7795 | setup.dtim_period = | |
7796 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7797 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7798 | return -EINVAL; | |
7799 | } | |
7800 | ||
c80d545d JC |
7801 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7802 | /* parse additional setup parameters if given */ | |
7803 | err = nl80211_parse_mesh_setup(info, &setup); | |
7804 | if (err) | |
7805 | return err; | |
7806 | } | |
7807 | ||
d37bb18a TP |
7808 | if (setup.user_mpm) |
7809 | cfg.auto_open_plinks = false; | |
7810 | ||
cc1d2806 | 7811 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7812 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7813 | if (err) | |
7814 | return err; | |
cc1d2806 JB |
7815 | } else { |
7816 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7817 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7818 | } |
7819 | ||
ffb3cf30 AN |
7820 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7821 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7822 | int n_rates = | |
7823 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7824 | struct ieee80211_supported_band *sband; | |
7825 | ||
7826 | if (!setup.chandef.chan) | |
7827 | return -EINVAL; | |
7828 | ||
7829 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
7830 | ||
7831 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
7832 | &setup.basic_rates); | |
7833 | if (err) | |
7834 | return err; | |
7835 | } | |
7836 | ||
c80d545d | 7837 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7838 | } |
7839 | ||
7840 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7841 | { | |
7842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7843 | struct net_device *dev = info->user_ptr[1]; | |
7844 | ||
7845 | return cfg80211_leave_mesh(rdev, dev); | |
7846 | } | |
7847 | ||
dfb89c56 | 7848 | #ifdef CONFIG_PM |
bb92d199 AK |
7849 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7850 | struct cfg80211_registered_device *rdev) | |
7851 | { | |
6abb9cb9 | 7852 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
7853 | struct nlattr *nl_pats, *nl_pat; |
7854 | int i, pat_len; | |
7855 | ||
6abb9cb9 | 7856 | if (!wowlan->n_patterns) |
bb92d199 AK |
7857 | return 0; |
7858 | ||
7859 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7860 | if (!nl_pats) | |
7861 | return -ENOBUFS; | |
7862 | ||
6abb9cb9 | 7863 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
7864 | nl_pat = nla_nest_start(msg, i + 1); |
7865 | if (!nl_pat) | |
7866 | return -ENOBUFS; | |
6abb9cb9 | 7867 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 7868 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 7869 | wowlan->patterns[i].mask) || |
50ac6607 AK |
7870 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
7871 | wowlan->patterns[i].pattern) || | |
7872 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 7873 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
7874 | return -ENOBUFS; |
7875 | nla_nest_end(msg, nl_pat); | |
7876 | } | |
7877 | nla_nest_end(msg, nl_pats); | |
7878 | ||
7879 | return 0; | |
7880 | } | |
7881 | ||
2a0e047e JB |
7882 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7883 | struct cfg80211_wowlan_tcp *tcp) | |
7884 | { | |
7885 | struct nlattr *nl_tcp; | |
7886 | ||
7887 | if (!tcp) | |
7888 | return 0; | |
7889 | ||
7890 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7891 | if (!nl_tcp) | |
7892 | return -ENOBUFS; | |
7893 | ||
7894 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7895 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7896 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7897 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7898 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7899 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7900 | tcp->payload_len, tcp->payload) || | |
7901 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7902 | tcp->data_interval) || | |
7903 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7904 | tcp->wake_len, tcp->wake_data) || | |
7905 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7906 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7907 | return -ENOBUFS; | |
7908 | ||
7909 | if (tcp->payload_seq.len && | |
7910 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7911 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7912 | return -ENOBUFS; | |
7913 | ||
7914 | if (tcp->payload_tok.len && | |
7915 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7916 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7917 | &tcp->payload_tok)) | |
7918 | return -ENOBUFS; | |
7919 | ||
e248ad30 JB |
7920 | nla_nest_end(msg, nl_tcp); |
7921 | ||
2a0e047e JB |
7922 | return 0; |
7923 | } | |
7924 | ||
ff1b6e69 JB |
7925 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7926 | { | |
7927 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7928 | struct sk_buff *msg; | |
7929 | void *hdr; | |
2a0e047e | 7930 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7931 | |
964dc9e2 | 7932 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
7933 | return -EOPNOTSUPP; |
7934 | ||
6abb9cb9 | 7935 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 7936 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
7937 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
7938 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
7939 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
7940 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
7941 | } |
7942 | ||
7943 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7944 | if (!msg) |
7945 | return -ENOMEM; | |
7946 | ||
15e47304 | 7947 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7948 | NL80211_CMD_GET_WOWLAN); |
7949 | if (!hdr) | |
7950 | goto nla_put_failure; | |
7951 | ||
6abb9cb9 | 7952 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
7953 | struct nlattr *nl_wowlan; |
7954 | ||
7955 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7956 | if (!nl_wowlan) | |
7957 | goto nla_put_failure; | |
7958 | ||
6abb9cb9 | 7959 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 7960 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 7961 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 7962 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 7963 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 7964 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 7965 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 7966 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 7967 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 7968 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 7969 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 7970 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 7971 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
7972 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
7973 | goto nla_put_failure; | |
2a0e047e | 7974 | |
bb92d199 AK |
7975 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7976 | goto nla_put_failure; | |
2a0e047e | 7977 | |
6abb9cb9 JB |
7978 | if (nl80211_send_wowlan_tcp(msg, |
7979 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
7980 | goto nla_put_failure; |
7981 | ||
ff1b6e69 JB |
7982 | nla_nest_end(msg, nl_wowlan); |
7983 | } | |
7984 | ||
7985 | genlmsg_end(msg, hdr); | |
7986 | return genlmsg_reply(msg, info); | |
7987 | ||
7988 | nla_put_failure: | |
7989 | nlmsg_free(msg); | |
7990 | return -ENOBUFS; | |
7991 | } | |
7992 | ||
2a0e047e JB |
7993 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7994 | struct nlattr *attr, | |
7995 | struct cfg80211_wowlan *trig) | |
7996 | { | |
7997 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7998 | struct cfg80211_wowlan_tcp *cfg; | |
7999 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8000 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8001 | u32 size; | |
8002 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8003 | int err, port; | |
8004 | ||
964dc9e2 | 8005 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8006 | return -EINVAL; |
8007 | ||
8008 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8009 | nla_data(attr), nla_len(attr), | |
8010 | nl80211_wowlan_tcp_policy); | |
8011 | if (err) | |
8012 | return err; | |
8013 | ||
8014 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8015 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8016 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8017 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8018 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8019 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8020 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8021 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8022 | return -EINVAL; | |
8023 | ||
8024 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8025 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8026 | return -EINVAL; |
8027 | ||
8028 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8029 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8030 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8031 | return -EINVAL; |
8032 | ||
8033 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8034 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8035 | return -EINVAL; |
8036 | ||
8037 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8038 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8039 | return -EINVAL; | |
8040 | ||
8041 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8042 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8043 | ||
8044 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8045 | tokens_size = tokln - sizeof(*tok); | |
8046 | ||
8047 | if (!tok->len || tokens_size % tok->len) | |
8048 | return -EINVAL; | |
964dc9e2 | 8049 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8050 | return -EINVAL; |
964dc9e2 | 8051 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8052 | return -EINVAL; |
964dc9e2 | 8053 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8054 | return -EINVAL; |
964dc9e2 | 8055 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8056 | return -EINVAL; |
8057 | if (tok->offset + tok->len > data_size) | |
8058 | return -EINVAL; | |
8059 | } | |
8060 | ||
8061 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8062 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8063 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8064 | return -EINVAL; |
8065 | if (seq->len == 0 || seq->len > 4) | |
8066 | return -EINVAL; | |
8067 | if (seq->len + seq->offset > data_size) | |
8068 | return -EINVAL; | |
8069 | } | |
8070 | ||
8071 | size = sizeof(*cfg); | |
8072 | size += data_size; | |
8073 | size += wake_size + wake_mask_size; | |
8074 | size += tokens_size; | |
8075 | ||
8076 | cfg = kzalloc(size, GFP_KERNEL); | |
8077 | if (!cfg) | |
8078 | return -ENOMEM; | |
8079 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8080 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8081 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8082 | ETH_ALEN); | |
8083 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8084 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8085 | else | |
8086 | port = 0; | |
8087 | #ifdef CONFIG_INET | |
8088 | /* allocate a socket and port for it and use it */ | |
8089 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8090 | IPPROTO_TCP, &cfg->sock, 1); | |
8091 | if (err) { | |
8092 | kfree(cfg); | |
8093 | return err; | |
8094 | } | |
8095 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8096 | sock_release(cfg->sock); | |
8097 | kfree(cfg); | |
8098 | return -EADDRINUSE; | |
8099 | } | |
8100 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8101 | #else | |
8102 | if (!port) { | |
8103 | kfree(cfg); | |
8104 | return -EINVAL; | |
8105 | } | |
8106 | cfg->src_port = port; | |
8107 | #endif | |
8108 | ||
8109 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8110 | cfg->payload_len = data_size; | |
8111 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8112 | memcpy((void *)cfg->payload, | |
8113 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8114 | data_size); | |
8115 | if (seq) | |
8116 | cfg->payload_seq = *seq; | |
8117 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8118 | cfg->wake_len = wake_size; | |
8119 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8120 | memcpy((void *)cfg->wake_data, | |
8121 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8122 | wake_size); | |
8123 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8124 | data_size + wake_size; | |
8125 | memcpy((void *)cfg->wake_mask, | |
8126 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8127 | wake_mask_size); | |
8128 | if (tok) { | |
8129 | cfg->tokens_size = tokens_size; | |
8130 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8131 | } | |
8132 | ||
8133 | trig->tcp = cfg; | |
8134 | ||
8135 | return 0; | |
8136 | } | |
8137 | ||
ff1b6e69 JB |
8138 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8139 | { | |
8140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8141 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8142 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8143 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8144 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8145 | int err, i; |
6abb9cb9 | 8146 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8147 | |
964dc9e2 | 8148 | if (!wowlan) |
ff1b6e69 JB |
8149 | return -EOPNOTSUPP; |
8150 | ||
ae33bd81 JB |
8151 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8152 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8153 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8154 | goto set_wakeup; |
8155 | } | |
ff1b6e69 JB |
8156 | |
8157 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8158 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8159 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8160 | nl80211_wowlan_policy); | |
8161 | if (err) | |
8162 | return err; | |
8163 | ||
8164 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8165 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8166 | return -EINVAL; | |
8167 | new_triggers.any = true; | |
8168 | } | |
8169 | ||
8170 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8171 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8172 | return -EINVAL; | |
8173 | new_triggers.disconnect = true; | |
8174 | } | |
8175 | ||
8176 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8177 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8178 | return -EINVAL; | |
8179 | new_triggers.magic_pkt = true; | |
8180 | } | |
8181 | ||
77dbbb13 JB |
8182 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8183 | return -EINVAL; | |
8184 | ||
8185 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8186 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8187 | return -EINVAL; | |
8188 | new_triggers.gtk_rekey_failure = true; | |
8189 | } | |
8190 | ||
8191 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8192 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8193 | return -EINVAL; | |
8194 | new_triggers.eap_identity_req = true; | |
8195 | } | |
8196 | ||
8197 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8198 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8199 | return -EINVAL; | |
8200 | new_triggers.four_way_handshake = true; | |
8201 | } | |
8202 | ||
8203 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8204 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8205 | return -EINVAL; | |
8206 | new_triggers.rfkill_release = true; | |
8207 | } | |
8208 | ||
ff1b6e69 JB |
8209 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8210 | struct nlattr *pat; | |
8211 | int n_patterns = 0; | |
bb92d199 | 8212 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8213 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8214 | |
8215 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8216 | rem) | |
8217 | n_patterns++; | |
8218 | if (n_patterns > wowlan->n_patterns) | |
8219 | return -EINVAL; | |
8220 | ||
8221 | new_triggers.patterns = kcalloc(n_patterns, | |
8222 | sizeof(new_triggers.patterns[0]), | |
8223 | GFP_KERNEL); | |
8224 | if (!new_triggers.patterns) | |
8225 | return -ENOMEM; | |
8226 | ||
8227 | new_triggers.n_patterns = n_patterns; | |
8228 | i = 0; | |
8229 | ||
8230 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8231 | rem) { | |
50ac6607 AK |
8232 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8233 | nla_len(pat), NULL); | |
ff1b6e69 | 8234 | err = -EINVAL; |
50ac6607 AK |
8235 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8236 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8237 | goto error; |
50ac6607 | 8238 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8239 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8240 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8241 | goto error; |
8242 | if (pat_len > wowlan->pattern_max_len || | |
8243 | pat_len < wowlan->pattern_min_len) | |
8244 | goto error; | |
8245 | ||
50ac6607 | 8246 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8247 | pkt_offset = 0; |
8248 | else | |
8249 | pkt_offset = nla_get_u32( | |
50ac6607 | 8250 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8251 | if (pkt_offset > wowlan->max_pkt_offset) |
8252 | goto error; | |
8253 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8254 | ||
ff1b6e69 JB |
8255 | new_triggers.patterns[i].mask = |
8256 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8257 | if (!new_triggers.patterns[i].mask) { | |
8258 | err = -ENOMEM; | |
8259 | goto error; | |
8260 | } | |
8261 | new_triggers.patterns[i].pattern = | |
8262 | new_triggers.patterns[i].mask + mask_len; | |
8263 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8264 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8265 | mask_len); |
8266 | new_triggers.patterns[i].pattern_len = pat_len; | |
8267 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8268 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8269 | pat_len); |
8270 | i++; | |
8271 | } | |
8272 | } | |
8273 | ||
2a0e047e JB |
8274 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8275 | err = nl80211_parse_wowlan_tcp( | |
8276 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8277 | &new_triggers); | |
8278 | if (err) | |
8279 | goto error; | |
8280 | } | |
8281 | ||
ae33bd81 JB |
8282 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8283 | if (!ntrig) { | |
8284 | err = -ENOMEM; | |
8285 | goto error; | |
ff1b6e69 | 8286 | } |
ae33bd81 | 8287 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8288 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8289 | |
ae33bd81 | 8290 | set_wakeup: |
6abb9cb9 JB |
8291 | if (rdev->ops->set_wakeup && |
8292 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8293 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8294 | |
ff1b6e69 JB |
8295 | return 0; |
8296 | error: | |
8297 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8298 | kfree(new_triggers.patterns[i].mask); | |
8299 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8300 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8301 | sock_release(new_triggers.tcp->sock); | |
8302 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8303 | return err; |
8304 | } | |
dfb89c56 | 8305 | #endif |
ff1b6e69 | 8306 | |
be29b99a AK |
8307 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8308 | struct cfg80211_registered_device *rdev) | |
8309 | { | |
8310 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8311 | int i, j, pat_len; | |
8312 | struct cfg80211_coalesce_rules *rule; | |
8313 | ||
8314 | if (!rdev->coalesce->n_rules) | |
8315 | return 0; | |
8316 | ||
8317 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8318 | if (!nl_rules) | |
8319 | return -ENOBUFS; | |
8320 | ||
8321 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8322 | nl_rule = nla_nest_start(msg, i + 1); | |
8323 | if (!nl_rule) | |
8324 | return -ENOBUFS; | |
8325 | ||
8326 | rule = &rdev->coalesce->rules[i]; | |
8327 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8328 | rule->delay)) | |
8329 | return -ENOBUFS; | |
8330 | ||
8331 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8332 | rule->condition)) | |
8333 | return -ENOBUFS; | |
8334 | ||
8335 | nl_pats = nla_nest_start(msg, | |
8336 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8337 | if (!nl_pats) | |
8338 | return -ENOBUFS; | |
8339 | ||
8340 | for (j = 0; j < rule->n_patterns; j++) { | |
8341 | nl_pat = nla_nest_start(msg, j + 1); | |
8342 | if (!nl_pat) | |
8343 | return -ENOBUFS; | |
8344 | pat_len = rule->patterns[j].pattern_len; | |
8345 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8346 | DIV_ROUND_UP(pat_len, 8), | |
8347 | rule->patterns[j].mask) || | |
8348 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8349 | rule->patterns[j].pattern) || | |
8350 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8351 | rule->patterns[j].pkt_offset)) | |
8352 | return -ENOBUFS; | |
8353 | nla_nest_end(msg, nl_pat); | |
8354 | } | |
8355 | nla_nest_end(msg, nl_pats); | |
8356 | nla_nest_end(msg, nl_rule); | |
8357 | } | |
8358 | nla_nest_end(msg, nl_rules); | |
8359 | ||
8360 | return 0; | |
8361 | } | |
8362 | ||
8363 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8364 | { | |
8365 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8366 | struct sk_buff *msg; | |
8367 | void *hdr; | |
8368 | ||
8369 | if (!rdev->wiphy.coalesce) | |
8370 | return -EOPNOTSUPP; | |
8371 | ||
8372 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8373 | if (!msg) | |
8374 | return -ENOMEM; | |
8375 | ||
8376 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8377 | NL80211_CMD_GET_COALESCE); | |
8378 | if (!hdr) | |
8379 | goto nla_put_failure; | |
8380 | ||
8381 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8382 | goto nla_put_failure; | |
8383 | ||
8384 | genlmsg_end(msg, hdr); | |
8385 | return genlmsg_reply(msg, info); | |
8386 | ||
8387 | nla_put_failure: | |
8388 | nlmsg_free(msg); | |
8389 | return -ENOBUFS; | |
8390 | } | |
8391 | ||
8392 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8393 | { | |
8394 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8395 | int i, j; | |
8396 | struct cfg80211_coalesce_rules *rule; | |
8397 | ||
8398 | if (!coalesce) | |
8399 | return; | |
8400 | ||
8401 | for (i = 0; i < coalesce->n_rules; i++) { | |
8402 | rule = &coalesce->rules[i]; | |
8403 | for (j = 0; j < rule->n_patterns; j++) | |
8404 | kfree(rule->patterns[j].mask); | |
8405 | kfree(rule->patterns); | |
8406 | } | |
8407 | kfree(coalesce->rules); | |
8408 | kfree(coalesce); | |
8409 | rdev->coalesce = NULL; | |
8410 | } | |
8411 | ||
8412 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8413 | struct nlattr *rule, | |
8414 | struct cfg80211_coalesce_rules *new_rule) | |
8415 | { | |
8416 | int err, i; | |
8417 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8418 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8419 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8420 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8421 | ||
8422 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8423 | nla_len(rule), nl80211_coalesce_policy); | |
8424 | if (err) | |
8425 | return err; | |
8426 | ||
8427 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8428 | new_rule->delay = | |
8429 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8430 | if (new_rule->delay > coalesce->max_delay) | |
8431 | return -EINVAL; | |
8432 | ||
8433 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8434 | new_rule->condition = | |
8435 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8436 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8437 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8438 | return -EINVAL; | |
8439 | ||
8440 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8441 | return -EINVAL; | |
8442 | ||
8443 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8444 | rem) | |
8445 | n_patterns++; | |
8446 | if (n_patterns > coalesce->n_patterns) | |
8447 | return -EINVAL; | |
8448 | ||
8449 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8450 | GFP_KERNEL); | |
8451 | if (!new_rule->patterns) | |
8452 | return -ENOMEM; | |
8453 | ||
8454 | new_rule->n_patterns = n_patterns; | |
8455 | i = 0; | |
8456 | ||
8457 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8458 | rem) { | |
8459 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8460 | nla_len(pat), NULL); | |
8461 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8462 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8463 | return -EINVAL; | |
8464 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8465 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8466 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8467 | return -EINVAL; | |
8468 | if (pat_len > coalesce->pattern_max_len || | |
8469 | pat_len < coalesce->pattern_min_len) | |
8470 | return -EINVAL; | |
8471 | ||
8472 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8473 | pkt_offset = 0; | |
8474 | else | |
8475 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8476 | if (pkt_offset > coalesce->max_pkt_offset) | |
8477 | return -EINVAL; | |
8478 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8479 | ||
8480 | new_rule->patterns[i].mask = | |
8481 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8482 | if (!new_rule->patterns[i].mask) | |
8483 | return -ENOMEM; | |
8484 | new_rule->patterns[i].pattern = | |
8485 | new_rule->patterns[i].mask + mask_len; | |
8486 | memcpy(new_rule->patterns[i].mask, | |
8487 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8488 | new_rule->patterns[i].pattern_len = pat_len; | |
8489 | memcpy(new_rule->patterns[i].pattern, | |
8490 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8491 | i++; | |
8492 | } | |
8493 | ||
8494 | return 0; | |
8495 | } | |
8496 | ||
8497 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8498 | { | |
8499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8500 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8501 | struct cfg80211_coalesce new_coalesce = {}; | |
8502 | struct cfg80211_coalesce *n_coalesce; | |
8503 | int err, rem_rule, n_rules = 0, i, j; | |
8504 | struct nlattr *rule; | |
8505 | struct cfg80211_coalesce_rules *tmp_rule; | |
8506 | ||
8507 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8508 | return -EOPNOTSUPP; | |
8509 | ||
8510 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8511 | cfg80211_rdev_free_coalesce(rdev); | |
8512 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8513 | return 0; | |
8514 | } | |
8515 | ||
8516 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8517 | rem_rule) | |
8518 | n_rules++; | |
8519 | if (n_rules > coalesce->n_rules) | |
8520 | return -EINVAL; | |
8521 | ||
8522 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8523 | GFP_KERNEL); | |
8524 | if (!new_coalesce.rules) | |
8525 | return -ENOMEM; | |
8526 | ||
8527 | new_coalesce.n_rules = n_rules; | |
8528 | i = 0; | |
8529 | ||
8530 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8531 | rem_rule) { | |
8532 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8533 | &new_coalesce.rules[i]); | |
8534 | if (err) | |
8535 | goto error; | |
8536 | ||
8537 | i++; | |
8538 | } | |
8539 | ||
8540 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8541 | if (err) | |
8542 | goto error; | |
8543 | ||
8544 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8545 | if (!n_coalesce) { | |
8546 | err = -ENOMEM; | |
8547 | goto error; | |
8548 | } | |
8549 | cfg80211_rdev_free_coalesce(rdev); | |
8550 | rdev->coalesce = n_coalesce; | |
8551 | ||
8552 | return 0; | |
8553 | error: | |
8554 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8555 | tmp_rule = &new_coalesce.rules[i]; | |
8556 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8557 | kfree(tmp_rule->patterns[j].mask); | |
8558 | kfree(tmp_rule->patterns); | |
8559 | } | |
8560 | kfree(new_coalesce.rules); | |
8561 | ||
8562 | return err; | |
8563 | } | |
8564 | ||
e5497d76 JB |
8565 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8566 | { | |
8567 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8568 | struct net_device *dev = info->user_ptr[1]; | |
8569 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8570 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8571 | struct cfg80211_gtk_rekey_data rekey_data; | |
8572 | int err; | |
8573 | ||
8574 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8575 | return -EINVAL; | |
8576 | ||
8577 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8578 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8579 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8580 | nl80211_rekey_policy); | |
8581 | if (err) | |
8582 | return err; | |
8583 | ||
8584 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8585 | return -ERANGE; | |
8586 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8587 | return -ERANGE; | |
8588 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8589 | return -ERANGE; | |
8590 | ||
8591 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8592 | NL80211_KEK_LEN); | |
8593 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8594 | NL80211_KCK_LEN); | |
8595 | memcpy(rekey_data.replay_ctr, | |
8596 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8597 | NL80211_REPLAY_CTR_LEN); | |
8598 | ||
8599 | wdev_lock(wdev); | |
8600 | if (!wdev->current_bss) { | |
8601 | err = -ENOTCONN; | |
8602 | goto out; | |
8603 | } | |
8604 | ||
8605 | if (!rdev->ops->set_rekey_data) { | |
8606 | err = -EOPNOTSUPP; | |
8607 | goto out; | |
8608 | } | |
8609 | ||
e35e4d28 | 8610 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8611 | out: |
8612 | wdev_unlock(wdev); | |
8613 | return err; | |
8614 | } | |
8615 | ||
28946da7 JB |
8616 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8617 | struct genl_info *info) | |
8618 | { | |
8619 | struct net_device *dev = info->user_ptr[1]; | |
8620 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8621 | ||
8622 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8623 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8624 | return -EINVAL; | |
8625 | ||
15e47304 | 8626 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8627 | return -EBUSY; |
8628 | ||
15e47304 | 8629 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8630 | return 0; |
8631 | } | |
8632 | ||
7f6cf311 JB |
8633 | static int nl80211_probe_client(struct sk_buff *skb, |
8634 | struct genl_info *info) | |
8635 | { | |
8636 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8637 | struct net_device *dev = info->user_ptr[1]; | |
8638 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8639 | struct sk_buff *msg; | |
8640 | void *hdr; | |
8641 | const u8 *addr; | |
8642 | u64 cookie; | |
8643 | int err; | |
8644 | ||
8645 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8646 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8647 | return -EOPNOTSUPP; | |
8648 | ||
8649 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8650 | return -EINVAL; | |
8651 | ||
8652 | if (!rdev->ops->probe_client) | |
8653 | return -EOPNOTSUPP; | |
8654 | ||
8655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8656 | if (!msg) | |
8657 | return -ENOMEM; | |
8658 | ||
15e47304 | 8659 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 8660 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
8661 | if (!hdr) { |
8662 | err = -ENOBUFS; | |
7f6cf311 JB |
8663 | goto free_msg; |
8664 | } | |
8665 | ||
8666 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8667 | ||
e35e4d28 | 8668 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8669 | if (err) |
8670 | goto free_msg; | |
8671 | ||
9360ffd1 DM |
8672 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8673 | goto nla_put_failure; | |
7f6cf311 JB |
8674 | |
8675 | genlmsg_end(msg, hdr); | |
8676 | ||
8677 | return genlmsg_reply(msg, info); | |
8678 | ||
8679 | nla_put_failure: | |
8680 | err = -ENOBUFS; | |
8681 | free_msg: | |
8682 | nlmsg_free(msg); | |
8683 | return err; | |
8684 | } | |
8685 | ||
5e760230 JB |
8686 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8687 | { | |
8688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8689 | struct cfg80211_beacon_registration *reg, *nreg; |
8690 | int rv; | |
5e760230 JB |
8691 | |
8692 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8693 | return -EOPNOTSUPP; | |
8694 | ||
37c73b5f BG |
8695 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8696 | if (!nreg) | |
8697 | return -ENOMEM; | |
8698 | ||
8699 | /* First, check if already registered. */ | |
8700 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8701 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8702 | if (reg->nlportid == info->snd_portid) { | |
8703 | rv = -EALREADY; | |
8704 | goto out_err; | |
8705 | } | |
8706 | } | |
8707 | /* Add it to the list */ | |
8708 | nreg->nlportid = info->snd_portid; | |
8709 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8710 | |
37c73b5f | 8711 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8712 | |
8713 | return 0; | |
37c73b5f BG |
8714 | out_err: |
8715 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8716 | kfree(nreg); | |
8717 | return rv; | |
5e760230 JB |
8718 | } |
8719 | ||
98104fde JB |
8720 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8721 | { | |
8722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8723 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8724 | int err; | |
8725 | ||
8726 | if (!rdev->ops->start_p2p_device) | |
8727 | return -EOPNOTSUPP; | |
8728 | ||
8729 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8730 | return -EOPNOTSUPP; | |
8731 | ||
8732 | if (wdev->p2p_started) | |
8733 | return 0; | |
8734 | ||
98104fde | 8735 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8736 | if (err) |
8737 | return err; | |
8738 | ||
eeb126e9 | 8739 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8740 | if (err) |
8741 | return err; | |
8742 | ||
8743 | wdev->p2p_started = true; | |
98104fde | 8744 | rdev->opencount++; |
98104fde JB |
8745 | |
8746 | return 0; | |
8747 | } | |
8748 | ||
8749 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8750 | { | |
8751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8752 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8753 | ||
8754 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8755 | return -EOPNOTSUPP; | |
8756 | ||
8757 | if (!rdev->ops->stop_p2p_device) | |
8758 | return -EOPNOTSUPP; | |
8759 | ||
f9f47529 | 8760 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8761 | |
8762 | return 0; | |
8763 | } | |
8764 | ||
3713b4e3 JB |
8765 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8766 | struct genl_info *info) | |
8767 | { | |
8768 | void *hdr; | |
8769 | struct sk_buff *msg; | |
8770 | ||
8771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8772 | if (!msg) | |
8773 | return -ENOMEM; | |
8774 | ||
8775 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8776 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8777 | if (!hdr) | |
8778 | goto nla_put_failure; | |
8779 | ||
8780 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8781 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8782 | goto nla_put_failure; | |
8783 | ||
8784 | genlmsg_end(msg, hdr); | |
8785 | return genlmsg_reply(msg, info); | |
8786 | ||
8787 | nla_put_failure: | |
8788 | kfree_skb(msg); | |
8789 | return -ENOBUFS; | |
8790 | } | |
8791 | ||
355199e0 JM |
8792 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8793 | { | |
8794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8795 | struct cfg80211_update_ft_ies_params ft_params; | |
8796 | struct net_device *dev = info->user_ptr[1]; | |
8797 | ||
8798 | if (!rdev->ops->update_ft_ies) | |
8799 | return -EOPNOTSUPP; | |
8800 | ||
8801 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8802 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8803 | return -EINVAL; | |
8804 | ||
8805 | memset(&ft_params, 0, sizeof(ft_params)); | |
8806 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8807 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8808 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8809 | ||
8810 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8811 | } | |
8812 | ||
5de17984 AS |
8813 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8814 | struct genl_info *info) | |
8815 | { | |
8816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8817 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8818 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8819 | u16 duration; | |
8820 | int ret; | |
8821 | ||
8822 | if (!rdev->ops->crit_proto_start) | |
8823 | return -EOPNOTSUPP; | |
8824 | ||
8825 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8826 | return -EINVAL; | |
8827 | ||
8828 | if (rdev->crit_proto_nlportid) | |
8829 | return -EBUSY; | |
8830 | ||
8831 | /* determine protocol if provided */ | |
8832 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8833 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8834 | ||
8835 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8836 | return -EINVAL; | |
8837 | ||
8838 | /* timeout must be provided */ | |
8839 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8840 | return -EINVAL; | |
8841 | ||
8842 | duration = | |
8843 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8844 | ||
8845 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8846 | return -ERANGE; | |
8847 | ||
8848 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8849 | if (!ret) | |
8850 | rdev->crit_proto_nlportid = info->snd_portid; | |
8851 | ||
8852 | return ret; | |
8853 | } | |
8854 | ||
8855 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8856 | struct genl_info *info) | |
8857 | { | |
8858 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8859 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8860 | ||
8861 | if (!rdev->ops->crit_proto_stop) | |
8862 | return -EOPNOTSUPP; | |
8863 | ||
8864 | if (rdev->crit_proto_nlportid) { | |
8865 | rdev->crit_proto_nlportid = 0; | |
8866 | rdev_crit_proto_stop(rdev, wdev); | |
8867 | } | |
8868 | return 0; | |
8869 | } | |
8870 | ||
4c476991 JB |
8871 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8872 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8873 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8874 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8875 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8876 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8877 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8878 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8879 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8880 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8881 | |
8882 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8883 | struct genl_info *info) | |
8884 | { | |
8885 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8886 | struct wireless_dev *wdev; |
4c476991 | 8887 | struct net_device *dev; |
4c476991 JB |
8888 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8889 | ||
8890 | if (rtnl) | |
8891 | rtnl_lock(); | |
8892 | ||
8893 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8894 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8895 | if (IS_ERR(rdev)) { |
8896 | if (rtnl) | |
8897 | rtnl_unlock(); | |
8898 | return PTR_ERR(rdev); | |
8899 | } | |
8900 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8901 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8902 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
8903 | ASSERT_RTNL(); |
8904 | ||
89a54e48 JB |
8905 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
8906 | info->attrs); | |
8907 | if (IS_ERR(wdev)) { | |
4c476991 JB |
8908 | if (rtnl) |
8909 | rtnl_unlock(); | |
89a54e48 | 8910 | return PTR_ERR(wdev); |
4c476991 | 8911 | } |
89a54e48 | 8912 | |
89a54e48 JB |
8913 | dev = wdev->netdev; |
8914 | rdev = wiphy_to_dev(wdev->wiphy); | |
8915 | ||
1bf614ef JB |
8916 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8917 | if (!dev) { | |
1bf614ef JB |
8918 | if (rtnl) |
8919 | rtnl_unlock(); | |
8920 | return -EINVAL; | |
8921 | } | |
8922 | ||
8923 | info->user_ptr[1] = dev; | |
8924 | } else { | |
8925 | info->user_ptr[1] = wdev; | |
41265714 | 8926 | } |
1bf614ef JB |
8927 | |
8928 | if (dev) { | |
8929 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8930 | !netif_running(dev)) { | |
1bf614ef JB |
8931 | if (rtnl) |
8932 | rtnl_unlock(); | |
8933 | return -ENETDOWN; | |
8934 | } | |
8935 | ||
8936 | dev_hold(dev); | |
98104fde JB |
8937 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8938 | if (!wdev->p2p_started) { | |
98104fde JB |
8939 | if (rtnl) |
8940 | rtnl_unlock(); | |
8941 | return -ENETDOWN; | |
8942 | } | |
41265714 | 8943 | } |
89a54e48 | 8944 | |
4c476991 | 8945 | info->user_ptr[0] = rdev; |
4c476991 JB |
8946 | } |
8947 | ||
8948 | return 0; | |
8949 | } | |
8950 | ||
8951 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8952 | struct genl_info *info) | |
8953 | { | |
1bf614ef JB |
8954 | if (info->user_ptr[1]) { |
8955 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8956 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8957 | ||
8958 | if (wdev->netdev) | |
8959 | dev_put(wdev->netdev); | |
8960 | } else { | |
8961 | dev_put(info->user_ptr[1]); | |
8962 | } | |
8963 | } | |
4c476991 JB |
8964 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8965 | rtnl_unlock(); | |
8966 | } | |
8967 | ||
55682965 JB |
8968 | static struct genl_ops nl80211_ops[] = { |
8969 | { | |
8970 | .cmd = NL80211_CMD_GET_WIPHY, | |
8971 | .doit = nl80211_get_wiphy, | |
8972 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 8973 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
8974 | .policy = nl80211_policy, |
8975 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8976 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8977 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8978 | }, |
8979 | { | |
8980 | .cmd = NL80211_CMD_SET_WIPHY, | |
8981 | .doit = nl80211_set_wiphy, | |
8982 | .policy = nl80211_policy, | |
8983 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8984 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8985 | }, |
8986 | { | |
8987 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8988 | .doit = nl80211_get_interface, | |
8989 | .dumpit = nl80211_dump_interface, | |
8990 | .policy = nl80211_policy, | |
8991 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8992 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
8993 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8994 | }, |
8995 | { | |
8996 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8997 | .doit = nl80211_set_interface, | |
8998 | .policy = nl80211_policy, | |
8999 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9000 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9001 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9002 | }, |
9003 | { | |
9004 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9005 | .doit = nl80211_new_interface, | |
9006 | .policy = nl80211_policy, | |
9007 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9008 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9009 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9010 | }, |
9011 | { | |
9012 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9013 | .doit = nl80211_del_interface, | |
9014 | .policy = nl80211_policy, | |
41ade00f | 9015 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9016 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9017 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9018 | }, |
9019 | { | |
9020 | .cmd = NL80211_CMD_GET_KEY, | |
9021 | .doit = nl80211_get_key, | |
9022 | .policy = nl80211_policy, | |
9023 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9024 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9025 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9026 | }, |
9027 | { | |
9028 | .cmd = NL80211_CMD_SET_KEY, | |
9029 | .doit = nl80211_set_key, | |
9030 | .policy = nl80211_policy, | |
9031 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9032 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9033 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9034 | }, |
9035 | { | |
9036 | .cmd = NL80211_CMD_NEW_KEY, | |
9037 | .doit = nl80211_new_key, | |
9038 | .policy = nl80211_policy, | |
9039 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9041 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9042 | }, |
9043 | { | |
9044 | .cmd = NL80211_CMD_DEL_KEY, | |
9045 | .doit = nl80211_del_key, | |
9046 | .policy = nl80211_policy, | |
55682965 | 9047 | .flags = GENL_ADMIN_PERM, |
41265714 | 9048 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9049 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9050 | }, |
ed1b6cc7 JB |
9051 | { |
9052 | .cmd = NL80211_CMD_SET_BEACON, | |
9053 | .policy = nl80211_policy, | |
9054 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9055 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9056 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9057 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9058 | }, |
9059 | { | |
8860020e | 9060 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9061 | .policy = nl80211_policy, |
9062 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9063 | .doit = nl80211_start_ap, |
2b5f8b0b | 9064 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9065 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9066 | }, |
9067 | { | |
8860020e | 9068 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9069 | .policy = nl80211_policy, |
9070 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9071 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9072 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9073 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9074 | }, |
5727ef1b JB |
9075 | { |
9076 | .cmd = NL80211_CMD_GET_STATION, | |
9077 | .doit = nl80211_get_station, | |
2ec600d6 | 9078 | .dumpit = nl80211_dump_station, |
5727ef1b | 9079 | .policy = nl80211_policy, |
4c476991 JB |
9080 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9081 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9082 | }, |
9083 | { | |
9084 | .cmd = NL80211_CMD_SET_STATION, | |
9085 | .doit = nl80211_set_station, | |
9086 | .policy = nl80211_policy, | |
9087 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9088 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9089 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9090 | }, |
9091 | { | |
9092 | .cmd = NL80211_CMD_NEW_STATION, | |
9093 | .doit = nl80211_new_station, | |
9094 | .policy = nl80211_policy, | |
9095 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9096 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9097 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9098 | }, |
9099 | { | |
9100 | .cmd = NL80211_CMD_DEL_STATION, | |
9101 | .doit = nl80211_del_station, | |
9102 | .policy = nl80211_policy, | |
2ec600d6 | 9103 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9104 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9105 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9106 | }, |
9107 | { | |
9108 | .cmd = NL80211_CMD_GET_MPATH, | |
9109 | .doit = nl80211_get_mpath, | |
9110 | .dumpit = nl80211_dump_mpath, | |
9111 | .policy = nl80211_policy, | |
9112 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9113 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9114 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9115 | }, |
9116 | { | |
9117 | .cmd = NL80211_CMD_SET_MPATH, | |
9118 | .doit = nl80211_set_mpath, | |
9119 | .policy = nl80211_policy, | |
9120 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9121 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9122 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9123 | }, |
9124 | { | |
9125 | .cmd = NL80211_CMD_NEW_MPATH, | |
9126 | .doit = nl80211_new_mpath, | |
9127 | .policy = nl80211_policy, | |
9128 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9129 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9130 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9131 | }, |
9132 | { | |
9133 | .cmd = NL80211_CMD_DEL_MPATH, | |
9134 | .doit = nl80211_del_mpath, | |
9135 | .policy = nl80211_policy, | |
9f1ba906 | 9136 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9137 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9138 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9139 | }, |
9140 | { | |
9141 | .cmd = NL80211_CMD_SET_BSS, | |
9142 | .doit = nl80211_set_bss, | |
9143 | .policy = nl80211_policy, | |
b2e1b302 | 9144 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9146 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9147 | }, |
f130347c LR |
9148 | { |
9149 | .cmd = NL80211_CMD_GET_REG, | |
9150 | .doit = nl80211_get_reg, | |
9151 | .policy = nl80211_policy, | |
5fe231e8 | 9152 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9153 | /* can be retrieved by unprivileged users */ |
9154 | }, | |
b2e1b302 LR |
9155 | { |
9156 | .cmd = NL80211_CMD_SET_REG, | |
9157 | .doit = nl80211_set_reg, | |
9158 | .policy = nl80211_policy, | |
9159 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9160 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9161 | }, |
9162 | { | |
9163 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9164 | .doit = nl80211_req_set_reg, | |
9165 | .policy = nl80211_policy, | |
93da9cc1 | 9166 | .flags = GENL_ADMIN_PERM, |
9167 | }, | |
9168 | { | |
24bdd9f4 JC |
9169 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9170 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9171 | .policy = nl80211_policy, |
9172 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9173 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9174 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9175 | }, |
9176 | { | |
24bdd9f4 JC |
9177 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9178 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9179 | .policy = nl80211_policy, |
9aed3cc1 | 9180 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9181 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9182 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9183 | }, |
2a519311 JB |
9184 | { |
9185 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9186 | .doit = nl80211_trigger_scan, | |
9187 | .policy = nl80211_policy, | |
9188 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9189 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9190 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9191 | }, |
9192 | { | |
9193 | .cmd = NL80211_CMD_GET_SCAN, | |
9194 | .policy = nl80211_policy, | |
9195 | .dumpit = nl80211_dump_scan, | |
9196 | }, | |
807f8a8c LC |
9197 | { |
9198 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9199 | .doit = nl80211_start_sched_scan, | |
9200 | .policy = nl80211_policy, | |
9201 | .flags = GENL_ADMIN_PERM, | |
9202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9203 | NL80211_FLAG_NEED_RTNL, | |
9204 | }, | |
9205 | { | |
9206 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9207 | .doit = nl80211_stop_sched_scan, | |
9208 | .policy = nl80211_policy, | |
9209 | .flags = GENL_ADMIN_PERM, | |
9210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9211 | NL80211_FLAG_NEED_RTNL, | |
9212 | }, | |
636a5d36 JM |
9213 | { |
9214 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9215 | .doit = nl80211_authenticate, | |
9216 | .policy = nl80211_policy, | |
9217 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9219 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9220 | }, |
9221 | { | |
9222 | .cmd = NL80211_CMD_ASSOCIATE, | |
9223 | .doit = nl80211_associate, | |
9224 | .policy = nl80211_policy, | |
9225 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9226 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9227 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9228 | }, |
9229 | { | |
9230 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9231 | .doit = nl80211_deauthenticate, | |
9232 | .policy = nl80211_policy, | |
9233 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9234 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9235 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9236 | }, |
9237 | { | |
9238 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9239 | .doit = nl80211_disassociate, | |
9240 | .policy = nl80211_policy, | |
9241 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9242 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9243 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9244 | }, |
04a773ad JB |
9245 | { |
9246 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9247 | .doit = nl80211_join_ibss, | |
9248 | .policy = nl80211_policy, | |
9249 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9250 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9251 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9252 | }, |
9253 | { | |
9254 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9255 | .doit = nl80211_leave_ibss, | |
9256 | .policy = nl80211_policy, | |
9257 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9258 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9259 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9260 | }, |
aff89a9b JB |
9261 | #ifdef CONFIG_NL80211_TESTMODE |
9262 | { | |
9263 | .cmd = NL80211_CMD_TESTMODE, | |
9264 | .doit = nl80211_testmode_do, | |
71063f0e | 9265 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9266 | .policy = nl80211_policy, |
9267 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9268 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9269 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9270 | }, |
9271 | #endif | |
b23aa676 SO |
9272 | { |
9273 | .cmd = NL80211_CMD_CONNECT, | |
9274 | .doit = nl80211_connect, | |
9275 | .policy = nl80211_policy, | |
9276 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9278 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9279 | }, |
9280 | { | |
9281 | .cmd = NL80211_CMD_DISCONNECT, | |
9282 | .doit = nl80211_disconnect, | |
9283 | .policy = nl80211_policy, | |
9284 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9285 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9286 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9287 | }, |
463d0183 JB |
9288 | { |
9289 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9290 | .doit = nl80211_wiphy_netns, | |
9291 | .policy = nl80211_policy, | |
9292 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9293 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9294 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9295 | }, |
61fa713c HS |
9296 | { |
9297 | .cmd = NL80211_CMD_GET_SURVEY, | |
9298 | .policy = nl80211_policy, | |
9299 | .dumpit = nl80211_dump_survey, | |
9300 | }, | |
67fbb16b SO |
9301 | { |
9302 | .cmd = NL80211_CMD_SET_PMKSA, | |
9303 | .doit = nl80211_setdel_pmksa, | |
9304 | .policy = nl80211_policy, | |
9305 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9307 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9308 | }, |
9309 | { | |
9310 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9311 | .doit = nl80211_setdel_pmksa, | |
9312 | .policy = nl80211_policy, | |
9313 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9315 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9316 | }, |
9317 | { | |
9318 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9319 | .doit = nl80211_flush_pmksa, | |
9320 | .policy = nl80211_policy, | |
9321 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9322 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9323 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9324 | }, |
9588bbd5 JM |
9325 | { |
9326 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9327 | .doit = nl80211_remain_on_channel, | |
9328 | .policy = nl80211_policy, | |
9329 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9330 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9331 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9332 | }, |
9333 | { | |
9334 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9335 | .doit = nl80211_cancel_remain_on_channel, | |
9336 | .policy = nl80211_policy, | |
9337 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9338 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9339 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9340 | }, |
13ae75b1 JM |
9341 | { |
9342 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9343 | .doit = nl80211_set_tx_bitrate_mask, | |
9344 | .policy = nl80211_policy, | |
9345 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9346 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9347 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9348 | }, |
026331c4 | 9349 | { |
2e161f78 JB |
9350 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9351 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9352 | .policy = nl80211_policy, |
9353 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9354 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9355 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9356 | }, |
9357 | { | |
2e161f78 JB |
9358 | .cmd = NL80211_CMD_FRAME, |
9359 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9360 | .policy = nl80211_policy, |
f7ca38df | 9361 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9362 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9363 | NL80211_FLAG_NEED_RTNL, |
9364 | }, | |
9365 | { | |
9366 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9367 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9368 | .policy = nl80211_policy, | |
026331c4 | 9369 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9370 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9371 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9372 | }, |
ffb9eb3d KV |
9373 | { |
9374 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9375 | .doit = nl80211_set_power_save, | |
9376 | .policy = nl80211_policy, | |
9377 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9378 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9379 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9380 | }, |
9381 | { | |
9382 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9383 | .doit = nl80211_get_power_save, | |
9384 | .policy = nl80211_policy, | |
9385 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9386 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9387 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9388 | }, |
d6dc1a38 JO |
9389 | { |
9390 | .cmd = NL80211_CMD_SET_CQM, | |
9391 | .doit = nl80211_set_cqm, | |
9392 | .policy = nl80211_policy, | |
9393 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9394 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9395 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9396 | }, |
f444de05 JB |
9397 | { |
9398 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9399 | .doit = nl80211_set_channel, | |
9400 | .policy = nl80211_policy, | |
9401 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9402 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9403 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9404 | }, |
e8347eba BJ |
9405 | { |
9406 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9407 | .doit = nl80211_set_wds_peer, | |
9408 | .policy = nl80211_policy, | |
9409 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9410 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9411 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9412 | }, |
29cbe68c JB |
9413 | { |
9414 | .cmd = NL80211_CMD_JOIN_MESH, | |
9415 | .doit = nl80211_join_mesh, | |
9416 | .policy = nl80211_policy, | |
9417 | .flags = GENL_ADMIN_PERM, | |
9418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9419 | NL80211_FLAG_NEED_RTNL, | |
9420 | }, | |
9421 | { | |
9422 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9423 | .doit = nl80211_leave_mesh, | |
9424 | .policy = nl80211_policy, | |
9425 | .flags = GENL_ADMIN_PERM, | |
9426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9427 | NL80211_FLAG_NEED_RTNL, | |
9428 | }, | |
dfb89c56 | 9429 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9430 | { |
9431 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9432 | .doit = nl80211_get_wowlan, | |
9433 | .policy = nl80211_policy, | |
9434 | /* can be retrieved by unprivileged users */ | |
9435 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9436 | NL80211_FLAG_NEED_RTNL, | |
9437 | }, | |
9438 | { | |
9439 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9440 | .doit = nl80211_set_wowlan, | |
9441 | .policy = nl80211_policy, | |
9442 | .flags = GENL_ADMIN_PERM, | |
9443 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9444 | NL80211_FLAG_NEED_RTNL, | |
9445 | }, | |
dfb89c56 | 9446 | #endif |
e5497d76 JB |
9447 | { |
9448 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9449 | .doit = nl80211_set_rekey_data, | |
9450 | .policy = nl80211_policy, | |
9451 | .flags = GENL_ADMIN_PERM, | |
9452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9453 | NL80211_FLAG_NEED_RTNL, | |
9454 | }, | |
109086ce AN |
9455 | { |
9456 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9457 | .doit = nl80211_tdls_mgmt, | |
9458 | .policy = nl80211_policy, | |
9459 | .flags = GENL_ADMIN_PERM, | |
9460 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9461 | NL80211_FLAG_NEED_RTNL, | |
9462 | }, | |
9463 | { | |
9464 | .cmd = NL80211_CMD_TDLS_OPER, | |
9465 | .doit = nl80211_tdls_oper, | |
9466 | .policy = nl80211_policy, | |
9467 | .flags = GENL_ADMIN_PERM, | |
9468 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9469 | NL80211_FLAG_NEED_RTNL, | |
9470 | }, | |
28946da7 JB |
9471 | { |
9472 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9473 | .doit = nl80211_register_unexpected_frame, | |
9474 | .policy = nl80211_policy, | |
9475 | .flags = GENL_ADMIN_PERM, | |
9476 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9477 | NL80211_FLAG_NEED_RTNL, | |
9478 | }, | |
7f6cf311 JB |
9479 | { |
9480 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9481 | .doit = nl80211_probe_client, | |
9482 | .policy = nl80211_policy, | |
9483 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9484 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9485 | NL80211_FLAG_NEED_RTNL, |
9486 | }, | |
5e760230 JB |
9487 | { |
9488 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9489 | .doit = nl80211_register_beacons, | |
9490 | .policy = nl80211_policy, | |
9491 | .flags = GENL_ADMIN_PERM, | |
9492 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9493 | NL80211_FLAG_NEED_RTNL, | |
9494 | }, | |
1d9d9213 SW |
9495 | { |
9496 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9497 | .doit = nl80211_set_noack_map, | |
9498 | .policy = nl80211_policy, | |
9499 | .flags = GENL_ADMIN_PERM, | |
9500 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9501 | NL80211_FLAG_NEED_RTNL, | |
9502 | }, | |
98104fde JB |
9503 | { |
9504 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9505 | .doit = nl80211_start_p2p_device, | |
9506 | .policy = nl80211_policy, | |
9507 | .flags = GENL_ADMIN_PERM, | |
9508 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9509 | NL80211_FLAG_NEED_RTNL, | |
9510 | }, | |
9511 | { | |
9512 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9513 | .doit = nl80211_stop_p2p_device, | |
9514 | .policy = nl80211_policy, | |
9515 | .flags = GENL_ADMIN_PERM, | |
9516 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9517 | NL80211_FLAG_NEED_RTNL, | |
9518 | }, | |
f4e583c8 AQ |
9519 | { |
9520 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9521 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9522 | .policy = nl80211_policy, |
9523 | .flags = GENL_ADMIN_PERM, | |
9524 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9525 | NL80211_FLAG_NEED_RTNL, | |
9526 | }, | |
9527 | { | |
9528 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9529 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9530 | .policy = nl80211_policy, |
9531 | .flags = GENL_ADMIN_PERM, | |
9532 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9533 | NL80211_FLAG_NEED_RTNL, | |
9534 | }, | |
04f39047 SW |
9535 | { |
9536 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9537 | .doit = nl80211_start_radar_detection, | |
9538 | .policy = nl80211_policy, | |
9539 | .flags = GENL_ADMIN_PERM, | |
9540 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9541 | NL80211_FLAG_NEED_RTNL, | |
9542 | }, | |
3713b4e3 JB |
9543 | { |
9544 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9545 | .doit = nl80211_get_protocol_features, | |
9546 | .policy = nl80211_policy, | |
9547 | }, | |
355199e0 JM |
9548 | { |
9549 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9550 | .doit = nl80211_update_ft_ies, | |
9551 | .policy = nl80211_policy, | |
9552 | .flags = GENL_ADMIN_PERM, | |
9553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9554 | NL80211_FLAG_NEED_RTNL, | |
9555 | }, | |
5de17984 AS |
9556 | { |
9557 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9558 | .doit = nl80211_crit_protocol_start, | |
9559 | .policy = nl80211_policy, | |
9560 | .flags = GENL_ADMIN_PERM, | |
9561 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9562 | NL80211_FLAG_NEED_RTNL, | |
9563 | }, | |
9564 | { | |
9565 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9566 | .doit = nl80211_crit_protocol_stop, | |
9567 | .policy = nl80211_policy, | |
9568 | .flags = GENL_ADMIN_PERM, | |
9569 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9570 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9571 | }, |
9572 | { | |
9573 | .cmd = NL80211_CMD_GET_COALESCE, | |
9574 | .doit = nl80211_get_coalesce, | |
9575 | .policy = nl80211_policy, | |
9576 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9577 | NL80211_FLAG_NEED_RTNL, | |
9578 | }, | |
9579 | { | |
9580 | .cmd = NL80211_CMD_SET_COALESCE, | |
9581 | .doit = nl80211_set_coalesce, | |
9582 | .policy = nl80211_policy, | |
9583 | .flags = GENL_ADMIN_PERM, | |
9584 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9585 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
9586 | }, |
9587 | { | |
9588 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
9589 | .doit = nl80211_channel_switch, | |
9590 | .policy = nl80211_policy, | |
9591 | .flags = GENL_ADMIN_PERM, | |
9592 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9593 | NL80211_FLAG_NEED_RTNL, | |
9594 | }, | |
55682965 | 9595 | }; |
9588bbd5 | 9596 | |
6039f6d2 JM |
9597 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
9598 | .name = "mlme", | |
9599 | }; | |
55682965 JB |
9600 | |
9601 | /* multicast groups */ | |
9602 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
9603 | .name = "config", | |
9604 | }; | |
2a519311 JB |
9605 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
9606 | .name = "scan", | |
9607 | }; | |
73d54c9e LR |
9608 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
9609 | .name = "regulatory", | |
9610 | }; | |
55682965 JB |
9611 | |
9612 | /* notification functions */ | |
9613 | ||
9614 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9615 | { | |
9616 | struct sk_buff *msg; | |
86e8cf98 | 9617 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 9618 | |
fd2120ca | 9619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9620 | if (!msg) |
9621 | return; | |
9622 | ||
86e8cf98 | 9623 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
9624 | nlmsg_free(msg); |
9625 | return; | |
9626 | } | |
9627 | ||
463d0183 JB |
9628 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9629 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
9630 | } |
9631 | ||
362a415d JB |
9632 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9633 | struct cfg80211_registered_device *rdev) | |
9634 | { | |
9635 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9636 | struct nlattr *nest; | |
9637 | int i; | |
9638 | ||
9639 | if (WARN_ON(!req)) | |
9640 | return 0; | |
9641 | ||
9642 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9643 | if (!nest) | |
9644 | goto nla_put_failure; | |
9360ffd1 DM |
9645 | for (i = 0; i < req->n_ssids; i++) { |
9646 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9647 | goto nla_put_failure; | |
9648 | } | |
362a415d JB |
9649 | nla_nest_end(msg, nest); |
9650 | ||
9651 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9652 | if (!nest) | |
9653 | goto nla_put_failure; | |
9360ffd1 DM |
9654 | for (i = 0; i < req->n_channels; i++) { |
9655 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9656 | goto nla_put_failure; | |
9657 | } | |
362a415d JB |
9658 | nla_nest_end(msg, nest); |
9659 | ||
9360ffd1 DM |
9660 | if (req->ie && |
9661 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9662 | goto nla_put_failure; | |
362a415d | 9663 | |
ed473771 SL |
9664 | if (req->flags) |
9665 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9666 | ||
362a415d JB |
9667 | return 0; |
9668 | nla_put_failure: | |
9669 | return -ENOBUFS; | |
9670 | } | |
9671 | ||
a538e2d5 JB |
9672 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9673 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9674 | struct wireless_dev *wdev, |
15e47304 | 9675 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9676 | u32 cmd) |
2a519311 JB |
9677 | { |
9678 | void *hdr; | |
9679 | ||
15e47304 | 9680 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9681 | if (!hdr) |
9682 | return -1; | |
9683 | ||
9360ffd1 | 9684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9685 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9686 | wdev->netdev->ifindex)) || | |
9687 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9688 | goto nla_put_failure; |
2a519311 | 9689 | |
362a415d JB |
9690 | /* ignore errors and send incomplete event anyway */ |
9691 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9692 | |
9693 | return genlmsg_end(msg, hdr); | |
9694 | ||
9695 | nla_put_failure: | |
9696 | genlmsg_cancel(msg, hdr); | |
9697 | return -EMSGSIZE; | |
9698 | } | |
9699 | ||
807f8a8c LC |
9700 | static int |
9701 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9702 | struct cfg80211_registered_device *rdev, | |
9703 | struct net_device *netdev, | |
15e47304 | 9704 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9705 | { |
9706 | void *hdr; | |
9707 | ||
15e47304 | 9708 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9709 | if (!hdr) |
9710 | return -1; | |
9711 | ||
9360ffd1 DM |
9712 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9713 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9714 | goto nla_put_failure; | |
807f8a8c LC |
9715 | |
9716 | return genlmsg_end(msg, hdr); | |
9717 | ||
9718 | nla_put_failure: | |
9719 | genlmsg_cancel(msg, hdr); | |
9720 | return -EMSGSIZE; | |
9721 | } | |
9722 | ||
a538e2d5 | 9723 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9724 | struct wireless_dev *wdev) |
a538e2d5 JB |
9725 | { |
9726 | struct sk_buff *msg; | |
9727 | ||
58050fce | 9728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9729 | if (!msg) |
9730 | return; | |
9731 | ||
fd014284 | 9732 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9733 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9734 | nlmsg_free(msg); | |
9735 | return; | |
9736 | } | |
9737 | ||
463d0183 JB |
9738 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9739 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9740 | } |
9741 | ||
2a519311 | 9742 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9743 | struct wireless_dev *wdev) |
2a519311 JB |
9744 | { |
9745 | struct sk_buff *msg; | |
9746 | ||
fd2120ca | 9747 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9748 | if (!msg) |
9749 | return; | |
9750 | ||
fd014284 | 9751 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9752 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9753 | nlmsg_free(msg); |
9754 | return; | |
9755 | } | |
9756 | ||
463d0183 JB |
9757 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9758 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9759 | } |
9760 | ||
9761 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9762 | struct wireless_dev *wdev) |
2a519311 JB |
9763 | { |
9764 | struct sk_buff *msg; | |
9765 | ||
fd2120ca | 9766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9767 | if (!msg) |
9768 | return; | |
9769 | ||
fd014284 | 9770 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9771 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9772 | nlmsg_free(msg); |
9773 | return; | |
9774 | } | |
9775 | ||
463d0183 JB |
9776 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9777 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9778 | } |
9779 | ||
807f8a8c LC |
9780 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9781 | struct net_device *netdev) | |
9782 | { | |
9783 | struct sk_buff *msg; | |
9784 | ||
9785 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9786 | if (!msg) | |
9787 | return; | |
9788 | ||
9789 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9790 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9791 | nlmsg_free(msg); | |
9792 | return; | |
9793 | } | |
9794 | ||
9795 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9796 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9797 | } | |
9798 | ||
9799 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9800 | struct net_device *netdev, u32 cmd) | |
9801 | { | |
9802 | struct sk_buff *msg; | |
9803 | ||
58050fce | 9804 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9805 | if (!msg) |
9806 | return; | |
9807 | ||
9808 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9809 | nlmsg_free(msg); | |
9810 | return; | |
9811 | } | |
9812 | ||
9813 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9814 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9815 | } | |
9816 | ||
73d54c9e LR |
9817 | /* |
9818 | * This can happen on global regulatory changes or device specific settings | |
9819 | * based on custom world regulatory domains. | |
9820 | */ | |
9821 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9822 | { | |
9823 | struct sk_buff *msg; | |
9824 | void *hdr; | |
9825 | ||
fd2120ca | 9826 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9827 | if (!msg) |
9828 | return; | |
9829 | ||
9830 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9831 | if (!hdr) { | |
9832 | nlmsg_free(msg); | |
9833 | return; | |
9834 | } | |
9835 | ||
9836 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9837 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9838 | goto nla_put_failure; | |
9839 | ||
9840 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9841 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9842 | NL80211_REGDOM_TYPE_WORLD)) | |
9843 | goto nla_put_failure; | |
9844 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9845 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9846 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9847 | goto nla_put_failure; | |
9848 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9849 | request->intersect) { | |
9850 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9851 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9852 | goto nla_put_failure; | |
9853 | } else { | |
9854 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9855 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9856 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9857 | request->alpha2)) | |
9858 | goto nla_put_failure; | |
9859 | } | |
9860 | ||
f4173766 | 9861 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9862 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9863 | goto nla_put_failure; | |
73d54c9e | 9864 | |
3b7b72ee | 9865 | genlmsg_end(msg, hdr); |
73d54c9e | 9866 | |
bc43b28c | 9867 | rcu_read_lock(); |
463d0183 | 9868 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9869 | GFP_ATOMIC); |
9870 | rcu_read_unlock(); | |
73d54c9e LR |
9871 | |
9872 | return; | |
9873 | ||
9874 | nla_put_failure: | |
9875 | genlmsg_cancel(msg, hdr); | |
9876 | nlmsg_free(msg); | |
9877 | } | |
9878 | ||
6039f6d2 JM |
9879 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9880 | struct net_device *netdev, | |
9881 | const u8 *buf, size_t len, | |
e6d6e342 | 9882 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9883 | { |
9884 | struct sk_buff *msg; | |
9885 | void *hdr; | |
9886 | ||
e6d6e342 | 9887 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9888 | if (!msg) |
9889 | return; | |
9890 | ||
9891 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9892 | if (!hdr) { | |
9893 | nlmsg_free(msg); | |
9894 | return; | |
9895 | } | |
9896 | ||
9360ffd1 DM |
9897 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9898 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9899 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9900 | goto nla_put_failure; | |
6039f6d2 | 9901 | |
3b7b72ee | 9902 | genlmsg_end(msg, hdr); |
6039f6d2 | 9903 | |
463d0183 JB |
9904 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9905 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9906 | return; |
9907 | ||
9908 | nla_put_failure: | |
9909 | genlmsg_cancel(msg, hdr); | |
9910 | nlmsg_free(msg); | |
9911 | } | |
9912 | ||
9913 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9914 | struct net_device *netdev, const u8 *buf, |
9915 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9916 | { |
9917 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9918 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9919 | } |
9920 | ||
9921 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9922 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9923 | size_t len, gfp_t gfp) |
6039f6d2 | 9924 | { |
e6d6e342 JB |
9925 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9926 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9927 | } |
9928 | ||
53b46b84 | 9929 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9930 | struct net_device *netdev, const u8 *buf, |
9931 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9932 | { |
9933 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9934 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9935 | } |
9936 | ||
53b46b84 JM |
9937 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9938 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9939 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9940 | { |
9941 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9942 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9943 | } |
9944 | ||
6ff57cf8 JB |
9945 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
9946 | size_t len) | |
cf4e594e | 9947 | { |
947add36 JB |
9948 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9949 | struct wiphy *wiphy = wdev->wiphy; | |
9950 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
9951 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
9952 | u32 cmd; | |
947add36 | 9953 | |
6ff57cf8 JB |
9954 | if (WARN_ON(len < 2)) |
9955 | return; | |
cf4e594e | 9956 | |
6ff57cf8 JB |
9957 | if (ieee80211_is_deauth(mgmt->frame_control)) |
9958 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
9959 | else | |
9960 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 9961 | |
6ff57cf8 JB |
9962 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
9963 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 9964 | } |
6ff57cf8 | 9965 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 9966 | |
1b06bb40 LR |
9967 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9968 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9969 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9970 | { |
9971 | struct sk_buff *msg; | |
9972 | void *hdr; | |
9973 | ||
e6d6e342 | 9974 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9975 | if (!msg) |
9976 | return; | |
9977 | ||
9978 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9979 | if (!hdr) { | |
9980 | nlmsg_free(msg); | |
9981 | return; | |
9982 | } | |
9983 | ||
9360ffd1 DM |
9984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9985 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9986 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9987 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9988 | goto nla_put_failure; | |
1965c853 | 9989 | |
3b7b72ee | 9990 | genlmsg_end(msg, hdr); |
1965c853 | 9991 | |
463d0183 JB |
9992 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9993 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9994 | return; |
9995 | ||
9996 | nla_put_failure: | |
9997 | genlmsg_cancel(msg, hdr); | |
9998 | nlmsg_free(msg); | |
9999 | } | |
10000 | ||
10001 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10002 | struct net_device *netdev, const u8 *addr, |
10003 | gfp_t gfp) | |
1965c853 JM |
10004 | { |
10005 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10006 | addr, gfp); |
1965c853 JM |
10007 | } |
10008 | ||
10009 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10010 | struct net_device *netdev, const u8 *addr, |
10011 | gfp_t gfp) | |
1965c853 | 10012 | { |
e6d6e342 JB |
10013 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10014 | addr, gfp); | |
1965c853 JM |
10015 | } |
10016 | ||
b23aa676 SO |
10017 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10018 | struct net_device *netdev, const u8 *bssid, | |
10019 | const u8 *req_ie, size_t req_ie_len, | |
10020 | const u8 *resp_ie, size_t resp_ie_len, | |
10021 | u16 status, gfp_t gfp) | |
10022 | { | |
10023 | struct sk_buff *msg; | |
10024 | void *hdr; | |
10025 | ||
58050fce | 10026 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10027 | if (!msg) |
10028 | return; | |
10029 | ||
10030 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10031 | if (!hdr) { | |
10032 | nlmsg_free(msg); | |
10033 | return; | |
10034 | } | |
10035 | ||
9360ffd1 DM |
10036 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10037 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10038 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10039 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10040 | (req_ie && | |
10041 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10042 | (resp_ie && | |
10043 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10044 | goto nla_put_failure; | |
b23aa676 | 10045 | |
3b7b72ee | 10046 | genlmsg_end(msg, hdr); |
b23aa676 | 10047 | |
463d0183 JB |
10048 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10049 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
10050 | return; |
10051 | ||
10052 | nla_put_failure: | |
10053 | genlmsg_cancel(msg, hdr); | |
10054 | nlmsg_free(msg); | |
10055 | ||
10056 | } | |
10057 | ||
10058 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10059 | struct net_device *netdev, const u8 *bssid, | |
10060 | const u8 *req_ie, size_t req_ie_len, | |
10061 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10062 | { | |
10063 | struct sk_buff *msg; | |
10064 | void *hdr; | |
10065 | ||
58050fce | 10066 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10067 | if (!msg) |
10068 | return; | |
10069 | ||
10070 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10071 | if (!hdr) { | |
10072 | nlmsg_free(msg); | |
10073 | return; | |
10074 | } | |
10075 | ||
9360ffd1 DM |
10076 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10077 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10078 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10079 | (req_ie && | |
10080 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10081 | (resp_ie && | |
10082 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10083 | goto nla_put_failure; | |
b23aa676 | 10084 | |
3b7b72ee | 10085 | genlmsg_end(msg, hdr); |
b23aa676 | 10086 | |
463d0183 JB |
10087 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10088 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
10089 | return; |
10090 | ||
10091 | nla_put_failure: | |
10092 | genlmsg_cancel(msg, hdr); | |
10093 | nlmsg_free(msg); | |
10094 | ||
10095 | } | |
10096 | ||
10097 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10098 | struct net_device *netdev, u16 reason, | |
667503dd | 10099 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10100 | { |
10101 | struct sk_buff *msg; | |
10102 | void *hdr; | |
10103 | ||
58050fce | 10104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10105 | if (!msg) |
10106 | return; | |
10107 | ||
10108 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10109 | if (!hdr) { | |
10110 | nlmsg_free(msg); | |
10111 | return; | |
10112 | } | |
10113 | ||
9360ffd1 DM |
10114 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10115 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10116 | (from_ap && reason && | |
10117 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10118 | (from_ap && | |
10119 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10120 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10121 | goto nla_put_failure; | |
b23aa676 | 10122 | |
3b7b72ee | 10123 | genlmsg_end(msg, hdr); |
b23aa676 | 10124 | |
463d0183 JB |
10125 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10126 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
10127 | return; |
10128 | ||
10129 | nla_put_failure: | |
10130 | genlmsg_cancel(msg, hdr); | |
10131 | nlmsg_free(msg); | |
10132 | ||
10133 | } | |
10134 | ||
04a773ad JB |
10135 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10136 | struct net_device *netdev, const u8 *bssid, | |
10137 | gfp_t gfp) | |
10138 | { | |
10139 | struct sk_buff *msg; | |
10140 | void *hdr; | |
10141 | ||
fd2120ca | 10142 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10143 | if (!msg) |
10144 | return; | |
10145 | ||
10146 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10147 | if (!hdr) { | |
10148 | nlmsg_free(msg); | |
10149 | return; | |
10150 | } | |
10151 | ||
9360ffd1 DM |
10152 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10153 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10154 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10155 | goto nla_put_failure; | |
04a773ad | 10156 | |
3b7b72ee | 10157 | genlmsg_end(msg, hdr); |
04a773ad | 10158 | |
463d0183 JB |
10159 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10160 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
10161 | return; |
10162 | ||
10163 | nla_put_failure: | |
10164 | genlmsg_cancel(msg, hdr); | |
10165 | nlmsg_free(msg); | |
10166 | } | |
10167 | ||
947add36 JB |
10168 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10169 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10170 | { |
947add36 JB |
10171 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10172 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
10173 | struct sk_buff *msg; |
10174 | void *hdr; | |
10175 | ||
947add36 JB |
10176 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10177 | return; | |
10178 | ||
10179 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10180 | ||
c93b5e71 JC |
10181 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10182 | if (!msg) | |
10183 | return; | |
10184 | ||
10185 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10186 | if (!hdr) { | |
10187 | nlmsg_free(msg); | |
10188 | return; | |
10189 | } | |
10190 | ||
9360ffd1 | 10191 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10192 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10193 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10194 | (ie_len && ie && |
10195 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10196 | goto nla_put_failure; | |
c93b5e71 | 10197 | |
3b7b72ee | 10198 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
10199 | |
10200 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10201 | nl80211_mlme_mcgrp.id, gfp); | |
10202 | return; | |
10203 | ||
10204 | nla_put_failure: | |
10205 | genlmsg_cancel(msg, hdr); | |
10206 | nlmsg_free(msg); | |
10207 | } | |
947add36 | 10208 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10209 | |
a3b8b056 JM |
10210 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10211 | struct net_device *netdev, const u8 *addr, | |
10212 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10213 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10214 | { |
10215 | struct sk_buff *msg; | |
10216 | void *hdr; | |
10217 | ||
e6d6e342 | 10218 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10219 | if (!msg) |
10220 | return; | |
10221 | ||
10222 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10223 | if (!hdr) { | |
10224 | nlmsg_free(msg); | |
10225 | return; | |
10226 | } | |
10227 | ||
9360ffd1 DM |
10228 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10229 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10230 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10231 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10232 | (key_id != -1 && | |
10233 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10234 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10235 | goto nla_put_failure; | |
a3b8b056 | 10236 | |
3b7b72ee | 10237 | genlmsg_end(msg, hdr); |
a3b8b056 | 10238 | |
463d0183 JB |
10239 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10240 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
10241 | return; |
10242 | ||
10243 | nla_put_failure: | |
10244 | genlmsg_cancel(msg, hdr); | |
10245 | nlmsg_free(msg); | |
10246 | } | |
10247 | ||
6bad8766 LR |
10248 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10249 | struct ieee80211_channel *channel_before, | |
10250 | struct ieee80211_channel *channel_after) | |
10251 | { | |
10252 | struct sk_buff *msg; | |
10253 | void *hdr; | |
10254 | struct nlattr *nl_freq; | |
10255 | ||
fd2120ca | 10256 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10257 | if (!msg) |
10258 | return; | |
10259 | ||
10260 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10261 | if (!hdr) { | |
10262 | nlmsg_free(msg); | |
10263 | return; | |
10264 | } | |
10265 | ||
10266 | /* | |
10267 | * Since we are applying the beacon hint to a wiphy we know its | |
10268 | * wiphy_idx is valid | |
10269 | */ | |
9360ffd1 DM |
10270 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10271 | goto nla_put_failure; | |
6bad8766 LR |
10272 | |
10273 | /* Before */ | |
10274 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10275 | if (!nl_freq) | |
10276 | goto nla_put_failure; | |
cdc89b97 | 10277 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10278 | goto nla_put_failure; |
10279 | nla_nest_end(msg, nl_freq); | |
10280 | ||
10281 | /* After */ | |
10282 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10283 | if (!nl_freq) | |
10284 | goto nla_put_failure; | |
cdc89b97 | 10285 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10286 | goto nla_put_failure; |
10287 | nla_nest_end(msg, nl_freq); | |
10288 | ||
3b7b72ee | 10289 | genlmsg_end(msg, hdr); |
6bad8766 | 10290 | |
463d0183 JB |
10291 | rcu_read_lock(); |
10292 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
10293 | GFP_ATOMIC); | |
10294 | rcu_read_unlock(); | |
6bad8766 LR |
10295 | |
10296 | return; | |
10297 | ||
10298 | nla_put_failure: | |
10299 | genlmsg_cancel(msg, hdr); | |
10300 | nlmsg_free(msg); | |
10301 | } | |
10302 | ||
9588bbd5 JM |
10303 | static void nl80211_send_remain_on_chan_event( |
10304 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10305 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10306 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10307 | unsigned int duration, gfp_t gfp) |
10308 | { | |
10309 | struct sk_buff *msg; | |
10310 | void *hdr; | |
10311 | ||
10312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10313 | if (!msg) | |
10314 | return; | |
10315 | ||
10316 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10317 | if (!hdr) { | |
10318 | nlmsg_free(msg); | |
10319 | return; | |
10320 | } | |
10321 | ||
9360ffd1 | 10322 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10323 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10324 | wdev->netdev->ifindex)) || | |
00f53350 | 10325 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10326 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10327 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10328 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10329 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10330 | goto nla_put_failure; | |
9588bbd5 | 10331 | |
9360ffd1 DM |
10332 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10333 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10334 | goto nla_put_failure; | |
9588bbd5 | 10335 | |
3b7b72ee | 10336 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
10337 | |
10338 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10339 | nl80211_mlme_mcgrp.id, gfp); | |
10340 | return; | |
10341 | ||
10342 | nla_put_failure: | |
10343 | genlmsg_cancel(msg, hdr); | |
10344 | nlmsg_free(msg); | |
10345 | } | |
10346 | ||
947add36 JB |
10347 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10348 | struct ieee80211_channel *chan, | |
10349 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10350 | { |
947add36 JB |
10351 | struct wiphy *wiphy = wdev->wiphy; |
10352 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10353 | ||
10354 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10355 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10356 | rdev, wdev, cookie, chan, |
42d97a59 | 10357 | duration, gfp); |
9588bbd5 | 10358 | } |
947add36 | 10359 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10360 | |
947add36 JB |
10361 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10362 | struct ieee80211_channel *chan, | |
10363 | gfp_t gfp) | |
9588bbd5 | 10364 | { |
947add36 JB |
10365 | struct wiphy *wiphy = wdev->wiphy; |
10366 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10367 | ||
10368 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10369 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10370 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10371 | } |
947add36 | 10372 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10373 | |
947add36 JB |
10374 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10375 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10376 | { |
947add36 JB |
10377 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10378 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
10379 | struct sk_buff *msg; |
10380 | ||
947add36 JB |
10381 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10382 | ||
58050fce | 10383 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10384 | if (!msg) |
10385 | return; | |
10386 | ||
66266b3a JL |
10387 | if (nl80211_send_station(msg, 0, 0, 0, |
10388 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10389 | nlmsg_free(msg); |
10390 | return; | |
10391 | } | |
10392 | ||
10393 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10394 | nl80211_mlme_mcgrp.id, gfp); | |
10395 | } | |
947add36 | 10396 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10397 | |
947add36 | 10398 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10399 | { |
947add36 JB |
10400 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10401 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
10402 | struct sk_buff *msg; |
10403 | void *hdr; | |
10404 | ||
947add36 JB |
10405 | trace_cfg80211_del_sta(dev, mac_addr); |
10406 | ||
58050fce | 10407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10408 | if (!msg) |
10409 | return; | |
10410 | ||
10411 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10412 | if (!hdr) { | |
10413 | nlmsg_free(msg); | |
10414 | return; | |
10415 | } | |
10416 | ||
9360ffd1 DM |
10417 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10418 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10419 | goto nla_put_failure; | |
ec15e68b | 10420 | |
3b7b72ee | 10421 | genlmsg_end(msg, hdr); |
ec15e68b JM |
10422 | |
10423 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10424 | nl80211_mlme_mcgrp.id, gfp); | |
10425 | return; | |
10426 | ||
10427 | nla_put_failure: | |
10428 | genlmsg_cancel(msg, hdr); | |
10429 | nlmsg_free(msg); | |
10430 | } | |
947add36 | 10431 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10432 | |
947add36 JB |
10433 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10434 | enum nl80211_connect_failed_reason reason, | |
10435 | gfp_t gfp) | |
ed44a951 | 10436 | { |
947add36 JB |
10437 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10438 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10439 | struct sk_buff *msg; |
10440 | void *hdr; | |
10441 | ||
10442 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10443 | if (!msg) | |
10444 | return; | |
10445 | ||
10446 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10447 | if (!hdr) { | |
10448 | nlmsg_free(msg); | |
10449 | return; | |
10450 | } | |
10451 | ||
10452 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10453 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10454 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10455 | goto nla_put_failure; | |
10456 | ||
10457 | genlmsg_end(msg, hdr); | |
10458 | ||
10459 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10460 | nl80211_mlme_mcgrp.id, gfp); | |
10461 | return; | |
10462 | ||
10463 | nla_put_failure: | |
10464 | genlmsg_cancel(msg, hdr); | |
10465 | nlmsg_free(msg); | |
10466 | } | |
947add36 | 10467 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10468 | |
b92ab5d8 JB |
10469 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10470 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10471 | { |
10472 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10473 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10474 | struct sk_buff *msg; | |
10475 | void *hdr; | |
15e47304 | 10476 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10477 | |
15e47304 | 10478 | if (!nlportid) |
28946da7 JB |
10479 | return false; |
10480 | ||
10481 | msg = nlmsg_new(100, gfp); | |
10482 | if (!msg) | |
10483 | return true; | |
10484 | ||
b92ab5d8 | 10485 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10486 | if (!hdr) { |
10487 | nlmsg_free(msg); | |
10488 | return true; | |
10489 | } | |
10490 | ||
9360ffd1 DM |
10491 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10492 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10494 | goto nla_put_failure; | |
28946da7 | 10495 | |
9c90a9f6 | 10496 | genlmsg_end(msg, hdr); |
15e47304 | 10497 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10498 | return true; |
10499 | ||
10500 | nla_put_failure: | |
10501 | genlmsg_cancel(msg, hdr); | |
10502 | nlmsg_free(msg); | |
10503 | return true; | |
10504 | } | |
10505 | ||
947add36 JB |
10506 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10507 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10508 | { |
947add36 JB |
10509 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10510 | bool ret; | |
10511 | ||
10512 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10513 | ||
10514 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10515 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10516 | trace_cfg80211_return_bool(false); | |
10517 | return false; | |
10518 | } | |
10519 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10520 | addr, gfp); | |
10521 | trace_cfg80211_return_bool(ret); | |
10522 | return ret; | |
b92ab5d8 | 10523 | } |
947add36 | 10524 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10525 | |
947add36 JB |
10526 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10527 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10528 | { |
947add36 JB |
10529 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10530 | bool ret; | |
10531 | ||
10532 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10533 | ||
10534 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10535 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10536 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10537 | trace_cfg80211_return_bool(false); | |
10538 | return false; | |
10539 | } | |
10540 | ret = __nl80211_unexpected_frame(dev, | |
10541 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10542 | addr, gfp); | |
10543 | trace_cfg80211_return_bool(ret); | |
10544 | return ret; | |
b92ab5d8 | 10545 | } |
947add36 | 10546 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10547 | |
2e161f78 | 10548 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10549 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 10550 | int freq, int sig_dbm, |
19504cf5 | 10551 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 10552 | { |
71bbc994 | 10553 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10554 | struct sk_buff *msg; |
10555 | void *hdr; | |
026331c4 JM |
10556 | |
10557 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10558 | if (!msg) | |
10559 | return -ENOMEM; | |
10560 | ||
2e161f78 | 10561 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10562 | if (!hdr) { |
10563 | nlmsg_free(msg); | |
10564 | return -ENOMEM; | |
10565 | } | |
10566 | ||
9360ffd1 | 10567 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10568 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10569 | netdev->ifindex)) || | |
a838490b | 10570 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10571 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10572 | (sig_dbm && | |
10573 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
10574 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10575 | (flags && | |
10576 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 10577 | goto nla_put_failure; |
026331c4 | 10578 | |
3b7b72ee | 10579 | genlmsg_end(msg, hdr); |
026331c4 | 10580 | |
15e47304 | 10581 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10582 | |
10583 | nla_put_failure: | |
10584 | genlmsg_cancel(msg, hdr); | |
10585 | nlmsg_free(msg); | |
10586 | return -ENOBUFS; | |
10587 | } | |
10588 | ||
947add36 JB |
10589 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10590 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10591 | { |
947add36 JB |
10592 | struct wiphy *wiphy = wdev->wiphy; |
10593 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10594 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10595 | struct sk_buff *msg; |
10596 | void *hdr; | |
10597 | ||
947add36 JB |
10598 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10599 | ||
026331c4 JM |
10600 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10601 | if (!msg) | |
10602 | return; | |
10603 | ||
2e161f78 | 10604 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10605 | if (!hdr) { |
10606 | nlmsg_free(msg); | |
10607 | return; | |
10608 | } | |
10609 | ||
9360ffd1 | 10610 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10611 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10612 | netdev->ifindex)) || | |
a838490b | 10613 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10614 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10615 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10616 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10617 | goto nla_put_failure; | |
026331c4 | 10618 | |
3b7b72ee | 10619 | genlmsg_end(msg, hdr); |
026331c4 | 10620 | |
a0ec570f MK |
10621 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10622 | nl80211_mlme_mcgrp.id, gfp); | |
026331c4 JM |
10623 | return; |
10624 | ||
10625 | nla_put_failure: | |
10626 | genlmsg_cancel(msg, hdr); | |
10627 | nlmsg_free(msg); | |
10628 | } | |
947add36 | 10629 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10630 | |
947add36 JB |
10631 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10632 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10633 | gfp_t gfp) | |
d6dc1a38 | 10634 | { |
947add36 JB |
10635 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10636 | struct wiphy *wiphy = wdev->wiphy; | |
10637 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10638 | struct sk_buff *msg; |
10639 | struct nlattr *pinfoattr; | |
10640 | void *hdr; | |
10641 | ||
947add36 JB |
10642 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10643 | ||
58050fce | 10644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10645 | if (!msg) |
10646 | return; | |
10647 | ||
10648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10649 | if (!hdr) { | |
10650 | nlmsg_free(msg); | |
10651 | return; | |
10652 | } | |
10653 | ||
9360ffd1 | 10654 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10655 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10656 | goto nla_put_failure; |
d6dc1a38 JO |
10657 | |
10658 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10659 | if (!pinfoattr) | |
10660 | goto nla_put_failure; | |
10661 | ||
9360ffd1 DM |
10662 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10663 | rssi_event)) | |
10664 | goto nla_put_failure; | |
d6dc1a38 JO |
10665 | |
10666 | nla_nest_end(msg, pinfoattr); | |
10667 | ||
3b7b72ee | 10668 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10669 | |
10670 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10671 | nl80211_mlme_mcgrp.id, gfp); | |
10672 | return; | |
10673 | ||
10674 | nla_put_failure: | |
10675 | genlmsg_cancel(msg, hdr); | |
10676 | nlmsg_free(msg); | |
10677 | } | |
947add36 | 10678 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10679 | |
947add36 JB |
10680 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10681 | struct net_device *netdev, const u8 *bssid, | |
10682 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10683 | { |
10684 | struct sk_buff *msg; | |
10685 | struct nlattr *rekey_attr; | |
10686 | void *hdr; | |
10687 | ||
58050fce | 10688 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10689 | if (!msg) |
10690 | return; | |
10691 | ||
10692 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10693 | if (!hdr) { | |
10694 | nlmsg_free(msg); | |
10695 | return; | |
10696 | } | |
10697 | ||
9360ffd1 DM |
10698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10699 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10700 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10701 | goto nla_put_failure; | |
e5497d76 JB |
10702 | |
10703 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10704 | if (!rekey_attr) | |
10705 | goto nla_put_failure; | |
10706 | ||
9360ffd1 DM |
10707 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10708 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10709 | goto nla_put_failure; | |
e5497d76 JB |
10710 | |
10711 | nla_nest_end(msg, rekey_attr); | |
10712 | ||
3b7b72ee | 10713 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10714 | |
10715 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10716 | nl80211_mlme_mcgrp.id, gfp); | |
10717 | return; | |
10718 | ||
10719 | nla_put_failure: | |
10720 | genlmsg_cancel(msg, hdr); | |
10721 | nlmsg_free(msg); | |
10722 | } | |
10723 | ||
947add36 JB |
10724 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10725 | const u8 *replay_ctr, gfp_t gfp) | |
10726 | { | |
10727 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10728 | struct wiphy *wiphy = wdev->wiphy; | |
10729 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10730 | ||
10731 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10732 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10733 | } | |
10734 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10735 | ||
10736 | static void | |
10737 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10738 | struct net_device *netdev, int index, | |
10739 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10740 | { |
10741 | struct sk_buff *msg; | |
10742 | struct nlattr *attr; | |
10743 | void *hdr; | |
10744 | ||
58050fce | 10745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10746 | if (!msg) |
10747 | return; | |
10748 | ||
10749 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10750 | if (!hdr) { | |
10751 | nlmsg_free(msg); | |
10752 | return; | |
10753 | } | |
10754 | ||
9360ffd1 DM |
10755 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10756 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10757 | goto nla_put_failure; | |
c9df56b4 JM |
10758 | |
10759 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10760 | if (!attr) | |
10761 | goto nla_put_failure; | |
10762 | ||
9360ffd1 DM |
10763 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10764 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10765 | (preauth && | |
10766 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10767 | goto nla_put_failure; | |
c9df56b4 JM |
10768 | |
10769 | nla_nest_end(msg, attr); | |
10770 | ||
3b7b72ee | 10771 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10772 | |
10773 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10774 | nl80211_mlme_mcgrp.id, gfp); | |
10775 | return; | |
10776 | ||
10777 | nla_put_failure: | |
10778 | genlmsg_cancel(msg, hdr); | |
10779 | nlmsg_free(msg); | |
10780 | } | |
10781 | ||
947add36 JB |
10782 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10783 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10784 | { | |
10785 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10786 | struct wiphy *wiphy = wdev->wiphy; | |
10787 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10788 | ||
10789 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10790 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10791 | } | |
10792 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10793 | ||
10794 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10795 | struct net_device *netdev, | |
10796 | struct cfg80211_chan_def *chandef, | |
10797 | gfp_t gfp) | |
5314526b TP |
10798 | { |
10799 | struct sk_buff *msg; | |
10800 | void *hdr; | |
10801 | ||
58050fce | 10802 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10803 | if (!msg) |
10804 | return; | |
10805 | ||
10806 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10807 | if (!hdr) { | |
10808 | nlmsg_free(msg); | |
10809 | return; | |
10810 | } | |
10811 | ||
683b6d3b JB |
10812 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10813 | goto nla_put_failure; | |
10814 | ||
10815 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10816 | goto nla_put_failure; |
5314526b TP |
10817 | |
10818 | genlmsg_end(msg, hdr); | |
10819 | ||
10820 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10821 | nl80211_mlme_mcgrp.id, gfp); | |
10822 | return; | |
10823 | ||
10824 | nla_put_failure: | |
10825 | genlmsg_cancel(msg, hdr); | |
10826 | nlmsg_free(msg); | |
10827 | } | |
10828 | ||
947add36 JB |
10829 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10830 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10831 | { |
947add36 JB |
10832 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10833 | struct wiphy *wiphy = wdev->wiphy; | |
10834 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10835 | ||
e487eaeb | 10836 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 10837 | |
e487eaeb | 10838 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
10839 | |
10840 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 10841 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
10842 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
10843 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 10844 | return; |
947add36 JB |
10845 | |
10846 | wdev->channel = chandef->chan; | |
10847 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
947add36 JB |
10848 | } |
10849 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10850 | ||
10851 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10852 | const u8 *peer, u32 num_packets, | |
10853 | u32 rate, u32 intvl, gfp_t gfp) | |
10854 | { | |
10855 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10856 | struct wiphy *wiphy = wdev->wiphy; | |
10857 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10858 | struct sk_buff *msg; |
10859 | struct nlattr *pinfoattr; | |
10860 | void *hdr; | |
10861 | ||
10862 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10863 | if (!msg) | |
10864 | return; | |
10865 | ||
10866 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10867 | if (!hdr) { | |
10868 | nlmsg_free(msg); | |
10869 | return; | |
10870 | } | |
10871 | ||
10872 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10873 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10874 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10875 | goto nla_put_failure; | |
10876 | ||
10877 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10878 | if (!pinfoattr) | |
10879 | goto nla_put_failure; | |
10880 | ||
10881 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10882 | goto nla_put_failure; | |
10883 | ||
10884 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10885 | goto nla_put_failure; | |
10886 | ||
10887 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10888 | goto nla_put_failure; | |
10889 | ||
10890 | nla_nest_end(msg, pinfoattr); | |
10891 | ||
10892 | genlmsg_end(msg, hdr); | |
10893 | ||
10894 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10895 | nl80211_mlme_mcgrp.id, gfp); | |
10896 | return; | |
10897 | ||
10898 | nla_put_failure: | |
10899 | genlmsg_cancel(msg, hdr); | |
10900 | nlmsg_free(msg); | |
10901 | } | |
947add36 | 10902 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10903 | |
04f39047 SW |
10904 | void |
10905 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 10906 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
10907 | enum nl80211_radar_event event, |
10908 | struct net_device *netdev, gfp_t gfp) | |
10909 | { | |
10910 | struct sk_buff *msg; | |
10911 | void *hdr; | |
10912 | ||
10913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10914 | if (!msg) | |
10915 | return; | |
10916 | ||
10917 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10918 | if (!hdr) { | |
10919 | nlmsg_free(msg); | |
10920 | return; | |
10921 | } | |
10922 | ||
10923 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10924 | goto nla_put_failure; | |
10925 | ||
10926 | /* NOP and radar events don't need a netdev parameter */ | |
10927 | if (netdev) { | |
10928 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10929 | ||
10930 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10931 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10932 | goto nla_put_failure; | |
10933 | } | |
10934 | ||
10935 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10936 | goto nla_put_failure; | |
10937 | ||
10938 | if (nl80211_send_chandef(msg, chandef)) | |
10939 | goto nla_put_failure; | |
10940 | ||
9c90a9f6 | 10941 | genlmsg_end(msg, hdr); |
04f39047 SW |
10942 | |
10943 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10944 | nl80211_mlme_mcgrp.id, gfp); | |
10945 | return; | |
10946 | ||
10947 | nla_put_failure: | |
10948 | genlmsg_cancel(msg, hdr); | |
10949 | nlmsg_free(msg); | |
10950 | } | |
10951 | ||
947add36 JB |
10952 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10953 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10954 | { |
947add36 JB |
10955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10956 | struct wiphy *wiphy = wdev->wiphy; | |
10957 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10958 | struct sk_buff *msg; |
10959 | struct nlattr *pinfoattr; | |
10960 | void *hdr; | |
10961 | ||
947add36 JB |
10962 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10963 | ||
58050fce | 10964 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10965 | if (!msg) |
10966 | return; | |
10967 | ||
10968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10969 | if (!hdr) { | |
10970 | nlmsg_free(msg); | |
10971 | return; | |
10972 | } | |
10973 | ||
9360ffd1 | 10974 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10975 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10976 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10977 | goto nla_put_failure; | |
c063dbf5 JB |
10978 | |
10979 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10980 | if (!pinfoattr) | |
10981 | goto nla_put_failure; | |
10982 | ||
9360ffd1 DM |
10983 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10984 | goto nla_put_failure; | |
c063dbf5 JB |
10985 | |
10986 | nla_nest_end(msg, pinfoattr); | |
10987 | ||
3b7b72ee | 10988 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10989 | |
10990 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10991 | nl80211_mlme_mcgrp.id, gfp); | |
10992 | return; | |
10993 | ||
10994 | nla_put_failure: | |
10995 | genlmsg_cancel(msg, hdr); | |
10996 | nlmsg_free(msg); | |
10997 | } | |
947add36 | 10998 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10999 | |
7f6cf311 JB |
11000 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11001 | u64 cookie, bool acked, gfp_t gfp) | |
11002 | { | |
11003 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11004 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11005 | struct sk_buff *msg; | |
11006 | void *hdr; | |
7f6cf311 | 11007 | |
4ee3e063 BL |
11008 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11009 | ||
58050fce | 11010 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11011 | |
7f6cf311 JB |
11012 | if (!msg) |
11013 | return; | |
11014 | ||
11015 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11016 | if (!hdr) { | |
11017 | nlmsg_free(msg); | |
11018 | return; | |
11019 | } | |
11020 | ||
9360ffd1 DM |
11021 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11022 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11023 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11024 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11025 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11026 | goto nla_put_failure; | |
7f6cf311 | 11027 | |
9c90a9f6 | 11028 | genlmsg_end(msg, hdr); |
7f6cf311 JB |
11029 | |
11030 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11031 | nl80211_mlme_mcgrp.id, gfp); | |
11032 | return; | |
11033 | ||
11034 | nla_put_failure: | |
11035 | genlmsg_cancel(msg, hdr); | |
11036 | nlmsg_free(msg); | |
11037 | } | |
11038 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11039 | ||
5e760230 JB |
11040 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11041 | const u8 *frame, size_t len, | |
37c73b5f | 11042 | int freq, int sig_dbm) |
5e760230 JB |
11043 | { |
11044 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11045 | struct sk_buff *msg; | |
11046 | void *hdr; | |
37c73b5f | 11047 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11048 | |
4ee3e063 BL |
11049 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11050 | ||
37c73b5f BG |
11051 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11052 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11053 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11054 | if (!msg) { | |
11055 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11056 | return; | |
11057 | } | |
5e760230 | 11058 | |
37c73b5f BG |
11059 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11060 | if (!hdr) | |
11061 | goto nla_put_failure; | |
5e760230 | 11062 | |
37c73b5f BG |
11063 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11064 | (freq && | |
11065 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11066 | (sig_dbm && | |
11067 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11068 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11069 | goto nla_put_failure; | |
5e760230 | 11070 | |
37c73b5f | 11071 | genlmsg_end(msg, hdr); |
5e760230 | 11072 | |
37c73b5f BG |
11073 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11074 | } | |
11075 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11076 | return; |
11077 | ||
11078 | nla_put_failure: | |
37c73b5f BG |
11079 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11080 | if (hdr) | |
11081 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11082 | nlmsg_free(msg); |
11083 | } | |
11084 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11085 | ||
cd8f7cb4 JB |
11086 | #ifdef CONFIG_PM |
11087 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11088 | struct cfg80211_wowlan_wakeup *wakeup, | |
11089 | gfp_t gfp) | |
11090 | { | |
11091 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11092 | struct sk_buff *msg; | |
11093 | void *hdr; | |
9c90a9f6 | 11094 | int size = 200; |
cd8f7cb4 JB |
11095 | |
11096 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11097 | ||
11098 | if (wakeup) | |
11099 | size += wakeup->packet_present_len; | |
11100 | ||
11101 | msg = nlmsg_new(size, gfp); | |
11102 | if (!msg) | |
11103 | return; | |
11104 | ||
11105 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11106 | if (!hdr) | |
11107 | goto free_msg; | |
11108 | ||
11109 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11110 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11111 | goto free_msg; | |
11112 | ||
11113 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11114 | wdev->netdev->ifindex)) | |
11115 | goto free_msg; | |
11116 | ||
11117 | if (wakeup) { | |
11118 | struct nlattr *reasons; | |
11119 | ||
11120 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
11121 | ||
11122 | if (wakeup->disconnect && | |
11123 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11124 | goto free_msg; | |
11125 | if (wakeup->magic_pkt && | |
11126 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11127 | goto free_msg; | |
11128 | if (wakeup->gtk_rekey_failure && | |
11129 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11130 | goto free_msg; | |
11131 | if (wakeup->eap_identity_req && | |
11132 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11133 | goto free_msg; | |
11134 | if (wakeup->four_way_handshake && | |
11135 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11136 | goto free_msg; | |
11137 | if (wakeup->rfkill_release && | |
11138 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11139 | goto free_msg; | |
11140 | ||
11141 | if (wakeup->pattern_idx >= 0 && | |
11142 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11143 | wakeup->pattern_idx)) | |
11144 | goto free_msg; | |
11145 | ||
2a0e047e JB |
11146 | if (wakeup->tcp_match) |
11147 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
11148 | ||
11149 | if (wakeup->tcp_connlost) | |
11150 | nla_put_flag(msg, | |
11151 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
11152 | ||
11153 | if (wakeup->tcp_nomoretokens) | |
11154 | nla_put_flag(msg, | |
11155 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
11156 | ||
cd8f7cb4 JB |
11157 | if (wakeup->packet) { |
11158 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11159 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11160 | ||
11161 | if (!wakeup->packet_80211) { | |
11162 | pkt_attr = | |
11163 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11164 | len_attr = | |
11165 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11166 | } | |
11167 | ||
11168 | if (wakeup->packet_len && | |
11169 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11170 | goto free_msg; | |
11171 | ||
11172 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11173 | wakeup->packet)) | |
11174 | goto free_msg; | |
11175 | } | |
11176 | ||
11177 | nla_nest_end(msg, reasons); | |
11178 | } | |
11179 | ||
9c90a9f6 | 11180 | genlmsg_end(msg, hdr); |
cd8f7cb4 JB |
11181 | |
11182 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11183 | nl80211_mlme_mcgrp.id, gfp); | |
11184 | return; | |
11185 | ||
11186 | free_msg: | |
11187 | nlmsg_free(msg); | |
11188 | } | |
11189 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11190 | #endif | |
11191 | ||
3475b094 JM |
11192 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11193 | enum nl80211_tdls_operation oper, | |
11194 | u16 reason_code, gfp_t gfp) | |
11195 | { | |
11196 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11197 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11198 | struct sk_buff *msg; | |
11199 | void *hdr; | |
3475b094 JM |
11200 | |
11201 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11202 | reason_code); | |
11203 | ||
11204 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11205 | if (!msg) | |
11206 | return; | |
11207 | ||
11208 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11209 | if (!hdr) { | |
11210 | nlmsg_free(msg); | |
11211 | return; | |
11212 | } | |
11213 | ||
11214 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11215 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11216 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11217 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11218 | (reason_code > 0 && | |
11219 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11220 | goto nla_put_failure; | |
11221 | ||
9c90a9f6 | 11222 | genlmsg_end(msg, hdr); |
3475b094 JM |
11223 | |
11224 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11225 | nl80211_mlme_mcgrp.id, gfp); | |
11226 | return; | |
11227 | ||
11228 | nla_put_failure: | |
11229 | genlmsg_cancel(msg, hdr); | |
11230 | nlmsg_free(msg); | |
11231 | } | |
11232 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11233 | ||
026331c4 JM |
11234 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11235 | unsigned long state, | |
11236 | void *_notify) | |
11237 | { | |
11238 | struct netlink_notify *notify = _notify; | |
11239 | struct cfg80211_registered_device *rdev; | |
11240 | struct wireless_dev *wdev; | |
37c73b5f | 11241 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11242 | |
11243 | if (state != NETLINK_URELEASE) | |
11244 | return NOTIFY_DONE; | |
11245 | ||
11246 | rcu_read_lock(); | |
11247 | ||
5e760230 | 11248 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 11249 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 11250 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
11251 | |
11252 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11253 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11254 | list) { | |
11255 | if (reg->nlportid == notify->portid) { | |
11256 | list_del(®->list); | |
11257 | kfree(reg); | |
11258 | break; | |
11259 | } | |
11260 | } | |
11261 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 11262 | } |
026331c4 JM |
11263 | |
11264 | rcu_read_unlock(); | |
11265 | ||
11266 | return NOTIFY_DONE; | |
11267 | } | |
11268 | ||
11269 | static struct notifier_block nl80211_netlink_notifier = { | |
11270 | .notifier_call = nl80211_netlink_notify, | |
11271 | }; | |
11272 | ||
355199e0 JM |
11273 | void cfg80211_ft_event(struct net_device *netdev, |
11274 | struct cfg80211_ft_event_params *ft_event) | |
11275 | { | |
11276 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
11277 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11278 | struct sk_buff *msg; | |
11279 | void *hdr; | |
355199e0 JM |
11280 | |
11281 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11282 | ||
11283 | if (!ft_event->target_ap) | |
11284 | return; | |
11285 | ||
11286 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11287 | if (!msg) | |
11288 | return; | |
11289 | ||
11290 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
11291 | if (!hdr) { | |
11292 | nlmsg_free(msg); | |
11293 | return; | |
11294 | } | |
11295 | ||
11296 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
11297 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
11298 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
11299 | if (ft_event->ies) | |
11300 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
11301 | if (ft_event->ric_ies) | |
11302 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11303 | ft_event->ric_ies); | |
11304 | ||
9c90a9f6 | 11305 | genlmsg_end(msg, hdr); |
355199e0 JM |
11306 | |
11307 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11308 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
11309 | } | |
11310 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11311 | ||
5de17984 AS |
11312 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11313 | { | |
11314 | struct cfg80211_registered_device *rdev; | |
11315 | struct sk_buff *msg; | |
11316 | void *hdr; | |
11317 | u32 nlportid; | |
11318 | ||
11319 | rdev = wiphy_to_dev(wdev->wiphy); | |
11320 | if (!rdev->crit_proto_nlportid) | |
11321 | return; | |
11322 | ||
11323 | nlportid = rdev->crit_proto_nlportid; | |
11324 | rdev->crit_proto_nlportid = 0; | |
11325 | ||
11326 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11327 | if (!msg) | |
11328 | return; | |
11329 | ||
11330 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11331 | if (!hdr) | |
11332 | goto nla_put_failure; | |
11333 | ||
11334 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11335 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11336 | goto nla_put_failure; | |
11337 | ||
11338 | genlmsg_end(msg, hdr); | |
11339 | ||
11340 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11341 | return; | |
11342 | ||
11343 | nla_put_failure: | |
11344 | if (hdr) | |
11345 | genlmsg_cancel(msg, hdr); | |
11346 | nlmsg_free(msg); | |
11347 | ||
11348 | } | |
11349 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11350 | ||
55682965 JB |
11351 | /* initialisation/exit functions */ |
11352 | ||
11353 | int nl80211_init(void) | |
11354 | { | |
0d63cbb5 | 11355 | int err; |
55682965 | 11356 | |
0d63cbb5 MM |
11357 | err = genl_register_family_with_ops(&nl80211_fam, |
11358 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
11359 | if (err) |
11360 | return err; | |
11361 | ||
55682965 JB |
11362 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
11363 | if (err) | |
11364 | goto err_out; | |
11365 | ||
2a519311 JB |
11366 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
11367 | if (err) | |
11368 | goto err_out; | |
11369 | ||
73d54c9e LR |
11370 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
11371 | if (err) | |
11372 | goto err_out; | |
11373 | ||
6039f6d2 JM |
11374 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
11375 | if (err) | |
11376 | goto err_out; | |
11377 | ||
aff89a9b JB |
11378 | #ifdef CONFIG_NL80211_TESTMODE |
11379 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
11380 | if (err) | |
11381 | goto err_out; | |
11382 | #endif | |
11383 | ||
026331c4 JM |
11384 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11385 | if (err) | |
11386 | goto err_out; | |
11387 | ||
55682965 JB |
11388 | return 0; |
11389 | err_out: | |
11390 | genl_unregister_family(&nl80211_fam); | |
11391 | return err; | |
11392 | } | |
11393 | ||
11394 | void nl80211_exit(void) | |
11395 | { | |
026331c4 | 11396 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11397 | genl_unregister_family(&nl80211_fam); |
11398 | } |