]>
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 }, |
55682965 JB |
352 | }; |
353 | ||
e31b8213 | 354 | /* policy for the key attributes */ |
b54452b0 | 355 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 356 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
357 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
358 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 359 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
360 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
361 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 362 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
363 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
364 | }; | |
365 | ||
366 | /* policy for the key default flags */ | |
367 | static const struct nla_policy | |
368 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
369 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
370 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
371 | }; |
372 | ||
ff1b6e69 JB |
373 | /* policy for WoWLAN attributes */ |
374 | static const struct nla_policy | |
375 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
376 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
377 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
378 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
379 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
380 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
381 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
382 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
383 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
384 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
385 | }; | |
386 | ||
387 | static const struct nla_policy | |
388 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
389 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
390 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
391 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
392 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
393 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
394 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
395 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
396 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
397 | }, | |
398 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
399 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
400 | }, | |
401 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
402 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
403 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
404 | }; |
405 | ||
be29b99a AK |
406 | /* policy for coalesce rule attributes */ |
407 | static const struct nla_policy | |
408 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
409 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
410 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
411 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
412 | }; | |
413 | ||
e5497d76 JB |
414 | /* policy for GTK rekey offload attributes */ |
415 | static const struct nla_policy | |
416 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
417 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
418 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
419 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
420 | }; | |
421 | ||
a1f1c21c LC |
422 | static const struct nla_policy |
423 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 424 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 425 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 426 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
427 | }; |
428 | ||
97990a06 JB |
429 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
430 | struct netlink_callback *cb, | |
431 | struct cfg80211_registered_device **rdev, | |
432 | struct wireless_dev **wdev) | |
a043897a | 433 | { |
97990a06 | 434 | int err; |
a043897a | 435 | |
97990a06 | 436 | rtnl_lock(); |
a043897a | 437 | |
97990a06 JB |
438 | if (!cb->args[0]) { |
439 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
440 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
441 | nl80211_policy); | |
442 | if (err) | |
443 | goto out_unlock; | |
67748893 | 444 | |
97990a06 JB |
445 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
446 | nl80211_fam.attrbuf); | |
447 | if (IS_ERR(*wdev)) { | |
448 | err = PTR_ERR(*wdev); | |
449 | goto out_unlock; | |
450 | } | |
451 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
452 | cb->args[0] = (*rdev)->wiphy_idx; | |
453 | cb->args[1] = (*wdev)->identifier; | |
454 | } else { | |
455 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); | |
456 | struct wireless_dev *tmp; | |
67748893 | 457 | |
97990a06 JB |
458 | if (!wiphy) { |
459 | err = -ENODEV; | |
460 | goto out_unlock; | |
461 | } | |
462 | *rdev = wiphy_to_dev(wiphy); | |
463 | *wdev = NULL; | |
67748893 | 464 | |
97990a06 JB |
465 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
466 | if (tmp->identifier == cb->args[1]) { | |
467 | *wdev = tmp; | |
468 | break; | |
469 | } | |
470 | } | |
67748893 | 471 | |
97990a06 JB |
472 | if (!*wdev) { |
473 | err = -ENODEV; | |
474 | goto out_unlock; | |
475 | } | |
67748893 JB |
476 | } |
477 | ||
67748893 | 478 | return 0; |
97990a06 | 479 | out_unlock: |
67748893 JB |
480 | rtnl_unlock(); |
481 | return err; | |
482 | } | |
483 | ||
97990a06 | 484 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 485 | { |
67748893 JB |
486 | rtnl_unlock(); |
487 | } | |
488 | ||
f4a11bb0 JB |
489 | /* IE validation */ |
490 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
491 | { | |
492 | const u8 *pos; | |
493 | int len; | |
494 | ||
495 | if (!attr) | |
496 | return true; | |
497 | ||
498 | pos = nla_data(attr); | |
499 | len = nla_len(attr); | |
500 | ||
501 | while (len) { | |
502 | u8 elemlen; | |
503 | ||
504 | if (len < 2) | |
505 | return false; | |
506 | len -= 2; | |
507 | ||
508 | elemlen = pos[1]; | |
509 | if (elemlen > len) | |
510 | return false; | |
511 | ||
512 | len -= elemlen; | |
513 | pos += 2 + elemlen; | |
514 | } | |
515 | ||
516 | return true; | |
517 | } | |
518 | ||
55682965 | 519 | /* message building helper */ |
15e47304 | 520 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
521 | int flags, u8 cmd) |
522 | { | |
523 | /* since there is no private header just add the generic one */ | |
15e47304 | 524 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
525 | } |
526 | ||
5dab3b8a | 527 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
528 | struct ieee80211_channel *chan, |
529 | bool large) | |
5dab3b8a | 530 | { |
9360ffd1 DM |
531 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
532 | chan->center_freq)) | |
533 | goto nla_put_failure; | |
5dab3b8a | 534 | |
9360ffd1 DM |
535 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
536 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
537 | goto nla_put_failure; | |
538 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
539 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
540 | goto nla_put_failure; | |
541 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
542 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
543 | goto nla_put_failure; | |
cdc89b97 JB |
544 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
545 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
546 | goto nla_put_failure; | |
547 | if (large) { | |
548 | u32 time; | |
549 | ||
550 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
551 | ||
552 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
553 | chan->dfs_state)) | |
554 | goto nla_put_failure; | |
555 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
556 | time)) | |
557 | goto nla_put_failure; | |
558 | } | |
559 | } | |
5dab3b8a | 560 | |
fe1abafd JB |
561 | if (large) { |
562 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
563 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
564 | goto nla_put_failure; | |
565 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
566 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
567 | goto nla_put_failure; | |
568 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
569 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
570 | goto nla_put_failure; | |
571 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
572 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
573 | goto nla_put_failure; | |
574 | } | |
575 | ||
9360ffd1 DM |
576 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
577 | DBM_TO_MBM(chan->max_power))) | |
578 | goto nla_put_failure; | |
5dab3b8a LR |
579 | |
580 | return 0; | |
581 | ||
582 | nla_put_failure: | |
583 | return -ENOBUFS; | |
584 | } | |
585 | ||
55682965 JB |
586 | /* netlink command implementations */ |
587 | ||
b9454e83 JB |
588 | struct key_parse { |
589 | struct key_params p; | |
590 | int idx; | |
e31b8213 | 591 | int type; |
b9454e83 | 592 | bool def, defmgmt; |
dbd2fd65 | 593 | bool def_uni, def_multi; |
b9454e83 JB |
594 | }; |
595 | ||
596 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
597 | { | |
598 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
599 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
600 | nl80211_key_policy); | |
601 | if (err) | |
602 | return err; | |
603 | ||
604 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
605 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
606 | ||
dbd2fd65 JB |
607 | if (k->def) { |
608 | k->def_uni = true; | |
609 | k->def_multi = true; | |
610 | } | |
611 | if (k->defmgmt) | |
612 | k->def_multi = true; | |
613 | ||
b9454e83 JB |
614 | if (tb[NL80211_KEY_IDX]) |
615 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
616 | ||
617 | if (tb[NL80211_KEY_DATA]) { | |
618 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
619 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
620 | } | |
621 | ||
622 | if (tb[NL80211_KEY_SEQ]) { | |
623 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
624 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
625 | } | |
626 | ||
627 | if (tb[NL80211_KEY_CIPHER]) | |
628 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
629 | ||
e31b8213 JB |
630 | if (tb[NL80211_KEY_TYPE]) { |
631 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
632 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
633 | return -EINVAL; | |
634 | } | |
635 | ||
dbd2fd65 JB |
636 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
637 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
638 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
639 | tb[NL80211_KEY_DEFAULT_TYPES], | |
640 | nl80211_key_default_policy); | |
dbd2fd65 JB |
641 | if (err) |
642 | return err; | |
643 | ||
644 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
645 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
646 | } | |
647 | ||
b9454e83 JB |
648 | return 0; |
649 | } | |
650 | ||
651 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
652 | { | |
653 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
654 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
655 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
656 | } | |
657 | ||
658 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
659 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
660 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
661 | } | |
662 | ||
663 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
664 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
665 | ||
666 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
667 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
668 | ||
669 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
670 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
671 | ||
dbd2fd65 JB |
672 | if (k->def) { |
673 | k->def_uni = true; | |
674 | k->def_multi = true; | |
675 | } | |
676 | if (k->defmgmt) | |
677 | k->def_multi = true; | |
678 | ||
e31b8213 JB |
679 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
680 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
681 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
682 | return -EINVAL; | |
683 | } | |
684 | ||
dbd2fd65 JB |
685 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
686 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
687 | int err = nla_parse_nested( | |
688 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
689 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
690 | nl80211_key_default_policy); | |
691 | if (err) | |
692 | return err; | |
693 | ||
694 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
695 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
696 | } | |
697 | ||
b9454e83 JB |
698 | return 0; |
699 | } | |
700 | ||
701 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
702 | { | |
703 | int err; | |
704 | ||
705 | memset(k, 0, sizeof(*k)); | |
706 | k->idx = -1; | |
e31b8213 | 707 | k->type = -1; |
b9454e83 JB |
708 | |
709 | if (info->attrs[NL80211_ATTR_KEY]) | |
710 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
711 | else | |
712 | err = nl80211_parse_key_old(info, k); | |
713 | ||
714 | if (err) | |
715 | return err; | |
716 | ||
717 | if (k->def && k->defmgmt) | |
718 | return -EINVAL; | |
719 | ||
dbd2fd65 JB |
720 | if (k->defmgmt) { |
721 | if (k->def_uni || !k->def_multi) | |
722 | return -EINVAL; | |
723 | } | |
724 | ||
b9454e83 JB |
725 | if (k->idx != -1) { |
726 | if (k->defmgmt) { | |
727 | if (k->idx < 4 || k->idx > 5) | |
728 | return -EINVAL; | |
729 | } else if (k->def) { | |
730 | if (k->idx < 0 || k->idx > 3) | |
731 | return -EINVAL; | |
732 | } else { | |
733 | if (k->idx < 0 || k->idx > 5) | |
734 | return -EINVAL; | |
735 | } | |
736 | } | |
737 | ||
738 | return 0; | |
739 | } | |
740 | ||
fffd0934 JB |
741 | static struct cfg80211_cached_keys * |
742 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 743 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
744 | { |
745 | struct key_parse parse; | |
746 | struct nlattr *key; | |
747 | struct cfg80211_cached_keys *result; | |
748 | int rem, err, def = 0; | |
749 | ||
750 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
751 | if (!result) | |
752 | return ERR_PTR(-ENOMEM); | |
753 | ||
754 | result->def = -1; | |
755 | result->defmgmt = -1; | |
756 | ||
757 | nla_for_each_nested(key, keys, rem) { | |
758 | memset(&parse, 0, sizeof(parse)); | |
759 | parse.idx = -1; | |
760 | ||
761 | err = nl80211_parse_key_new(key, &parse); | |
762 | if (err) | |
763 | goto error; | |
764 | err = -EINVAL; | |
765 | if (!parse.p.key) | |
766 | goto error; | |
767 | if (parse.idx < 0 || parse.idx > 4) | |
768 | goto error; | |
769 | if (parse.def) { | |
770 | if (def) | |
771 | goto error; | |
772 | def = 1; | |
773 | result->def = parse.idx; | |
dbd2fd65 JB |
774 | if (!parse.def_uni || !parse.def_multi) |
775 | goto error; | |
fffd0934 JB |
776 | } else if (parse.defmgmt) |
777 | goto error; | |
778 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 779 | parse.idx, false, NULL); |
fffd0934 JB |
780 | if (err) |
781 | goto error; | |
782 | result->params[parse.idx].cipher = parse.p.cipher; | |
783 | result->params[parse.idx].key_len = parse.p.key_len; | |
784 | result->params[parse.idx].key = result->data[parse.idx]; | |
785 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
786 | |
787 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
788 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
789 | if (no_ht) | |
790 | *no_ht = true; | |
791 | } | |
fffd0934 JB |
792 | } |
793 | ||
794 | return result; | |
795 | error: | |
796 | kfree(result); | |
797 | return ERR_PTR(err); | |
798 | } | |
799 | ||
800 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
801 | { | |
802 | ASSERT_WDEV_LOCK(wdev); | |
803 | ||
fffd0934 JB |
804 | switch (wdev->iftype) { |
805 | case NL80211_IFTYPE_AP: | |
806 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 807 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 808 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
809 | break; |
810 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 811 | case NL80211_IFTYPE_STATION: |
074ac8df | 812 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 813 | if (!wdev->current_bss) |
fffd0934 JB |
814 | return -ENOLINK; |
815 | break; | |
816 | default: | |
817 | return -EINVAL; | |
818 | } | |
819 | ||
820 | return 0; | |
821 | } | |
822 | ||
7527a782 JB |
823 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
824 | { | |
825 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
826 | int i; | |
827 | ||
828 | if (!nl_modes) | |
829 | goto nla_put_failure; | |
830 | ||
831 | i = 0; | |
832 | while (ifmodes) { | |
9360ffd1 DM |
833 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
834 | goto nla_put_failure; | |
7527a782 JB |
835 | ifmodes >>= 1; |
836 | i++; | |
837 | } | |
838 | ||
839 | nla_nest_end(msg, nl_modes); | |
840 | return 0; | |
841 | ||
842 | nla_put_failure: | |
843 | return -ENOBUFS; | |
844 | } | |
845 | ||
846 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
847 | struct sk_buff *msg, |
848 | bool large) | |
7527a782 JB |
849 | { |
850 | struct nlattr *nl_combis; | |
851 | int i, j; | |
852 | ||
853 | nl_combis = nla_nest_start(msg, | |
854 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
855 | if (!nl_combis) | |
856 | goto nla_put_failure; | |
857 | ||
858 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
859 | const struct ieee80211_iface_combination *c; | |
860 | struct nlattr *nl_combi, *nl_limits; | |
861 | ||
862 | c = &wiphy->iface_combinations[i]; | |
863 | ||
864 | nl_combi = nla_nest_start(msg, i + 1); | |
865 | if (!nl_combi) | |
866 | goto nla_put_failure; | |
867 | ||
868 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
869 | if (!nl_limits) | |
870 | goto nla_put_failure; | |
871 | ||
872 | for (j = 0; j < c->n_limits; j++) { | |
873 | struct nlattr *nl_limit; | |
874 | ||
875 | nl_limit = nla_nest_start(msg, j + 1); | |
876 | if (!nl_limit) | |
877 | goto nla_put_failure; | |
9360ffd1 DM |
878 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
879 | c->limits[j].max)) | |
880 | goto nla_put_failure; | |
7527a782 JB |
881 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
882 | c->limits[j].types)) | |
883 | goto nla_put_failure; | |
884 | nla_nest_end(msg, nl_limit); | |
885 | } | |
886 | ||
887 | nla_nest_end(msg, nl_limits); | |
888 | ||
9360ffd1 DM |
889 | if (c->beacon_int_infra_match && |
890 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
891 | goto nla_put_failure; | |
892 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
893 | c->num_different_channels) || | |
894 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
895 | c->max_interfaces)) | |
896 | goto nla_put_failure; | |
cdc89b97 JB |
897 | if (large && |
898 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
899 | c->radar_detect_widths)) | |
900 | goto nla_put_failure; | |
7527a782 JB |
901 | |
902 | nla_nest_end(msg, nl_combi); | |
903 | } | |
904 | ||
905 | nla_nest_end(msg, nl_combis); | |
906 | ||
907 | return 0; | |
908 | nla_put_failure: | |
909 | return -ENOBUFS; | |
910 | } | |
911 | ||
3713b4e3 | 912 | #ifdef CONFIG_PM |
b56cf720 JB |
913 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
914 | struct sk_buff *msg) | |
915 | { | |
964dc9e2 | 916 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
917 | struct nlattr *nl_tcp; |
918 | ||
919 | if (!tcp) | |
920 | return 0; | |
921 | ||
922 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
923 | if (!nl_tcp) | |
924 | return -ENOBUFS; | |
925 | ||
926 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
927 | tcp->data_payload_max)) | |
928 | return -ENOBUFS; | |
929 | ||
930 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
931 | tcp->data_payload_max)) | |
932 | return -ENOBUFS; | |
933 | ||
934 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
935 | return -ENOBUFS; | |
936 | ||
937 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
938 | sizeof(*tcp->tok), tcp->tok)) | |
939 | return -ENOBUFS; | |
940 | ||
941 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
942 | tcp->data_interval_max)) | |
943 | return -ENOBUFS; | |
944 | ||
945 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
946 | tcp->wake_payload_max)) | |
947 | return -ENOBUFS; | |
948 | ||
949 | nla_nest_end(msg, nl_tcp); | |
950 | return 0; | |
951 | } | |
952 | ||
3713b4e3 | 953 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
954 | struct cfg80211_registered_device *dev, |
955 | bool large) | |
55682965 | 956 | { |
3713b4e3 | 957 | struct nlattr *nl_wowlan; |
55682965 | 958 | |
964dc9e2 | 959 | if (!dev->wiphy.wowlan) |
3713b4e3 | 960 | return 0; |
55682965 | 961 | |
3713b4e3 JB |
962 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
963 | if (!nl_wowlan) | |
964 | return -ENOBUFS; | |
9360ffd1 | 965 | |
964dc9e2 | 966 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
964dc9e2 | 968 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
964dc9e2 | 970 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
964dc9e2 | 972 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 973 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
964dc9e2 | 974 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 975 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
964dc9e2 | 976 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 977 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
964dc9e2 | 978 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 979 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
964dc9e2 | 980 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
981 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
982 | return -ENOBUFS; | |
9360ffd1 | 983 | |
964dc9e2 | 984 | if (dev->wiphy.wowlan->n_patterns) { |
50ac6607 | 985 | struct nl80211_pattern_support pat = { |
964dc9e2 JB |
986 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
987 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, | |
988 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, | |
989 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 990 | }; |
9360ffd1 | 991 | |
3713b4e3 JB |
992 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
993 | sizeof(pat), &pat)) | |
994 | return -ENOBUFS; | |
995 | } | |
9360ffd1 | 996 | |
b56cf720 JB |
997 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
998 | return -ENOBUFS; | |
999 | ||
3713b4e3 | 1000 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1001 | |
3713b4e3 JB |
1002 | return 0; |
1003 | } | |
1004 | #endif | |
9360ffd1 | 1005 | |
be29b99a AK |
1006 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1007 | struct cfg80211_registered_device *dev) | |
1008 | { | |
1009 | struct nl80211_coalesce_rule_support rule; | |
1010 | ||
1011 | if (!dev->wiphy.coalesce) | |
1012 | return 0; | |
1013 | ||
1014 | rule.max_rules = dev->wiphy.coalesce->n_rules; | |
1015 | rule.max_delay = dev->wiphy.coalesce->max_delay; | |
1016 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; | |
1017 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; | |
1018 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; | |
1019 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; | |
1020 | ||
1021 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1022 | return -ENOBUFS; | |
1023 | ||
1024 | return 0; | |
1025 | } | |
1026 | ||
3713b4e3 JB |
1027 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1028 | struct ieee80211_supported_band *sband) | |
1029 | { | |
1030 | struct nlattr *nl_rates, *nl_rate; | |
1031 | struct ieee80211_rate *rate; | |
1032 | int i; | |
87bbbe22 | 1033 | |
3713b4e3 JB |
1034 | /* add HT info */ |
1035 | if (sband->ht_cap.ht_supported && | |
1036 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1037 | sizeof(sband->ht_cap.mcs), | |
1038 | &sband->ht_cap.mcs) || | |
1039 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1040 | sband->ht_cap.cap) || | |
1041 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1042 | sband->ht_cap.ampdu_factor) || | |
1043 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1044 | sband->ht_cap.ampdu_density))) | |
1045 | return -ENOBUFS; | |
afe0cbf8 | 1046 | |
3713b4e3 JB |
1047 | /* add VHT info */ |
1048 | if (sband->vht_cap.vht_supported && | |
1049 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1050 | sizeof(sband->vht_cap.vht_mcs), | |
1051 | &sband->vht_cap.vht_mcs) || | |
1052 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1053 | sband->vht_cap.cap))) | |
1054 | return -ENOBUFS; | |
f59ac048 | 1055 | |
3713b4e3 JB |
1056 | /* add bitrates */ |
1057 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1058 | if (!nl_rates) | |
1059 | return -ENOBUFS; | |
ee688b00 | 1060 | |
3713b4e3 JB |
1061 | for (i = 0; i < sband->n_bitrates; i++) { |
1062 | nl_rate = nla_nest_start(msg, i); | |
1063 | if (!nl_rate) | |
1064 | return -ENOBUFS; | |
ee688b00 | 1065 | |
3713b4e3 JB |
1066 | rate = &sband->bitrates[i]; |
1067 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1068 | rate->bitrate)) | |
1069 | return -ENOBUFS; | |
1070 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1071 | nla_put_flag(msg, | |
1072 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1073 | return -ENOBUFS; | |
ee688b00 | 1074 | |
3713b4e3 JB |
1075 | nla_nest_end(msg, nl_rate); |
1076 | } | |
d51626df | 1077 | |
3713b4e3 | 1078 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1079 | |
3713b4e3 JB |
1080 | return 0; |
1081 | } | |
ee688b00 | 1082 | |
3713b4e3 JB |
1083 | static int |
1084 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1085 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1086 | { | |
1087 | u16 stypes; | |
1088 | struct nlattr *nl_ftypes, *nl_ifs; | |
1089 | enum nl80211_iftype ift; | |
1090 | int i; | |
ee688b00 | 1091 | |
3713b4e3 JB |
1092 | if (!mgmt_stypes) |
1093 | return 0; | |
5dab3b8a | 1094 | |
3713b4e3 JB |
1095 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1096 | if (!nl_ifs) | |
1097 | return -ENOBUFS; | |
e2f367f2 | 1098 | |
3713b4e3 JB |
1099 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1100 | nl_ftypes = nla_nest_start(msg, ift); | |
1101 | if (!nl_ftypes) | |
1102 | return -ENOBUFS; | |
1103 | i = 0; | |
1104 | stypes = mgmt_stypes[ift].tx; | |
1105 | while (stypes) { | |
1106 | if ((stypes & 1) && | |
1107 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1108 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1109 | return -ENOBUFS; | |
1110 | stypes >>= 1; | |
1111 | i++; | |
ee688b00 | 1112 | } |
3713b4e3 JB |
1113 | nla_nest_end(msg, nl_ftypes); |
1114 | } | |
ee688b00 | 1115 | |
3713b4e3 | 1116 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1117 | |
3713b4e3 JB |
1118 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1119 | if (!nl_ifs) | |
1120 | return -ENOBUFS; | |
ee688b00 | 1121 | |
3713b4e3 JB |
1122 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1123 | nl_ftypes = nla_nest_start(msg, ift); | |
1124 | if (!nl_ftypes) | |
1125 | return -ENOBUFS; | |
1126 | i = 0; | |
1127 | stypes = mgmt_stypes[ift].rx; | |
1128 | while (stypes) { | |
1129 | if ((stypes & 1) && | |
1130 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1131 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1132 | return -ENOBUFS; | |
1133 | stypes >>= 1; | |
1134 | i++; | |
1135 | } | |
1136 | nla_nest_end(msg, nl_ftypes); | |
1137 | } | |
1138 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1139 | |
3713b4e3 JB |
1140 | return 0; |
1141 | } | |
ee688b00 | 1142 | |
86e8cf98 JB |
1143 | struct nl80211_dump_wiphy_state { |
1144 | s64 filter_wiphy; | |
1145 | long start; | |
1146 | long split_start, band_start, chan_start; | |
1147 | bool split; | |
1148 | }; | |
1149 | ||
3713b4e3 JB |
1150 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1151 | struct sk_buff *msg, u32 portid, u32 seq, | |
86e8cf98 | 1152 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1153 | { |
1154 | void *hdr; | |
1155 | struct nlattr *nl_bands, *nl_band; | |
1156 | struct nlattr *nl_freqs, *nl_freq; | |
1157 | struct nlattr *nl_cmds; | |
1158 | enum ieee80211_band band; | |
1159 | struct ieee80211_channel *chan; | |
1160 | int i; | |
1161 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1162 | dev->wiphy.mgmt_stypes; | |
fe1abafd | 1163 | u32 features; |
ee688b00 | 1164 | |
3713b4e3 JB |
1165 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1166 | if (!hdr) | |
1167 | return -ENOBUFS; | |
ee688b00 | 1168 | |
86e8cf98 JB |
1169 | if (WARN_ON(!state)) |
1170 | return -EINVAL; | |
ee688b00 | 1171 | |
3713b4e3 JB |
1172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1173 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1174 | wiphy_name(&dev->wiphy)) || | |
1175 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1176 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1177 | goto nla_put_failure; |
1178 | ||
86e8cf98 | 1179 | switch (state->split_start) { |
3713b4e3 JB |
1180 | case 0: |
1181 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1182 | dev->wiphy.retry_short) || | |
1183 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1184 | dev->wiphy.retry_long) || | |
1185 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1186 | dev->wiphy.frag_threshold) || | |
1187 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1188 | dev->wiphy.rts_threshold) || | |
1189 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1190 | dev->wiphy.coverage_class) || | |
1191 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1192 | dev->wiphy.max_scan_ssids) || | |
1193 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1194 | dev->wiphy.max_sched_scan_ssids) || | |
1195 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1196 | dev->wiphy.max_scan_ie_len) || | |
1197 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1198 | dev->wiphy.max_sched_scan_ie_len) || | |
1199 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1200 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1201 | goto nla_put_failure; |
3713b4e3 JB |
1202 | |
1203 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1204 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1205 | goto nla_put_failure; |
3713b4e3 JB |
1206 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1207 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1208 | goto nla_put_failure; | |
1209 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1210 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1211 | goto nla_put_failure; | |
1212 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1213 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1214 | goto nla_put_failure; | |
1215 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1216 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1217 | goto nla_put_failure; | |
1218 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1219 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1220 | goto nla_put_failure; |
2f301ab2 SW |
1221 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
1222 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1223 | goto nla_put_failure; | |
8fdc621d | 1224 | |
86e8cf98 JB |
1225 | state->split_start++; |
1226 | if (state->split) | |
3713b4e3 JB |
1227 | break; |
1228 | case 1: | |
1229 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1230 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1231 | dev->wiphy.cipher_suites)) | |
1232 | goto nla_put_failure; | |
4745fc09 | 1233 | |
3713b4e3 JB |
1234 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1235 | dev->wiphy.max_num_pmkids)) | |
1236 | goto nla_put_failure; | |
b23aa676 | 1237 | |
3713b4e3 JB |
1238 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1239 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1240 | goto nla_put_failure; |
b23aa676 | 1241 | |
3713b4e3 JB |
1242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1243 | dev->wiphy.available_antennas_tx) || | |
1244 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1245 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1246 | goto nla_put_failure; |
b23aa676 | 1247 | |
3713b4e3 JB |
1248 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1249 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1250 | dev->wiphy.probe_resp_offload)) | |
1251 | goto nla_put_failure; | |
8fdc621d | 1252 | |
3713b4e3 JB |
1253 | if ((dev->wiphy.available_antennas_tx || |
1254 | dev->wiphy.available_antennas_rx) && | |
1255 | dev->ops->get_antenna) { | |
1256 | u32 tx_ant = 0, rx_ant = 0; | |
1257 | int res; | |
1258 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1259 | if (!res) { | |
1260 | if (nla_put_u32(msg, | |
1261 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1262 | tx_ant) || | |
1263 | nla_put_u32(msg, | |
1264 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1265 | rx_ant)) | |
1266 | goto nla_put_failure; | |
1267 | } | |
1268 | } | |
a293911d | 1269 | |
86e8cf98 JB |
1270 | state->split_start++; |
1271 | if (state->split) | |
3713b4e3 JB |
1272 | break; |
1273 | case 2: | |
1274 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1275 | dev->wiphy.interface_modes)) | |
1276 | goto nla_put_failure; | |
86e8cf98 JB |
1277 | state->split_start++; |
1278 | if (state->split) | |
3713b4e3 JB |
1279 | break; |
1280 | case 3: | |
1281 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1282 | if (!nl_bands) | |
1283 | goto nla_put_failure; | |
f7ca38df | 1284 | |
86e8cf98 JB |
1285 | for (band = state->band_start; |
1286 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1287 | struct ieee80211_supported_band *sband; |
2e161f78 | 1288 | |
3713b4e3 | 1289 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1290 | |
3713b4e3 JB |
1291 | if (!sband) |
1292 | continue; | |
1293 | ||
1294 | nl_band = nla_nest_start(msg, band); | |
1295 | if (!nl_band) | |
2e161f78 | 1296 | goto nla_put_failure; |
3713b4e3 | 1297 | |
86e8cf98 | 1298 | switch (state->chan_start) { |
3713b4e3 JB |
1299 | case 0: |
1300 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1301 | goto nla_put_failure; |
86e8cf98 JB |
1302 | state->chan_start++; |
1303 | if (state->split) | |
3713b4e3 JB |
1304 | break; |
1305 | default: | |
1306 | /* add frequencies */ | |
1307 | nl_freqs = nla_nest_start( | |
1308 | msg, NL80211_BAND_ATTR_FREQS); | |
1309 | if (!nl_freqs) | |
1310 | goto nla_put_failure; | |
1311 | ||
86e8cf98 | 1312 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1313 | i < sband->n_channels; |
1314 | i++) { | |
1315 | nl_freq = nla_nest_start(msg, i); | |
1316 | if (!nl_freq) | |
1317 | goto nla_put_failure; | |
1318 | ||
1319 | chan = &sband->channels[i]; | |
1320 | ||
86e8cf98 JB |
1321 | if (nl80211_msg_put_channel( |
1322 | msg, chan, | |
1323 | state->split)) | |
3713b4e3 JB |
1324 | goto nla_put_failure; |
1325 | ||
1326 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1327 | if (state->split) |
3713b4e3 JB |
1328 | break; |
1329 | } | |
1330 | if (i < sband->n_channels) | |
86e8cf98 | 1331 | state->chan_start = i + 2; |
3713b4e3 | 1332 | else |
86e8cf98 | 1333 | state->chan_start = 0; |
3713b4e3 JB |
1334 | nla_nest_end(msg, nl_freqs); |
1335 | } | |
1336 | ||
1337 | nla_nest_end(msg, nl_band); | |
1338 | ||
86e8cf98 | 1339 | if (state->split) { |
3713b4e3 | 1340 | /* start again here */ |
86e8cf98 | 1341 | if (state->chan_start) |
3713b4e3 JB |
1342 | band--; |
1343 | break; | |
2e161f78 | 1344 | } |
2e161f78 | 1345 | } |
3713b4e3 | 1346 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1347 | |
3713b4e3 | 1348 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1349 | state->band_start = band + 1; |
3713b4e3 | 1350 | else |
86e8cf98 | 1351 | state->band_start = 0; |
74b70a4e | 1352 | |
3713b4e3 | 1353 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1354 | if (state->band_start == 0 && state->chan_start == 0) |
1355 | state->split_start++; | |
1356 | if (state->split) | |
3713b4e3 JB |
1357 | break; |
1358 | case 4: | |
1359 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1360 | if (!nl_cmds) | |
2e161f78 JB |
1361 | goto nla_put_failure; |
1362 | ||
3713b4e3 JB |
1363 | i = 0; |
1364 | #define CMD(op, n) \ | |
1365 | do { \ | |
1366 | if (dev->ops->op) { \ | |
1367 | i++; \ | |
1368 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1369 | goto nla_put_failure; \ | |
1370 | } \ | |
1371 | } while (0) | |
1372 | ||
1373 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1374 | CMD(change_virtual_intf, SET_INTERFACE); | |
1375 | CMD(add_key, NEW_KEY); | |
1376 | CMD(start_ap, START_AP); | |
1377 | CMD(add_station, NEW_STATION); | |
1378 | CMD(add_mpath, NEW_MPATH); | |
1379 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1380 | CMD(change_bss, SET_BSS); | |
1381 | CMD(auth, AUTHENTICATE); | |
1382 | CMD(assoc, ASSOCIATE); | |
1383 | CMD(deauth, DEAUTHENTICATE); | |
1384 | CMD(disassoc, DISASSOCIATE); | |
1385 | CMD(join_ibss, JOIN_IBSS); | |
1386 | CMD(join_mesh, JOIN_MESH); | |
1387 | CMD(set_pmksa, SET_PMKSA); | |
1388 | CMD(del_pmksa, DEL_PMKSA); | |
1389 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1390 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1391 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1392 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1393 | CMD(mgmt_tx, FRAME); | |
1394 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1395 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1396 | i++; | |
1397 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1398 | goto nla_put_failure; |
2e161f78 | 1399 | } |
3713b4e3 JB |
1400 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1401 | dev->ops->join_mesh) { | |
1402 | i++; | |
1403 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1404 | goto nla_put_failure; | |
1405 | } | |
1406 | CMD(set_wds_peer, SET_WDS_PEER); | |
1407 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1408 | CMD(tdls_mgmt, TDLS_MGMT); | |
1409 | CMD(tdls_oper, TDLS_OPER); | |
1410 | } | |
1411 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1412 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1413 | CMD(probe_client, PROBE_CLIENT); | |
1414 | CMD(set_noack_map, SET_NOACK_MAP); | |
1415 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1416 | i++; | |
1417 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1418 | goto nla_put_failure; | |
1419 | } | |
1420 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1421 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
86e8cf98 | 1422 | if (state->split) { |
5de17984 AS |
1423 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1424 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1425 | } | |
2e161f78 | 1426 | |
3713b4e3 JB |
1427 | #ifdef CONFIG_NL80211_TESTMODE |
1428 | CMD(testmode_cmd, TESTMODE); | |
1429 | #endif | |
ff1b6e69 | 1430 | |
3713b4e3 | 1431 | #undef CMD |
ff1b6e69 | 1432 | |
3713b4e3 JB |
1433 | if (dev->ops->connect || dev->ops->auth) { |
1434 | i++; | |
1435 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1436 | goto nla_put_failure; |
ff1b6e69 JB |
1437 | } |
1438 | ||
3713b4e3 JB |
1439 | if (dev->ops->disconnect || dev->ops->deauth) { |
1440 | i++; | |
1441 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1442 | goto nla_put_failure; | |
1443 | } | |
1444 | ||
1445 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1446 | state->split_start++; |
1447 | if (state->split) | |
3713b4e3 JB |
1448 | break; |
1449 | case 5: | |
1450 | if (dev->ops->remain_on_channel && | |
1451 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1452 | nla_put_u32(msg, | |
1453 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1454 | dev->wiphy.max_remain_on_channel_duration)) | |
1455 | goto nla_put_failure; | |
1456 | ||
1457 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1458 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1459 | goto nla_put_failure; | |
1460 | ||
1461 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1462 | goto nla_put_failure; | |
86e8cf98 JB |
1463 | state->split_start++; |
1464 | if (state->split) | |
3713b4e3 JB |
1465 | break; |
1466 | case 6: | |
1467 | #ifdef CONFIG_PM | |
86e8cf98 | 1468 | if (nl80211_send_wowlan(msg, dev, state->split)) |
3713b4e3 | 1469 | goto nla_put_failure; |
86e8cf98 JB |
1470 | state->split_start++; |
1471 | if (state->split) | |
3713b4e3 JB |
1472 | break; |
1473 | #else | |
86e8cf98 | 1474 | state->split_start++; |
dfb89c56 | 1475 | #endif |
3713b4e3 JB |
1476 | case 7: |
1477 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1478 | dev->wiphy.software_iftypes)) | |
1479 | goto nla_put_failure; | |
ff1b6e69 | 1480 | |
86e8cf98 JB |
1481 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
1482 | state->split)) | |
3713b4e3 | 1483 | goto nla_put_failure; |
7527a782 | 1484 | |
86e8cf98 JB |
1485 | state->split_start++; |
1486 | if (state->split) | |
3713b4e3 JB |
1487 | break; |
1488 | case 8: | |
1489 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1490 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1491 | dev->wiphy.ap_sme_capa)) | |
1492 | goto nla_put_failure; | |
7527a782 | 1493 | |
fe1abafd JB |
1494 | features = dev->wiphy.features; |
1495 | /* | |
1496 | * We can only add the per-channel limit information if the | |
1497 | * dump is split, otherwise it makes it too big. Therefore | |
1498 | * only advertise it in that case. | |
1499 | */ | |
86e8cf98 | 1500 | if (state->split) |
fe1abafd JB |
1501 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1502 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1503 | goto nla_put_failure; |
562a7480 | 1504 | |
3713b4e3 JB |
1505 | if (dev->wiphy.ht_capa_mod_mask && |
1506 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1507 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1508 | dev->wiphy.ht_capa_mod_mask)) | |
1509 | goto nla_put_failure; | |
1f074bd8 | 1510 | |
3713b4e3 JB |
1511 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1512 | dev->wiphy.max_acl_mac_addrs && | |
1513 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1514 | dev->wiphy.max_acl_mac_addrs)) | |
1515 | goto nla_put_failure; | |
7e7c8926 | 1516 | |
3713b4e3 JB |
1517 | /* |
1518 | * Any information below this point is only available to | |
1519 | * applications that can deal with it being split. This | |
1520 | * helps ensure that newly added capabilities don't break | |
1521 | * older tools by overrunning their buffers. | |
1522 | * | |
1523 | * We still increment split_start so that in the split | |
1524 | * case we'll continue with more data in the next round, | |
1525 | * but break unconditionally so unsplit data stops here. | |
1526 | */ | |
86e8cf98 | 1527 | state->split_start++; |
3713b4e3 JB |
1528 | break; |
1529 | case 9: | |
fe1abafd JB |
1530 | if (dev->wiphy.extended_capabilities && |
1531 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1532 | dev->wiphy.extended_capabilities_len, | |
1533 | dev->wiphy.extended_capabilities) || | |
1534 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1535 | dev->wiphy.extended_capabilities_len, | |
1536 | dev->wiphy.extended_capabilities_mask))) | |
1537 | goto nla_put_failure; | |
a50df0c4 | 1538 | |
ee2aca34 JB |
1539 | if (dev->wiphy.vht_capa_mod_mask && |
1540 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1541 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1542 | dev->wiphy.vht_capa_mod_mask)) | |
1543 | goto nla_put_failure; | |
1544 | ||
be29b99a AK |
1545 | state->split_start++; |
1546 | break; | |
1547 | case 10: | |
1548 | if (nl80211_send_coalesce(msg, dev)) | |
1549 | goto nla_put_failure; | |
1550 | ||
3713b4e3 | 1551 | /* done */ |
86e8cf98 | 1552 | state->split_start = 0; |
3713b4e3 JB |
1553 | break; |
1554 | } | |
55682965 JB |
1555 | return genlmsg_end(msg, hdr); |
1556 | ||
1557 | nla_put_failure: | |
bc3ed28c TG |
1558 | genlmsg_cancel(msg, hdr); |
1559 | return -EMSGSIZE; | |
55682965 JB |
1560 | } |
1561 | ||
86e8cf98 JB |
1562 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1563 | struct netlink_callback *cb, | |
1564 | struct nl80211_dump_wiphy_state *state) | |
1565 | { | |
1566 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1567 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1568 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1569 | /* ignore parse errors for backward compatibility */ | |
1570 | if (ret) | |
1571 | return 0; | |
1572 | ||
1573 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1574 | if (tb[NL80211_ATTR_WIPHY]) | |
1575 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1576 | if (tb[NL80211_ATTR_WDEV]) | |
1577 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1578 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1579 | struct net_device *netdev; | |
1580 | struct cfg80211_registered_device *rdev; | |
1581 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1582 | ||
1583 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1584 | if (!netdev) | |
1585 | return -ENODEV; | |
1586 | if (netdev->ieee80211_ptr) { | |
1587 | rdev = wiphy_to_dev( | |
1588 | netdev->ieee80211_ptr->wiphy); | |
1589 | state->filter_wiphy = rdev->wiphy_idx; | |
1590 | } | |
1591 | dev_put(netdev); | |
1592 | } | |
1593 | ||
1594 | return 0; | |
1595 | } | |
1596 | ||
55682965 JB |
1597 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1598 | { | |
645e77de | 1599 | int idx = 0, ret; |
86e8cf98 | 1600 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
55682965 | 1601 | struct cfg80211_registered_device *dev; |
3a5a423b | 1602 | |
5fe231e8 | 1603 | rtnl_lock(); |
86e8cf98 JB |
1604 | if (!state) { |
1605 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1606 | if (!state) { |
1607 | rtnl_unlock(); | |
86e8cf98 | 1608 | return -ENOMEM; |
3713b4e3 | 1609 | } |
86e8cf98 JB |
1610 | state->filter_wiphy = -1; |
1611 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1612 | if (ret) { | |
1613 | kfree(state); | |
1614 | rtnl_unlock(); | |
1615 | return ret; | |
3713b4e3 | 1616 | } |
86e8cf98 | 1617 | cb->args[0] = (long)state; |
3713b4e3 JB |
1618 | } |
1619 | ||
79c97e97 | 1620 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1621 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1622 | continue; | |
86e8cf98 | 1623 | if (++idx <= state->start) |
55682965 | 1624 | continue; |
86e8cf98 JB |
1625 | if (state->filter_wiphy != -1 && |
1626 | state->filter_wiphy != dev->wiphy_idx) | |
3713b4e3 JB |
1627 | continue; |
1628 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1629 | do { | |
1630 | ret = nl80211_send_wiphy(dev, skb, | |
1631 | NETLINK_CB(cb->skb).portid, | |
1632 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1633 | NLM_F_MULTI, state); |
3713b4e3 JB |
1634 | if (ret < 0) { |
1635 | /* | |
1636 | * If sending the wiphy data didn't fit (ENOBUFS | |
1637 | * or EMSGSIZE returned), this SKB is still | |
1638 | * empty (so it's not too big because another | |
1639 | * wiphy dataset is already in the skb) and | |
1640 | * we've not tried to adjust the dump allocation | |
1641 | * yet ... then adjust the alloc size to be | |
1642 | * bigger, and return 1 but with the empty skb. | |
1643 | * This results in an empty message being RX'ed | |
1644 | * in userspace, but that is ignored. | |
1645 | * | |
1646 | * We can then retry with the larger buffer. | |
1647 | */ | |
1648 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1649 | !skb->len && | |
1650 | cb->min_dump_alloc < 4096) { | |
1651 | cb->min_dump_alloc = 4096; | |
d98cae64 | 1652 | rtnl_unlock(); |
3713b4e3 JB |
1653 | return 1; |
1654 | } | |
1655 | idx--; | |
1656 | break; | |
645e77de | 1657 | } |
86e8cf98 | 1658 | } while (state->split_start > 0); |
3713b4e3 | 1659 | break; |
55682965 | 1660 | } |
5fe231e8 | 1661 | rtnl_unlock(); |
55682965 | 1662 | |
86e8cf98 | 1663 | state->start = idx; |
55682965 JB |
1664 | |
1665 | return skb->len; | |
1666 | } | |
1667 | ||
86e8cf98 JB |
1668 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1669 | { | |
1670 | kfree((void *)cb->args[0]); | |
1671 | return 0; | |
1672 | } | |
1673 | ||
55682965 JB |
1674 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1675 | { | |
1676 | struct sk_buff *msg; | |
4c476991 | 1677 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
86e8cf98 | 1678 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1679 | |
645e77de | 1680 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1681 | if (!msg) |
4c476991 | 1682 | return -ENOMEM; |
55682965 | 1683 | |
3713b4e3 | 1684 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
86e8cf98 | 1685 | &state) < 0) { |
4c476991 JB |
1686 | nlmsg_free(msg); |
1687 | return -ENOBUFS; | |
1688 | } | |
55682965 | 1689 | |
134e6375 | 1690 | return genlmsg_reply(msg, info); |
55682965 JB |
1691 | } |
1692 | ||
31888487 JM |
1693 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1694 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1695 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1696 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1697 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1698 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1699 | }; | |
1700 | ||
1701 | static int parse_txq_params(struct nlattr *tb[], | |
1702 | struct ieee80211_txq_params *txq_params) | |
1703 | { | |
a3304b0a | 1704 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1705 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1706 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1707 | return -EINVAL; | |
1708 | ||
a3304b0a | 1709 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1710 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1711 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1712 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1713 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1714 | ||
a3304b0a JB |
1715 | if (txq_params->ac >= NL80211_NUM_ACS) |
1716 | return -EINVAL; | |
1717 | ||
31888487 JM |
1718 | return 0; |
1719 | } | |
1720 | ||
f444de05 JB |
1721 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1722 | { | |
1723 | /* | |
cc1d2806 JB |
1724 | * You can only set the channel explicitly for WDS interfaces, |
1725 | * all others have their channel managed via their respective | |
1726 | * "establish a connection" command (connect, join, ...) | |
1727 | * | |
1728 | * For AP/GO and mesh mode, the channel can be set with the | |
1729 | * channel userspace API, but is only stored and passed to the | |
1730 | * low-level driver when the AP starts or the mesh is joined. | |
1731 | * This is for backward compatibility, userspace can also give | |
1732 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1733 | * |
1734 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1735 | * whatever else is going on, so they have their own special |
1736 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1737 | */ |
1738 | return !wdev || | |
1739 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1740 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1741 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1742 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1743 | } |
1744 | ||
683b6d3b JB |
1745 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1746 | struct genl_info *info, | |
1747 | struct cfg80211_chan_def *chandef) | |
1748 | { | |
dbeca2ea | 1749 | u32 control_freq; |
683b6d3b JB |
1750 | |
1751 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1752 | return -EINVAL; | |
1753 | ||
1754 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1755 | ||
1756 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1757 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1758 | chandef->center_freq1 = control_freq; | |
1759 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1760 | |
1761 | /* Primary channel not allowed */ | |
1762 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1763 | return -EINVAL; | |
1764 | ||
3d9d1d66 JB |
1765 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1766 | enum nl80211_channel_type chantype; | |
1767 | ||
1768 | chantype = nla_get_u32( | |
1769 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1770 | ||
1771 | switch (chantype) { | |
1772 | case NL80211_CHAN_NO_HT: | |
1773 | case NL80211_CHAN_HT20: | |
1774 | case NL80211_CHAN_HT40PLUS: | |
1775 | case NL80211_CHAN_HT40MINUS: | |
1776 | cfg80211_chandef_create(chandef, chandef->chan, | |
1777 | chantype); | |
1778 | break; | |
1779 | default: | |
1780 | return -EINVAL; | |
1781 | } | |
1782 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1783 | chandef->width = | |
1784 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1785 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1786 | chandef->center_freq1 = | |
1787 | nla_get_u32( | |
1788 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1789 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1790 | chandef->center_freq2 = | |
1791 | nla_get_u32( | |
1792 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1793 | } | |
1794 | ||
9f5e8f6e | 1795 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1796 | return -EINVAL; |
1797 | ||
9f5e8f6e JB |
1798 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1799 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1800 | return -EINVAL; |
1801 | ||
2f301ab2 SW |
1802 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1803 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1804 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1805 | return -EINVAL; | |
1806 | ||
683b6d3b JB |
1807 | return 0; |
1808 | } | |
1809 | ||
f444de05 JB |
1810 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1811 | struct wireless_dev *wdev, | |
1812 | struct genl_info *info) | |
1813 | { | |
683b6d3b | 1814 | struct cfg80211_chan_def chandef; |
f444de05 | 1815 | int result; |
e8c9bd5b JB |
1816 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1817 | ||
1818 | if (wdev) | |
1819 | iftype = wdev->iftype; | |
f444de05 | 1820 | |
f444de05 JB |
1821 | if (!nl80211_can_set_dev_channel(wdev)) |
1822 | return -EOPNOTSUPP; | |
1823 | ||
683b6d3b JB |
1824 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1825 | if (result) | |
1826 | return result; | |
f444de05 | 1827 | |
e8c9bd5b | 1828 | switch (iftype) { |
aa430da4 JB |
1829 | case NL80211_IFTYPE_AP: |
1830 | case NL80211_IFTYPE_P2P_GO: | |
1831 | if (wdev->beacon_interval) { | |
1832 | result = -EBUSY; | |
1833 | break; | |
1834 | } | |
683b6d3b | 1835 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1836 | result = -EINVAL; |
1837 | break; | |
1838 | } | |
683b6d3b | 1839 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1840 | result = 0; |
1841 | break; | |
cc1d2806 | 1842 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1843 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1844 | break; |
e8c9bd5b | 1845 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1846 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1847 | break; |
aa430da4 | 1848 | default: |
e8c9bd5b | 1849 | result = -EINVAL; |
f444de05 | 1850 | } |
f444de05 JB |
1851 | |
1852 | return result; | |
1853 | } | |
1854 | ||
1855 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1856 | { | |
4c476991 JB |
1857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1858 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1859 | |
4c476991 | 1860 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1861 | } |
1862 | ||
e8347eba BJ |
1863 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1864 | { | |
43b19952 JB |
1865 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1866 | struct net_device *dev = info->user_ptr[1]; | |
1867 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1868 | const u8 *bssid; |
e8347eba BJ |
1869 | |
1870 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1871 | return -EINVAL; | |
1872 | ||
43b19952 JB |
1873 | if (netif_running(dev)) |
1874 | return -EBUSY; | |
e8347eba | 1875 | |
43b19952 JB |
1876 | if (!rdev->ops->set_wds_peer) |
1877 | return -EOPNOTSUPP; | |
e8347eba | 1878 | |
43b19952 JB |
1879 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1880 | return -EOPNOTSUPP; | |
e8347eba BJ |
1881 | |
1882 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1883 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1884 | } |
1885 | ||
1886 | ||
55682965 JB |
1887 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1888 | { | |
1889 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1890 | struct net_device *netdev = NULL; |
1891 | struct wireless_dev *wdev; | |
a1e567c8 | 1892 | int result = 0, rem_txq_params = 0; |
31888487 | 1893 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1894 | u32 changed; |
1895 | u8 retry_short = 0, retry_long = 0; | |
1896 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1897 | u8 coverage_class = 0; |
55682965 | 1898 | |
5fe231e8 JB |
1899 | ASSERT_RTNL(); |
1900 | ||
f444de05 JB |
1901 | /* |
1902 | * Try to find the wiphy and netdev. Normally this | |
1903 | * function shouldn't need the netdev, but this is | |
1904 | * done for backward compatibility -- previously | |
1905 | * setting the channel was done per wiphy, but now | |
1906 | * it is per netdev. Previous userland like hostapd | |
1907 | * also passed a netdev to set_wiphy, so that it is | |
1908 | * possible to let that go to the right netdev! | |
1909 | */ | |
4bbf4d56 | 1910 | |
f444de05 JB |
1911 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1912 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1913 | ||
1914 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
5fe231e8 | 1915 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 1916 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 1917 | else |
f444de05 | 1918 | netdev = NULL; |
4bbf4d56 JB |
1919 | } |
1920 | ||
f444de05 | 1921 | if (!netdev) { |
878d9ec7 JB |
1922 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1923 | info->attrs); | |
5fe231e8 | 1924 | if (IS_ERR(rdev)) |
4c476991 | 1925 | return PTR_ERR(rdev); |
f444de05 JB |
1926 | wdev = NULL; |
1927 | netdev = NULL; | |
1928 | result = 0; | |
71fe96bf | 1929 | } else |
f444de05 | 1930 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1931 | |
1932 | /* | |
1933 | * end workaround code, by now the rdev is available | |
1934 | * and locked, and wdev may or may not be NULL. | |
1935 | */ | |
4bbf4d56 JB |
1936 | |
1937 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1938 | result = cfg80211_dev_rename( |
1939 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 1940 | |
4bbf4d56 JB |
1941 | if (result) |
1942 | goto bad_res; | |
31888487 JM |
1943 | |
1944 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1945 | struct ieee80211_txq_params txq_params; | |
1946 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1947 | ||
1948 | if (!rdev->ops->set_txq_params) { | |
1949 | result = -EOPNOTSUPP; | |
1950 | goto bad_res; | |
1951 | } | |
1952 | ||
f70f01c2 EP |
1953 | if (!netdev) { |
1954 | result = -EINVAL; | |
1955 | goto bad_res; | |
1956 | } | |
1957 | ||
133a3ff2 JB |
1958 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1959 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1960 | result = -EINVAL; | |
1961 | goto bad_res; | |
1962 | } | |
1963 | ||
2b5f8b0b JB |
1964 | if (!netif_running(netdev)) { |
1965 | result = -ENETDOWN; | |
1966 | goto bad_res; | |
1967 | } | |
1968 | ||
31888487 JM |
1969 | nla_for_each_nested(nl_txq_params, |
1970 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1971 | rem_txq_params) { | |
1972 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1973 | nla_data(nl_txq_params), | |
1974 | nla_len(nl_txq_params), | |
1975 | txq_params_policy); | |
1976 | result = parse_txq_params(tb, &txq_params); | |
1977 | if (result) | |
1978 | goto bad_res; | |
1979 | ||
e35e4d28 HG |
1980 | result = rdev_set_txq_params(rdev, netdev, |
1981 | &txq_params); | |
31888487 JM |
1982 | if (result) |
1983 | goto bad_res; | |
1984 | } | |
1985 | } | |
55682965 | 1986 | |
72bdcf34 | 1987 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1988 | result = __nl80211_set_channel(rdev, |
1989 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1990 | info); | |
72bdcf34 JM |
1991 | if (result) |
1992 | goto bad_res; | |
1993 | } | |
1994 | ||
98d2ff8b | 1995 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1996 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1997 | enum nl80211_tx_power_setting type; |
1998 | int idx, mbm = 0; | |
1999 | ||
c8442118 JB |
2000 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2001 | txp_wdev = NULL; | |
2002 | ||
98d2ff8b | 2003 | if (!rdev->ops->set_tx_power) { |
60ea385f | 2004 | result = -EOPNOTSUPP; |
98d2ff8b JO |
2005 | goto bad_res; |
2006 | } | |
2007 | ||
2008 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2009 | type = nla_get_u32(info->attrs[idx]); | |
2010 | ||
2011 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
2012 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
2013 | result = -EINVAL; | |
2014 | goto bad_res; | |
2015 | } | |
2016 | ||
2017 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2018 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2019 | mbm = nla_get_u32(info->attrs[idx]); | |
2020 | } | |
2021 | ||
c8442118 | 2022 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
2023 | if (result) |
2024 | goto bad_res; | |
2025 | } | |
2026 | ||
afe0cbf8 BR |
2027 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2028 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2029 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2030 | if ((!rdev->wiphy.available_antennas_tx && |
2031 | !rdev->wiphy.available_antennas_rx) || | |
2032 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
2033 | result = -EOPNOTSUPP; |
2034 | goto bad_res; | |
2035 | } | |
2036 | ||
2037 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2038 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2039 | ||
a7ffac95 | 2040 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2041 | * available antenna masks, except for the "all" mask */ |
2042 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2043 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2044 | result = -EINVAL; |
2045 | goto bad_res; | |
2046 | } | |
2047 | ||
7f531e03 BR |
2048 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2049 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2050 | |
e35e4d28 | 2051 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2052 | if (result) |
2053 | goto bad_res; | |
2054 | } | |
2055 | ||
b9a5f8ca JM |
2056 | changed = 0; |
2057 | ||
2058 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2059 | retry_short = nla_get_u8( | |
2060 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2061 | if (retry_short == 0) { | |
2062 | result = -EINVAL; | |
2063 | goto bad_res; | |
2064 | } | |
2065 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2066 | } | |
2067 | ||
2068 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2069 | retry_long = nla_get_u8( | |
2070 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2071 | if (retry_long == 0) { | |
2072 | result = -EINVAL; | |
2073 | goto bad_res; | |
2074 | } | |
2075 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2076 | } | |
2077 | ||
2078 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2079 | frag_threshold = nla_get_u32( | |
2080 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2081 | if (frag_threshold < 256) { | |
2082 | result = -EINVAL; | |
2083 | goto bad_res; | |
2084 | } | |
2085 | if (frag_threshold != (u32) -1) { | |
2086 | /* | |
2087 | * Fragments (apart from the last one) are required to | |
2088 | * have even length. Make the fragmentation code | |
2089 | * simpler by stripping LSB should someone try to use | |
2090 | * odd threshold value. | |
2091 | */ | |
2092 | frag_threshold &= ~0x1; | |
2093 | } | |
2094 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2095 | } | |
2096 | ||
2097 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2098 | rts_threshold = nla_get_u32( | |
2099 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2100 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2101 | } | |
2102 | ||
81077e82 LT |
2103 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2104 | coverage_class = nla_get_u8( | |
2105 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2106 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2107 | } | |
2108 | ||
b9a5f8ca JM |
2109 | if (changed) { |
2110 | u8 old_retry_short, old_retry_long; | |
2111 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2112 | u8 old_coverage_class; |
b9a5f8ca JM |
2113 | |
2114 | if (!rdev->ops->set_wiphy_params) { | |
2115 | result = -EOPNOTSUPP; | |
2116 | goto bad_res; | |
2117 | } | |
2118 | ||
2119 | old_retry_short = rdev->wiphy.retry_short; | |
2120 | old_retry_long = rdev->wiphy.retry_long; | |
2121 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2122 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2123 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2124 | |
2125 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2126 | rdev->wiphy.retry_short = retry_short; | |
2127 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2128 | rdev->wiphy.retry_long = retry_long; | |
2129 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2130 | rdev->wiphy.frag_threshold = frag_threshold; | |
2131 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2132 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2133 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2134 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2135 | |
e35e4d28 | 2136 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2137 | if (result) { |
2138 | rdev->wiphy.retry_short = old_retry_short; | |
2139 | rdev->wiphy.retry_long = old_retry_long; | |
2140 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2141 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2142 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2143 | } |
2144 | } | |
72bdcf34 | 2145 | |
306d6112 | 2146 | bad_res: |
f444de05 JB |
2147 | if (netdev) |
2148 | dev_put(netdev); | |
55682965 JB |
2149 | return result; |
2150 | } | |
2151 | ||
71bbc994 JB |
2152 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2153 | { | |
2154 | return (u64)wdev->identifier | | |
2155 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2156 | } | |
55682965 | 2157 | |
683b6d3b JB |
2158 | static int nl80211_send_chandef(struct sk_buff *msg, |
2159 | struct cfg80211_chan_def *chandef) | |
2160 | { | |
9f5e8f6e | 2161 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2162 | |
683b6d3b JB |
2163 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2164 | chandef->chan->center_freq)) | |
2165 | return -ENOBUFS; | |
3d9d1d66 JB |
2166 | switch (chandef->width) { |
2167 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2168 | case NL80211_CHAN_WIDTH_20: | |
2169 | case NL80211_CHAN_WIDTH_40: | |
2170 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2171 | cfg80211_get_chandef_type(chandef))) | |
2172 | return -ENOBUFS; | |
2173 | break; | |
2174 | default: | |
2175 | break; | |
2176 | } | |
2177 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2178 | return -ENOBUFS; | |
2179 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2180 | return -ENOBUFS; | |
2181 | if (chandef->center_freq2 && | |
2182 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2183 | return -ENOBUFS; |
2184 | return 0; | |
2185 | } | |
2186 | ||
15e47304 | 2187 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2188 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2189 | struct wireless_dev *wdev) |
55682965 | 2190 | { |
72fb2abc | 2191 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2192 | void *hdr; |
2193 | ||
15e47304 | 2194 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2195 | if (!hdr) |
2196 | return -1; | |
2197 | ||
72fb2abc JB |
2198 | if (dev && |
2199 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2200 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2201 | goto nla_put_failure; |
2202 | ||
2203 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2204 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2205 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2206 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2207 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2208 | rdev->devlist_generation ^ | |
2209 | (cfg80211_rdev_list_generation << 2))) | |
2210 | goto nla_put_failure; | |
f5ea9120 | 2211 | |
5b7ccaf3 | 2212 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2213 | int ret; |
2214 | struct cfg80211_chan_def chandef; | |
2215 | ||
2216 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2217 | if (ret == 0) { | |
2218 | if (nl80211_send_chandef(msg, &chandef)) | |
2219 | goto nla_put_failure; | |
2220 | } | |
d91df0e3 PF |
2221 | } |
2222 | ||
b84e7a05 AQ |
2223 | if (wdev->ssid_len) { |
2224 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2225 | goto nla_put_failure; | |
2226 | } | |
2227 | ||
55682965 JB |
2228 | return genlmsg_end(msg, hdr); |
2229 | ||
2230 | nla_put_failure: | |
bc3ed28c TG |
2231 | genlmsg_cancel(msg, hdr); |
2232 | return -EMSGSIZE; | |
55682965 JB |
2233 | } |
2234 | ||
2235 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2236 | { | |
2237 | int wp_idx = 0; | |
2238 | int if_idx = 0; | |
2239 | int wp_start = cb->args[0]; | |
2240 | int if_start = cb->args[1]; | |
f5ea9120 | 2241 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2242 | struct wireless_dev *wdev; |
2243 | ||
5fe231e8 | 2244 | rtnl_lock(); |
f5ea9120 JB |
2245 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2246 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2247 | continue; |
bba95fef JB |
2248 | if (wp_idx < wp_start) { |
2249 | wp_idx++; | |
55682965 | 2250 | continue; |
bba95fef | 2251 | } |
55682965 JB |
2252 | if_idx = 0; |
2253 | ||
89a54e48 | 2254 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2255 | if (if_idx < if_start) { |
2256 | if_idx++; | |
55682965 | 2257 | continue; |
bba95fef | 2258 | } |
15e47304 | 2259 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2260 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2261 | rdev, wdev) < 0) { |
bba95fef JB |
2262 | goto out; |
2263 | } | |
2264 | if_idx++; | |
55682965 | 2265 | } |
bba95fef JB |
2266 | |
2267 | wp_idx++; | |
55682965 | 2268 | } |
bba95fef | 2269 | out: |
5fe231e8 | 2270 | rtnl_unlock(); |
55682965 JB |
2271 | |
2272 | cb->args[0] = wp_idx; | |
2273 | cb->args[1] = if_idx; | |
2274 | ||
2275 | return skb->len; | |
2276 | } | |
2277 | ||
2278 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2279 | { | |
2280 | struct sk_buff *msg; | |
4c476991 | 2281 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2282 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2283 | |
fd2120ca | 2284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2285 | if (!msg) |
4c476991 | 2286 | return -ENOMEM; |
55682965 | 2287 | |
15e47304 | 2288 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2289 | dev, wdev) < 0) { |
4c476991 JB |
2290 | nlmsg_free(msg); |
2291 | return -ENOBUFS; | |
2292 | } | |
55682965 | 2293 | |
134e6375 | 2294 | return genlmsg_reply(msg, info); |
55682965 JB |
2295 | } |
2296 | ||
66f7ac50 MW |
2297 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2298 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2299 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2300 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2301 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2302 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2303 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2304 | }; |
2305 | ||
2306 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2307 | { | |
2308 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2309 | int flag; | |
2310 | ||
2311 | *mntrflags = 0; | |
2312 | ||
2313 | if (!nla) | |
2314 | return -EINVAL; | |
2315 | ||
2316 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2317 | nla, mntr_flags_policy)) | |
2318 | return -EINVAL; | |
2319 | ||
2320 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2321 | if (flags[flag]) | |
2322 | *mntrflags |= (1<<flag); | |
2323 | ||
2324 | return 0; | |
2325 | } | |
2326 | ||
9bc383de | 2327 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2328 | struct net_device *netdev, u8 use_4addr, |
2329 | enum nl80211_iftype iftype) | |
9bc383de | 2330 | { |
ad4bb6f8 | 2331 | if (!use_4addr) { |
f350a0a8 | 2332 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2333 | return -EBUSY; |
9bc383de | 2334 | return 0; |
ad4bb6f8 | 2335 | } |
9bc383de JB |
2336 | |
2337 | switch (iftype) { | |
2338 | case NL80211_IFTYPE_AP_VLAN: | |
2339 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2340 | return 0; | |
2341 | break; | |
2342 | case NL80211_IFTYPE_STATION: | |
2343 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2344 | return 0; | |
2345 | break; | |
2346 | default: | |
2347 | break; | |
2348 | } | |
2349 | ||
2350 | return -EOPNOTSUPP; | |
2351 | } | |
2352 | ||
55682965 JB |
2353 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2354 | { | |
4c476991 | 2355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2356 | struct vif_params params; |
e36d56b6 | 2357 | int err; |
04a773ad | 2358 | enum nl80211_iftype otype, ntype; |
4c476991 | 2359 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2360 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2361 | bool change = false; |
55682965 | 2362 | |
2ec600d6 LCC |
2363 | memset(¶ms, 0, sizeof(params)); |
2364 | ||
04a773ad | 2365 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2366 | |
723b038d | 2367 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2368 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2369 | if (otype != ntype) |
ac7f9cfa | 2370 | change = true; |
4c476991 JB |
2371 | if (ntype > NL80211_IFTYPE_MAX) |
2372 | return -EINVAL; | |
723b038d JB |
2373 | } |
2374 | ||
92ffe055 | 2375 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2376 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2377 | ||
4c476991 JB |
2378 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2379 | return -EINVAL; | |
29cbe68c JB |
2380 | if (netif_running(dev)) |
2381 | return -EBUSY; | |
2382 | ||
2383 | wdev_lock(wdev); | |
2384 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2385 | IEEE80211_MAX_MESH_ID_LEN); | |
2386 | wdev->mesh_id_up_len = | |
2387 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2388 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2389 | wdev->mesh_id_up_len); | |
2390 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2391 | } |
2392 | ||
8b787643 FF |
2393 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2394 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2395 | change = true; | |
ad4bb6f8 | 2396 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2397 | if (err) |
4c476991 | 2398 | return err; |
8b787643 FF |
2399 | } else { |
2400 | params.use_4addr = -1; | |
2401 | } | |
2402 | ||
92ffe055 | 2403 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2404 | if (ntype != NL80211_IFTYPE_MONITOR) |
2405 | return -EINVAL; | |
92ffe055 JB |
2406 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2407 | &_flags); | |
ac7f9cfa | 2408 | if (err) |
4c476991 | 2409 | return err; |
ac7f9cfa JB |
2410 | |
2411 | flags = &_flags; | |
2412 | change = true; | |
92ffe055 | 2413 | } |
3b85875a | 2414 | |
e057d3c3 FF |
2415 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
2416 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2417 | return -EOPNOTSUPP; | |
2418 | ||
ac7f9cfa | 2419 | if (change) |
3d54d255 | 2420 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2421 | else |
2422 | err = 0; | |
60719ffd | 2423 | |
9bc383de JB |
2424 | if (!err && params.use_4addr != -1) |
2425 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2426 | ||
55682965 JB |
2427 | return err; |
2428 | } | |
2429 | ||
2430 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2431 | { | |
4c476991 | 2432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2433 | struct vif_params params; |
84efbb84 | 2434 | struct wireless_dev *wdev; |
1c90f9d4 | 2435 | struct sk_buff *msg; |
55682965 JB |
2436 | int err; |
2437 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2438 | u32 flags; |
55682965 | 2439 | |
2ec600d6 LCC |
2440 | memset(¶ms, 0, sizeof(params)); |
2441 | ||
55682965 JB |
2442 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2443 | return -EINVAL; | |
2444 | ||
2445 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2446 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2447 | if (type > NL80211_IFTYPE_MAX) | |
2448 | return -EINVAL; | |
2449 | } | |
2450 | ||
79c97e97 | 2451 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2452 | !(rdev->wiphy.interface_modes & (1 << type))) |
2453 | return -EOPNOTSUPP; | |
55682965 | 2454 | |
1c18f145 AS |
2455 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2456 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2457 | ETH_ALEN); | |
2458 | if (!is_valid_ether_addr(params.macaddr)) | |
2459 | return -EADDRNOTAVAIL; | |
2460 | } | |
2461 | ||
9bc383de | 2462 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2463 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2464 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2465 | if (err) |
4c476991 | 2466 | return err; |
9bc383de | 2467 | } |
8b787643 | 2468 | |
1c90f9d4 JB |
2469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2470 | if (!msg) | |
2471 | return -ENOMEM; | |
2472 | ||
66f7ac50 MW |
2473 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2474 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2475 | &flags); | |
e057d3c3 FF |
2476 | |
2477 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && | |
2478 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2479 | return -EOPNOTSUPP; | |
2480 | ||
e35e4d28 HG |
2481 | wdev = rdev_add_virtual_intf(rdev, |
2482 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2483 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2484 | if (IS_ERR(wdev)) { |
2485 | nlmsg_free(msg); | |
84efbb84 | 2486 | return PTR_ERR(wdev); |
1c90f9d4 | 2487 | } |
2ec600d6 | 2488 | |
98104fde JB |
2489 | switch (type) { |
2490 | case NL80211_IFTYPE_MESH_POINT: | |
2491 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2492 | break; | |
29cbe68c JB |
2493 | wdev_lock(wdev); |
2494 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2495 | IEEE80211_MAX_MESH_ID_LEN); | |
2496 | wdev->mesh_id_up_len = | |
2497 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2498 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2499 | wdev->mesh_id_up_len); | |
2500 | wdev_unlock(wdev); | |
98104fde JB |
2501 | break; |
2502 | case NL80211_IFTYPE_P2P_DEVICE: | |
2503 | /* | |
2504 | * P2P Device doesn't have a netdev, so doesn't go | |
2505 | * through the netdev notifier and must be added here | |
2506 | */ | |
2507 | mutex_init(&wdev->mtx); | |
2508 | INIT_LIST_HEAD(&wdev->event_list); | |
2509 | spin_lock_init(&wdev->event_lock); | |
2510 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2511 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2512 | ||
98104fde JB |
2513 | wdev->identifier = ++rdev->wdev_id; |
2514 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2515 | rdev->devlist_generation++; | |
98104fde JB |
2516 | break; |
2517 | default: | |
2518 | break; | |
29cbe68c JB |
2519 | } |
2520 | ||
15e47304 | 2521 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2522 | rdev, wdev) < 0) { |
2523 | nlmsg_free(msg); | |
2524 | return -ENOBUFS; | |
2525 | } | |
2526 | ||
2527 | return genlmsg_reply(msg, info); | |
55682965 JB |
2528 | } |
2529 | ||
2530 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2531 | { | |
4c476991 | 2532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2533 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2534 | |
4c476991 JB |
2535 | if (!rdev->ops->del_virtual_intf) |
2536 | return -EOPNOTSUPP; | |
55682965 | 2537 | |
84efbb84 JB |
2538 | /* |
2539 | * If we remove a wireless device without a netdev then clear | |
2540 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2541 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2542 | * since the wdev has been freed, unlike with a netdev where | |
2543 | * we need the dev_put() for the netdev to really be freed. | |
2544 | */ | |
2545 | if (!wdev->netdev) | |
2546 | info->user_ptr[1] = NULL; | |
2547 | ||
e35e4d28 | 2548 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2549 | } |
2550 | ||
1d9d9213 SW |
2551 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2552 | { | |
2553 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2554 | struct net_device *dev = info->user_ptr[1]; | |
2555 | u16 noack_map; | |
2556 | ||
2557 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2558 | return -EINVAL; | |
2559 | ||
2560 | if (!rdev->ops->set_noack_map) | |
2561 | return -EOPNOTSUPP; | |
2562 | ||
2563 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2564 | ||
e35e4d28 | 2565 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2566 | } |
2567 | ||
41ade00f JB |
2568 | struct get_key_cookie { |
2569 | struct sk_buff *msg; | |
2570 | int error; | |
b9454e83 | 2571 | int idx; |
41ade00f JB |
2572 | }; |
2573 | ||
2574 | static void get_key_callback(void *c, struct key_params *params) | |
2575 | { | |
b9454e83 | 2576 | struct nlattr *key; |
41ade00f JB |
2577 | struct get_key_cookie *cookie = c; |
2578 | ||
9360ffd1 DM |
2579 | if ((params->key && |
2580 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2581 | params->key_len, params->key)) || | |
2582 | (params->seq && | |
2583 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2584 | params->seq_len, params->seq)) || | |
2585 | (params->cipher && | |
2586 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2587 | params->cipher))) | |
2588 | goto nla_put_failure; | |
41ade00f | 2589 | |
b9454e83 JB |
2590 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2591 | if (!key) | |
2592 | goto nla_put_failure; | |
2593 | ||
9360ffd1 DM |
2594 | if ((params->key && |
2595 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2596 | params->key_len, params->key)) || | |
2597 | (params->seq && | |
2598 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2599 | params->seq_len, params->seq)) || | |
2600 | (params->cipher && | |
2601 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2602 | params->cipher))) | |
2603 | goto nla_put_failure; | |
b9454e83 | 2604 | |
9360ffd1 DM |
2605 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2606 | goto nla_put_failure; | |
b9454e83 JB |
2607 | |
2608 | nla_nest_end(cookie->msg, key); | |
2609 | ||
41ade00f JB |
2610 | return; |
2611 | nla_put_failure: | |
2612 | cookie->error = 1; | |
2613 | } | |
2614 | ||
2615 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2616 | { | |
4c476991 | 2617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2618 | int err; |
4c476991 | 2619 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2620 | u8 key_idx = 0; |
e31b8213 JB |
2621 | const u8 *mac_addr = NULL; |
2622 | bool pairwise; | |
41ade00f JB |
2623 | struct get_key_cookie cookie = { |
2624 | .error = 0, | |
2625 | }; | |
2626 | void *hdr; | |
2627 | struct sk_buff *msg; | |
2628 | ||
2629 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2630 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2631 | ||
3cfcf6ac | 2632 | if (key_idx > 5) |
41ade00f JB |
2633 | return -EINVAL; |
2634 | ||
2635 | if (info->attrs[NL80211_ATTR_MAC]) | |
2636 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2637 | ||
e31b8213 JB |
2638 | pairwise = !!mac_addr; |
2639 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2640 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2641 | if (kt >= NUM_NL80211_KEYTYPES) | |
2642 | return -EINVAL; | |
2643 | if (kt != NL80211_KEYTYPE_GROUP && | |
2644 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2645 | return -EINVAL; | |
2646 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2647 | } | |
2648 | ||
4c476991 JB |
2649 | if (!rdev->ops->get_key) |
2650 | return -EOPNOTSUPP; | |
41ade00f | 2651 | |
fd2120ca | 2652 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2653 | if (!msg) |
2654 | return -ENOMEM; | |
41ade00f | 2655 | |
15e47304 | 2656 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2657 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2658 | if (IS_ERR(hdr)) |
2659 | return PTR_ERR(hdr); | |
41ade00f JB |
2660 | |
2661 | cookie.msg = msg; | |
b9454e83 | 2662 | cookie.idx = key_idx; |
41ade00f | 2663 | |
9360ffd1 DM |
2664 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2665 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2666 | goto nla_put_failure; | |
2667 | if (mac_addr && | |
2668 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2669 | goto nla_put_failure; | |
41ade00f | 2670 | |
e31b8213 JB |
2671 | if (pairwise && mac_addr && |
2672 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2673 | return -ENOENT; | |
2674 | ||
e35e4d28 HG |
2675 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2676 | get_key_callback); | |
41ade00f JB |
2677 | |
2678 | if (err) | |
6c95e2a2 | 2679 | goto free_msg; |
41ade00f JB |
2680 | |
2681 | if (cookie.error) | |
2682 | goto nla_put_failure; | |
2683 | ||
2684 | genlmsg_end(msg, hdr); | |
4c476991 | 2685 | return genlmsg_reply(msg, info); |
41ade00f JB |
2686 | |
2687 | nla_put_failure: | |
2688 | err = -ENOBUFS; | |
6c95e2a2 | 2689 | free_msg: |
41ade00f | 2690 | nlmsg_free(msg); |
41ade00f JB |
2691 | return err; |
2692 | } | |
2693 | ||
2694 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2695 | { | |
4c476991 | 2696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2697 | struct key_parse key; |
41ade00f | 2698 | int err; |
4c476991 | 2699 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2700 | |
b9454e83 JB |
2701 | err = nl80211_parse_key(info, &key); |
2702 | if (err) | |
2703 | return err; | |
41ade00f | 2704 | |
b9454e83 | 2705 | if (key.idx < 0) |
41ade00f JB |
2706 | return -EINVAL; |
2707 | ||
b9454e83 JB |
2708 | /* only support setting default key */ |
2709 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2710 | return -EINVAL; |
2711 | ||
dbd2fd65 | 2712 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2713 | |
dbd2fd65 JB |
2714 | if (key.def) { |
2715 | if (!rdev->ops->set_default_key) { | |
2716 | err = -EOPNOTSUPP; | |
2717 | goto out; | |
2718 | } | |
41ade00f | 2719 | |
dbd2fd65 JB |
2720 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2721 | if (err) | |
2722 | goto out; | |
2723 | ||
e35e4d28 | 2724 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2725 | key.def_uni, key.def_multi); |
2726 | ||
2727 | if (err) | |
2728 | goto out; | |
fffd0934 | 2729 | |
3d23e349 | 2730 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2731 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2732 | #endif | |
2733 | } else { | |
2734 | if (key.def_uni || !key.def_multi) { | |
2735 | err = -EINVAL; | |
2736 | goto out; | |
2737 | } | |
2738 | ||
2739 | if (!rdev->ops->set_default_mgmt_key) { | |
2740 | err = -EOPNOTSUPP; | |
2741 | goto out; | |
2742 | } | |
2743 | ||
2744 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2745 | if (err) | |
2746 | goto out; | |
2747 | ||
e35e4d28 | 2748 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2749 | if (err) |
2750 | goto out; | |
2751 | ||
2752 | #ifdef CONFIG_CFG80211_WEXT | |
2753 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2754 | #endif |
dbd2fd65 JB |
2755 | } |
2756 | ||
2757 | out: | |
fffd0934 | 2758 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2759 | |
41ade00f JB |
2760 | return err; |
2761 | } | |
2762 | ||
2763 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2764 | { | |
4c476991 | 2765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2766 | int err; |
4c476991 | 2767 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2768 | struct key_parse key; |
e31b8213 | 2769 | const u8 *mac_addr = NULL; |
41ade00f | 2770 | |
b9454e83 JB |
2771 | err = nl80211_parse_key(info, &key); |
2772 | if (err) | |
2773 | return err; | |
41ade00f | 2774 | |
b9454e83 | 2775 | if (!key.p.key) |
41ade00f JB |
2776 | return -EINVAL; |
2777 | ||
41ade00f JB |
2778 | if (info->attrs[NL80211_ATTR_MAC]) |
2779 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2780 | ||
e31b8213 JB |
2781 | if (key.type == -1) { |
2782 | if (mac_addr) | |
2783 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2784 | else | |
2785 | key.type = NL80211_KEYTYPE_GROUP; | |
2786 | } | |
2787 | ||
2788 | /* for now */ | |
2789 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2790 | key.type != NL80211_KEYTYPE_GROUP) | |
2791 | return -EINVAL; | |
2792 | ||
4c476991 JB |
2793 | if (!rdev->ops->add_key) |
2794 | return -EOPNOTSUPP; | |
25e47c18 | 2795 | |
e31b8213 JB |
2796 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2797 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2798 | mac_addr)) | |
4c476991 | 2799 | return -EINVAL; |
41ade00f | 2800 | |
fffd0934 JB |
2801 | wdev_lock(dev->ieee80211_ptr); |
2802 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2803 | if (!err) | |
e35e4d28 HG |
2804 | err = rdev_add_key(rdev, dev, key.idx, |
2805 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2806 | mac_addr, &key.p); | |
fffd0934 | 2807 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2808 | |
41ade00f JB |
2809 | return err; |
2810 | } | |
2811 | ||
2812 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2813 | { | |
4c476991 | 2814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2815 | int err; |
4c476991 | 2816 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2817 | u8 *mac_addr = NULL; |
b9454e83 | 2818 | struct key_parse key; |
41ade00f | 2819 | |
b9454e83 JB |
2820 | err = nl80211_parse_key(info, &key); |
2821 | if (err) | |
2822 | return err; | |
41ade00f JB |
2823 | |
2824 | if (info->attrs[NL80211_ATTR_MAC]) | |
2825 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2826 | ||
e31b8213 JB |
2827 | if (key.type == -1) { |
2828 | if (mac_addr) | |
2829 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2830 | else | |
2831 | key.type = NL80211_KEYTYPE_GROUP; | |
2832 | } | |
2833 | ||
2834 | /* for now */ | |
2835 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2836 | key.type != NL80211_KEYTYPE_GROUP) | |
2837 | return -EINVAL; | |
2838 | ||
4c476991 JB |
2839 | if (!rdev->ops->del_key) |
2840 | return -EOPNOTSUPP; | |
41ade00f | 2841 | |
fffd0934 JB |
2842 | wdev_lock(dev->ieee80211_ptr); |
2843 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2844 | |
2845 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2846 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2847 | err = -ENOENT; | |
2848 | ||
fffd0934 | 2849 | if (!err) |
e35e4d28 HG |
2850 | err = rdev_del_key(rdev, dev, key.idx, |
2851 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2852 | mac_addr); | |
41ade00f | 2853 | |
3d23e349 | 2854 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2855 | if (!err) { |
b9454e83 | 2856 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2857 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2858 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2859 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2860 | } | |
2861 | #endif | |
fffd0934 | 2862 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2863 | |
41ade00f JB |
2864 | return err; |
2865 | } | |
2866 | ||
77765eaf VT |
2867 | /* This function returns an error or the number of nested attributes */ |
2868 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2869 | { | |
2870 | struct nlattr *attr; | |
2871 | int n_entries = 0, tmp; | |
2872 | ||
2873 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2874 | if (nla_len(attr) != ETH_ALEN) | |
2875 | return -EINVAL; | |
2876 | ||
2877 | n_entries++; | |
2878 | } | |
2879 | ||
2880 | return n_entries; | |
2881 | } | |
2882 | ||
2883 | /* | |
2884 | * This function parses ACL information and allocates memory for ACL data. | |
2885 | * On successful return, the calling function is responsible to free the | |
2886 | * ACL buffer returned by this function. | |
2887 | */ | |
2888 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2889 | struct genl_info *info) | |
2890 | { | |
2891 | enum nl80211_acl_policy acl_policy; | |
2892 | struct nlattr *attr; | |
2893 | struct cfg80211_acl_data *acl; | |
2894 | int i = 0, n_entries, tmp; | |
2895 | ||
2896 | if (!wiphy->max_acl_mac_addrs) | |
2897 | return ERR_PTR(-EOPNOTSUPP); | |
2898 | ||
2899 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2900 | return ERR_PTR(-EINVAL); | |
2901 | ||
2902 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2903 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2904 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2905 | return ERR_PTR(-EINVAL); | |
2906 | ||
2907 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2908 | return ERR_PTR(-EINVAL); | |
2909 | ||
2910 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2911 | if (n_entries < 0) | |
2912 | return ERR_PTR(n_entries); | |
2913 | ||
2914 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2915 | return ERR_PTR(-ENOTSUPP); | |
2916 | ||
2917 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2918 | GFP_KERNEL); | |
2919 | if (!acl) | |
2920 | return ERR_PTR(-ENOMEM); | |
2921 | ||
2922 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2923 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2924 | i++; | |
2925 | } | |
2926 | ||
2927 | acl->n_acl_entries = n_entries; | |
2928 | acl->acl_policy = acl_policy; | |
2929 | ||
2930 | return acl; | |
2931 | } | |
2932 | ||
2933 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2934 | { | |
2935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2936 | struct net_device *dev = info->user_ptr[1]; | |
2937 | struct cfg80211_acl_data *acl; | |
2938 | int err; | |
2939 | ||
2940 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2941 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2942 | return -EOPNOTSUPP; | |
2943 | ||
2944 | if (!dev->ieee80211_ptr->beacon_interval) | |
2945 | return -EINVAL; | |
2946 | ||
2947 | acl = parse_acl_data(&rdev->wiphy, info); | |
2948 | if (IS_ERR(acl)) | |
2949 | return PTR_ERR(acl); | |
2950 | ||
2951 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2952 | ||
2953 | kfree(acl); | |
2954 | ||
2955 | return err; | |
2956 | } | |
2957 | ||
a1193be8 | 2958 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 2959 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 2960 | { |
8860020e | 2961 | bool haveinfo = false; |
ed1b6cc7 | 2962 | |
a1193be8 SW |
2963 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
2964 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
2965 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2966 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2967 | return -EINVAL; |
2968 | ||
8860020e | 2969 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2970 | |
a1193be8 SW |
2971 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
2972 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
2973 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
2974 | if (!bcn->head_len) |
2975 | return -EINVAL; | |
2976 | haveinfo = true; | |
ed1b6cc7 JB |
2977 | } |
2978 | ||
a1193be8 SW |
2979 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
2980 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
2981 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 2982 | haveinfo = true; |
ed1b6cc7 JB |
2983 | } |
2984 | ||
4c476991 JB |
2985 | if (!haveinfo) |
2986 | return -EINVAL; | |
3b85875a | 2987 | |
a1193be8 SW |
2988 | if (attrs[NL80211_ATTR_IE]) { |
2989 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
2990 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2991 | } |
2992 | ||
a1193be8 | 2993 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 2994 | bcn->proberesp_ies = |
a1193be8 | 2995 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2996 | bcn->proberesp_ies_len = |
a1193be8 | 2997 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
2998 | } |
2999 | ||
a1193be8 | 3000 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3001 | bcn->assocresp_ies = |
a1193be8 | 3002 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3003 | bcn->assocresp_ies_len = |
a1193be8 | 3004 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3005 | } |
3006 | ||
a1193be8 SW |
3007 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3008 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3009 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3010 | } |
3011 | ||
8860020e JB |
3012 | return 0; |
3013 | } | |
3014 | ||
46c1dd0c FF |
3015 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3016 | struct cfg80211_ap_settings *params) | |
3017 | { | |
3018 | struct wireless_dev *wdev; | |
3019 | bool ret = false; | |
3020 | ||
89a54e48 | 3021 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3022 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3023 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3024 | continue; | |
3025 | ||
683b6d3b | 3026 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3027 | continue; |
3028 | ||
683b6d3b | 3029 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3030 | ret = true; |
3031 | break; | |
3032 | } | |
3033 | ||
46c1dd0c FF |
3034 | return ret; |
3035 | } | |
3036 | ||
e39e5b5e JM |
3037 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3038 | enum nl80211_auth_type auth_type, | |
3039 | enum nl80211_commands cmd) | |
3040 | { | |
3041 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3042 | return false; | |
3043 | ||
3044 | switch (cmd) { | |
3045 | case NL80211_CMD_AUTHENTICATE: | |
3046 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3047 | auth_type == NL80211_AUTHTYPE_SAE) | |
3048 | return false; | |
3049 | return true; | |
3050 | case NL80211_CMD_CONNECT: | |
3051 | case NL80211_CMD_START_AP: | |
3052 | /* SAE not supported yet */ | |
3053 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3054 | return false; | |
3055 | return true; | |
3056 | default: | |
3057 | return false; | |
3058 | } | |
3059 | } | |
3060 | ||
8860020e JB |
3061 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3062 | { | |
3063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3064 | struct net_device *dev = info->user_ptr[1]; | |
3065 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3066 | struct cfg80211_ap_settings params; | |
3067 | int err; | |
04f39047 | 3068 | u8 radar_detect_width = 0; |
8860020e JB |
3069 | |
3070 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3071 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3072 | return -EOPNOTSUPP; | |
3073 | ||
3074 | if (!rdev->ops->start_ap) | |
3075 | return -EOPNOTSUPP; | |
3076 | ||
3077 | if (wdev->beacon_interval) | |
3078 | return -EALREADY; | |
3079 | ||
3080 | memset(¶ms, 0, sizeof(params)); | |
3081 | ||
3082 | /* these are required for START_AP */ | |
3083 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3084 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3085 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3086 | return -EINVAL; | |
3087 | ||
a1193be8 | 3088 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3089 | if (err) |
3090 | return err; | |
3091 | ||
3092 | params.beacon_interval = | |
3093 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3094 | params.dtim_period = | |
3095 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3096 | ||
3097 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3098 | if (err) | |
3099 | return err; | |
3100 | ||
3101 | /* | |
3102 | * In theory, some of these attributes should be required here | |
3103 | * but since they were not used when the command was originally | |
3104 | * added, keep them optional for old user space programs to let | |
3105 | * them continue to work with drivers that do not need the | |
3106 | * additional information -- drivers must check! | |
3107 | */ | |
3108 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3109 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3110 | params.ssid_len = | |
3111 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3112 | if (params.ssid_len == 0 || | |
3113 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3114 | return -EINVAL; | |
3115 | } | |
3116 | ||
3117 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3118 | params.hidden_ssid = nla_get_u32( | |
3119 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3120 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3121 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3122 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3123 | return -EINVAL; | |
3124 | } | |
3125 | ||
3126 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3127 | ||
3128 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3129 | params.auth_type = nla_get_u32( | |
3130 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3131 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3132 | NL80211_CMD_START_AP)) | |
8860020e JB |
3133 | return -EINVAL; |
3134 | } else | |
3135 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3136 | ||
3137 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3138 | NL80211_MAX_NR_CIPHER_SUITES); | |
3139 | if (err) | |
3140 | return err; | |
3141 | ||
1b658f11 VT |
3142 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3143 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3144 | return -EOPNOTSUPP; | |
3145 | params.inactivity_timeout = nla_get_u16( | |
3146 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3147 | } | |
3148 | ||
53cabad7 JB |
3149 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3151 | return -EINVAL; | |
3152 | params.p2p_ctwindow = | |
3153 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3154 | if (params.p2p_ctwindow > 127) | |
3155 | return -EINVAL; | |
3156 | if (params.p2p_ctwindow != 0 && | |
3157 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3158 | return -EINVAL; | |
3159 | } | |
3160 | ||
3161 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3162 | u8 tmp; | |
3163 | ||
3164 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3165 | return -EINVAL; | |
3166 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3167 | if (tmp > 1) | |
3168 | return -EINVAL; | |
3169 | params.p2p_opp_ps = tmp; | |
3170 | if (params.p2p_opp_ps != 0 && | |
3171 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3172 | return -EINVAL; | |
3173 | } | |
3174 | ||
aa430da4 | 3175 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3176 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3177 | if (err) | |
3178 | return err; | |
3179 | } else if (wdev->preset_chandef.chan) { | |
3180 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3181 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3182 | return -EINVAL; |
3183 | ||
683b6d3b | 3184 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3185 | return -EINVAL; |
3186 | ||
04f39047 SW |
3187 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3188 | if (err < 0) | |
3189 | return err; | |
3190 | if (err) { | |
3191 | radar_detect_width = BIT(params.chandef.width); | |
3192 | params.radar_required = true; | |
3193 | } | |
3194 | ||
04f39047 SW |
3195 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3196 | params.chandef.chan, | |
3197 | CHAN_MODE_SHARED, | |
3198 | radar_detect_width); | |
e4e32459 MK |
3199 | if (err) |
3200 | return err; | |
3201 | ||
77765eaf VT |
3202 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3203 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3204 | if (IS_ERR(params.acl)) | |
3205 | return PTR_ERR(params.acl); | |
3206 | } | |
3207 | ||
e35e4d28 | 3208 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3209 | if (!err) { |
683b6d3b | 3210 | wdev->preset_chandef = params.chandef; |
8860020e | 3211 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3212 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3213 | wdev->ssid_len = params.ssid_len; |
3214 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3215 | } |
77765eaf VT |
3216 | |
3217 | kfree(params.acl); | |
3218 | ||
56d1893d | 3219 | return err; |
ed1b6cc7 JB |
3220 | } |
3221 | ||
8860020e JB |
3222 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3223 | { | |
3224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3225 | struct net_device *dev = info->user_ptr[1]; | |
3226 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3227 | struct cfg80211_beacon_data params; | |
3228 | int err; | |
3229 | ||
3230 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3231 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3232 | return -EOPNOTSUPP; | |
3233 | ||
3234 | if (!rdev->ops->change_beacon) | |
3235 | return -EOPNOTSUPP; | |
3236 | ||
3237 | if (!wdev->beacon_interval) | |
3238 | return -EINVAL; | |
3239 | ||
a1193be8 | 3240 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3241 | if (err) |
3242 | return err; | |
3243 | ||
e35e4d28 | 3244 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3245 | } |
3246 | ||
3247 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3248 | { |
4c476991 JB |
3249 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3250 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3251 | |
60771780 | 3252 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3253 | } |
3254 | ||
5727ef1b JB |
3255 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3256 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3257 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3258 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3259 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3260 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3261 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3262 | }; |
3263 | ||
eccb8e8f | 3264 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3265 | enum nl80211_iftype iftype, |
eccb8e8f | 3266 | struct station_parameters *params) |
5727ef1b JB |
3267 | { |
3268 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3269 | struct nlattr *nla; |
5727ef1b JB |
3270 | int flag; |
3271 | ||
eccb8e8f JB |
3272 | /* |
3273 | * Try parsing the new attribute first so userspace | |
3274 | * can specify both for older kernels. | |
3275 | */ | |
3276 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3277 | if (nla) { | |
3278 | struct nl80211_sta_flag_update *sta_flags; | |
3279 | ||
3280 | sta_flags = nla_data(nla); | |
3281 | params->sta_flags_mask = sta_flags->mask; | |
3282 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3283 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3284 | if ((params->sta_flags_mask | |
3285 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3286 | return -EINVAL; | |
3287 | return 0; | |
3288 | } | |
3289 | ||
3290 | /* if present, parse the old attribute */ | |
5727ef1b | 3291 | |
eccb8e8f | 3292 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3293 | if (!nla) |
3294 | return 0; | |
3295 | ||
3296 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3297 | nla, sta_flags_policy)) | |
3298 | return -EINVAL; | |
3299 | ||
bdd3ae3d JB |
3300 | /* |
3301 | * Only allow certain flags for interface types so that | |
3302 | * other attributes are silently ignored. Remember that | |
3303 | * this is backward compatibility code with old userspace | |
3304 | * and shouldn't be hit in other cases anyway. | |
3305 | */ | |
3306 | switch (iftype) { | |
3307 | case NL80211_IFTYPE_AP: | |
3308 | case NL80211_IFTYPE_AP_VLAN: | |
3309 | case NL80211_IFTYPE_P2P_GO: | |
3310 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3311 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3312 | BIT(NL80211_STA_FLAG_WME) | | |
3313 | BIT(NL80211_STA_FLAG_MFP); | |
3314 | break; | |
3315 | case NL80211_IFTYPE_P2P_CLIENT: | |
3316 | case NL80211_IFTYPE_STATION: | |
3317 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3318 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3319 | break; | |
3320 | case NL80211_IFTYPE_MESH_POINT: | |
3321 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3322 | BIT(NL80211_STA_FLAG_MFP) | | |
3323 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3324 | default: | |
3325 | return -EINVAL; | |
3326 | } | |
5727ef1b | 3327 | |
3383b5a6 JB |
3328 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3329 | if (flags[flag]) { | |
eccb8e8f | 3330 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3331 | |
3383b5a6 JB |
3332 | /* no longer support new API additions in old API */ |
3333 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3334 | return -EINVAL; | |
3335 | } | |
3336 | } | |
3337 | ||
5727ef1b JB |
3338 | return 0; |
3339 | } | |
3340 | ||
c8dcfd8a FF |
3341 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3342 | int attr) | |
3343 | { | |
3344 | struct nlattr *rate; | |
8eb41c8d VK |
3345 | u32 bitrate; |
3346 | u16 bitrate_compat; | |
c8dcfd8a FF |
3347 | |
3348 | rate = nla_nest_start(msg, attr); | |
3349 | if (!rate) | |
db9c64cf | 3350 | return false; |
c8dcfd8a FF |
3351 | |
3352 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3353 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3354 | /* report 16-bit bitrate only if we can */ |
3355 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3356 | if (bitrate > 0 && |
3357 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3358 | return false; | |
3359 | if (bitrate_compat > 0 && | |
3360 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3361 | return false; | |
3362 | ||
3363 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3364 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3365 | return false; | |
3366 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3367 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3368 | return false; | |
3369 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3370 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3371 | return false; | |
3372 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3373 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3374 | return false; | |
3375 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3376 | return false; | |
3377 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3378 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3379 | return false; | |
3380 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3381 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3382 | return false; | |
3383 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3384 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3385 | return false; | |
3386 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3387 | nla_put_flag(msg, NL80211_RATE_INFO_160_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 | } | |
c8dcfd8a FF |
3393 | |
3394 | nla_nest_end(msg, rate); | |
3395 | return true; | |
c8dcfd8a FF |
3396 | } |
3397 | ||
119363c7 FF |
3398 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3399 | int id) | |
3400 | { | |
3401 | void *attr; | |
3402 | int i = 0; | |
3403 | ||
3404 | if (!mask) | |
3405 | return true; | |
3406 | ||
3407 | attr = nla_nest_start(msg, id); | |
3408 | if (!attr) | |
3409 | return false; | |
3410 | ||
3411 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3412 | if (!(mask & BIT(i))) | |
3413 | continue; | |
3414 | ||
3415 | if (nla_put_u8(msg, i, signal[i])) | |
3416 | return false; | |
3417 | } | |
3418 | ||
3419 | nla_nest_end(msg, attr); | |
3420 | ||
3421 | return true; | |
3422 | } | |
3423 | ||
15e47304 | 3424 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3425 | int flags, |
3426 | struct cfg80211_registered_device *rdev, | |
3427 | struct net_device *dev, | |
98b62183 | 3428 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3429 | { |
3430 | void *hdr; | |
f4263c98 | 3431 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3432 | |
15e47304 | 3433 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3434 | if (!hdr) |
3435 | return -1; | |
3436 | ||
9360ffd1 DM |
3437 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3438 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3439 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3440 | goto nla_put_failure; | |
f5ea9120 | 3441 | |
2ec600d6 LCC |
3442 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3443 | if (!sinfoattr) | |
fd5b74dc | 3444 | goto nla_put_failure; |
9360ffd1 DM |
3445 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3446 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3447 | sinfo->connected_time)) | |
3448 | goto nla_put_failure; | |
3449 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3450 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3451 | sinfo->inactive_time)) | |
3452 | goto nla_put_failure; | |
42745e03 VK |
3453 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3454 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3455 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3456 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3457 | goto nla_put_failure; |
42745e03 | 3458 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3459 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3460 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3461 | (u32)sinfo->tx_bytes)) |
3462 | goto nla_put_failure; | |
3463 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3464 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3465 | sinfo->rx_bytes)) | |
3466 | goto nla_put_failure; | |
3467 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3468 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3469 | sinfo->tx_bytes)) |
3470 | goto nla_put_failure; | |
3471 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3472 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3473 | goto nla_put_failure; | |
3474 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3475 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3476 | goto nla_put_failure; | |
3477 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3478 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3479 | sinfo->plink_state)) | |
3480 | goto nla_put_failure; | |
66266b3a JL |
3481 | switch (rdev->wiphy.signal_type) { |
3482 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3483 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3484 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3485 | sinfo->signal)) | |
3486 | goto nla_put_failure; | |
3487 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3488 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3489 | sinfo->signal_avg)) | |
3490 | goto nla_put_failure; | |
66266b3a JL |
3491 | break; |
3492 | default: | |
3493 | break; | |
3494 | } | |
119363c7 FF |
3495 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3496 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3497 | sinfo->chain_signal, | |
3498 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3499 | goto nla_put_failure; | |
3500 | } | |
3501 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3502 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3503 | sinfo->chain_signal_avg, | |
3504 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3505 | goto nla_put_failure; | |
3506 | } | |
420e7fab | 3507 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3508 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3509 | NL80211_STA_INFO_TX_BITRATE)) | |
3510 | goto nla_put_failure; | |
3511 | } | |
3512 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3513 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3514 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3515 | goto nla_put_failure; |
420e7fab | 3516 | } |
9360ffd1 DM |
3517 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3518 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3519 | sinfo->rx_packets)) | |
3520 | goto nla_put_failure; | |
3521 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3522 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3523 | sinfo->tx_packets)) | |
3524 | goto nla_put_failure; | |
3525 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3526 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3527 | sinfo->tx_retries)) | |
3528 | goto nla_put_failure; | |
3529 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3530 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3531 | sinfo->tx_failed)) | |
3532 | goto nla_put_failure; | |
3533 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3534 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3535 | sinfo->beacon_loss_count)) | |
3536 | goto nla_put_failure; | |
3b1c5a53 MP |
3537 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3538 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3539 | sinfo->local_pm)) | |
3540 | goto nla_put_failure; | |
3541 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3542 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3543 | sinfo->peer_pm)) | |
3544 | goto nla_put_failure; | |
3545 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3546 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3547 | sinfo->nonpeer_pm)) | |
3548 | goto nla_put_failure; | |
f4263c98 PS |
3549 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3550 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3551 | if (!bss_param) | |
3552 | goto nla_put_failure; | |
3553 | ||
9360ffd1 DM |
3554 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3555 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3556 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3557 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3558 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3559 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3560 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3561 | sinfo->bss_param.dtim_period) || | |
3562 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3563 | sinfo->bss_param.beacon_interval)) | |
3564 | goto nla_put_failure; | |
f4263c98 PS |
3565 | |
3566 | nla_nest_end(msg, bss_param); | |
3567 | } | |
9360ffd1 DM |
3568 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3569 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3570 | sizeof(struct nl80211_sta_flag_update), | |
3571 | &sinfo->sta_flags)) | |
3572 | goto nla_put_failure; | |
7eab0f64 JL |
3573 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3574 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3575 | sinfo->t_offset)) | |
3576 | goto nla_put_failure; | |
2ec600d6 | 3577 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3578 | |
9360ffd1 DM |
3579 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3580 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3581 | sinfo->assoc_req_ies)) | |
3582 | goto nla_put_failure; | |
50d3dfb7 | 3583 | |
fd5b74dc JB |
3584 | return genlmsg_end(msg, hdr); |
3585 | ||
3586 | nla_put_failure: | |
bc3ed28c TG |
3587 | genlmsg_cancel(msg, hdr); |
3588 | return -EMSGSIZE; | |
fd5b74dc JB |
3589 | } |
3590 | ||
2ec600d6 | 3591 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3592 | struct netlink_callback *cb) |
2ec600d6 | 3593 | { |
2ec600d6 LCC |
3594 | struct station_info sinfo; |
3595 | struct cfg80211_registered_device *dev; | |
97990a06 | 3596 | struct wireless_dev *wdev; |
2ec600d6 | 3597 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3598 | int sta_idx = cb->args[2]; |
2ec600d6 | 3599 | int err; |
2ec600d6 | 3600 | |
97990a06 | 3601 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3602 | if (err) |
3603 | return err; | |
bba95fef | 3604 | |
97990a06 JB |
3605 | if (!wdev->netdev) { |
3606 | err = -EINVAL; | |
3607 | goto out_err; | |
3608 | } | |
3609 | ||
bba95fef | 3610 | if (!dev->ops->dump_station) { |
eec60b03 | 3611 | err = -EOPNOTSUPP; |
bba95fef JB |
3612 | goto out_err; |
3613 | } | |
3614 | ||
bba95fef | 3615 | while (1) { |
f612cedf | 3616 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3617 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3618 | mac_addr, &sinfo); |
bba95fef JB |
3619 | if (err == -ENOENT) |
3620 | break; | |
3621 | if (err) | |
3b85875a | 3622 | goto out_err; |
bba95fef JB |
3623 | |
3624 | if (nl80211_send_station(skb, | |
15e47304 | 3625 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3626 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3627 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3628 | &sinfo) < 0) |
3629 | goto out; | |
3630 | ||
3631 | sta_idx++; | |
3632 | } | |
3633 | ||
3634 | ||
3635 | out: | |
97990a06 | 3636 | cb->args[2] = sta_idx; |
bba95fef | 3637 | err = skb->len; |
bba95fef | 3638 | out_err: |
97990a06 | 3639 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3640 | |
3641 | return err; | |
2ec600d6 | 3642 | } |
fd5b74dc | 3643 | |
5727ef1b JB |
3644 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3645 | { | |
4c476991 JB |
3646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3647 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3648 | struct station_info sinfo; |
fd5b74dc JB |
3649 | struct sk_buff *msg; |
3650 | u8 *mac_addr = NULL; | |
4c476991 | 3651 | int err; |
fd5b74dc | 3652 | |
2ec600d6 | 3653 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3654 | |
3655 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3656 | return -EINVAL; | |
3657 | ||
3658 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3659 | ||
4c476991 JB |
3660 | if (!rdev->ops->get_station) |
3661 | return -EOPNOTSUPP; | |
3b85875a | 3662 | |
e35e4d28 | 3663 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3664 | if (err) |
4c476991 | 3665 | return err; |
2ec600d6 | 3666 | |
fd2120ca | 3667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3668 | if (!msg) |
4c476991 | 3669 | return -ENOMEM; |
fd5b74dc | 3670 | |
15e47304 | 3671 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3672 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3673 | nlmsg_free(msg); |
3674 | return -ENOBUFS; | |
3675 | } | |
3b85875a | 3676 | |
4c476991 | 3677 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3678 | } |
3679 | ||
77ee7c89 JB |
3680 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3681 | struct station_parameters *params, | |
3682 | enum cfg80211_station_type statype) | |
3683 | { | |
3684 | if (params->listen_interval != -1) | |
3685 | return -EINVAL; | |
3686 | if (params->aid) | |
3687 | return -EINVAL; | |
3688 | ||
3689 | /* When you run into this, adjust the code below for the new flag */ | |
3690 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3691 | ||
3692 | switch (statype) { | |
eef941e6 TP |
3693 | case CFG80211_STA_MESH_PEER_KERNEL: |
3694 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3695 | /* |
3696 | * No ignoring the TDLS flag here -- the userspace mesh | |
3697 | * code doesn't have the bug of including TDLS in the | |
3698 | * mask everywhere. | |
3699 | */ | |
3700 | if (params->sta_flags_mask & | |
3701 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3702 | BIT(NL80211_STA_FLAG_MFP) | | |
3703 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3704 | return -EINVAL; | |
3705 | break; | |
3706 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3707 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3708 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3709 | return -EINVAL; | |
3710 | /* ignore since it can't change */ | |
3711 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3712 | break; | |
3713 | default: | |
3714 | /* disallow mesh-specific things */ | |
3715 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3716 | return -EINVAL; | |
3717 | if (params->local_pm) | |
3718 | return -EINVAL; | |
3719 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3720 | return -EINVAL; | |
3721 | } | |
3722 | ||
3723 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3724 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3725 | /* TDLS can't be set, ... */ | |
3726 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3727 | return -EINVAL; | |
3728 | /* | |
3729 | * ... but don't bother the driver with it. This works around | |
3730 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3731 | * TLDS_PEER flag in the mask even for AP mode. | |
3732 | */ | |
3733 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3734 | } | |
3735 | ||
3736 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3737 | /* reject other things that can't change */ | |
3738 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3739 | return -EINVAL; | |
3740 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3741 | return -EINVAL; | |
3742 | if (params->supported_rates) | |
3743 | return -EINVAL; | |
3744 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3745 | return -EINVAL; | |
3746 | } | |
3747 | ||
3748 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3749 | if (params->vlan) | |
3750 | return -EINVAL; | |
3751 | } | |
3752 | ||
3753 | switch (statype) { | |
3754 | case CFG80211_STA_AP_MLME_CLIENT: | |
3755 | /* Use this only for authorizing/unauthorizing a station */ | |
3756 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3757 | return -EOPNOTSUPP; | |
3758 | break; | |
3759 | case CFG80211_STA_AP_CLIENT: | |
3760 | /* accept only the listed bits */ | |
3761 | if (params->sta_flags_mask & | |
3762 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3763 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3764 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3765 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3766 | BIT(NL80211_STA_FLAG_WME) | | |
3767 | BIT(NL80211_STA_FLAG_MFP))) | |
3768 | return -EINVAL; | |
3769 | ||
3770 | /* but authenticated/associated only if driver handles it */ | |
3771 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3772 | params->sta_flags_mask & | |
3773 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3774 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3775 | return -EINVAL; | |
3776 | break; | |
3777 | case CFG80211_STA_IBSS: | |
3778 | case CFG80211_STA_AP_STA: | |
3779 | /* reject any changes other than AUTHORIZED */ | |
3780 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3781 | return -EINVAL; | |
3782 | break; | |
3783 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3784 | /* reject any changes other than AUTHORIZED or WME */ | |
3785 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3786 | BIT(NL80211_STA_FLAG_WME))) | |
3787 | return -EINVAL; | |
3788 | /* force (at least) rates when authorizing */ | |
3789 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3790 | !params->supported_rates) | |
3791 | return -EINVAL; | |
3792 | break; | |
3793 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3794 | /* reject any changes */ | |
3795 | return -EINVAL; | |
eef941e6 | 3796 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3797 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3798 | return -EINVAL; | |
3799 | break; | |
eef941e6 | 3800 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3801 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3802 | return -EINVAL; | |
3803 | break; | |
3804 | } | |
3805 | ||
3806 | return 0; | |
3807 | } | |
3808 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3809 | ||
5727ef1b | 3810 | /* |
c258d2de | 3811 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3812 | */ |
80b99899 JB |
3813 | static struct net_device *get_vlan(struct genl_info *info, |
3814 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3815 | { |
463d0183 | 3816 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3817 | struct net_device *v; |
3818 | int ret; | |
3819 | ||
3820 | if (!vlanattr) | |
3821 | return NULL; | |
3822 | ||
3823 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3824 | if (!v) | |
3825 | return ERR_PTR(-ENODEV); | |
3826 | ||
3827 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3828 | ret = -EINVAL; | |
3829 | goto error; | |
5727ef1b | 3830 | } |
80b99899 | 3831 | |
77ee7c89 JB |
3832 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3833 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3834 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3835 | ret = -EINVAL; | |
3836 | goto error; | |
3837 | } | |
3838 | ||
80b99899 JB |
3839 | if (!netif_running(v)) { |
3840 | ret = -ENETDOWN; | |
3841 | goto error; | |
3842 | } | |
3843 | ||
3844 | return v; | |
3845 | error: | |
3846 | dev_put(v); | |
3847 | return ERR_PTR(ret); | |
5727ef1b JB |
3848 | } |
3849 | ||
df881293 JM |
3850 | static struct nla_policy |
3851 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3852 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3853 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3854 | }; | |
3855 | ||
ff276691 JB |
3856 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3857 | struct station_parameters *params) | |
df881293 | 3858 | { |
df881293 JM |
3859 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3860 | struct nlattr *nla; | |
3861 | int err; | |
3862 | ||
df881293 JM |
3863 | /* parse WME attributes if present */ |
3864 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3865 | return 0; | |
3866 | ||
3867 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3868 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3869 | nl80211_sta_wme_policy); | |
3870 | if (err) | |
3871 | return err; | |
3872 | ||
3873 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3874 | params->uapsd_queues = nla_get_u8( | |
3875 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3876 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3877 | return -EINVAL; | |
3878 | ||
3879 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3880 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3881 | ||
3882 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3883 | return -EINVAL; | |
3884 | ||
3885 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3886 | ||
3887 | return 0; | |
3888 | } | |
3889 | ||
ff276691 JB |
3890 | static int nl80211_set_station_tdls(struct genl_info *info, |
3891 | struct station_parameters *params) | |
3892 | { | |
3893 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
5e4b6f56 JM |
3894 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
3895 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
3896 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3897 | params->ht_capa = | |
3898 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3899 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3900 | params->vht_capa = | |
3901 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3902 | ||
3903 | return nl80211_parse_sta_wme(info, params); | |
3904 | } | |
3905 | ||
5727ef1b JB |
3906 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3907 | { | |
4c476991 | 3908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3909 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3910 | struct station_parameters params; |
77ee7c89 JB |
3911 | u8 *mac_addr; |
3912 | int err; | |
5727ef1b JB |
3913 | |
3914 | memset(¶ms, 0, sizeof(params)); | |
3915 | ||
3916 | params.listen_interval = -1; | |
3917 | ||
77ee7c89 JB |
3918 | if (!rdev->ops->change_station) |
3919 | return -EOPNOTSUPP; | |
3920 | ||
5727ef1b JB |
3921 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3922 | return -EINVAL; | |
3923 | ||
3924 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3925 | return -EINVAL; | |
3926 | ||
3927 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3928 | ||
3929 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3930 | params.supported_rates = | |
3931 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3932 | params.supported_rates_len = | |
3933 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3934 | } | |
3935 | ||
9d62a986 JM |
3936 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3937 | params.capability = | |
3938 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3939 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3940 | } | |
3941 | ||
3942 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3943 | params.ext_capab = | |
3944 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3945 | params.ext_capab_len = | |
3946 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3947 | } | |
3948 | ||
df881293 | 3949 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3950 | return -EINVAL; |
36aedc90 | 3951 | |
bdd3ae3d | 3952 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3953 | return -EINVAL; |
3954 | ||
f8bacc21 | 3955 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3956 | params.plink_action = |
f8bacc21 JB |
3957 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3958 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3959 | return -EINVAL; | |
3960 | } | |
2ec600d6 | 3961 | |
f8bacc21 | 3962 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3963 | params.plink_state = |
f8bacc21 JB |
3964 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3965 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3966 | return -EINVAL; | |
3967 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3968 | } | |
9c3990aa | 3969 | |
3b1c5a53 MP |
3970 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3971 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3972 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3973 | ||
3974 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3975 | pm > NL80211_MESH_POWER_MAX) | |
3976 | return -EINVAL; | |
3977 | ||
3978 | params.local_pm = pm; | |
3979 | } | |
3980 | ||
77ee7c89 JB |
3981 | /* Include parameters for TDLS peer (will check later) */ |
3982 | err = nl80211_set_station_tdls(info, ¶ms); | |
3983 | if (err) | |
3984 | return err; | |
3985 | ||
3986 | params.vlan = get_vlan(info, rdev); | |
3987 | if (IS_ERR(params.vlan)) | |
3988 | return PTR_ERR(params.vlan); | |
3989 | ||
a97f4424 JB |
3990 | switch (dev->ieee80211_ptr->iftype) { |
3991 | case NL80211_IFTYPE_AP: | |
3992 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3993 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3994 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3995 | case NL80211_IFTYPE_STATION: |
267335d6 | 3996 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3997 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3998 | break; |
3999 | default: | |
77ee7c89 JB |
4000 | err = -EOPNOTSUPP; |
4001 | goto out_put_vlan; | |
034d655e JB |
4002 | } |
4003 | ||
77ee7c89 | 4004 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4005 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4006 | |
77ee7c89 | 4007 | out_put_vlan: |
5727ef1b JB |
4008 | if (params.vlan) |
4009 | dev_put(params.vlan); | |
3b85875a | 4010 | |
5727ef1b JB |
4011 | return err; |
4012 | } | |
4013 | ||
4014 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4015 | { | |
4c476991 | 4016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4017 | int err; |
4c476991 | 4018 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4019 | struct station_parameters params; |
4020 | u8 *mac_addr = NULL; | |
4021 | ||
4022 | memset(¶ms, 0, sizeof(params)); | |
4023 | ||
984c311b JB |
4024 | if (!rdev->ops->add_station) |
4025 | return -EOPNOTSUPP; | |
4026 | ||
5727ef1b JB |
4027 | if (!info->attrs[NL80211_ATTR_MAC]) |
4028 | return -EINVAL; | |
4029 | ||
5727ef1b JB |
4030 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4031 | return -EINVAL; | |
4032 | ||
4033 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4034 | return -EINVAL; | |
4035 | ||
5e4b6f56 JM |
4036 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4037 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4038 | return -EINVAL; |
4039 | ||
5727ef1b JB |
4040 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4041 | params.supported_rates = | |
4042 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4043 | params.supported_rates_len = | |
4044 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4045 | params.listen_interval = | |
4046 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4047 | |
3d124ea2 | 4048 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4049 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4050 | else |
4051 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4052 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4053 | return -EINVAL; | |
51b50fbe | 4054 | |
9d62a986 JM |
4055 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4056 | params.capability = | |
4057 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4058 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4059 | } | |
4060 | ||
4061 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4062 | params.ext_capab = | |
4063 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4064 | params.ext_capab_len = | |
4065 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4066 | } | |
4067 | ||
36aedc90 JM |
4068 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4069 | params.ht_capa = | |
4070 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4071 | |
f461be3e MP |
4072 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4073 | params.vht_capa = | |
4074 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4075 | ||
f8bacc21 | 4076 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4077 | params.plink_action = |
f8bacc21 JB |
4078 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4079 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4080 | return -EINVAL; | |
4081 | } | |
96b78dff | 4082 | |
ff276691 JB |
4083 | err = nl80211_parse_sta_wme(info, ¶ms); |
4084 | if (err) | |
4085 | return err; | |
bdd90d5e | 4086 | |
bdd3ae3d | 4087 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4088 | return -EINVAL; |
4089 | ||
77ee7c89 JB |
4090 | /* When you run into this, adjust the code below for the new flag */ |
4091 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4092 | ||
bdd90d5e JB |
4093 | switch (dev->ieee80211_ptr->iftype) { |
4094 | case NL80211_IFTYPE_AP: | |
4095 | case NL80211_IFTYPE_AP_VLAN: | |
4096 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4097 | /* ignore WME attributes if iface/sta is not capable */ |
4098 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4099 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4100 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4101 | |
bdd90d5e | 4102 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4103 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4104 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4105 | return -EINVAL; |
bdd90d5e JB |
4106 | /* but don't bother the driver with it */ |
4107 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4108 | |
d582cffb JB |
4109 | /* allow authenticated/associated only if driver handles it */ |
4110 | if (!(rdev->wiphy.features & | |
4111 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4112 | params.sta_flags_mask & | |
4113 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4114 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4115 | return -EINVAL; | |
4116 | ||
bdd90d5e JB |
4117 | /* must be last in here for error handling */ |
4118 | params.vlan = get_vlan(info, rdev); | |
4119 | if (IS_ERR(params.vlan)) | |
4120 | return PTR_ERR(params.vlan); | |
4121 | break; | |
4122 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4123 | /* ignore uAPSD data */ |
4124 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4125 | ||
d582cffb JB |
4126 | /* associated is disallowed */ |
4127 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4128 | return -EINVAL; | |
bdd90d5e | 4129 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4130 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4131 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4132 | return -EINVAL; |
4133 | break; | |
4134 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4135 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4136 | /* ignore uAPSD data */ |
4137 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4138 | ||
77ee7c89 JB |
4139 | /* these are disallowed */ |
4140 | if (params.sta_flags_mask & | |
4141 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4142 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4143 | return -EINVAL; |
bdd90d5e JB |
4144 | /* Only TDLS peers can be added */ |
4145 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4146 | return -EINVAL; | |
4147 | /* Can only add if TDLS ... */ | |
4148 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4149 | return -EOPNOTSUPP; | |
4150 | /* ... with external setup is supported */ | |
4151 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4152 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4153 | /* |
4154 | * Older wpa_supplicant versions always mark the TDLS peer | |
4155 | * as authorized, but it shouldn't yet be. | |
4156 | */ | |
4157 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4158 | break; |
4159 | default: | |
4160 | return -EOPNOTSUPP; | |
c75786c9 EP |
4161 | } |
4162 | ||
bdd90d5e | 4163 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4164 | |
e35e4d28 | 4165 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4166 | |
5727ef1b JB |
4167 | if (params.vlan) |
4168 | dev_put(params.vlan); | |
5727ef1b JB |
4169 | return err; |
4170 | } | |
4171 | ||
4172 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4173 | { | |
4c476991 JB |
4174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4175 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4176 | u8 *mac_addr = NULL; |
4177 | ||
4178 | if (info->attrs[NL80211_ATTR_MAC]) | |
4179 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4180 | ||
e80cf853 | 4181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4183 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4184 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4185 | return -EINVAL; | |
5727ef1b | 4186 | |
4c476991 JB |
4187 | if (!rdev->ops->del_station) |
4188 | return -EOPNOTSUPP; | |
3b85875a | 4189 | |
e35e4d28 | 4190 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4191 | } |
4192 | ||
15e47304 | 4193 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4194 | int flags, struct net_device *dev, |
4195 | u8 *dst, u8 *next_hop, | |
4196 | struct mpath_info *pinfo) | |
4197 | { | |
4198 | void *hdr; | |
4199 | struct nlattr *pinfoattr; | |
4200 | ||
15e47304 | 4201 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4202 | if (!hdr) |
4203 | return -1; | |
4204 | ||
9360ffd1 DM |
4205 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4206 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4207 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4208 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4209 | goto nla_put_failure; | |
f5ea9120 | 4210 | |
2ec600d6 LCC |
4211 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4212 | if (!pinfoattr) | |
4213 | goto nla_put_failure; | |
9360ffd1 DM |
4214 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4215 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4216 | pinfo->frame_qlen)) | |
4217 | goto nla_put_failure; | |
4218 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4219 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4220 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4221 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4222 | pinfo->metric)) || | |
4223 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4224 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4225 | pinfo->exptime)) || | |
4226 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4227 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4228 | pinfo->flags)) || | |
4229 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4230 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4231 | pinfo->discovery_timeout)) || | |
4232 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4233 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4234 | pinfo->discovery_retries))) | |
4235 | goto nla_put_failure; | |
2ec600d6 LCC |
4236 | |
4237 | nla_nest_end(msg, pinfoattr); | |
4238 | ||
4239 | return genlmsg_end(msg, hdr); | |
4240 | ||
4241 | nla_put_failure: | |
bc3ed28c TG |
4242 | genlmsg_cancel(msg, hdr); |
4243 | return -EMSGSIZE; | |
2ec600d6 LCC |
4244 | } |
4245 | ||
4246 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4247 | struct netlink_callback *cb) |
2ec600d6 | 4248 | { |
2ec600d6 LCC |
4249 | struct mpath_info pinfo; |
4250 | struct cfg80211_registered_device *dev; | |
97990a06 | 4251 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4252 | u8 dst[ETH_ALEN]; |
4253 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4254 | int path_idx = cb->args[2]; |
2ec600d6 | 4255 | int err; |
2ec600d6 | 4256 | |
97990a06 | 4257 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4258 | if (err) |
4259 | return err; | |
bba95fef JB |
4260 | |
4261 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4262 | err = -EOPNOTSUPP; |
bba95fef JB |
4263 | goto out_err; |
4264 | } | |
4265 | ||
97990a06 | 4266 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4267 | err = -EOPNOTSUPP; |
0448b5fc | 4268 | goto out_err; |
eec60b03 JM |
4269 | } |
4270 | ||
bba95fef | 4271 | while (1) { |
97990a06 JB |
4272 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4273 | next_hop, &pinfo); | |
bba95fef | 4274 | if (err == -ENOENT) |
2ec600d6 | 4275 | break; |
bba95fef | 4276 | if (err) |
3b85875a | 4277 | goto out_err; |
2ec600d6 | 4278 | |
15e47304 | 4279 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4280 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4281 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4282 | &pinfo) < 0) |
4283 | goto out; | |
2ec600d6 | 4284 | |
bba95fef | 4285 | path_idx++; |
2ec600d6 | 4286 | } |
2ec600d6 | 4287 | |
2ec600d6 | 4288 | |
bba95fef | 4289 | out: |
97990a06 | 4290 | cb->args[2] = path_idx; |
bba95fef | 4291 | err = skb->len; |
bba95fef | 4292 | out_err: |
97990a06 | 4293 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4294 | return err; |
2ec600d6 LCC |
4295 | } |
4296 | ||
4297 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4298 | { | |
4c476991 | 4299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4300 | int err; |
4c476991 | 4301 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4302 | struct mpath_info pinfo; |
4303 | struct sk_buff *msg; | |
4304 | u8 *dst = NULL; | |
4305 | u8 next_hop[ETH_ALEN]; | |
4306 | ||
4307 | memset(&pinfo, 0, sizeof(pinfo)); | |
4308 | ||
4309 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4310 | return -EINVAL; | |
4311 | ||
4312 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4313 | ||
4c476991 JB |
4314 | if (!rdev->ops->get_mpath) |
4315 | return -EOPNOTSUPP; | |
2ec600d6 | 4316 | |
4c476991 JB |
4317 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4318 | return -EOPNOTSUPP; | |
eec60b03 | 4319 | |
e35e4d28 | 4320 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4321 | if (err) |
4c476991 | 4322 | return err; |
2ec600d6 | 4323 | |
fd2120ca | 4324 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4325 | if (!msg) |
4c476991 | 4326 | return -ENOMEM; |
2ec600d6 | 4327 | |
15e47304 | 4328 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4329 | dev, dst, next_hop, &pinfo) < 0) { |
4330 | nlmsg_free(msg); | |
4331 | return -ENOBUFS; | |
4332 | } | |
3b85875a | 4333 | |
4c476991 | 4334 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4335 | } |
4336 | ||
4337 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4338 | { | |
4c476991 JB |
4339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4340 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4341 | u8 *dst = NULL; |
4342 | u8 *next_hop = NULL; | |
4343 | ||
4344 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4345 | return -EINVAL; | |
4346 | ||
4347 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4348 | return -EINVAL; | |
4349 | ||
4350 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4351 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4352 | ||
4c476991 JB |
4353 | if (!rdev->ops->change_mpath) |
4354 | return -EOPNOTSUPP; | |
35a8efe1 | 4355 | |
4c476991 JB |
4356 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4357 | return -EOPNOTSUPP; | |
2ec600d6 | 4358 | |
e35e4d28 | 4359 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4360 | } |
4c476991 | 4361 | |
2ec600d6 LCC |
4362 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4363 | { | |
4c476991 JB |
4364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4365 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4366 | u8 *dst = NULL; |
4367 | u8 *next_hop = NULL; | |
4368 | ||
4369 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4370 | return -EINVAL; | |
4371 | ||
4372 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4373 | return -EINVAL; | |
4374 | ||
4375 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4376 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4377 | ||
4c476991 JB |
4378 | if (!rdev->ops->add_mpath) |
4379 | return -EOPNOTSUPP; | |
35a8efe1 | 4380 | |
4c476991 JB |
4381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4382 | return -EOPNOTSUPP; | |
2ec600d6 | 4383 | |
e35e4d28 | 4384 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4385 | } |
4386 | ||
4387 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4388 | { | |
4c476991 JB |
4389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4390 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4391 | u8 *dst = NULL; |
4392 | ||
4393 | if (info->attrs[NL80211_ATTR_MAC]) | |
4394 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4395 | ||
4c476991 JB |
4396 | if (!rdev->ops->del_mpath) |
4397 | return -EOPNOTSUPP; | |
3b85875a | 4398 | |
e35e4d28 | 4399 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4400 | } |
4401 | ||
9f1ba906 JM |
4402 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4403 | { | |
4c476991 JB |
4404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4405 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4406 | struct bss_parameters params; |
4407 | ||
4408 | memset(¶ms, 0, sizeof(params)); | |
4409 | /* default to not changing parameters */ | |
4410 | params.use_cts_prot = -1; | |
4411 | params.use_short_preamble = -1; | |
4412 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4413 | params.ap_isolate = -1; |
50b12f59 | 4414 | params.ht_opmode = -1; |
53cabad7 JB |
4415 | params.p2p_ctwindow = -1; |
4416 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4417 | |
4418 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4419 | params.use_cts_prot = | |
4420 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4421 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4422 | params.use_short_preamble = | |
4423 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4424 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4425 | params.use_short_slot_time = | |
4426 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4427 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4428 | params.basic_rates = | |
4429 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4430 | params.basic_rates_len = | |
4431 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4432 | } | |
fd8aaaf3 FF |
4433 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4434 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4435 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4436 | params.ht_opmode = | |
4437 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4438 | |
53cabad7 JB |
4439 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4440 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4441 | return -EINVAL; | |
4442 | params.p2p_ctwindow = | |
4443 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4444 | if (params.p2p_ctwindow < 0) | |
4445 | return -EINVAL; | |
4446 | if (params.p2p_ctwindow != 0 && | |
4447 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4448 | return -EINVAL; | |
4449 | } | |
4450 | ||
4451 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4452 | u8 tmp; | |
4453 | ||
4454 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4455 | return -EINVAL; | |
4456 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4457 | if (tmp > 1) | |
4458 | return -EINVAL; | |
4459 | params.p2p_opp_ps = tmp; | |
4460 | if (params.p2p_opp_ps && | |
4461 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4462 | return -EINVAL; | |
4463 | } | |
4464 | ||
4c476991 JB |
4465 | if (!rdev->ops->change_bss) |
4466 | return -EOPNOTSUPP; | |
9f1ba906 | 4467 | |
074ac8df | 4468 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4469 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4470 | return -EOPNOTSUPP; | |
3b85875a | 4471 | |
e35e4d28 | 4472 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4473 | } |
4474 | ||
b54452b0 | 4475 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4476 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4477 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4478 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4479 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4480 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4481 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4482 | }; | |
4483 | ||
4484 | static int parse_reg_rule(struct nlattr *tb[], | |
4485 | struct ieee80211_reg_rule *reg_rule) | |
4486 | { | |
4487 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4488 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4489 | ||
4490 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4491 | return -EINVAL; | |
4492 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4493 | return -EINVAL; | |
4494 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4495 | return -EINVAL; | |
4496 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4497 | return -EINVAL; | |
4498 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4499 | return -EINVAL; | |
4500 | ||
4501 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4502 | ||
4503 | freq_range->start_freq_khz = | |
4504 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4505 | freq_range->end_freq_khz = | |
4506 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4507 | freq_range->max_bandwidth_khz = | |
4508 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4509 | ||
4510 | power_rule->max_eirp = | |
4511 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4512 | ||
4513 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4514 | power_rule->max_antenna_gain = | |
4515 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4516 | ||
4517 | return 0; | |
4518 | } | |
4519 | ||
4520 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4521 | { | |
4522 | int r; | |
4523 | char *data = NULL; | |
57b5ce07 | 4524 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4525 | |
80778f18 LR |
4526 | /* |
4527 | * You should only get this when cfg80211 hasn't yet initialized | |
4528 | * completely when built-in to the kernel right between the time | |
4529 | * window between nl80211_init() and regulatory_init(), if that is | |
4530 | * even possible. | |
4531 | */ | |
458f4f9e | 4532 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4533 | return -EINPROGRESS; |
80778f18 | 4534 | |
fe33eb39 LR |
4535 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4536 | return -EINVAL; | |
b2e1b302 LR |
4537 | |
4538 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4539 | ||
57b5ce07 LR |
4540 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4541 | user_reg_hint_type = | |
4542 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4543 | else | |
4544 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4545 | ||
4546 | switch (user_reg_hint_type) { | |
4547 | case NL80211_USER_REG_HINT_USER: | |
4548 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4549 | break; | |
4550 | default: | |
4551 | return -EINVAL; | |
4552 | } | |
4553 | ||
4554 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4555 | |
b2e1b302 LR |
4556 | return r; |
4557 | } | |
4558 | ||
24bdd9f4 | 4559 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4560 | struct genl_info *info) |
93da9cc1 | 4561 | { |
4c476991 | 4562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4563 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4565 | struct mesh_config cur_params; | |
4566 | int err = 0; | |
93da9cc1 | 4567 | void *hdr; |
4568 | struct nlattr *pinfoattr; | |
4569 | struct sk_buff *msg; | |
4570 | ||
29cbe68c JB |
4571 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4572 | return -EOPNOTSUPP; | |
4573 | ||
24bdd9f4 | 4574 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4575 | return -EOPNOTSUPP; |
f3f92586 | 4576 | |
29cbe68c JB |
4577 | wdev_lock(wdev); |
4578 | /* If not connected, get default parameters */ | |
4579 | if (!wdev->mesh_id_len) | |
4580 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4581 | else | |
e35e4d28 | 4582 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4583 | wdev_unlock(wdev); |
4584 | ||
93da9cc1 | 4585 | if (err) |
4c476991 | 4586 | return err; |
93da9cc1 | 4587 | |
4588 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4589 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4590 | if (!msg) |
4591 | return -ENOMEM; | |
15e47304 | 4592 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4593 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4594 | if (!hdr) |
efe1cf0c | 4595 | goto out; |
24bdd9f4 | 4596 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4597 | if (!pinfoattr) |
4598 | goto nla_put_failure; | |
9360ffd1 DM |
4599 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4600 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4601 | cur_params.dot11MeshRetryTimeout) || | |
4602 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4603 | cur_params.dot11MeshConfirmTimeout) || | |
4604 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4605 | cur_params.dot11MeshHoldingTimeout) || | |
4606 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4607 | cur_params.dot11MeshMaxPeerLinks) || | |
4608 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4609 | cur_params.dot11MeshMaxRetries) || | |
4610 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4611 | cur_params.dot11MeshTTL) || | |
4612 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4613 | cur_params.element_ttl) || | |
4614 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4615 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4616 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4617 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4618 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4619 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4620 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4621 | cur_params.path_refresh_time) || | |
4622 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4623 | cur_params.min_discovery_timeout) || | |
4624 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4625 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4626 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4627 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4628 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4629 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4630 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4631 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4632 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4633 | cur_params.dot11MeshHWMPRootMode) || | |
4634 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4635 | cur_params.dot11MeshHWMPRannInterval) || | |
4636 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4637 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4638 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4639 | cur_params.dot11MeshForwarding) || | |
4640 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4641 | cur_params.rssi_threshold) || |
4642 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4643 | cur_params.ht_opmode) || |
4644 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4645 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4646 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4647 | cur_params.dot11MeshHWMProotInterval) || |
4648 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4649 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4650 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4651 | cur_params.power_mode) || | |
4652 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4653 | cur_params.dot11MeshAwakeWindowDuration) || |
4654 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4655 | cur_params.plink_timeout)) | |
9360ffd1 | 4656 | goto nla_put_failure; |
93da9cc1 | 4657 | nla_nest_end(msg, pinfoattr); |
4658 | genlmsg_end(msg, hdr); | |
4c476991 | 4659 | return genlmsg_reply(msg, info); |
93da9cc1 | 4660 | |
3b85875a | 4661 | nla_put_failure: |
93da9cc1 | 4662 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4663 | out: |
d080e275 | 4664 | nlmsg_free(msg); |
4c476991 | 4665 | return -ENOBUFS; |
93da9cc1 | 4666 | } |
4667 | ||
b54452b0 | 4668 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4669 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4670 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4671 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4672 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4673 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4674 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4675 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4676 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4677 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4678 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4679 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4680 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4681 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4682 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4683 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4684 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4685 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4686 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4687 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4688 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4689 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4690 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4691 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4692 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4693 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4694 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4695 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4696 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4697 | }; |
4698 | ||
c80d545d JC |
4699 | static const struct nla_policy |
4700 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4701 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4702 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4703 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4704 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4705 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4706 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4707 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4708 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4709 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4710 | }; |
4711 | ||
24bdd9f4 | 4712 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4713 | struct mesh_config *cfg, |
4714 | u32 *mask_out) | |
93da9cc1 | 4715 | { |
93da9cc1 | 4716 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4717 | u32 mask = 0; |
93da9cc1 | 4718 | |
ea54fba2 MP |
4719 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4720 | do { \ | |
4721 | if (tb[attr]) { \ | |
4722 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4723 | return -EINVAL; \ | |
4724 | cfg->param = fn(tb[attr]); \ | |
4725 | mask |= (1 << (attr - 1)); \ | |
4726 | } \ | |
4727 | } while (0) | |
bd90fdcc JB |
4728 | |
4729 | ||
24bdd9f4 | 4730 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4731 | return -EINVAL; |
4732 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4733 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4734 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4735 | return -EINVAL; |
4736 | ||
93da9cc1 | 4737 | /* This makes sure that there aren't more than 32 mesh config |
4738 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4739 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4740 | ||
4741 | /* Fill in the params struct */ | |
ea54fba2 | 4742 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4743 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4744 | nla_get_u16); | |
ea54fba2 | 4745 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4746 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4747 | nla_get_u16); | |
ea54fba2 | 4748 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4749 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4750 | nla_get_u16); | |
ea54fba2 | 4751 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4752 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4753 | nla_get_u16); | |
ea54fba2 | 4754 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4755 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4756 | nla_get_u8); | |
ea54fba2 | 4757 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4758 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4759 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4760 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4761 | nla_get_u8); | |
ea54fba2 | 4762 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4763 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4764 | nla_get_u8); | |
ea54fba2 MP |
4765 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4766 | 1, 255, mask, | |
a4f606ea CYY |
4767 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4768 | nla_get_u32); | |
ea54fba2 | 4769 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4770 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4771 | nla_get_u8); | |
ea54fba2 | 4772 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4773 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4774 | nla_get_u32); | |
ea54fba2 | 4775 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4776 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4777 | nla_get_u16); | |
ea54fba2 MP |
4778 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4779 | 1, 65535, mask, | |
a4f606ea CYY |
4780 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4781 | nla_get_u32); | |
93da9cc1 | 4782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4783 | 1, 65535, mask, |
4784 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4785 | nla_get_u16); |
dca7e943 | 4786 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4787 | 1, 65535, mask, |
4788 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4789 | nla_get_u16); |
93da9cc1 | 4790 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4791 | dot11MeshHWMPnetDiameterTraversalTime, |
4792 | 1, 65535, mask, | |
a4f606ea CYY |
4793 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4794 | nla_get_u16); | |
ea54fba2 MP |
4795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4796 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4797 | nla_get_u8); | |
4798 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4799 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4800 | nla_get_u16); |
63c5723b | 4801 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4802 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4803 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4804 | nla_get_u8); |
ea54fba2 | 4805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4806 | mask, NL80211_MESHCONF_FORWARDING, |
4807 | nla_get_u8); | |
ea54fba2 | 4808 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4809 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4810 | nla_get_u32); | |
ea54fba2 | 4811 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4812 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4813 | nla_get_u16); |
4814 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4815 | 1, 65535, mask, |
ac1073a6 CYY |
4816 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4817 | nla_get_u32); | |
ea54fba2 | 4818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4819 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4820 | nla_get_u16); |
4821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4822 | dot11MeshHWMPconfirmationInterval, |
4823 | 1, 65535, mask, | |
728b19e5 | 4824 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4825 | nla_get_u16); |
3b1c5a53 MP |
4826 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4827 | NL80211_MESH_POWER_ACTIVE, | |
4828 | NL80211_MESH_POWER_MAX, | |
4829 | mask, NL80211_MESHCONF_POWER_MODE, | |
4830 | nla_get_u32); | |
4831 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4832 | 0, 65535, mask, | |
4833 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
4834 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
4835 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4836 | nla_get_u32); | |
bd90fdcc JB |
4837 | if (mask_out) |
4838 | *mask_out = mask; | |
c80d545d | 4839 | |
bd90fdcc JB |
4840 | return 0; |
4841 | ||
4842 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4843 | } | |
4844 | ||
c80d545d JC |
4845 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4846 | struct mesh_setup *setup) | |
4847 | { | |
bb2798d4 | 4848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4849 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4850 | ||
4851 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4852 | return -EINVAL; | |
4853 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4854 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4855 | nl80211_mesh_setup_params_policy)) | |
4856 | return -EINVAL; | |
4857 | ||
d299a1f2 JC |
4858 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4859 | setup->sync_method = | |
4860 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4861 | IEEE80211_SYNC_METHOD_VENDOR : | |
4862 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4863 | ||
c80d545d JC |
4864 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4865 | setup->path_sel_proto = | |
4866 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4867 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4868 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4869 | ||
4870 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4871 | setup->path_metric = | |
4872 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4873 | IEEE80211_PATH_METRIC_VENDOR : | |
4874 | IEEE80211_PATH_METRIC_AIRTIME; | |
4875 | ||
581a8b0f JC |
4876 | |
4877 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4878 | struct nlattr *ieattr = |
581a8b0f | 4879 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4880 | if (!is_valid_ie_attr(ieattr)) |
4881 | return -EINVAL; | |
581a8b0f JC |
4882 | setup->ie = nla_data(ieattr); |
4883 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4884 | } |
bb2798d4 TP |
4885 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4886 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4887 | return -EINVAL; | |
4888 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4889 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4890 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4891 | if (setup->is_secure) |
4892 | setup->user_mpm = true; | |
c80d545d | 4893 | |
6e16d90b CT |
4894 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
4895 | if (!setup->user_mpm) | |
4896 | return -EINVAL; | |
4897 | setup->auth_id = | |
4898 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
4899 | } | |
4900 | ||
c80d545d JC |
4901 | return 0; |
4902 | } | |
4903 | ||
24bdd9f4 | 4904 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4905 | struct genl_info *info) |
bd90fdcc JB |
4906 | { |
4907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4908 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4909 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4910 | struct mesh_config cfg; |
4911 | u32 mask; | |
4912 | int err; | |
4913 | ||
29cbe68c JB |
4914 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4915 | return -EOPNOTSUPP; | |
4916 | ||
24bdd9f4 | 4917 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4918 | return -EOPNOTSUPP; |
4919 | ||
24bdd9f4 | 4920 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4921 | if (err) |
4922 | return err; | |
4923 | ||
29cbe68c JB |
4924 | wdev_lock(wdev); |
4925 | if (!wdev->mesh_id_len) | |
4926 | err = -ENOLINK; | |
4927 | ||
4928 | if (!err) | |
e35e4d28 | 4929 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4930 | |
4931 | wdev_unlock(wdev); | |
4932 | ||
4933 | return err; | |
93da9cc1 | 4934 | } |
4935 | ||
f130347c LR |
4936 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4937 | { | |
458f4f9e | 4938 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4939 | struct sk_buff *msg; |
4940 | void *hdr = NULL; | |
4941 | struct nlattr *nl_reg_rules; | |
4942 | unsigned int i; | |
f130347c LR |
4943 | |
4944 | if (!cfg80211_regdomain) | |
5fe231e8 | 4945 | return -EINVAL; |
f130347c | 4946 | |
fd2120ca | 4947 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
4948 | if (!msg) |
4949 | return -ENOBUFS; | |
f130347c | 4950 | |
15e47304 | 4951 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4952 | NL80211_CMD_GET_REG); |
4953 | if (!hdr) | |
efe1cf0c | 4954 | goto put_failure; |
f130347c | 4955 | |
57b5ce07 LR |
4956 | if (reg_last_request_cell_base() && |
4957 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4958 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4959 | goto nla_put_failure; | |
4960 | ||
458f4f9e JB |
4961 | rcu_read_lock(); |
4962 | regdom = rcu_dereference(cfg80211_regdomain); | |
4963 | ||
4964 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4965 | (regdom->dfs_region && | |
4966 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4967 | goto nla_put_failure_rcu; | |
4968 | ||
f130347c LR |
4969 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4970 | if (!nl_reg_rules) | |
458f4f9e | 4971 | goto nla_put_failure_rcu; |
f130347c | 4972 | |
458f4f9e | 4973 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4974 | struct nlattr *nl_reg_rule; |
4975 | const struct ieee80211_reg_rule *reg_rule; | |
4976 | const struct ieee80211_freq_range *freq_range; | |
4977 | const struct ieee80211_power_rule *power_rule; | |
4978 | ||
458f4f9e | 4979 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4980 | freq_range = ®_rule->freq_range; |
4981 | power_rule = ®_rule->power_rule; | |
4982 | ||
4983 | nl_reg_rule = nla_nest_start(msg, i); | |
4984 | if (!nl_reg_rule) | |
458f4f9e | 4985 | goto nla_put_failure_rcu; |
f130347c | 4986 | |
9360ffd1 DM |
4987 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4988 | reg_rule->flags) || | |
4989 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4990 | freq_range->start_freq_khz) || | |
4991 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4992 | freq_range->end_freq_khz) || | |
4993 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4994 | freq_range->max_bandwidth_khz) || | |
4995 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4996 | power_rule->max_antenna_gain) || | |
4997 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4998 | power_rule->max_eirp)) | |
458f4f9e | 4999 | goto nla_put_failure_rcu; |
f130347c LR |
5000 | |
5001 | nla_nest_end(msg, nl_reg_rule); | |
5002 | } | |
458f4f9e | 5003 | rcu_read_unlock(); |
f130347c LR |
5004 | |
5005 | nla_nest_end(msg, nl_reg_rules); | |
5006 | ||
5007 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5008 | return genlmsg_reply(msg, info); |
f130347c | 5009 | |
458f4f9e JB |
5010 | nla_put_failure_rcu: |
5011 | rcu_read_unlock(); | |
f130347c LR |
5012 | nla_put_failure: |
5013 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5014 | put_failure: |
d080e275 | 5015 | nlmsg_free(msg); |
5fe231e8 | 5016 | return -EMSGSIZE; |
f130347c LR |
5017 | } |
5018 | ||
b2e1b302 LR |
5019 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5020 | { | |
5021 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5022 | struct nlattr *nl_reg_rule; | |
5023 | char *alpha2 = NULL; | |
5024 | int rem_reg_rules = 0, r = 0; | |
5025 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 5026 | u8 dfs_region = 0; |
b2e1b302 LR |
5027 | struct ieee80211_regdomain *rd = NULL; |
5028 | ||
5029 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5030 | return -EINVAL; | |
5031 | ||
5032 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5033 | return -EINVAL; | |
5034 | ||
5035 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5036 | ||
8b60b078 LR |
5037 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5038 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5039 | ||
b2e1b302 | 5040 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5041 | rem_reg_rules) { |
b2e1b302 LR |
5042 | num_rules++; |
5043 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5044 | return -EINVAL; |
b2e1b302 LR |
5045 | } |
5046 | ||
b2e1b302 | 5047 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5048 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5049 | |
5050 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5051 | if (!rd) |
5052 | return -ENOMEM; | |
b2e1b302 LR |
5053 | |
5054 | rd->n_reg_rules = num_rules; | |
5055 | rd->alpha2[0] = alpha2[0]; | |
5056 | rd->alpha2[1] = alpha2[1]; | |
5057 | ||
8b60b078 LR |
5058 | /* |
5059 | * Disable DFS master mode if the DFS region was | |
5060 | * not supported or known on this kernel. | |
5061 | */ | |
5062 | if (reg_supported_dfs_region(dfs_region)) | |
5063 | rd->dfs_region = dfs_region; | |
5064 | ||
b2e1b302 | 5065 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5066 | rem_reg_rules) { |
b2e1b302 | 5067 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
5068 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
5069 | reg_rule_policy); | |
b2e1b302 LR |
5070 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5071 | if (r) | |
5072 | goto bad_reg; | |
5073 | ||
5074 | rule_idx++; | |
5075 | ||
d0e18f83 LR |
5076 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5077 | r = -EINVAL; | |
b2e1b302 | 5078 | goto bad_reg; |
d0e18f83 | 5079 | } |
b2e1b302 LR |
5080 | } |
5081 | ||
b2e1b302 | 5082 | r = set_regdom(rd); |
6913b49a | 5083 | /* set_regdom took ownership */ |
1a919318 | 5084 | rd = NULL; |
b2e1b302 | 5085 | |
d2372b31 | 5086 | bad_reg: |
b2e1b302 | 5087 | kfree(rd); |
d0e18f83 | 5088 | return r; |
b2e1b302 LR |
5089 | } |
5090 | ||
83f5e2cf JB |
5091 | static int validate_scan_freqs(struct nlattr *freqs) |
5092 | { | |
5093 | struct nlattr *attr1, *attr2; | |
5094 | int n_channels = 0, tmp1, tmp2; | |
5095 | ||
5096 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5097 | n_channels++; | |
5098 | /* | |
5099 | * Some hardware has a limited channel list for | |
5100 | * scanning, and it is pretty much nonsensical | |
5101 | * to scan for a channel twice, so disallow that | |
5102 | * and don't require drivers to check that the | |
5103 | * channel list they get isn't longer than what | |
5104 | * they can scan, as long as they can scan all | |
5105 | * the channels they registered at once. | |
5106 | */ | |
5107 | nla_for_each_nested(attr2, freqs, tmp2) | |
5108 | if (attr1 != attr2 && | |
5109 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5110 | return 0; | |
5111 | } | |
5112 | ||
5113 | return n_channels; | |
5114 | } | |
5115 | ||
2a519311 JB |
5116 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5117 | { | |
4c476991 | 5118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5119 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5120 | struct cfg80211_scan_request *request; |
2a519311 JB |
5121 | struct nlattr *attr; |
5122 | struct wiphy *wiphy; | |
83f5e2cf | 5123 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5124 | size_t ie_len; |
2a519311 | 5125 | |
f4a11bb0 JB |
5126 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5127 | return -EINVAL; | |
5128 | ||
79c97e97 | 5129 | wiphy = &rdev->wiphy; |
2a519311 | 5130 | |
4c476991 JB |
5131 | if (!rdev->ops->scan) |
5132 | return -EOPNOTSUPP; | |
2a519311 | 5133 | |
f9f47529 JB |
5134 | if (rdev->scan_req) { |
5135 | err = -EBUSY; | |
5136 | goto unlock; | |
5137 | } | |
2a519311 JB |
5138 | |
5139 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5140 | n_channels = validate_scan_freqs( |
5141 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5142 | if (!n_channels) { |
5143 | err = -EINVAL; | |
5144 | goto unlock; | |
5145 | } | |
2a519311 | 5146 | } else { |
34850ab2 | 5147 | enum ieee80211_band band; |
83f5e2cf JB |
5148 | n_channels = 0; |
5149 | ||
2a519311 JB |
5150 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5151 | if (wiphy->bands[band]) | |
5152 | n_channels += wiphy->bands[band]->n_channels; | |
5153 | } | |
5154 | ||
5155 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5156 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5157 | n_ssids++; | |
5158 | ||
f9f47529 JB |
5159 | if (n_ssids > wiphy->max_scan_ssids) { |
5160 | err = -EINVAL; | |
5161 | goto unlock; | |
5162 | } | |
2a519311 | 5163 | |
70692ad2 JM |
5164 | if (info->attrs[NL80211_ATTR_IE]) |
5165 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5166 | else | |
5167 | ie_len = 0; | |
5168 | ||
f9f47529 JB |
5169 | if (ie_len > wiphy->max_scan_ie_len) { |
5170 | err = -EINVAL; | |
5171 | goto unlock; | |
5172 | } | |
18a83659 | 5173 | |
2a519311 | 5174 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5175 | + sizeof(*request->ssids) * n_ssids |
5176 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5177 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5178 | if (!request) { |
5179 | err = -ENOMEM; | |
5180 | goto unlock; | |
5181 | } | |
2a519311 | 5182 | |
2a519311 | 5183 | if (n_ssids) |
5ba63533 | 5184 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5185 | request->n_ssids = n_ssids; |
70692ad2 JM |
5186 | if (ie_len) { |
5187 | if (request->ssids) | |
5188 | request->ie = (void *)(request->ssids + n_ssids); | |
5189 | else | |
5190 | request->ie = (void *)(request->channels + n_channels); | |
5191 | } | |
2a519311 | 5192 | |
584991dc | 5193 | i = 0; |
2a519311 JB |
5194 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5195 | /* user specified, bail out if channel not found */ | |
2a519311 | 5196 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5197 | struct ieee80211_channel *chan; |
5198 | ||
5199 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5200 | ||
5201 | if (!chan) { | |
2a519311 JB |
5202 | err = -EINVAL; |
5203 | goto out_free; | |
5204 | } | |
584991dc JB |
5205 | |
5206 | /* ignore disabled channels */ | |
5207 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5208 | continue; | |
5209 | ||
5210 | request->channels[i] = chan; | |
2a519311 JB |
5211 | i++; |
5212 | } | |
5213 | } else { | |
34850ab2 JB |
5214 | enum ieee80211_band band; |
5215 | ||
2a519311 | 5216 | /* all channels */ |
2a519311 JB |
5217 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5218 | int j; | |
5219 | if (!wiphy->bands[band]) | |
5220 | continue; | |
5221 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5222 | struct ieee80211_channel *chan; |
5223 | ||
5224 | chan = &wiphy->bands[band]->channels[j]; | |
5225 | ||
5226 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5227 | continue; | |
5228 | ||
5229 | request->channels[i] = chan; | |
2a519311 JB |
5230 | i++; |
5231 | } | |
5232 | } | |
5233 | } | |
5234 | ||
584991dc JB |
5235 | if (!i) { |
5236 | err = -EINVAL; | |
5237 | goto out_free; | |
5238 | } | |
5239 | ||
5240 | request->n_channels = i; | |
5241 | ||
2a519311 JB |
5242 | i = 0; |
5243 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5244 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5245 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5246 | err = -EINVAL; |
5247 | goto out_free; | |
5248 | } | |
57a27e1d | 5249 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5250 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5251 | i++; |
5252 | } | |
5253 | } | |
5254 | ||
70692ad2 JM |
5255 | if (info->attrs[NL80211_ATTR_IE]) { |
5256 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5257 | memcpy((void *)request->ie, |
5258 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5259 | request->ie_len); |
5260 | } | |
5261 | ||
34850ab2 | 5262 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5263 | if (wiphy->bands[i]) |
5264 | request->rates[i] = | |
5265 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5266 | |
5267 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5268 | nla_for_each_nested(attr, | |
5269 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5270 | tmp) { | |
5271 | enum ieee80211_band band = nla_type(attr); | |
5272 | ||
84404623 | 5273 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5274 | err = -EINVAL; |
5275 | goto out_free; | |
5276 | } | |
5277 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5278 | nla_data(attr), | |
5279 | nla_len(attr), | |
5280 | &request->rates[band]); | |
5281 | if (err) | |
5282 | goto out_free; | |
5283 | } | |
5284 | } | |
5285 | ||
46856bbf | 5286 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5287 | request->flags = nla_get_u32( |
5288 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5289 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5290 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5291 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5292 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5293 | err = -EOPNOTSUPP; |
5294 | goto out_free; | |
5295 | } | |
5296 | } | |
ed473771 | 5297 | |
e9f935e3 RM |
5298 | request->no_cck = |
5299 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5300 | ||
fd014284 | 5301 | request->wdev = wdev; |
79c97e97 | 5302 | request->wiphy = &rdev->wiphy; |
15d6030b | 5303 | request->scan_start = jiffies; |
2a519311 | 5304 | |
79c97e97 | 5305 | rdev->scan_req = request; |
e35e4d28 | 5306 | err = rdev_scan(rdev, request); |
2a519311 | 5307 | |
463d0183 | 5308 | if (!err) { |
fd014284 JB |
5309 | nl80211_send_scan_start(rdev, wdev); |
5310 | if (wdev->netdev) | |
5311 | dev_hold(wdev->netdev); | |
4c476991 | 5312 | } else { |
2a519311 | 5313 | out_free: |
79c97e97 | 5314 | rdev->scan_req = NULL; |
2a519311 JB |
5315 | kfree(request); |
5316 | } | |
3b85875a | 5317 | |
f9f47529 | 5318 | unlock: |
2a519311 JB |
5319 | return err; |
5320 | } | |
5321 | ||
807f8a8c LC |
5322 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5323 | struct genl_info *info) | |
5324 | { | |
5325 | struct cfg80211_sched_scan_request *request; | |
5326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5327 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5328 | struct nlattr *attr; |
5329 | struct wiphy *wiphy; | |
a1f1c21c | 5330 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5331 | u32 interval; |
807f8a8c LC |
5332 | enum ieee80211_band band; |
5333 | size_t ie_len; | |
a1f1c21c | 5334 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5335 | |
5336 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5337 | !rdev->ops->sched_scan_start) | |
5338 | return -EOPNOTSUPP; | |
5339 | ||
5340 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5341 | return -EINVAL; | |
5342 | ||
bbe6ad6d LC |
5343 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5344 | return -EINVAL; | |
5345 | ||
5346 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5347 | if (interval == 0) | |
5348 | return -EINVAL; | |
5349 | ||
807f8a8c LC |
5350 | wiphy = &rdev->wiphy; |
5351 | ||
5352 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5353 | n_channels = validate_scan_freqs( | |
5354 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5355 | if (!n_channels) | |
5356 | return -EINVAL; | |
5357 | } else { | |
5358 | n_channels = 0; | |
5359 | ||
5360 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5361 | if (wiphy->bands[band]) | |
5362 | n_channels += wiphy->bands[band]->n_channels; | |
5363 | } | |
5364 | ||
5365 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5366 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5367 | tmp) | |
5368 | n_ssids++; | |
5369 | ||
93b6aa69 | 5370 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5371 | return -EINVAL; |
5372 | ||
a1f1c21c LC |
5373 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5374 | nla_for_each_nested(attr, | |
5375 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5376 | tmp) | |
5377 | n_match_sets++; | |
5378 | ||
5379 | if (n_match_sets > wiphy->max_match_sets) | |
5380 | return -EINVAL; | |
5381 | ||
807f8a8c LC |
5382 | if (info->attrs[NL80211_ATTR_IE]) |
5383 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5384 | else | |
5385 | ie_len = 0; | |
5386 | ||
5a865bad | 5387 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5388 | return -EINVAL; |
5389 | ||
c10841ca LC |
5390 | if (rdev->sched_scan_req) { |
5391 | err = -EINPROGRESS; | |
5392 | goto out; | |
5393 | } | |
5394 | ||
807f8a8c | 5395 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5396 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5397 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5398 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5399 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5400 | if (!request) { |
5401 | err = -ENOMEM; | |
5402 | goto out; | |
5403 | } | |
807f8a8c LC |
5404 | |
5405 | if (n_ssids) | |
5406 | request->ssids = (void *)&request->channels[n_channels]; | |
5407 | request->n_ssids = n_ssids; | |
5408 | if (ie_len) { | |
5409 | if (request->ssids) | |
5410 | request->ie = (void *)(request->ssids + n_ssids); | |
5411 | else | |
5412 | request->ie = (void *)(request->channels + n_channels); | |
5413 | } | |
5414 | ||
a1f1c21c LC |
5415 | if (n_match_sets) { |
5416 | if (request->ie) | |
5417 | request->match_sets = (void *)(request->ie + ie_len); | |
5418 | else if (request->ssids) | |
5419 | request->match_sets = | |
5420 | (void *)(request->ssids + n_ssids); | |
5421 | else | |
5422 | request->match_sets = | |
5423 | (void *)(request->channels + n_channels); | |
5424 | } | |
5425 | request->n_match_sets = n_match_sets; | |
5426 | ||
807f8a8c LC |
5427 | i = 0; |
5428 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5429 | /* user specified, bail out if channel not found */ | |
5430 | nla_for_each_nested(attr, | |
5431 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5432 | tmp) { | |
5433 | struct ieee80211_channel *chan; | |
5434 | ||
5435 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5436 | ||
5437 | if (!chan) { | |
5438 | err = -EINVAL; | |
5439 | goto out_free; | |
5440 | } | |
5441 | ||
5442 | /* ignore disabled channels */ | |
5443 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5444 | continue; | |
5445 | ||
5446 | request->channels[i] = chan; | |
5447 | i++; | |
5448 | } | |
5449 | } else { | |
5450 | /* all channels */ | |
5451 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5452 | int j; | |
5453 | if (!wiphy->bands[band]) | |
5454 | continue; | |
5455 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5456 | struct ieee80211_channel *chan; | |
5457 | ||
5458 | chan = &wiphy->bands[band]->channels[j]; | |
5459 | ||
5460 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5461 | continue; | |
5462 | ||
5463 | request->channels[i] = chan; | |
5464 | i++; | |
5465 | } | |
5466 | } | |
5467 | } | |
5468 | ||
5469 | if (!i) { | |
5470 | err = -EINVAL; | |
5471 | goto out_free; | |
5472 | } | |
5473 | ||
5474 | request->n_channels = i; | |
5475 | ||
5476 | i = 0; | |
5477 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5478 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5479 | tmp) { | |
57a27e1d | 5480 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5481 | err = -EINVAL; |
5482 | goto out_free; | |
5483 | } | |
57a27e1d | 5484 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5485 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5486 | nla_len(attr)); | |
807f8a8c LC |
5487 | i++; |
5488 | } | |
5489 | } | |
5490 | ||
a1f1c21c LC |
5491 | i = 0; |
5492 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5493 | nla_for_each_nested(attr, | |
5494 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5495 | tmp) { | |
88e920b4 | 5496 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5497 | |
5498 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5499 | nla_data(attr), nla_len(attr), | |
5500 | nl80211_match_policy); | |
4a4ab0d7 | 5501 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5502 | if (ssid) { |
5503 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5504 | err = -EINVAL; | |
5505 | goto out_free; | |
5506 | } | |
5507 | memcpy(request->match_sets[i].ssid.ssid, | |
5508 | nla_data(ssid), nla_len(ssid)); | |
5509 | request->match_sets[i].ssid.ssid_len = | |
5510 | nla_len(ssid); | |
5511 | } | |
88e920b4 TP |
5512 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5513 | if (rssi) | |
5514 | request->rssi_thold = nla_get_u32(rssi); | |
5515 | else | |
5516 | request->rssi_thold = | |
5517 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5518 | i++; |
5519 | } | |
5520 | } | |
5521 | ||
807f8a8c LC |
5522 | if (info->attrs[NL80211_ATTR_IE]) { |
5523 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5524 | memcpy((void *)request->ie, | |
5525 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5526 | request->ie_len); | |
5527 | } | |
5528 | ||
46856bbf | 5529 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5530 | request->flags = nla_get_u32( |
5531 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5532 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5533 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5534 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5535 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5536 | err = -EOPNOTSUPP; |
5537 | goto out_free; | |
5538 | } | |
5539 | } | |
ed473771 | 5540 | |
807f8a8c LC |
5541 | request->dev = dev; |
5542 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5543 | request->interval = interval; |
15d6030b | 5544 | request->scan_start = jiffies; |
807f8a8c | 5545 | |
e35e4d28 | 5546 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5547 | if (!err) { |
5548 | rdev->sched_scan_req = request; | |
5549 | nl80211_send_sched_scan(rdev, dev, | |
5550 | NL80211_CMD_START_SCHED_SCAN); | |
5551 | goto out; | |
5552 | } | |
5553 | ||
5554 | out_free: | |
5555 | kfree(request); | |
5556 | out: | |
5557 | return err; | |
5558 | } | |
5559 | ||
5560 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5561 | struct genl_info *info) | |
5562 | { | |
5563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5564 | ||
5565 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5566 | !rdev->ops->sched_scan_stop) | |
5567 | return -EOPNOTSUPP; | |
5568 | ||
5fe231e8 | 5569 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5570 | } |
5571 | ||
04f39047 SW |
5572 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5573 | struct genl_info *info) | |
5574 | { | |
5575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5576 | struct net_device *dev = info->user_ptr[1]; | |
5577 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5578 | struct cfg80211_chan_def chandef; | |
5579 | int err; | |
5580 | ||
5581 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5582 | if (err) | |
5583 | return err; | |
5584 | ||
5585 | if (wdev->cac_started) | |
5586 | return -EBUSY; | |
5587 | ||
5588 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5589 | if (err < 0) | |
5590 | return err; | |
5591 | ||
5592 | if (err == 0) | |
5593 | return -EINVAL; | |
5594 | ||
5595 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5596 | return -EINVAL; | |
5597 | ||
5598 | if (!rdev->ops->start_radar_detection) | |
5599 | return -EOPNOTSUPP; | |
5600 | ||
04f39047 SW |
5601 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5602 | chandef.chan, CHAN_MODE_SHARED, | |
5603 | BIT(chandef.width)); | |
5604 | if (err) | |
5fe231e8 | 5605 | return err; |
04f39047 SW |
5606 | |
5607 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5608 | if (!err) { | |
5609 | wdev->channel = chandef.chan; | |
5610 | wdev->cac_started = true; | |
5611 | wdev->cac_start_time = jiffies; | |
5612 | } | |
04f39047 SW |
5613 | return err; |
5614 | } | |
5615 | ||
9720bb3a JB |
5616 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5617 | u32 seq, int flags, | |
2a519311 | 5618 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5619 | struct wireless_dev *wdev, |
5620 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5621 | { |
48ab905d | 5622 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5623 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5624 | void *hdr; |
5625 | struct nlattr *bss; | |
8cef2c9d | 5626 | bool tsf = false; |
48ab905d JB |
5627 | |
5628 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5629 | |
15e47304 | 5630 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5631 | NL80211_CMD_NEW_SCAN_RESULTS); |
5632 | if (!hdr) | |
5633 | return -1; | |
5634 | ||
9720bb3a JB |
5635 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5636 | ||
97990a06 JB |
5637 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5638 | goto nla_put_failure; | |
5639 | if (wdev->netdev && | |
9360ffd1 DM |
5640 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5641 | goto nla_put_failure; | |
97990a06 JB |
5642 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5643 | goto nla_put_failure; | |
2a519311 JB |
5644 | |
5645 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5646 | if (!bss) | |
5647 | goto nla_put_failure; | |
9360ffd1 | 5648 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5649 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5650 | goto nla_put_failure; |
9caf0364 JB |
5651 | |
5652 | rcu_read_lock(); | |
5653 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5654 | if (ies) { |
5655 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5656 | goto fail_unlock_rcu; | |
5657 | tsf = true; | |
5658 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5659 | ies->len, ies->data)) | |
5660 | goto fail_unlock_rcu; | |
9caf0364 JB |
5661 | } |
5662 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5663 | if (ies) { |
5664 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5665 | goto fail_unlock_rcu; | |
5666 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5667 | ies->len, ies->data)) | |
5668 | goto fail_unlock_rcu; | |
9caf0364 JB |
5669 | } |
5670 | rcu_read_unlock(); | |
5671 | ||
9360ffd1 DM |
5672 | if (res->beacon_interval && |
5673 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5674 | goto nla_put_failure; | |
5675 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5676 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 5677 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
5678 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
5679 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5680 | goto nla_put_failure; | |
2a519311 | 5681 | |
77965c97 | 5682 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5683 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5684 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5685 | goto nla_put_failure; | |
2a519311 JB |
5686 | break; |
5687 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5688 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5689 | goto nla_put_failure; | |
2a519311 JB |
5690 | break; |
5691 | default: | |
5692 | break; | |
5693 | } | |
5694 | ||
48ab905d | 5695 | switch (wdev->iftype) { |
074ac8df | 5696 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5697 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5698 | if (intbss == wdev->current_bss && |
5699 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5700 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5701 | goto nla_put_failure; | |
48ab905d JB |
5702 | break; |
5703 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5704 | if (intbss == wdev->current_bss && |
5705 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5706 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5707 | goto nla_put_failure; | |
48ab905d JB |
5708 | break; |
5709 | default: | |
5710 | break; | |
5711 | } | |
5712 | ||
2a519311 JB |
5713 | nla_nest_end(msg, bss); |
5714 | ||
5715 | return genlmsg_end(msg, hdr); | |
5716 | ||
8cef2c9d JB |
5717 | fail_unlock_rcu: |
5718 | rcu_read_unlock(); | |
2a519311 JB |
5719 | nla_put_failure: |
5720 | genlmsg_cancel(msg, hdr); | |
5721 | return -EMSGSIZE; | |
5722 | } | |
5723 | ||
97990a06 | 5724 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5725 | { |
48ab905d | 5726 | struct cfg80211_registered_device *rdev; |
2a519311 | 5727 | struct cfg80211_internal_bss *scan; |
48ab905d | 5728 | struct wireless_dev *wdev; |
97990a06 | 5729 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5730 | int err; |
5731 | ||
97990a06 | 5732 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5733 | if (err) |
5734 | return err; | |
2a519311 | 5735 | |
48ab905d JB |
5736 | wdev_lock(wdev); |
5737 | spin_lock_bh(&rdev->bss_lock); | |
5738 | cfg80211_bss_expire(rdev); | |
5739 | ||
9720bb3a JB |
5740 | cb->seq = rdev->bss_generation; |
5741 | ||
48ab905d | 5742 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5743 | if (++idx <= start) |
5744 | continue; | |
9720bb3a | 5745 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5746 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5747 | rdev, wdev, scan) < 0) { |
2a519311 | 5748 | idx--; |
67748893 | 5749 | break; |
2a519311 JB |
5750 | } |
5751 | } | |
5752 | ||
48ab905d JB |
5753 | spin_unlock_bh(&rdev->bss_lock); |
5754 | wdev_unlock(wdev); | |
2a519311 | 5755 | |
97990a06 JB |
5756 | cb->args[2] = idx; |
5757 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5758 | |
67748893 | 5759 | return skb->len; |
2a519311 JB |
5760 | } |
5761 | ||
15e47304 | 5762 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5763 | int flags, struct net_device *dev, |
5764 | struct survey_info *survey) | |
5765 | { | |
5766 | void *hdr; | |
5767 | struct nlattr *infoattr; | |
5768 | ||
15e47304 | 5769 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5770 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5771 | if (!hdr) | |
5772 | return -ENOMEM; | |
5773 | ||
9360ffd1 DM |
5774 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5775 | goto nla_put_failure; | |
61fa713c HS |
5776 | |
5777 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5778 | if (!infoattr) | |
5779 | goto nla_put_failure; | |
5780 | ||
9360ffd1 DM |
5781 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5782 | survey->channel->center_freq)) | |
5783 | goto nla_put_failure; | |
5784 | ||
5785 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5786 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5787 | goto nla_put_failure; | |
5788 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5789 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5790 | goto nla_put_failure; | |
5791 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5792 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5793 | survey->channel_time)) | |
5794 | goto nla_put_failure; | |
5795 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5796 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5797 | survey->channel_time_busy)) | |
5798 | goto nla_put_failure; | |
5799 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5800 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5801 | survey->channel_time_ext_busy)) | |
5802 | goto nla_put_failure; | |
5803 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5804 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5805 | survey->channel_time_rx)) | |
5806 | goto nla_put_failure; | |
5807 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5808 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5809 | survey->channel_time_tx)) | |
5810 | goto nla_put_failure; | |
61fa713c HS |
5811 | |
5812 | nla_nest_end(msg, infoattr); | |
5813 | ||
5814 | return genlmsg_end(msg, hdr); | |
5815 | ||
5816 | nla_put_failure: | |
5817 | genlmsg_cancel(msg, hdr); | |
5818 | return -EMSGSIZE; | |
5819 | } | |
5820 | ||
5821 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5822 | struct netlink_callback *cb) | |
5823 | { | |
5824 | struct survey_info survey; | |
5825 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5826 | struct wireless_dev *wdev; |
5827 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5828 | int res; |
5829 | ||
97990a06 | 5830 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5831 | if (res) |
5832 | return res; | |
61fa713c | 5833 | |
97990a06 JB |
5834 | if (!wdev->netdev) { |
5835 | res = -EINVAL; | |
5836 | goto out_err; | |
5837 | } | |
5838 | ||
61fa713c HS |
5839 | if (!dev->ops->dump_survey) { |
5840 | res = -EOPNOTSUPP; | |
5841 | goto out_err; | |
5842 | } | |
5843 | ||
5844 | while (1) { | |
180cdc79 LR |
5845 | struct ieee80211_channel *chan; |
5846 | ||
97990a06 | 5847 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5848 | if (res == -ENOENT) |
5849 | break; | |
5850 | if (res) | |
5851 | goto out_err; | |
5852 | ||
180cdc79 LR |
5853 | /* Survey without a channel doesn't make sense */ |
5854 | if (!survey.channel) { | |
5855 | res = -EINVAL; | |
5856 | goto out; | |
5857 | } | |
5858 | ||
5859 | chan = ieee80211_get_channel(&dev->wiphy, | |
5860 | survey.channel->center_freq); | |
5861 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5862 | survey_idx++; | |
5863 | continue; | |
5864 | } | |
5865 | ||
61fa713c | 5866 | if (nl80211_send_survey(skb, |
15e47304 | 5867 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5868 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5869 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5870 | goto out; |
5871 | survey_idx++; | |
5872 | } | |
5873 | ||
5874 | out: | |
97990a06 | 5875 | cb->args[2] = survey_idx; |
61fa713c HS |
5876 | res = skb->len; |
5877 | out_err: | |
97990a06 | 5878 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5879 | return res; |
5880 | } | |
5881 | ||
b23aa676 SO |
5882 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5883 | { | |
5884 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5885 | NL80211_WPA_VERSION_2)); | |
5886 | } | |
5887 | ||
636a5d36 JM |
5888 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5889 | { | |
4c476991 JB |
5890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5891 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5892 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5893 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5894 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5895 | enum nl80211_auth_type auth_type; |
fffd0934 | 5896 | struct key_parse key; |
d5cdfacb | 5897 | bool local_state_change; |
636a5d36 | 5898 | |
f4a11bb0 JB |
5899 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5900 | return -EINVAL; | |
5901 | ||
5902 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5903 | return -EINVAL; | |
5904 | ||
1778092e JM |
5905 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5906 | return -EINVAL; | |
5907 | ||
19957bb3 JB |
5908 | if (!info->attrs[NL80211_ATTR_SSID]) |
5909 | return -EINVAL; | |
5910 | ||
5911 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5912 | return -EINVAL; | |
5913 | ||
fffd0934 JB |
5914 | err = nl80211_parse_key(info, &key); |
5915 | if (err) | |
5916 | return err; | |
5917 | ||
5918 | if (key.idx >= 0) { | |
e31b8213 JB |
5919 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5920 | return -EINVAL; | |
fffd0934 JB |
5921 | if (!key.p.key || !key.p.key_len) |
5922 | return -EINVAL; | |
5923 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5924 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5925 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5926 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5927 | return -EINVAL; | |
5928 | if (key.idx > 4) | |
5929 | return -EINVAL; | |
5930 | } else { | |
5931 | key.p.key_len = 0; | |
5932 | key.p.key = NULL; | |
5933 | } | |
5934 | ||
afea0b7a JB |
5935 | if (key.idx >= 0) { |
5936 | int i; | |
5937 | bool ok = false; | |
5938 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5939 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5940 | ok = true; | |
5941 | break; | |
5942 | } | |
5943 | } | |
4c476991 JB |
5944 | if (!ok) |
5945 | return -EINVAL; | |
afea0b7a JB |
5946 | } |
5947 | ||
4c476991 JB |
5948 | if (!rdev->ops->auth) |
5949 | return -EOPNOTSUPP; | |
636a5d36 | 5950 | |
074ac8df | 5951 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5952 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5953 | return -EOPNOTSUPP; | |
eec60b03 | 5954 | |
19957bb3 | 5955 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5956 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5957 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5958 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5959 | return -EINVAL; | |
636a5d36 | 5960 | |
19957bb3 JB |
5961 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5962 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5963 | |
5964 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5965 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5966 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5967 | } |
5968 | ||
19957bb3 | 5969 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5970 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5971 | return -EINVAL; |
636a5d36 | 5972 | |
e39e5b5e JM |
5973 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5974 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5975 | return -EINVAL; | |
5976 | ||
5977 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5978 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5979 | return -EINVAL; | |
5980 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5981 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5982 | /* need to include at least Auth Transaction and Status Code */ | |
5983 | if (sae_data_len < 4) | |
5984 | return -EINVAL; | |
5985 | } | |
5986 | ||
d5cdfacb JM |
5987 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5988 | ||
95de817b JB |
5989 | /* |
5990 | * Since we no longer track auth state, ignore | |
5991 | * requests to only change local state. | |
5992 | */ | |
5993 | if (local_state_change) | |
5994 | return 0; | |
5995 | ||
91bf9b26 JB |
5996 | wdev_lock(dev->ieee80211_ptr); |
5997 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
5998 | ssid, ssid_len, ie, ie_len, | |
5999 | key.p.key, key.p.key_len, key.idx, | |
6000 | sae_data, sae_data_len); | |
6001 | wdev_unlock(dev->ieee80211_ptr); | |
6002 | return err; | |
636a5d36 JM |
6003 | } |
6004 | ||
c0692b8f JB |
6005 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6006 | struct genl_info *info, | |
3dc27d25 JB |
6007 | struct cfg80211_crypto_settings *settings, |
6008 | int cipher_limit) | |
b23aa676 | 6009 | { |
c0b2bbd8 JB |
6010 | memset(settings, 0, sizeof(*settings)); |
6011 | ||
b23aa676 SO |
6012 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6013 | ||
c0692b8f JB |
6014 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6015 | u16 proto; | |
6016 | proto = nla_get_u16( | |
6017 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6018 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6019 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6020 | proto != ETH_P_PAE) | |
6021 | return -EINVAL; | |
6022 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6023 | settings->control_port_no_encrypt = true; | |
6024 | } else | |
6025 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6026 | ||
b23aa676 SO |
6027 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6028 | void *data; | |
6029 | int len, i; | |
6030 | ||
6031 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6032 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6033 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6034 | ||
6035 | if (len % sizeof(u32)) | |
6036 | return -EINVAL; | |
6037 | ||
3dc27d25 | 6038 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6039 | return -EINVAL; |
6040 | ||
6041 | memcpy(settings->ciphers_pairwise, data, len); | |
6042 | ||
6043 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6044 | if (!cfg80211_supported_cipher_suite( |
6045 | &rdev->wiphy, | |
b23aa676 SO |
6046 | settings->ciphers_pairwise[i])) |
6047 | return -EINVAL; | |
6048 | } | |
6049 | ||
6050 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6051 | settings->cipher_group = | |
6052 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6053 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6054 | settings->cipher_group)) | |
b23aa676 SO |
6055 | return -EINVAL; |
6056 | } | |
6057 | ||
6058 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6059 | settings->wpa_versions = | |
6060 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6061 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6062 | return -EINVAL; | |
6063 | } | |
6064 | ||
6065 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6066 | void *data; | |
6d30240e | 6067 | int len; |
b23aa676 SO |
6068 | |
6069 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6070 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6071 | settings->n_akm_suites = len / sizeof(u32); | |
6072 | ||
6073 | if (len % sizeof(u32)) | |
6074 | return -EINVAL; | |
6075 | ||
1b9ca027 JM |
6076 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6077 | return -EINVAL; | |
6078 | ||
b23aa676 | 6079 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6080 | } |
6081 | ||
6082 | return 0; | |
6083 | } | |
6084 | ||
636a5d36 JM |
6085 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6086 | { | |
4c476991 JB |
6087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6088 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6089 | struct ieee80211_channel *chan; |
f62fab73 JB |
6090 | struct cfg80211_assoc_request req = {}; |
6091 | const u8 *bssid, *ssid; | |
6092 | int err, ssid_len = 0; | |
636a5d36 | 6093 | |
f4a11bb0 JB |
6094 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6095 | return -EINVAL; | |
6096 | ||
6097 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6098 | !info->attrs[NL80211_ATTR_SSID] || |
6099 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6100 | return -EINVAL; |
6101 | ||
4c476991 JB |
6102 | if (!rdev->ops->assoc) |
6103 | return -EOPNOTSUPP; | |
636a5d36 | 6104 | |
074ac8df | 6105 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6106 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6107 | return -EOPNOTSUPP; | |
eec60b03 | 6108 | |
19957bb3 | 6109 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6110 | |
19957bb3 JB |
6111 | chan = ieee80211_get_channel(&rdev->wiphy, |
6112 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6113 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6114 | return -EINVAL; | |
636a5d36 | 6115 | |
19957bb3 JB |
6116 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6117 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6118 | |
6119 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6120 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6121 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6122 | } |
6123 | ||
dc6382ce | 6124 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6125 | enum nl80211_mfp mfp = |
dc6382ce | 6126 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6127 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6128 | req.use_mfp = true; |
4c476991 JB |
6129 | else if (mfp != NL80211_MFP_NO) |
6130 | return -EINVAL; | |
dc6382ce JM |
6131 | } |
6132 | ||
3e5d7649 | 6133 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6134 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6135 | |
7e7c8926 | 6136 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6137 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6138 | |
6139 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6140 | memcpy(&req.ht_capa_mask, |
6141 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6142 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6143 | |
6144 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6145 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6146 | return -EINVAL; |
f62fab73 JB |
6147 | memcpy(&req.ht_capa, |
6148 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6149 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6150 | } |
6151 | ||
ee2aca34 | 6152 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6153 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6154 | |
6155 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6156 | memcpy(&req.vht_capa_mask, |
6157 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6158 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6159 | |
6160 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6161 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6162 | return -EINVAL; |
f62fab73 JB |
6163 | memcpy(&req.vht_capa, |
6164 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6165 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6166 | } |
6167 | ||
f62fab73 | 6168 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6169 | if (!err) { |
6170 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6171 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6172 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6173 | wdev_unlock(dev->ieee80211_ptr); |
6174 | } | |
636a5d36 | 6175 | |
636a5d36 JM |
6176 | return err; |
6177 | } | |
6178 | ||
6179 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6180 | { | |
4c476991 JB |
6181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6182 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6183 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6184 | int ie_len = 0, err; |
19957bb3 | 6185 | u16 reason_code; |
d5cdfacb | 6186 | bool local_state_change; |
636a5d36 | 6187 | |
f4a11bb0 JB |
6188 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6189 | return -EINVAL; | |
6190 | ||
6191 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6192 | return -EINVAL; | |
6193 | ||
6194 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6195 | return -EINVAL; | |
6196 | ||
4c476991 JB |
6197 | if (!rdev->ops->deauth) |
6198 | return -EOPNOTSUPP; | |
636a5d36 | 6199 | |
074ac8df | 6200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6202 | return -EOPNOTSUPP; | |
eec60b03 | 6203 | |
19957bb3 | 6204 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6205 | |
19957bb3 JB |
6206 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6207 | if (reason_code == 0) { | |
f4a11bb0 | 6208 | /* Reason Code 0 is reserved */ |
4c476991 | 6209 | return -EINVAL; |
255e737e | 6210 | } |
636a5d36 JM |
6211 | |
6212 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6213 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6214 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6215 | } |
6216 | ||
d5cdfacb JM |
6217 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6218 | ||
91bf9b26 JB |
6219 | wdev_lock(dev->ieee80211_ptr); |
6220 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6221 | local_state_change); | |
6222 | wdev_unlock(dev->ieee80211_ptr); | |
6223 | return err; | |
636a5d36 JM |
6224 | } |
6225 | ||
6226 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6227 | { | |
4c476991 JB |
6228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6229 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6230 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6231 | int ie_len = 0, err; |
19957bb3 | 6232 | u16 reason_code; |
d5cdfacb | 6233 | bool local_state_change; |
636a5d36 | 6234 | |
f4a11bb0 JB |
6235 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6236 | return -EINVAL; | |
6237 | ||
6238 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6239 | return -EINVAL; | |
6240 | ||
6241 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6242 | return -EINVAL; | |
6243 | ||
4c476991 JB |
6244 | if (!rdev->ops->disassoc) |
6245 | return -EOPNOTSUPP; | |
636a5d36 | 6246 | |
074ac8df | 6247 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6248 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6249 | return -EOPNOTSUPP; | |
eec60b03 | 6250 | |
19957bb3 | 6251 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6252 | |
19957bb3 JB |
6253 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6254 | if (reason_code == 0) { | |
f4a11bb0 | 6255 | /* Reason Code 0 is reserved */ |
4c476991 | 6256 | return -EINVAL; |
255e737e | 6257 | } |
636a5d36 JM |
6258 | |
6259 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6260 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6261 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6262 | } |
6263 | ||
d5cdfacb JM |
6264 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6265 | ||
91bf9b26 JB |
6266 | wdev_lock(dev->ieee80211_ptr); |
6267 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6268 | local_state_change); | |
6269 | wdev_unlock(dev->ieee80211_ptr); | |
6270 | return err; | |
636a5d36 JM |
6271 | } |
6272 | ||
dd5b4cc7 FF |
6273 | static bool |
6274 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6275 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6276 | int rateval) | |
6277 | { | |
6278 | struct wiphy *wiphy = &rdev->wiphy; | |
6279 | bool found = false; | |
6280 | int band, i; | |
6281 | ||
6282 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6283 | struct ieee80211_supported_band *sband; | |
6284 | ||
6285 | sband = wiphy->bands[band]; | |
6286 | if (!sband) | |
6287 | continue; | |
6288 | ||
6289 | for (i = 0; i < sband->n_bitrates; i++) { | |
6290 | if (sband->bitrates[i].bitrate == rateval) { | |
6291 | mcast_rate[band] = i + 1; | |
6292 | found = true; | |
6293 | break; | |
6294 | } | |
6295 | } | |
6296 | } | |
6297 | ||
6298 | return found; | |
6299 | } | |
6300 | ||
04a773ad JB |
6301 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6302 | { | |
4c476991 JB |
6303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6304 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6305 | struct cfg80211_ibss_params ibss; |
6306 | struct wiphy *wiphy; | |
fffd0934 | 6307 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6308 | int err; |
6309 | ||
8e30bc55 JB |
6310 | memset(&ibss, 0, sizeof(ibss)); |
6311 | ||
04a773ad JB |
6312 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6313 | return -EINVAL; | |
6314 | ||
683b6d3b | 6315 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6316 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6317 | return -EINVAL; | |
6318 | ||
8e30bc55 JB |
6319 | ibss.beacon_interval = 100; |
6320 | ||
6321 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6322 | ibss.beacon_interval = | |
6323 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6324 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6325 | return -EINVAL; | |
6326 | } | |
6327 | ||
4c476991 JB |
6328 | if (!rdev->ops->join_ibss) |
6329 | return -EOPNOTSUPP; | |
04a773ad | 6330 | |
4c476991 JB |
6331 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6332 | return -EOPNOTSUPP; | |
04a773ad | 6333 | |
79c97e97 | 6334 | wiphy = &rdev->wiphy; |
04a773ad | 6335 | |
39193498 | 6336 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6337 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6338 | |
6339 | if (!is_valid_ether_addr(ibss.bssid)) | |
6340 | return -EINVAL; | |
6341 | } | |
04a773ad JB |
6342 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6343 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6344 | ||
6345 | if (info->attrs[NL80211_ATTR_IE]) { | |
6346 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6347 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6348 | } | |
6349 | ||
683b6d3b JB |
6350 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6351 | if (err) | |
6352 | return err; | |
04a773ad | 6353 | |
683b6d3b | 6354 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6355 | return -EINVAL; |
6356 | ||
2f301ab2 SW |
6357 | switch (ibss.chandef.width) { |
6358 | case NL80211_CHAN_WIDTH_20_NOHT: | |
6359 | break; | |
6360 | case NL80211_CHAN_WIDTH_20: | |
6361 | case NL80211_CHAN_WIDTH_40: | |
6362 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6363 | break; | |
6364 | default: | |
c04d6150 | 6365 | return -EINVAL; |
2f301ab2 | 6366 | } |
db9c64cf | 6367 | |
04a773ad | 6368 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6369 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6370 | ||
fbd2c8dc TP |
6371 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6372 | u8 *rates = | |
6373 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6374 | int n_rates = | |
6375 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6376 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6377 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6378 | |
34850ab2 JB |
6379 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6380 | &ibss.basic_rates); | |
6381 | if (err) | |
6382 | return err; | |
fbd2c8dc | 6383 | } |
dd5b4cc7 | 6384 | |
803768f5 SW |
6385 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6386 | memcpy(&ibss.ht_capa_mask, | |
6387 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6388 | sizeof(ibss.ht_capa_mask)); | |
6389 | ||
6390 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6391 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6392 | return -EINVAL; | |
6393 | memcpy(&ibss.ht_capa, | |
6394 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6395 | sizeof(ibss.ht_capa)); | |
6396 | } | |
6397 | ||
dd5b4cc7 FF |
6398 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6399 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6400 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6401 | return -EINVAL; | |
fbd2c8dc | 6402 | |
4c476991 | 6403 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6404 | bool no_ht = false; |
6405 | ||
4c476991 | 6406 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6407 | info->attrs[NL80211_ATTR_KEYS], |
6408 | &no_ht); | |
4c476991 JB |
6409 | if (IS_ERR(connkeys)) |
6410 | return PTR_ERR(connkeys); | |
de7044ee | 6411 | |
3d9d1d66 JB |
6412 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6413 | no_ht) { | |
de7044ee SM |
6414 | kfree(connkeys); |
6415 | return -EINVAL; | |
6416 | } | |
4c476991 | 6417 | } |
04a773ad | 6418 | |
267335d6 AQ |
6419 | ibss.control_port = |
6420 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6421 | ||
4c476991 | 6422 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6423 | if (err) |
6424 | kfree(connkeys); | |
04a773ad JB |
6425 | return err; |
6426 | } | |
6427 | ||
6428 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6429 | { | |
4c476991 JB |
6430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6431 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6432 | |
4c476991 JB |
6433 | if (!rdev->ops->leave_ibss) |
6434 | return -EOPNOTSUPP; | |
04a773ad | 6435 | |
4c476991 JB |
6436 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6437 | return -EOPNOTSUPP; | |
04a773ad | 6438 | |
4c476991 | 6439 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6440 | } |
6441 | ||
f4e583c8 AQ |
6442 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6443 | { | |
6444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6445 | struct net_device *dev = info->user_ptr[1]; | |
6446 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6447 | u32 nla_rate; | |
6448 | int err; | |
6449 | ||
6450 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6451 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6452 | return -EOPNOTSUPP; | |
6453 | ||
6454 | if (!rdev->ops->set_mcast_rate) | |
6455 | return -EOPNOTSUPP; | |
6456 | ||
6457 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6458 | ||
6459 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6460 | return -EINVAL; | |
6461 | ||
6462 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6463 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6464 | return -EINVAL; | |
6465 | ||
6466 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6467 | ||
6468 | return err; | |
6469 | } | |
6470 | ||
6471 | ||
aff89a9b JB |
6472 | #ifdef CONFIG_NL80211_TESTMODE |
6473 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6474 | .name = "testmode", | |
6475 | }; | |
6476 | ||
6477 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6478 | { | |
4c476991 | 6479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6480 | int err; |
6481 | ||
6482 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6483 | return -EINVAL; | |
6484 | ||
aff89a9b JB |
6485 | err = -EOPNOTSUPP; |
6486 | if (rdev->ops->testmode_cmd) { | |
6487 | rdev->testmode_info = info; | |
e35e4d28 | 6488 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6489 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6490 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6491 | rdev->testmode_info = NULL; | |
6492 | } | |
6493 | ||
aff89a9b JB |
6494 | return err; |
6495 | } | |
6496 | ||
71063f0e WYG |
6497 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6498 | struct netlink_callback *cb) | |
6499 | { | |
00918d33 | 6500 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6501 | int err; |
6502 | long phy_idx; | |
6503 | void *data = NULL; | |
6504 | int data_len = 0; | |
6505 | ||
5fe231e8 JB |
6506 | rtnl_lock(); |
6507 | ||
71063f0e WYG |
6508 | if (cb->args[0]) { |
6509 | /* | |
6510 | * 0 is a valid index, but not valid for args[0], | |
6511 | * so we need to offset by 1. | |
6512 | */ | |
6513 | phy_idx = cb->args[0] - 1; | |
6514 | } else { | |
6515 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6516 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6517 | nl80211_policy); | |
6518 | if (err) | |
5fe231e8 | 6519 | goto out_err; |
00918d33 | 6520 | |
2bd7e35d JB |
6521 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6522 | nl80211_fam.attrbuf); | |
6523 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6524 | err = PTR_ERR(rdev); |
6525 | goto out_err; | |
00918d33 | 6526 | } |
2bd7e35d JB |
6527 | phy_idx = rdev->wiphy_idx; |
6528 | rdev = NULL; | |
2bd7e35d | 6529 | |
71063f0e WYG |
6530 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6531 | cb->args[1] = | |
6532 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6533 | } | |
6534 | ||
6535 | if (cb->args[1]) { | |
6536 | data = nla_data((void *)cb->args[1]); | |
6537 | data_len = nla_len((void *)cb->args[1]); | |
6538 | } | |
6539 | ||
00918d33 JB |
6540 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6541 | if (!rdev) { | |
5fe231e8 JB |
6542 | err = -ENOENT; |
6543 | goto out_err; | |
71063f0e | 6544 | } |
71063f0e | 6545 | |
00918d33 | 6546 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6547 | err = -EOPNOTSUPP; |
6548 | goto out_err; | |
6549 | } | |
6550 | ||
6551 | while (1) { | |
15e47304 | 6552 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6553 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6554 | NL80211_CMD_TESTMODE); | |
6555 | struct nlattr *tmdata; | |
6556 | ||
9360ffd1 | 6557 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6558 | genlmsg_cancel(skb, hdr); |
6559 | break; | |
6560 | } | |
6561 | ||
6562 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6563 | if (!tmdata) { | |
6564 | genlmsg_cancel(skb, hdr); | |
6565 | break; | |
6566 | } | |
e35e4d28 | 6567 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6568 | nla_nest_end(skb, tmdata); |
6569 | ||
6570 | if (err == -ENOBUFS || err == -ENOENT) { | |
6571 | genlmsg_cancel(skb, hdr); | |
6572 | break; | |
6573 | } else if (err) { | |
6574 | genlmsg_cancel(skb, hdr); | |
6575 | goto out_err; | |
6576 | } | |
6577 | ||
6578 | genlmsg_end(skb, hdr); | |
6579 | } | |
6580 | ||
6581 | err = skb->len; | |
6582 | /* see above */ | |
6583 | cb->args[0] = phy_idx + 1; | |
6584 | out_err: | |
5fe231e8 | 6585 | rtnl_unlock(); |
71063f0e WYG |
6586 | return err; |
6587 | } | |
6588 | ||
aff89a9b JB |
6589 | static struct sk_buff * |
6590 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6591 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6592 | { |
6593 | struct sk_buff *skb; | |
6594 | void *hdr; | |
6595 | struct nlattr *data; | |
6596 | ||
6597 | skb = nlmsg_new(approxlen + 100, gfp); | |
6598 | if (!skb) | |
6599 | return NULL; | |
6600 | ||
15e47304 | 6601 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6602 | if (!hdr) { |
6603 | kfree_skb(skb); | |
6604 | return NULL; | |
6605 | } | |
6606 | ||
9360ffd1 DM |
6607 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6608 | goto nla_put_failure; | |
aff89a9b JB |
6609 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6610 | ||
6611 | ((void **)skb->cb)[0] = rdev; | |
6612 | ((void **)skb->cb)[1] = hdr; | |
6613 | ((void **)skb->cb)[2] = data; | |
6614 | ||
6615 | return skb; | |
6616 | ||
6617 | nla_put_failure: | |
6618 | kfree_skb(skb); | |
6619 | return NULL; | |
6620 | } | |
6621 | ||
6622 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6623 | int approxlen) | |
6624 | { | |
6625 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6626 | ||
6627 | if (WARN_ON(!rdev->testmode_info)) | |
6628 | return NULL; | |
6629 | ||
6630 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6631 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6632 | rdev->testmode_info->snd_seq, |
6633 | GFP_KERNEL); | |
6634 | } | |
6635 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6636 | ||
6637 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6638 | { | |
6639 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6640 | void *hdr = ((void **)skb->cb)[1]; | |
6641 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6642 | ||
6643 | if (WARN_ON(!rdev->testmode_info)) { | |
6644 | kfree_skb(skb); | |
6645 | return -EINVAL; | |
6646 | } | |
6647 | ||
6648 | nla_nest_end(skb, data); | |
6649 | genlmsg_end(skb, hdr); | |
6650 | return genlmsg_reply(skb, rdev->testmode_info); | |
6651 | } | |
6652 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6653 | ||
6654 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6655 | int approxlen, gfp_t gfp) | |
6656 | { | |
6657 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6658 | ||
6659 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6660 | } | |
6661 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6662 | ||
6663 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6664 | { | |
6665 | void *hdr = ((void **)skb->cb)[1]; | |
6666 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6667 | ||
6668 | nla_nest_end(skb, data); | |
6669 | genlmsg_end(skb, hdr); | |
6670 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6671 | } | |
6672 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6673 | #endif | |
6674 | ||
b23aa676 SO |
6675 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6676 | { | |
4c476991 JB |
6677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6678 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6679 | struct cfg80211_connect_params connect; |
6680 | struct wiphy *wiphy; | |
fffd0934 | 6681 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6682 | int err; |
6683 | ||
6684 | memset(&connect, 0, sizeof(connect)); | |
6685 | ||
6686 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6687 | return -EINVAL; | |
6688 | ||
6689 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6690 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6691 | return -EINVAL; | |
6692 | ||
6693 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6694 | connect.auth_type = | |
6695 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6696 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6697 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6698 | return -EINVAL; |
6699 | } else | |
6700 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6701 | ||
6702 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6703 | ||
c0692b8f | 6704 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6705 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6706 | if (err) |
6707 | return err; | |
b23aa676 | 6708 | |
074ac8df | 6709 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6710 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6711 | return -EOPNOTSUPP; | |
b23aa676 | 6712 | |
79c97e97 | 6713 | wiphy = &rdev->wiphy; |
b23aa676 | 6714 | |
4486ea98 BS |
6715 | connect.bg_scan_period = -1; |
6716 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6717 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6718 | connect.bg_scan_period = | |
6719 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6720 | } | |
6721 | ||
b23aa676 SO |
6722 | if (info->attrs[NL80211_ATTR_MAC]) |
6723 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6724 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6725 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6726 | ||
6727 | if (info->attrs[NL80211_ATTR_IE]) { | |
6728 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6729 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6730 | } | |
6731 | ||
cee00a95 JM |
6732 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6733 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6734 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6735 | connect.mfp != NL80211_MFP_NO) | |
6736 | return -EINVAL; | |
6737 | } else { | |
6738 | connect.mfp = NL80211_MFP_NO; | |
6739 | } | |
6740 | ||
b23aa676 SO |
6741 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6742 | connect.channel = | |
6743 | ieee80211_get_channel(wiphy, | |
6744 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6745 | if (!connect.channel || | |
4c476991 JB |
6746 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6747 | return -EINVAL; | |
b23aa676 SO |
6748 | } |
6749 | ||
fffd0934 JB |
6750 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6751 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6752 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6753 | if (IS_ERR(connkeys)) |
6754 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6755 | } |
6756 | ||
7e7c8926 BG |
6757 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6758 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6759 | ||
6760 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6761 | memcpy(&connect.ht_capa_mask, | |
6762 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6763 | sizeof(connect.ht_capa_mask)); | |
6764 | ||
6765 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6766 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6767 | kfree(connkeys); | |
7e7c8926 | 6768 | return -EINVAL; |
b4e4f47e | 6769 | } |
7e7c8926 BG |
6770 | memcpy(&connect.ht_capa, |
6771 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6772 | sizeof(connect.ht_capa)); | |
6773 | } | |
6774 | ||
ee2aca34 JB |
6775 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6776 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6777 | ||
6778 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6779 | memcpy(&connect.vht_capa_mask, | |
6780 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6781 | sizeof(connect.vht_capa_mask)); | |
6782 | ||
6783 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6784 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6785 | kfree(connkeys); | |
6786 | return -EINVAL; | |
6787 | } | |
6788 | memcpy(&connect.vht_capa, | |
6789 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6790 | sizeof(connect.vht_capa)); | |
6791 | } | |
6792 | ||
83739b03 JB |
6793 | wdev_lock(dev->ieee80211_ptr); |
6794 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
6795 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
6796 | if (err) |
6797 | kfree(connkeys); | |
b23aa676 SO |
6798 | return err; |
6799 | } | |
6800 | ||
6801 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6802 | { | |
4c476991 JB |
6803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6804 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 6805 | u16 reason; |
83739b03 | 6806 | int ret; |
b23aa676 SO |
6807 | |
6808 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6809 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6810 | else | |
6811 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6812 | ||
6813 | if (reason == 0) | |
6814 | return -EINVAL; | |
6815 | ||
074ac8df | 6816 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6817 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6818 | return -EOPNOTSUPP; | |
b23aa676 | 6819 | |
83739b03 JB |
6820 | wdev_lock(dev->ieee80211_ptr); |
6821 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
6822 | wdev_unlock(dev->ieee80211_ptr); | |
6823 | return ret; | |
b23aa676 SO |
6824 | } |
6825 | ||
463d0183 JB |
6826 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6827 | { | |
4c476991 | 6828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6829 | struct net *net; |
6830 | int err; | |
6831 | u32 pid; | |
6832 | ||
6833 | if (!info->attrs[NL80211_ATTR_PID]) | |
6834 | return -EINVAL; | |
6835 | ||
6836 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6837 | ||
463d0183 | 6838 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6839 | if (IS_ERR(net)) |
6840 | return PTR_ERR(net); | |
463d0183 JB |
6841 | |
6842 | err = 0; | |
6843 | ||
6844 | /* check if anything to do */ | |
4c476991 JB |
6845 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6846 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6847 | |
463d0183 | 6848 | put_net(net); |
463d0183 JB |
6849 | return err; |
6850 | } | |
6851 | ||
67fbb16b SO |
6852 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6853 | { | |
4c476991 | 6854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6855 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6856 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6857 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6858 | struct cfg80211_pmksa pmksa; |
6859 | ||
6860 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6861 | ||
6862 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6863 | return -EINVAL; | |
6864 | ||
6865 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6866 | return -EINVAL; | |
6867 | ||
67fbb16b SO |
6868 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6869 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6870 | ||
074ac8df | 6871 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6872 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6873 | return -EOPNOTSUPP; | |
67fbb16b SO |
6874 | |
6875 | switch (info->genlhdr->cmd) { | |
6876 | case NL80211_CMD_SET_PMKSA: | |
6877 | rdev_ops = rdev->ops->set_pmksa; | |
6878 | break; | |
6879 | case NL80211_CMD_DEL_PMKSA: | |
6880 | rdev_ops = rdev->ops->del_pmksa; | |
6881 | break; | |
6882 | default: | |
6883 | WARN_ON(1); | |
6884 | break; | |
6885 | } | |
6886 | ||
4c476991 JB |
6887 | if (!rdev_ops) |
6888 | return -EOPNOTSUPP; | |
67fbb16b | 6889 | |
4c476991 | 6890 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6891 | } |
6892 | ||
6893 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6894 | { | |
4c476991 JB |
6895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6896 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6897 | |
074ac8df | 6898 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6899 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6900 | return -EOPNOTSUPP; | |
67fbb16b | 6901 | |
4c476991 JB |
6902 | if (!rdev->ops->flush_pmksa) |
6903 | return -EOPNOTSUPP; | |
67fbb16b | 6904 | |
e35e4d28 | 6905 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6906 | } |
6907 | ||
109086ce AN |
6908 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6909 | { | |
6910 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6911 | struct net_device *dev = info->user_ptr[1]; | |
6912 | u8 action_code, dialog_token; | |
6913 | u16 status_code; | |
6914 | u8 *peer; | |
6915 | ||
6916 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6917 | !rdev->ops->tdls_mgmt) | |
6918 | return -EOPNOTSUPP; | |
6919 | ||
6920 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6921 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6922 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6923 | !info->attrs[NL80211_ATTR_IE] || | |
6924 | !info->attrs[NL80211_ATTR_MAC]) | |
6925 | return -EINVAL; | |
6926 | ||
6927 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6928 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6929 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6930 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6931 | ||
e35e4d28 HG |
6932 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6933 | dialog_token, status_code, | |
6934 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6935 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6936 | } |
6937 | ||
6938 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6939 | { | |
6940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6941 | struct net_device *dev = info->user_ptr[1]; | |
6942 | enum nl80211_tdls_operation operation; | |
6943 | u8 *peer; | |
6944 | ||
6945 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6946 | !rdev->ops->tdls_oper) | |
6947 | return -EOPNOTSUPP; | |
6948 | ||
6949 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6950 | !info->attrs[NL80211_ATTR_MAC]) | |
6951 | return -EINVAL; | |
6952 | ||
6953 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6954 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6955 | ||
e35e4d28 | 6956 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6957 | } |
6958 | ||
9588bbd5 JM |
6959 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6960 | struct genl_info *info) | |
6961 | { | |
4c476991 | 6962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6963 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6964 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6965 | struct sk_buff *msg; |
6966 | void *hdr; | |
6967 | u64 cookie; | |
683b6d3b | 6968 | u32 duration; |
9588bbd5 JM |
6969 | int err; |
6970 | ||
6971 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6972 | !info->attrs[NL80211_ATTR_DURATION]) | |
6973 | return -EINVAL; | |
6974 | ||
6975 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6976 | ||
ebf348fc JB |
6977 | if (!rdev->ops->remain_on_channel || |
6978 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6979 | return -EOPNOTSUPP; | |
6980 | ||
9588bbd5 | 6981 | /* |
ebf348fc JB |
6982 | * We should be on that channel for at least a minimum amount of |
6983 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6984 | */ |
ebf348fc | 6985 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6986 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6987 | return -EINVAL; |
6988 | ||
683b6d3b JB |
6989 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6990 | if (err) | |
6991 | return err; | |
9588bbd5 JM |
6992 | |
6993 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6994 | if (!msg) |
6995 | return -ENOMEM; | |
9588bbd5 | 6996 | |
15e47304 | 6997 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6998 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6999 | ||
7000 | if (IS_ERR(hdr)) { | |
7001 | err = PTR_ERR(hdr); | |
7002 | goto free_msg; | |
7003 | } | |
7004 | ||
683b6d3b JB |
7005 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7006 | duration, &cookie); | |
9588bbd5 JM |
7007 | |
7008 | if (err) | |
7009 | goto free_msg; | |
7010 | ||
9360ffd1 DM |
7011 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7012 | goto nla_put_failure; | |
9588bbd5 JM |
7013 | |
7014 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7015 | |
7016 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7017 | |
7018 | nla_put_failure: | |
7019 | err = -ENOBUFS; | |
7020 | free_msg: | |
7021 | nlmsg_free(msg); | |
9588bbd5 JM |
7022 | return err; |
7023 | } | |
7024 | ||
7025 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7026 | struct genl_info *info) | |
7027 | { | |
4c476991 | 7028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7029 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7030 | u64 cookie; |
9588bbd5 JM |
7031 | |
7032 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7033 | return -EINVAL; | |
7034 | ||
4c476991 JB |
7035 | if (!rdev->ops->cancel_remain_on_channel) |
7036 | return -EOPNOTSUPP; | |
9588bbd5 | 7037 | |
9588bbd5 JM |
7038 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7039 | ||
e35e4d28 | 7040 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7041 | } |
7042 | ||
13ae75b1 JM |
7043 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7044 | u8 *rates, u8 rates_len) | |
7045 | { | |
7046 | u8 i; | |
7047 | u32 mask = 0; | |
7048 | ||
7049 | for (i = 0; i < rates_len; i++) { | |
7050 | int rate = (rates[i] & 0x7f) * 5; | |
7051 | int ridx; | |
7052 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7053 | struct ieee80211_rate *srate = | |
7054 | &sband->bitrates[ridx]; | |
7055 | if (rate == srate->bitrate) { | |
7056 | mask |= 1 << ridx; | |
7057 | break; | |
7058 | } | |
7059 | } | |
7060 | if (ridx == sband->n_bitrates) | |
7061 | return 0; /* rate not found */ | |
7062 | } | |
7063 | ||
7064 | return mask; | |
7065 | } | |
7066 | ||
24db78c0 SW |
7067 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7068 | u8 *rates, u8 rates_len, | |
7069 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7070 | { | |
7071 | u8 i; | |
7072 | ||
7073 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7074 | ||
7075 | for (i = 0; i < rates_len; i++) { | |
7076 | int ridx, rbit; | |
7077 | ||
7078 | ridx = rates[i] / 8; | |
7079 | rbit = BIT(rates[i] % 8); | |
7080 | ||
7081 | /* check validity */ | |
910570b5 | 7082 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7083 | return false; |
7084 | ||
7085 | /* check availability */ | |
7086 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7087 | mcs[ridx] |= rbit; | |
7088 | else | |
7089 | return false; | |
7090 | } | |
7091 | ||
7092 | return true; | |
7093 | } | |
7094 | ||
b54452b0 | 7095 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7096 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7097 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7098 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7099 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7100 | }; |
7101 | ||
7102 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7103 | struct genl_info *info) | |
7104 | { | |
7105 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7107 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7108 | int rem, i; |
7109 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7110 | struct nlattr *tx_rates; |
7111 | struct ieee80211_supported_band *sband; | |
7112 | ||
7113 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7114 | return -EINVAL; | |
7115 | ||
4c476991 JB |
7116 | if (!rdev->ops->set_bitrate_mask) |
7117 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7118 | |
7119 | memset(&mask, 0, sizeof(mask)); | |
7120 | /* Default to all rates enabled */ | |
7121 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7122 | sband = rdev->wiphy.bands[i]; | |
7123 | mask.control[i].legacy = | |
7124 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7125 | if (sband) |
7126 | memcpy(mask.control[i].mcs, | |
7127 | sband->ht_cap.mcs.rx_mask, | |
7128 | sizeof(mask.control[i].mcs)); | |
7129 | else | |
7130 | memset(mask.control[i].mcs, 0, | |
7131 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7132 | } |
7133 | ||
7134 | /* | |
7135 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7136 | * directly to the enum ieee80211_band values used in cfg80211. | |
7137 | */ | |
24db78c0 | 7138 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7139 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7140 | { | |
7141 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7142 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7143 | return -EINVAL; | |
13ae75b1 | 7144 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7145 | if (sband == NULL) |
7146 | return -EINVAL; | |
13ae75b1 JM |
7147 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7148 | nla_len(tx_rates), nl80211_txattr_policy); | |
7149 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7150 | mask.control[band].legacy = rateset_to_mask( | |
7151 | sband, | |
7152 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7153 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7154 | if ((mask.control[band].legacy == 0) && |
7155 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7156 | return -EINVAL; | |
24db78c0 SW |
7157 | } |
7158 | if (tb[NL80211_TXRATE_MCS]) { | |
7159 | if (!ht_rateset_to_mask( | |
7160 | sband, | |
7161 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7162 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7163 | mask.control[band].mcs)) | |
7164 | return -EINVAL; | |
7165 | } | |
7166 | ||
7167 | if (mask.control[band].legacy == 0) { | |
7168 | /* don't allow empty legacy rates if HT | |
7169 | * is not even supported. */ | |
7170 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7171 | return -EINVAL; | |
7172 | ||
7173 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7174 | if (mask.control[band].mcs[i]) | |
7175 | break; | |
7176 | ||
7177 | /* legacy and mcs rates may not be both empty */ | |
7178 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7179 | return -EINVAL; |
13ae75b1 JM |
7180 | } |
7181 | } | |
7182 | ||
e35e4d28 | 7183 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7184 | } |
7185 | ||
2e161f78 | 7186 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7187 | { |
4c476991 | 7188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7189 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7190 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7191 | |
7192 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7193 | return -EINVAL; | |
7194 | ||
2e161f78 JB |
7195 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7196 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7197 | |
71bbc994 JB |
7198 | switch (wdev->iftype) { |
7199 | case NL80211_IFTYPE_STATION: | |
7200 | case NL80211_IFTYPE_ADHOC: | |
7201 | case NL80211_IFTYPE_P2P_CLIENT: | |
7202 | case NL80211_IFTYPE_AP: | |
7203 | case NL80211_IFTYPE_AP_VLAN: | |
7204 | case NL80211_IFTYPE_MESH_POINT: | |
7205 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7206 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7207 | break; |
7208 | default: | |
4c476991 | 7209 | return -EOPNOTSUPP; |
71bbc994 | 7210 | } |
026331c4 JM |
7211 | |
7212 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7213 | if (!rdev->ops->mgmt_tx) |
7214 | return -EOPNOTSUPP; | |
026331c4 | 7215 | |
15e47304 | 7216 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7217 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7218 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7219 | } |
7220 | ||
2e161f78 | 7221 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7222 | { |
4c476991 | 7223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7224 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7225 | struct cfg80211_chan_def chandef; |
026331c4 | 7226 | int err; |
d64d373f | 7227 | void *hdr = NULL; |
026331c4 | 7228 | u64 cookie; |
e247bd90 | 7229 | struct sk_buff *msg = NULL; |
f7ca38df | 7230 | unsigned int wait = 0; |
e247bd90 JB |
7231 | bool offchan, no_cck, dont_wait_for_ack; |
7232 | ||
7233 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7234 | |
683b6d3b | 7235 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7236 | return -EINVAL; |
7237 | ||
4c476991 JB |
7238 | if (!rdev->ops->mgmt_tx) |
7239 | return -EOPNOTSUPP; | |
026331c4 | 7240 | |
71bbc994 | 7241 | switch (wdev->iftype) { |
ea141b75 AQ |
7242 | case NL80211_IFTYPE_P2P_DEVICE: |
7243 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7244 | return -EINVAL; | |
71bbc994 JB |
7245 | case NL80211_IFTYPE_STATION: |
7246 | case NL80211_IFTYPE_ADHOC: | |
7247 | case NL80211_IFTYPE_P2P_CLIENT: | |
7248 | case NL80211_IFTYPE_AP: | |
7249 | case NL80211_IFTYPE_AP_VLAN: | |
7250 | case NL80211_IFTYPE_MESH_POINT: | |
7251 | case NL80211_IFTYPE_P2P_GO: | |
7252 | break; | |
7253 | default: | |
4c476991 | 7254 | return -EOPNOTSUPP; |
71bbc994 | 7255 | } |
026331c4 | 7256 | |
f7ca38df | 7257 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7258 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7259 | return -EINVAL; |
7260 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7261 | |
7262 | /* | |
7263 | * We should wait on the channel for at least a minimum amount | |
7264 | * of time (10ms) but no longer than the driver supports. | |
7265 | */ | |
7266 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7267 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7268 | return -EINVAL; | |
7269 | ||
f7ca38df JB |
7270 | } |
7271 | ||
f7ca38df JB |
7272 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7273 | ||
7c4ef712 JB |
7274 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7275 | return -EINVAL; | |
7276 | ||
e9f935e3 RM |
7277 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7278 | ||
ea141b75 AQ |
7279 | /* get the channel if any has been specified, otherwise pass NULL to |
7280 | * the driver. The latter will use the current one | |
7281 | */ | |
7282 | chandef.chan = NULL; | |
7283 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7284 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7285 | if (err) | |
7286 | return err; | |
7287 | } | |
7288 | ||
7289 | if (!chandef.chan && offchan) | |
7290 | return -EINVAL; | |
026331c4 | 7291 | |
e247bd90 JB |
7292 | if (!dont_wait_for_ack) { |
7293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7294 | if (!msg) | |
7295 | return -ENOMEM; | |
026331c4 | 7296 | |
15e47304 | 7297 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7298 | NL80211_CMD_FRAME); |
026331c4 | 7299 | |
e247bd90 JB |
7300 | if (IS_ERR(hdr)) { |
7301 | err = PTR_ERR(hdr); | |
7302 | goto free_msg; | |
7303 | } | |
026331c4 | 7304 | } |
e247bd90 | 7305 | |
683b6d3b | 7306 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7307 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7308 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7309 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7310 | if (err) |
7311 | goto free_msg; | |
7312 | ||
e247bd90 | 7313 | if (msg) { |
9360ffd1 DM |
7314 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7315 | goto nla_put_failure; | |
026331c4 | 7316 | |
e247bd90 JB |
7317 | genlmsg_end(msg, hdr); |
7318 | return genlmsg_reply(msg, info); | |
7319 | } | |
7320 | ||
7321 | return 0; | |
026331c4 JM |
7322 | |
7323 | nla_put_failure: | |
7324 | err = -ENOBUFS; | |
7325 | free_msg: | |
7326 | nlmsg_free(msg); | |
026331c4 JM |
7327 | return err; |
7328 | } | |
7329 | ||
f7ca38df JB |
7330 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7331 | { | |
7332 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7333 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7334 | u64 cookie; |
7335 | ||
7336 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7337 | return -EINVAL; | |
7338 | ||
7339 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7340 | return -EOPNOTSUPP; | |
7341 | ||
71bbc994 JB |
7342 | switch (wdev->iftype) { |
7343 | case NL80211_IFTYPE_STATION: | |
7344 | case NL80211_IFTYPE_ADHOC: | |
7345 | case NL80211_IFTYPE_P2P_CLIENT: | |
7346 | case NL80211_IFTYPE_AP: | |
7347 | case NL80211_IFTYPE_AP_VLAN: | |
7348 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7349 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7350 | break; |
7351 | default: | |
f7ca38df | 7352 | return -EOPNOTSUPP; |
71bbc994 | 7353 | } |
f7ca38df JB |
7354 | |
7355 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7356 | ||
e35e4d28 | 7357 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7358 | } |
7359 | ||
ffb9eb3d KV |
7360 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7361 | { | |
4c476991 | 7362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7363 | struct wireless_dev *wdev; |
4c476991 | 7364 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7365 | u8 ps_state; |
7366 | bool state; | |
7367 | int err; | |
7368 | ||
4c476991 JB |
7369 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7370 | return -EINVAL; | |
ffb9eb3d KV |
7371 | |
7372 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7373 | ||
4c476991 JB |
7374 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7375 | return -EINVAL; | |
ffb9eb3d KV |
7376 | |
7377 | wdev = dev->ieee80211_ptr; | |
7378 | ||
4c476991 JB |
7379 | if (!rdev->ops->set_power_mgmt) |
7380 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7381 | |
7382 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7383 | ||
7384 | if (state == wdev->ps) | |
4c476991 | 7385 | return 0; |
ffb9eb3d | 7386 | |
e35e4d28 | 7387 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7388 | if (!err) |
7389 | wdev->ps = state; | |
ffb9eb3d KV |
7390 | return err; |
7391 | } | |
7392 | ||
7393 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7394 | { | |
4c476991 | 7395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7396 | enum nl80211_ps_state ps_state; |
7397 | struct wireless_dev *wdev; | |
4c476991 | 7398 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7399 | struct sk_buff *msg; |
7400 | void *hdr; | |
7401 | int err; | |
7402 | ||
ffb9eb3d KV |
7403 | wdev = dev->ieee80211_ptr; |
7404 | ||
4c476991 JB |
7405 | if (!rdev->ops->set_power_mgmt) |
7406 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7407 | |
7408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7409 | if (!msg) |
7410 | return -ENOMEM; | |
ffb9eb3d | 7411 | |
15e47304 | 7412 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7413 | NL80211_CMD_GET_POWER_SAVE); |
7414 | if (!hdr) { | |
4c476991 | 7415 | err = -ENOBUFS; |
ffb9eb3d KV |
7416 | goto free_msg; |
7417 | } | |
7418 | ||
7419 | if (wdev->ps) | |
7420 | ps_state = NL80211_PS_ENABLED; | |
7421 | else | |
7422 | ps_state = NL80211_PS_DISABLED; | |
7423 | ||
9360ffd1 DM |
7424 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7425 | goto nla_put_failure; | |
ffb9eb3d KV |
7426 | |
7427 | genlmsg_end(msg, hdr); | |
4c476991 | 7428 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7429 | |
4c476991 | 7430 | nla_put_failure: |
ffb9eb3d | 7431 | err = -ENOBUFS; |
4c476991 | 7432 | free_msg: |
ffb9eb3d | 7433 | nlmsg_free(msg); |
ffb9eb3d KV |
7434 | return err; |
7435 | } | |
7436 | ||
d6dc1a38 JO |
7437 | static struct nla_policy |
7438 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7439 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7440 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7441 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7442 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7443 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7444 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7445 | }; |
7446 | ||
84f10708 | 7447 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7448 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7449 | { |
7450 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7451 | struct wireless_dev *wdev; | |
7452 | struct net_device *dev = info->user_ptr[1]; | |
7453 | ||
d9d8b019 | 7454 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7455 | return -EINVAL; |
7456 | ||
7457 | wdev = dev->ieee80211_ptr; | |
7458 | ||
7459 | if (!rdev->ops->set_cqm_txe_config) | |
7460 | return -EOPNOTSUPP; | |
7461 | ||
7462 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7463 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7464 | return -EOPNOTSUPP; | |
7465 | ||
e35e4d28 | 7466 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7467 | } |
7468 | ||
d6dc1a38 JO |
7469 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7470 | s32 threshold, u32 hysteresis) | |
7471 | { | |
4c476991 | 7472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7473 | struct wireless_dev *wdev; |
4c476991 | 7474 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7475 | |
7476 | if (threshold > 0) | |
7477 | return -EINVAL; | |
7478 | ||
d6dc1a38 JO |
7479 | wdev = dev->ieee80211_ptr; |
7480 | ||
4c476991 JB |
7481 | if (!rdev->ops->set_cqm_rssi_config) |
7482 | return -EOPNOTSUPP; | |
d6dc1a38 | 7483 | |
074ac8df | 7484 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7485 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7486 | return -EOPNOTSUPP; | |
d6dc1a38 | 7487 | |
e35e4d28 | 7488 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7489 | } |
7490 | ||
7491 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7492 | { | |
7493 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7494 | struct nlattr *cqm; | |
7495 | int err; | |
7496 | ||
7497 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7498 | if (!cqm) { | |
7499 | err = -EINVAL; | |
7500 | goto out; | |
7501 | } | |
7502 | ||
7503 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7504 | nl80211_attr_cqm_policy); | |
7505 | if (err) | |
7506 | goto out; | |
7507 | ||
7508 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7509 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7510 | s32 threshold; | |
7511 | u32 hysteresis; | |
7512 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7513 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7514 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7515 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7516 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7517 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7518 | u32 rate, pkts, intvl; | |
7519 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7520 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7521 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7522 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7523 | } else |
7524 | err = -EINVAL; | |
7525 | ||
7526 | out: | |
7527 | return err; | |
7528 | } | |
7529 | ||
29cbe68c JB |
7530 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7531 | { | |
7532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7533 | struct net_device *dev = info->user_ptr[1]; | |
7534 | struct mesh_config cfg; | |
c80d545d | 7535 | struct mesh_setup setup; |
29cbe68c JB |
7536 | int err; |
7537 | ||
7538 | /* start with default */ | |
7539 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7540 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7541 | |
24bdd9f4 | 7542 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7543 | /* and parse parameters if given */ |
24bdd9f4 | 7544 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7545 | if (err) |
7546 | return err; | |
7547 | } | |
7548 | ||
7549 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7550 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7551 | return -EINVAL; | |
7552 | ||
c80d545d JC |
7553 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7554 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7555 | ||
4bb62344 CYY |
7556 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7557 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7558 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7559 | return -EINVAL; | |
7560 | ||
9bdbf04d MP |
7561 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7562 | setup.beacon_interval = | |
7563 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7564 | if (setup.beacon_interval < 10 || | |
7565 | setup.beacon_interval > 10000) | |
7566 | return -EINVAL; | |
7567 | } | |
7568 | ||
7569 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7570 | setup.dtim_period = | |
7571 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7572 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7573 | return -EINVAL; | |
7574 | } | |
7575 | ||
c80d545d JC |
7576 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7577 | /* parse additional setup parameters if given */ | |
7578 | err = nl80211_parse_mesh_setup(info, &setup); | |
7579 | if (err) | |
7580 | return err; | |
7581 | } | |
7582 | ||
d37bb18a TP |
7583 | if (setup.user_mpm) |
7584 | cfg.auto_open_plinks = false; | |
7585 | ||
cc1d2806 | 7586 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7587 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7588 | if (err) | |
7589 | return err; | |
cc1d2806 JB |
7590 | } else { |
7591 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7592 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7593 | } |
7594 | ||
ffb3cf30 AN |
7595 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7596 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7597 | int n_rates = | |
7598 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7599 | struct ieee80211_supported_band *sband; | |
7600 | ||
7601 | if (!setup.chandef.chan) | |
7602 | return -EINVAL; | |
7603 | ||
7604 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
7605 | ||
7606 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
7607 | &setup.basic_rates); | |
7608 | if (err) | |
7609 | return err; | |
7610 | } | |
7611 | ||
c80d545d | 7612 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7613 | } |
7614 | ||
7615 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7616 | { | |
7617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7618 | struct net_device *dev = info->user_ptr[1]; | |
7619 | ||
7620 | return cfg80211_leave_mesh(rdev, dev); | |
7621 | } | |
7622 | ||
dfb89c56 | 7623 | #ifdef CONFIG_PM |
bb92d199 AK |
7624 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7625 | struct cfg80211_registered_device *rdev) | |
7626 | { | |
6abb9cb9 | 7627 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
7628 | struct nlattr *nl_pats, *nl_pat; |
7629 | int i, pat_len; | |
7630 | ||
6abb9cb9 | 7631 | if (!wowlan->n_patterns) |
bb92d199 AK |
7632 | return 0; |
7633 | ||
7634 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7635 | if (!nl_pats) | |
7636 | return -ENOBUFS; | |
7637 | ||
6abb9cb9 | 7638 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
7639 | nl_pat = nla_nest_start(msg, i + 1); |
7640 | if (!nl_pat) | |
7641 | return -ENOBUFS; | |
6abb9cb9 | 7642 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 7643 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 7644 | wowlan->patterns[i].mask) || |
50ac6607 AK |
7645 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
7646 | wowlan->patterns[i].pattern) || | |
7647 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 7648 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
7649 | return -ENOBUFS; |
7650 | nla_nest_end(msg, nl_pat); | |
7651 | } | |
7652 | nla_nest_end(msg, nl_pats); | |
7653 | ||
7654 | return 0; | |
7655 | } | |
7656 | ||
2a0e047e JB |
7657 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7658 | struct cfg80211_wowlan_tcp *tcp) | |
7659 | { | |
7660 | struct nlattr *nl_tcp; | |
7661 | ||
7662 | if (!tcp) | |
7663 | return 0; | |
7664 | ||
7665 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7666 | if (!nl_tcp) | |
7667 | return -ENOBUFS; | |
7668 | ||
7669 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7670 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7671 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7672 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7673 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7674 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7675 | tcp->payload_len, tcp->payload) || | |
7676 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7677 | tcp->data_interval) || | |
7678 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7679 | tcp->wake_len, tcp->wake_data) || | |
7680 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7681 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7682 | return -ENOBUFS; | |
7683 | ||
7684 | if (tcp->payload_seq.len && | |
7685 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7686 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7687 | return -ENOBUFS; | |
7688 | ||
7689 | if (tcp->payload_tok.len && | |
7690 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7691 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7692 | &tcp->payload_tok)) | |
7693 | return -ENOBUFS; | |
7694 | ||
e248ad30 JB |
7695 | nla_nest_end(msg, nl_tcp); |
7696 | ||
2a0e047e JB |
7697 | return 0; |
7698 | } | |
7699 | ||
ff1b6e69 JB |
7700 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7701 | { | |
7702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7703 | struct sk_buff *msg; | |
7704 | void *hdr; | |
2a0e047e | 7705 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7706 | |
964dc9e2 | 7707 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
7708 | return -EOPNOTSUPP; |
7709 | ||
6abb9cb9 | 7710 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 7711 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
7712 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
7713 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
7714 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
7715 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
7716 | } |
7717 | ||
7718 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7719 | if (!msg) |
7720 | return -ENOMEM; | |
7721 | ||
15e47304 | 7722 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7723 | NL80211_CMD_GET_WOWLAN); |
7724 | if (!hdr) | |
7725 | goto nla_put_failure; | |
7726 | ||
6abb9cb9 | 7727 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
7728 | struct nlattr *nl_wowlan; |
7729 | ||
7730 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7731 | if (!nl_wowlan) | |
7732 | goto nla_put_failure; | |
7733 | ||
6abb9cb9 | 7734 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 7735 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 7736 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 7737 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 7738 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 7739 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 7740 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 7741 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 7742 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 7743 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 7744 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 7745 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 7746 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
7747 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
7748 | goto nla_put_failure; | |
2a0e047e | 7749 | |
bb92d199 AK |
7750 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7751 | goto nla_put_failure; | |
2a0e047e | 7752 | |
6abb9cb9 JB |
7753 | if (nl80211_send_wowlan_tcp(msg, |
7754 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
7755 | goto nla_put_failure; |
7756 | ||
ff1b6e69 JB |
7757 | nla_nest_end(msg, nl_wowlan); |
7758 | } | |
7759 | ||
7760 | genlmsg_end(msg, hdr); | |
7761 | return genlmsg_reply(msg, info); | |
7762 | ||
7763 | nla_put_failure: | |
7764 | nlmsg_free(msg); | |
7765 | return -ENOBUFS; | |
7766 | } | |
7767 | ||
2a0e047e JB |
7768 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7769 | struct nlattr *attr, | |
7770 | struct cfg80211_wowlan *trig) | |
7771 | { | |
7772 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7773 | struct cfg80211_wowlan_tcp *cfg; | |
7774 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7775 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7776 | u32 size; | |
7777 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7778 | int err, port; | |
7779 | ||
964dc9e2 | 7780 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
7781 | return -EINVAL; |
7782 | ||
7783 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7784 | nla_data(attr), nla_len(attr), | |
7785 | nl80211_wowlan_tcp_policy); | |
7786 | if (err) | |
7787 | return err; | |
7788 | ||
7789 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7790 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7791 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7792 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7793 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7794 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7795 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7796 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7797 | return -EINVAL; | |
7798 | ||
7799 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 7800 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
7801 | return -EINVAL; |
7802 | ||
7803 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 7804 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 7805 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
7806 | return -EINVAL; |
7807 | ||
7808 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 7809 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
7810 | return -EINVAL; |
7811 | ||
7812 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7813 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7814 | return -EINVAL; | |
7815 | ||
7816 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7817 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7818 | ||
7819 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7820 | tokens_size = tokln - sizeof(*tok); | |
7821 | ||
7822 | if (!tok->len || tokens_size % tok->len) | |
7823 | return -EINVAL; | |
964dc9e2 | 7824 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 7825 | return -EINVAL; |
964dc9e2 | 7826 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 7827 | return -EINVAL; |
964dc9e2 | 7828 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 7829 | return -EINVAL; |
964dc9e2 | 7830 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
7831 | return -EINVAL; |
7832 | if (tok->offset + tok->len > data_size) | |
7833 | return -EINVAL; | |
7834 | } | |
7835 | ||
7836 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7837 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 7838 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
7839 | return -EINVAL; |
7840 | if (seq->len == 0 || seq->len > 4) | |
7841 | return -EINVAL; | |
7842 | if (seq->len + seq->offset > data_size) | |
7843 | return -EINVAL; | |
7844 | } | |
7845 | ||
7846 | size = sizeof(*cfg); | |
7847 | size += data_size; | |
7848 | size += wake_size + wake_mask_size; | |
7849 | size += tokens_size; | |
7850 | ||
7851 | cfg = kzalloc(size, GFP_KERNEL); | |
7852 | if (!cfg) | |
7853 | return -ENOMEM; | |
7854 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7855 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7856 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7857 | ETH_ALEN); | |
7858 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7859 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7860 | else | |
7861 | port = 0; | |
7862 | #ifdef CONFIG_INET | |
7863 | /* allocate a socket and port for it and use it */ | |
7864 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7865 | IPPROTO_TCP, &cfg->sock, 1); | |
7866 | if (err) { | |
7867 | kfree(cfg); | |
7868 | return err; | |
7869 | } | |
7870 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7871 | sock_release(cfg->sock); | |
7872 | kfree(cfg); | |
7873 | return -EADDRINUSE; | |
7874 | } | |
7875 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7876 | #else | |
7877 | if (!port) { | |
7878 | kfree(cfg); | |
7879 | return -EINVAL; | |
7880 | } | |
7881 | cfg->src_port = port; | |
7882 | #endif | |
7883 | ||
7884 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7885 | cfg->payload_len = data_size; | |
7886 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7887 | memcpy((void *)cfg->payload, | |
7888 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7889 | data_size); | |
7890 | if (seq) | |
7891 | cfg->payload_seq = *seq; | |
7892 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7893 | cfg->wake_len = wake_size; | |
7894 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7895 | memcpy((void *)cfg->wake_data, | |
7896 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7897 | wake_size); | |
7898 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7899 | data_size + wake_size; | |
7900 | memcpy((void *)cfg->wake_mask, | |
7901 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7902 | wake_mask_size); | |
7903 | if (tok) { | |
7904 | cfg->tokens_size = tokens_size; | |
7905 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7906 | } | |
7907 | ||
7908 | trig->tcp = cfg; | |
7909 | ||
7910 | return 0; | |
7911 | } | |
7912 | ||
ff1b6e69 JB |
7913 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7914 | { | |
7915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7916 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7917 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7918 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 7919 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 7920 | int err, i; |
6abb9cb9 | 7921 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 7922 | |
964dc9e2 | 7923 | if (!wowlan) |
ff1b6e69 JB |
7924 | return -EOPNOTSUPP; |
7925 | ||
ae33bd81 JB |
7926 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7927 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 7928 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
7929 | goto set_wakeup; |
7930 | } | |
ff1b6e69 JB |
7931 | |
7932 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7933 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7934 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7935 | nl80211_wowlan_policy); | |
7936 | if (err) | |
7937 | return err; | |
7938 | ||
7939 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7940 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7941 | return -EINVAL; | |
7942 | new_triggers.any = true; | |
7943 | } | |
7944 | ||
7945 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7946 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7947 | return -EINVAL; | |
7948 | new_triggers.disconnect = true; | |
7949 | } | |
7950 | ||
7951 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7952 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7953 | return -EINVAL; | |
7954 | new_triggers.magic_pkt = true; | |
7955 | } | |
7956 | ||
77dbbb13 JB |
7957 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7958 | return -EINVAL; | |
7959 | ||
7960 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7961 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7962 | return -EINVAL; | |
7963 | new_triggers.gtk_rekey_failure = true; | |
7964 | } | |
7965 | ||
7966 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7967 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7968 | return -EINVAL; | |
7969 | new_triggers.eap_identity_req = true; | |
7970 | } | |
7971 | ||
7972 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7973 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7974 | return -EINVAL; | |
7975 | new_triggers.four_way_handshake = true; | |
7976 | } | |
7977 | ||
7978 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7979 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7980 | return -EINVAL; | |
7981 | new_triggers.rfkill_release = true; | |
7982 | } | |
7983 | ||
ff1b6e69 JB |
7984 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7985 | struct nlattr *pat; | |
7986 | int n_patterns = 0; | |
bb92d199 | 7987 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 7988 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
7989 | |
7990 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7991 | rem) | |
7992 | n_patterns++; | |
7993 | if (n_patterns > wowlan->n_patterns) | |
7994 | return -EINVAL; | |
7995 | ||
7996 | new_triggers.patterns = kcalloc(n_patterns, | |
7997 | sizeof(new_triggers.patterns[0]), | |
7998 | GFP_KERNEL); | |
7999 | if (!new_triggers.patterns) | |
8000 | return -ENOMEM; | |
8001 | ||
8002 | new_triggers.n_patterns = n_patterns; | |
8003 | i = 0; | |
8004 | ||
8005 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8006 | rem) { | |
50ac6607 AK |
8007 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8008 | nla_len(pat), NULL); | |
ff1b6e69 | 8009 | err = -EINVAL; |
50ac6607 AK |
8010 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8011 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8012 | goto error; |
50ac6607 | 8013 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8014 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8015 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8016 | goto error; |
8017 | if (pat_len > wowlan->pattern_max_len || | |
8018 | pat_len < wowlan->pattern_min_len) | |
8019 | goto error; | |
8020 | ||
50ac6607 | 8021 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8022 | pkt_offset = 0; |
8023 | else | |
8024 | pkt_offset = nla_get_u32( | |
50ac6607 | 8025 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8026 | if (pkt_offset > wowlan->max_pkt_offset) |
8027 | goto error; | |
8028 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8029 | ||
ff1b6e69 JB |
8030 | new_triggers.patterns[i].mask = |
8031 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8032 | if (!new_triggers.patterns[i].mask) { | |
8033 | err = -ENOMEM; | |
8034 | goto error; | |
8035 | } | |
8036 | new_triggers.patterns[i].pattern = | |
8037 | new_triggers.patterns[i].mask + mask_len; | |
8038 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8039 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8040 | mask_len); |
8041 | new_triggers.patterns[i].pattern_len = pat_len; | |
8042 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8043 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8044 | pat_len); |
8045 | i++; | |
8046 | } | |
8047 | } | |
8048 | ||
2a0e047e JB |
8049 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8050 | err = nl80211_parse_wowlan_tcp( | |
8051 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8052 | &new_triggers); | |
8053 | if (err) | |
8054 | goto error; | |
8055 | } | |
8056 | ||
ae33bd81 JB |
8057 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8058 | if (!ntrig) { | |
8059 | err = -ENOMEM; | |
8060 | goto error; | |
ff1b6e69 | 8061 | } |
ae33bd81 | 8062 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8063 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8064 | |
ae33bd81 | 8065 | set_wakeup: |
6abb9cb9 JB |
8066 | if (rdev->ops->set_wakeup && |
8067 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8068 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8069 | |
ff1b6e69 JB |
8070 | return 0; |
8071 | error: | |
8072 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8073 | kfree(new_triggers.patterns[i].mask); | |
8074 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8075 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8076 | sock_release(new_triggers.tcp->sock); | |
8077 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8078 | return err; |
8079 | } | |
dfb89c56 | 8080 | #endif |
ff1b6e69 | 8081 | |
be29b99a AK |
8082 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8083 | struct cfg80211_registered_device *rdev) | |
8084 | { | |
8085 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8086 | int i, j, pat_len; | |
8087 | struct cfg80211_coalesce_rules *rule; | |
8088 | ||
8089 | if (!rdev->coalesce->n_rules) | |
8090 | return 0; | |
8091 | ||
8092 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8093 | if (!nl_rules) | |
8094 | return -ENOBUFS; | |
8095 | ||
8096 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8097 | nl_rule = nla_nest_start(msg, i + 1); | |
8098 | if (!nl_rule) | |
8099 | return -ENOBUFS; | |
8100 | ||
8101 | rule = &rdev->coalesce->rules[i]; | |
8102 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8103 | rule->delay)) | |
8104 | return -ENOBUFS; | |
8105 | ||
8106 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8107 | rule->condition)) | |
8108 | return -ENOBUFS; | |
8109 | ||
8110 | nl_pats = nla_nest_start(msg, | |
8111 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8112 | if (!nl_pats) | |
8113 | return -ENOBUFS; | |
8114 | ||
8115 | for (j = 0; j < rule->n_patterns; j++) { | |
8116 | nl_pat = nla_nest_start(msg, j + 1); | |
8117 | if (!nl_pat) | |
8118 | return -ENOBUFS; | |
8119 | pat_len = rule->patterns[j].pattern_len; | |
8120 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8121 | DIV_ROUND_UP(pat_len, 8), | |
8122 | rule->patterns[j].mask) || | |
8123 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8124 | rule->patterns[j].pattern) || | |
8125 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8126 | rule->patterns[j].pkt_offset)) | |
8127 | return -ENOBUFS; | |
8128 | nla_nest_end(msg, nl_pat); | |
8129 | } | |
8130 | nla_nest_end(msg, nl_pats); | |
8131 | nla_nest_end(msg, nl_rule); | |
8132 | } | |
8133 | nla_nest_end(msg, nl_rules); | |
8134 | ||
8135 | return 0; | |
8136 | } | |
8137 | ||
8138 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8139 | { | |
8140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8141 | struct sk_buff *msg; | |
8142 | void *hdr; | |
8143 | ||
8144 | if (!rdev->wiphy.coalesce) | |
8145 | return -EOPNOTSUPP; | |
8146 | ||
8147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8148 | if (!msg) | |
8149 | return -ENOMEM; | |
8150 | ||
8151 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8152 | NL80211_CMD_GET_COALESCE); | |
8153 | if (!hdr) | |
8154 | goto nla_put_failure; | |
8155 | ||
8156 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8157 | goto nla_put_failure; | |
8158 | ||
8159 | genlmsg_end(msg, hdr); | |
8160 | return genlmsg_reply(msg, info); | |
8161 | ||
8162 | nla_put_failure: | |
8163 | nlmsg_free(msg); | |
8164 | return -ENOBUFS; | |
8165 | } | |
8166 | ||
8167 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8168 | { | |
8169 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8170 | int i, j; | |
8171 | struct cfg80211_coalesce_rules *rule; | |
8172 | ||
8173 | if (!coalesce) | |
8174 | return; | |
8175 | ||
8176 | for (i = 0; i < coalesce->n_rules; i++) { | |
8177 | rule = &coalesce->rules[i]; | |
8178 | for (j = 0; j < rule->n_patterns; j++) | |
8179 | kfree(rule->patterns[j].mask); | |
8180 | kfree(rule->patterns); | |
8181 | } | |
8182 | kfree(coalesce->rules); | |
8183 | kfree(coalesce); | |
8184 | rdev->coalesce = NULL; | |
8185 | } | |
8186 | ||
8187 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8188 | struct nlattr *rule, | |
8189 | struct cfg80211_coalesce_rules *new_rule) | |
8190 | { | |
8191 | int err, i; | |
8192 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8193 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8194 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8195 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8196 | ||
8197 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8198 | nla_len(rule), nl80211_coalesce_policy); | |
8199 | if (err) | |
8200 | return err; | |
8201 | ||
8202 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8203 | new_rule->delay = | |
8204 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8205 | if (new_rule->delay > coalesce->max_delay) | |
8206 | return -EINVAL; | |
8207 | ||
8208 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8209 | new_rule->condition = | |
8210 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8211 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8212 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8213 | return -EINVAL; | |
8214 | ||
8215 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8216 | return -EINVAL; | |
8217 | ||
8218 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8219 | rem) | |
8220 | n_patterns++; | |
8221 | if (n_patterns > coalesce->n_patterns) | |
8222 | return -EINVAL; | |
8223 | ||
8224 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8225 | GFP_KERNEL); | |
8226 | if (!new_rule->patterns) | |
8227 | return -ENOMEM; | |
8228 | ||
8229 | new_rule->n_patterns = n_patterns; | |
8230 | i = 0; | |
8231 | ||
8232 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8233 | rem) { | |
8234 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8235 | nla_len(pat), NULL); | |
8236 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8237 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8238 | return -EINVAL; | |
8239 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8240 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8241 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8242 | return -EINVAL; | |
8243 | if (pat_len > coalesce->pattern_max_len || | |
8244 | pat_len < coalesce->pattern_min_len) | |
8245 | return -EINVAL; | |
8246 | ||
8247 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8248 | pkt_offset = 0; | |
8249 | else | |
8250 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8251 | if (pkt_offset > coalesce->max_pkt_offset) | |
8252 | return -EINVAL; | |
8253 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8254 | ||
8255 | new_rule->patterns[i].mask = | |
8256 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8257 | if (!new_rule->patterns[i].mask) | |
8258 | return -ENOMEM; | |
8259 | new_rule->patterns[i].pattern = | |
8260 | new_rule->patterns[i].mask + mask_len; | |
8261 | memcpy(new_rule->patterns[i].mask, | |
8262 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8263 | new_rule->patterns[i].pattern_len = pat_len; | |
8264 | memcpy(new_rule->patterns[i].pattern, | |
8265 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8266 | i++; | |
8267 | } | |
8268 | ||
8269 | return 0; | |
8270 | } | |
8271 | ||
8272 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8273 | { | |
8274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8275 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8276 | struct cfg80211_coalesce new_coalesce = {}; | |
8277 | struct cfg80211_coalesce *n_coalesce; | |
8278 | int err, rem_rule, n_rules = 0, i, j; | |
8279 | struct nlattr *rule; | |
8280 | struct cfg80211_coalesce_rules *tmp_rule; | |
8281 | ||
8282 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8283 | return -EOPNOTSUPP; | |
8284 | ||
8285 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8286 | cfg80211_rdev_free_coalesce(rdev); | |
8287 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8288 | return 0; | |
8289 | } | |
8290 | ||
8291 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8292 | rem_rule) | |
8293 | n_rules++; | |
8294 | if (n_rules > coalesce->n_rules) | |
8295 | return -EINVAL; | |
8296 | ||
8297 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8298 | GFP_KERNEL); | |
8299 | if (!new_coalesce.rules) | |
8300 | return -ENOMEM; | |
8301 | ||
8302 | new_coalesce.n_rules = n_rules; | |
8303 | i = 0; | |
8304 | ||
8305 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8306 | rem_rule) { | |
8307 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8308 | &new_coalesce.rules[i]); | |
8309 | if (err) | |
8310 | goto error; | |
8311 | ||
8312 | i++; | |
8313 | } | |
8314 | ||
8315 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8316 | if (err) | |
8317 | goto error; | |
8318 | ||
8319 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8320 | if (!n_coalesce) { | |
8321 | err = -ENOMEM; | |
8322 | goto error; | |
8323 | } | |
8324 | cfg80211_rdev_free_coalesce(rdev); | |
8325 | rdev->coalesce = n_coalesce; | |
8326 | ||
8327 | return 0; | |
8328 | error: | |
8329 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8330 | tmp_rule = &new_coalesce.rules[i]; | |
8331 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8332 | kfree(tmp_rule->patterns[j].mask); | |
8333 | kfree(tmp_rule->patterns); | |
8334 | } | |
8335 | kfree(new_coalesce.rules); | |
8336 | ||
8337 | return err; | |
8338 | } | |
8339 | ||
e5497d76 JB |
8340 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8341 | { | |
8342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8343 | struct net_device *dev = info->user_ptr[1]; | |
8344 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8345 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8346 | struct cfg80211_gtk_rekey_data rekey_data; | |
8347 | int err; | |
8348 | ||
8349 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8350 | return -EINVAL; | |
8351 | ||
8352 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8353 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8354 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8355 | nl80211_rekey_policy); | |
8356 | if (err) | |
8357 | return err; | |
8358 | ||
8359 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8360 | return -ERANGE; | |
8361 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8362 | return -ERANGE; | |
8363 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8364 | return -ERANGE; | |
8365 | ||
8366 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8367 | NL80211_KEK_LEN); | |
8368 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8369 | NL80211_KCK_LEN); | |
8370 | memcpy(rekey_data.replay_ctr, | |
8371 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8372 | NL80211_REPLAY_CTR_LEN); | |
8373 | ||
8374 | wdev_lock(wdev); | |
8375 | if (!wdev->current_bss) { | |
8376 | err = -ENOTCONN; | |
8377 | goto out; | |
8378 | } | |
8379 | ||
8380 | if (!rdev->ops->set_rekey_data) { | |
8381 | err = -EOPNOTSUPP; | |
8382 | goto out; | |
8383 | } | |
8384 | ||
e35e4d28 | 8385 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8386 | out: |
8387 | wdev_unlock(wdev); | |
8388 | return err; | |
8389 | } | |
8390 | ||
28946da7 JB |
8391 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8392 | struct genl_info *info) | |
8393 | { | |
8394 | struct net_device *dev = info->user_ptr[1]; | |
8395 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8396 | ||
8397 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8398 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8399 | return -EINVAL; | |
8400 | ||
15e47304 | 8401 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8402 | return -EBUSY; |
8403 | ||
15e47304 | 8404 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8405 | return 0; |
8406 | } | |
8407 | ||
7f6cf311 JB |
8408 | static int nl80211_probe_client(struct sk_buff *skb, |
8409 | struct genl_info *info) | |
8410 | { | |
8411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8412 | struct net_device *dev = info->user_ptr[1]; | |
8413 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8414 | struct sk_buff *msg; | |
8415 | void *hdr; | |
8416 | const u8 *addr; | |
8417 | u64 cookie; | |
8418 | int err; | |
8419 | ||
8420 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8421 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8422 | return -EOPNOTSUPP; | |
8423 | ||
8424 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8425 | return -EINVAL; | |
8426 | ||
8427 | if (!rdev->ops->probe_client) | |
8428 | return -EOPNOTSUPP; | |
8429 | ||
8430 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8431 | if (!msg) | |
8432 | return -ENOMEM; | |
8433 | ||
15e47304 | 8434 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8435 | NL80211_CMD_PROBE_CLIENT); |
8436 | ||
8437 | if (IS_ERR(hdr)) { | |
8438 | err = PTR_ERR(hdr); | |
8439 | goto free_msg; | |
8440 | } | |
8441 | ||
8442 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8443 | ||
e35e4d28 | 8444 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8445 | if (err) |
8446 | goto free_msg; | |
8447 | ||
9360ffd1 DM |
8448 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8449 | goto nla_put_failure; | |
7f6cf311 JB |
8450 | |
8451 | genlmsg_end(msg, hdr); | |
8452 | ||
8453 | return genlmsg_reply(msg, info); | |
8454 | ||
8455 | nla_put_failure: | |
8456 | err = -ENOBUFS; | |
8457 | free_msg: | |
8458 | nlmsg_free(msg); | |
8459 | return err; | |
8460 | } | |
8461 | ||
5e760230 JB |
8462 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8463 | { | |
8464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8465 | struct cfg80211_beacon_registration *reg, *nreg; |
8466 | int rv; | |
5e760230 JB |
8467 | |
8468 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8469 | return -EOPNOTSUPP; | |
8470 | ||
37c73b5f BG |
8471 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8472 | if (!nreg) | |
8473 | return -ENOMEM; | |
8474 | ||
8475 | /* First, check if already registered. */ | |
8476 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8477 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8478 | if (reg->nlportid == info->snd_portid) { | |
8479 | rv = -EALREADY; | |
8480 | goto out_err; | |
8481 | } | |
8482 | } | |
8483 | /* Add it to the list */ | |
8484 | nreg->nlportid = info->snd_portid; | |
8485 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8486 | |
37c73b5f | 8487 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8488 | |
8489 | return 0; | |
37c73b5f BG |
8490 | out_err: |
8491 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8492 | kfree(nreg); | |
8493 | return rv; | |
5e760230 JB |
8494 | } |
8495 | ||
98104fde JB |
8496 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8497 | { | |
8498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8499 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8500 | int err; | |
8501 | ||
8502 | if (!rdev->ops->start_p2p_device) | |
8503 | return -EOPNOTSUPP; | |
8504 | ||
8505 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8506 | return -EOPNOTSUPP; | |
8507 | ||
8508 | if (wdev->p2p_started) | |
8509 | return 0; | |
8510 | ||
98104fde | 8511 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8512 | if (err) |
8513 | return err; | |
8514 | ||
eeb126e9 | 8515 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8516 | if (err) |
8517 | return err; | |
8518 | ||
8519 | wdev->p2p_started = true; | |
98104fde | 8520 | rdev->opencount++; |
98104fde JB |
8521 | |
8522 | return 0; | |
8523 | } | |
8524 | ||
8525 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8526 | { | |
8527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8528 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8529 | ||
8530 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8531 | return -EOPNOTSUPP; | |
8532 | ||
8533 | if (!rdev->ops->stop_p2p_device) | |
8534 | return -EOPNOTSUPP; | |
8535 | ||
f9f47529 | 8536 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8537 | |
8538 | return 0; | |
8539 | } | |
8540 | ||
3713b4e3 JB |
8541 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8542 | struct genl_info *info) | |
8543 | { | |
8544 | void *hdr; | |
8545 | struct sk_buff *msg; | |
8546 | ||
8547 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8548 | if (!msg) | |
8549 | return -ENOMEM; | |
8550 | ||
8551 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8552 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8553 | if (!hdr) | |
8554 | goto nla_put_failure; | |
8555 | ||
8556 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8557 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8558 | goto nla_put_failure; | |
8559 | ||
8560 | genlmsg_end(msg, hdr); | |
8561 | return genlmsg_reply(msg, info); | |
8562 | ||
8563 | nla_put_failure: | |
8564 | kfree_skb(msg); | |
8565 | return -ENOBUFS; | |
8566 | } | |
8567 | ||
355199e0 JM |
8568 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8569 | { | |
8570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8571 | struct cfg80211_update_ft_ies_params ft_params; | |
8572 | struct net_device *dev = info->user_ptr[1]; | |
8573 | ||
8574 | if (!rdev->ops->update_ft_ies) | |
8575 | return -EOPNOTSUPP; | |
8576 | ||
8577 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8578 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8579 | return -EINVAL; | |
8580 | ||
8581 | memset(&ft_params, 0, sizeof(ft_params)); | |
8582 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8583 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8584 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8585 | ||
8586 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8587 | } | |
8588 | ||
5de17984 AS |
8589 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8590 | struct genl_info *info) | |
8591 | { | |
8592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8593 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8594 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8595 | u16 duration; | |
8596 | int ret; | |
8597 | ||
8598 | if (!rdev->ops->crit_proto_start) | |
8599 | return -EOPNOTSUPP; | |
8600 | ||
8601 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8602 | return -EINVAL; | |
8603 | ||
8604 | if (rdev->crit_proto_nlportid) | |
8605 | return -EBUSY; | |
8606 | ||
8607 | /* determine protocol if provided */ | |
8608 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8609 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8610 | ||
8611 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8612 | return -EINVAL; | |
8613 | ||
8614 | /* timeout must be provided */ | |
8615 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8616 | return -EINVAL; | |
8617 | ||
8618 | duration = | |
8619 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8620 | ||
8621 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8622 | return -ERANGE; | |
8623 | ||
8624 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8625 | if (!ret) | |
8626 | rdev->crit_proto_nlportid = info->snd_portid; | |
8627 | ||
8628 | return ret; | |
8629 | } | |
8630 | ||
8631 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8632 | struct genl_info *info) | |
8633 | { | |
8634 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8635 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8636 | ||
8637 | if (!rdev->ops->crit_proto_stop) | |
8638 | return -EOPNOTSUPP; | |
8639 | ||
8640 | if (rdev->crit_proto_nlportid) { | |
8641 | rdev->crit_proto_nlportid = 0; | |
8642 | rdev_crit_proto_stop(rdev, wdev); | |
8643 | } | |
8644 | return 0; | |
8645 | } | |
8646 | ||
4c476991 JB |
8647 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8648 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8649 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8650 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8651 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8652 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8653 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8654 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8655 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8656 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8657 | |
8658 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8659 | struct genl_info *info) | |
8660 | { | |
8661 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8662 | struct wireless_dev *wdev; |
4c476991 | 8663 | struct net_device *dev; |
4c476991 JB |
8664 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8665 | ||
8666 | if (rtnl) | |
8667 | rtnl_lock(); | |
8668 | ||
8669 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8670 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8671 | if (IS_ERR(rdev)) { |
8672 | if (rtnl) | |
8673 | rtnl_unlock(); | |
8674 | return PTR_ERR(rdev); | |
8675 | } | |
8676 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8677 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8678 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
8679 | ASSERT_RTNL(); |
8680 | ||
89a54e48 JB |
8681 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
8682 | info->attrs); | |
8683 | if (IS_ERR(wdev)) { | |
4c476991 JB |
8684 | if (rtnl) |
8685 | rtnl_unlock(); | |
89a54e48 | 8686 | return PTR_ERR(wdev); |
4c476991 | 8687 | } |
89a54e48 | 8688 | |
89a54e48 JB |
8689 | dev = wdev->netdev; |
8690 | rdev = wiphy_to_dev(wdev->wiphy); | |
8691 | ||
1bf614ef JB |
8692 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8693 | if (!dev) { | |
1bf614ef JB |
8694 | if (rtnl) |
8695 | rtnl_unlock(); | |
8696 | return -EINVAL; | |
8697 | } | |
8698 | ||
8699 | info->user_ptr[1] = dev; | |
8700 | } else { | |
8701 | info->user_ptr[1] = wdev; | |
41265714 | 8702 | } |
1bf614ef JB |
8703 | |
8704 | if (dev) { | |
8705 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8706 | !netif_running(dev)) { | |
1bf614ef JB |
8707 | if (rtnl) |
8708 | rtnl_unlock(); | |
8709 | return -ENETDOWN; | |
8710 | } | |
8711 | ||
8712 | dev_hold(dev); | |
98104fde JB |
8713 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8714 | if (!wdev->p2p_started) { | |
98104fde JB |
8715 | if (rtnl) |
8716 | rtnl_unlock(); | |
8717 | return -ENETDOWN; | |
8718 | } | |
41265714 | 8719 | } |
89a54e48 | 8720 | |
4c476991 | 8721 | info->user_ptr[0] = rdev; |
4c476991 JB |
8722 | } |
8723 | ||
8724 | return 0; | |
8725 | } | |
8726 | ||
8727 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8728 | struct genl_info *info) | |
8729 | { | |
1bf614ef JB |
8730 | if (info->user_ptr[1]) { |
8731 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8732 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8733 | ||
8734 | if (wdev->netdev) | |
8735 | dev_put(wdev->netdev); | |
8736 | } else { | |
8737 | dev_put(info->user_ptr[1]); | |
8738 | } | |
8739 | } | |
4c476991 JB |
8740 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8741 | rtnl_unlock(); | |
8742 | } | |
8743 | ||
55682965 JB |
8744 | static struct genl_ops nl80211_ops[] = { |
8745 | { | |
8746 | .cmd = NL80211_CMD_GET_WIPHY, | |
8747 | .doit = nl80211_get_wiphy, | |
8748 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 8749 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
8750 | .policy = nl80211_policy, |
8751 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8752 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8753 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8754 | }, |
8755 | { | |
8756 | .cmd = NL80211_CMD_SET_WIPHY, | |
8757 | .doit = nl80211_set_wiphy, | |
8758 | .policy = nl80211_policy, | |
8759 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8760 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8761 | }, |
8762 | { | |
8763 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8764 | .doit = nl80211_get_interface, | |
8765 | .dumpit = nl80211_dump_interface, | |
8766 | .policy = nl80211_policy, | |
8767 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8768 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
8769 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8770 | }, |
8771 | { | |
8772 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8773 | .doit = nl80211_set_interface, | |
8774 | .policy = nl80211_policy, | |
8775 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8776 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8777 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8778 | }, |
8779 | { | |
8780 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8781 | .doit = nl80211_new_interface, | |
8782 | .policy = nl80211_policy, | |
8783 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8784 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8785 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8786 | }, |
8787 | { | |
8788 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8789 | .doit = nl80211_del_interface, | |
8790 | .policy = nl80211_policy, | |
41ade00f | 8791 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8792 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8793 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8794 | }, |
8795 | { | |
8796 | .cmd = NL80211_CMD_GET_KEY, | |
8797 | .doit = nl80211_get_key, | |
8798 | .policy = nl80211_policy, | |
8799 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8801 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8802 | }, |
8803 | { | |
8804 | .cmd = NL80211_CMD_SET_KEY, | |
8805 | .doit = nl80211_set_key, | |
8806 | .policy = nl80211_policy, | |
8807 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8809 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8810 | }, |
8811 | { | |
8812 | .cmd = NL80211_CMD_NEW_KEY, | |
8813 | .doit = nl80211_new_key, | |
8814 | .policy = nl80211_policy, | |
8815 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8817 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8818 | }, |
8819 | { | |
8820 | .cmd = NL80211_CMD_DEL_KEY, | |
8821 | .doit = nl80211_del_key, | |
8822 | .policy = nl80211_policy, | |
55682965 | 8823 | .flags = GENL_ADMIN_PERM, |
41265714 | 8824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8825 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8826 | }, |
ed1b6cc7 JB |
8827 | { |
8828 | .cmd = NL80211_CMD_SET_BEACON, | |
8829 | .policy = nl80211_policy, | |
8830 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8831 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8833 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8834 | }, |
8835 | { | |
8860020e | 8836 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8837 | .policy = nl80211_policy, |
8838 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8839 | .doit = nl80211_start_ap, |
2b5f8b0b | 8840 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8841 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8842 | }, |
8843 | { | |
8860020e | 8844 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8845 | .policy = nl80211_policy, |
8846 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8847 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8848 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8849 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8850 | }, |
5727ef1b JB |
8851 | { |
8852 | .cmd = NL80211_CMD_GET_STATION, | |
8853 | .doit = nl80211_get_station, | |
2ec600d6 | 8854 | .dumpit = nl80211_dump_station, |
5727ef1b | 8855 | .policy = nl80211_policy, |
4c476991 JB |
8856 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8857 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8858 | }, |
8859 | { | |
8860 | .cmd = NL80211_CMD_SET_STATION, | |
8861 | .doit = nl80211_set_station, | |
8862 | .policy = nl80211_policy, | |
8863 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8864 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8865 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8866 | }, |
8867 | { | |
8868 | .cmd = NL80211_CMD_NEW_STATION, | |
8869 | .doit = nl80211_new_station, | |
8870 | .policy = nl80211_policy, | |
8871 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8872 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8873 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8874 | }, |
8875 | { | |
8876 | .cmd = NL80211_CMD_DEL_STATION, | |
8877 | .doit = nl80211_del_station, | |
8878 | .policy = nl80211_policy, | |
2ec600d6 | 8879 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8880 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8881 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8882 | }, |
8883 | { | |
8884 | .cmd = NL80211_CMD_GET_MPATH, | |
8885 | .doit = nl80211_get_mpath, | |
8886 | .dumpit = nl80211_dump_mpath, | |
8887 | .policy = nl80211_policy, | |
8888 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8890 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8891 | }, |
8892 | { | |
8893 | .cmd = NL80211_CMD_SET_MPATH, | |
8894 | .doit = nl80211_set_mpath, | |
8895 | .policy = nl80211_policy, | |
8896 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8897 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8898 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8899 | }, |
8900 | { | |
8901 | .cmd = NL80211_CMD_NEW_MPATH, | |
8902 | .doit = nl80211_new_mpath, | |
8903 | .policy = nl80211_policy, | |
8904 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8906 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8907 | }, |
8908 | { | |
8909 | .cmd = NL80211_CMD_DEL_MPATH, | |
8910 | .doit = nl80211_del_mpath, | |
8911 | .policy = nl80211_policy, | |
9f1ba906 | 8912 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8914 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8915 | }, |
8916 | { | |
8917 | .cmd = NL80211_CMD_SET_BSS, | |
8918 | .doit = nl80211_set_bss, | |
8919 | .policy = nl80211_policy, | |
b2e1b302 | 8920 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8922 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8923 | }, |
f130347c LR |
8924 | { |
8925 | .cmd = NL80211_CMD_GET_REG, | |
8926 | .doit = nl80211_get_reg, | |
8927 | .policy = nl80211_policy, | |
5fe231e8 | 8928 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
8929 | /* can be retrieved by unprivileged users */ |
8930 | }, | |
b2e1b302 LR |
8931 | { |
8932 | .cmd = NL80211_CMD_SET_REG, | |
8933 | .doit = nl80211_set_reg, | |
8934 | .policy = nl80211_policy, | |
8935 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 8936 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
8937 | }, |
8938 | { | |
8939 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8940 | .doit = nl80211_req_set_reg, | |
8941 | .policy = nl80211_policy, | |
93da9cc1 | 8942 | .flags = GENL_ADMIN_PERM, |
8943 | }, | |
8944 | { | |
24bdd9f4 JC |
8945 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8946 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8947 | .policy = nl80211_policy, |
8948 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8950 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8951 | }, |
8952 | { | |
24bdd9f4 JC |
8953 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8954 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8955 | .policy = nl80211_policy, |
9aed3cc1 | 8956 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8958 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8959 | }, |
2a519311 JB |
8960 | { |
8961 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8962 | .doit = nl80211_trigger_scan, | |
8963 | .policy = nl80211_policy, | |
8964 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8965 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8966 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8967 | }, |
8968 | { | |
8969 | .cmd = NL80211_CMD_GET_SCAN, | |
8970 | .policy = nl80211_policy, | |
8971 | .dumpit = nl80211_dump_scan, | |
8972 | }, | |
807f8a8c LC |
8973 | { |
8974 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8975 | .doit = nl80211_start_sched_scan, | |
8976 | .policy = nl80211_policy, | |
8977 | .flags = GENL_ADMIN_PERM, | |
8978 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8979 | NL80211_FLAG_NEED_RTNL, | |
8980 | }, | |
8981 | { | |
8982 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8983 | .doit = nl80211_stop_sched_scan, | |
8984 | .policy = nl80211_policy, | |
8985 | .flags = GENL_ADMIN_PERM, | |
8986 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8987 | NL80211_FLAG_NEED_RTNL, | |
8988 | }, | |
636a5d36 JM |
8989 | { |
8990 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8991 | .doit = nl80211_authenticate, | |
8992 | .policy = nl80211_policy, | |
8993 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8995 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8996 | }, |
8997 | { | |
8998 | .cmd = NL80211_CMD_ASSOCIATE, | |
8999 | .doit = nl80211_associate, | |
9000 | .policy = nl80211_policy, | |
9001 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9003 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9004 | }, |
9005 | { | |
9006 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9007 | .doit = nl80211_deauthenticate, | |
9008 | .policy = nl80211_policy, | |
9009 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9010 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9011 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9012 | }, |
9013 | { | |
9014 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9015 | .doit = nl80211_disassociate, | |
9016 | .policy = nl80211_policy, | |
9017 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9018 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9019 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9020 | }, |
04a773ad JB |
9021 | { |
9022 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9023 | .doit = nl80211_join_ibss, | |
9024 | .policy = nl80211_policy, | |
9025 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9026 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9027 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9028 | }, |
9029 | { | |
9030 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9031 | .doit = nl80211_leave_ibss, | |
9032 | .policy = nl80211_policy, | |
9033 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9034 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9035 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9036 | }, |
aff89a9b JB |
9037 | #ifdef CONFIG_NL80211_TESTMODE |
9038 | { | |
9039 | .cmd = NL80211_CMD_TESTMODE, | |
9040 | .doit = nl80211_testmode_do, | |
71063f0e | 9041 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9042 | .policy = nl80211_policy, |
9043 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9044 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9045 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9046 | }, |
9047 | #endif | |
b23aa676 SO |
9048 | { |
9049 | .cmd = NL80211_CMD_CONNECT, | |
9050 | .doit = nl80211_connect, | |
9051 | .policy = nl80211_policy, | |
9052 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9053 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9054 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9055 | }, |
9056 | { | |
9057 | .cmd = NL80211_CMD_DISCONNECT, | |
9058 | .doit = nl80211_disconnect, | |
9059 | .policy = nl80211_policy, | |
9060 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9061 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9062 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9063 | }, |
463d0183 JB |
9064 | { |
9065 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9066 | .doit = nl80211_wiphy_netns, | |
9067 | .policy = nl80211_policy, | |
9068 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9069 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9070 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9071 | }, |
61fa713c HS |
9072 | { |
9073 | .cmd = NL80211_CMD_GET_SURVEY, | |
9074 | .policy = nl80211_policy, | |
9075 | .dumpit = nl80211_dump_survey, | |
9076 | }, | |
67fbb16b SO |
9077 | { |
9078 | .cmd = NL80211_CMD_SET_PMKSA, | |
9079 | .doit = nl80211_setdel_pmksa, | |
9080 | .policy = nl80211_policy, | |
9081 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9082 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9083 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9084 | }, |
9085 | { | |
9086 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9087 | .doit = nl80211_setdel_pmksa, | |
9088 | .policy = nl80211_policy, | |
9089 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9090 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9091 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9092 | }, |
9093 | { | |
9094 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9095 | .doit = nl80211_flush_pmksa, | |
9096 | .policy = nl80211_policy, | |
9097 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9098 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9099 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9100 | }, |
9588bbd5 JM |
9101 | { |
9102 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9103 | .doit = nl80211_remain_on_channel, | |
9104 | .policy = nl80211_policy, | |
9105 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9106 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9107 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9108 | }, |
9109 | { | |
9110 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9111 | .doit = nl80211_cancel_remain_on_channel, | |
9112 | .policy = nl80211_policy, | |
9113 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9114 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9115 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9116 | }, |
13ae75b1 JM |
9117 | { |
9118 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9119 | .doit = nl80211_set_tx_bitrate_mask, | |
9120 | .policy = nl80211_policy, | |
9121 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9122 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9123 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9124 | }, |
026331c4 | 9125 | { |
2e161f78 JB |
9126 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9127 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9128 | .policy = nl80211_policy, |
9129 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9130 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9131 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9132 | }, |
9133 | { | |
2e161f78 JB |
9134 | .cmd = NL80211_CMD_FRAME, |
9135 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9136 | .policy = nl80211_policy, |
f7ca38df | 9137 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9138 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9139 | NL80211_FLAG_NEED_RTNL, |
9140 | }, | |
9141 | { | |
9142 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9143 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9144 | .policy = nl80211_policy, | |
026331c4 | 9145 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9146 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9147 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9148 | }, |
ffb9eb3d KV |
9149 | { |
9150 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9151 | .doit = nl80211_set_power_save, | |
9152 | .policy = nl80211_policy, | |
9153 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9154 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9155 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9156 | }, |
9157 | { | |
9158 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9159 | .doit = nl80211_get_power_save, | |
9160 | .policy = nl80211_policy, | |
9161 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9162 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9163 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9164 | }, |
d6dc1a38 JO |
9165 | { |
9166 | .cmd = NL80211_CMD_SET_CQM, | |
9167 | .doit = nl80211_set_cqm, | |
9168 | .policy = nl80211_policy, | |
9169 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9170 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9171 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9172 | }, |
f444de05 JB |
9173 | { |
9174 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9175 | .doit = nl80211_set_channel, | |
9176 | .policy = nl80211_policy, | |
9177 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9178 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9179 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9180 | }, |
e8347eba BJ |
9181 | { |
9182 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9183 | .doit = nl80211_set_wds_peer, | |
9184 | .policy = nl80211_policy, | |
9185 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9186 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9187 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9188 | }, |
29cbe68c JB |
9189 | { |
9190 | .cmd = NL80211_CMD_JOIN_MESH, | |
9191 | .doit = nl80211_join_mesh, | |
9192 | .policy = nl80211_policy, | |
9193 | .flags = GENL_ADMIN_PERM, | |
9194 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9195 | NL80211_FLAG_NEED_RTNL, | |
9196 | }, | |
9197 | { | |
9198 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9199 | .doit = nl80211_leave_mesh, | |
9200 | .policy = nl80211_policy, | |
9201 | .flags = GENL_ADMIN_PERM, | |
9202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9203 | NL80211_FLAG_NEED_RTNL, | |
9204 | }, | |
dfb89c56 | 9205 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9206 | { |
9207 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9208 | .doit = nl80211_get_wowlan, | |
9209 | .policy = nl80211_policy, | |
9210 | /* can be retrieved by unprivileged users */ | |
9211 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9212 | NL80211_FLAG_NEED_RTNL, | |
9213 | }, | |
9214 | { | |
9215 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9216 | .doit = nl80211_set_wowlan, | |
9217 | .policy = nl80211_policy, | |
9218 | .flags = GENL_ADMIN_PERM, | |
9219 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9220 | NL80211_FLAG_NEED_RTNL, | |
9221 | }, | |
dfb89c56 | 9222 | #endif |
e5497d76 JB |
9223 | { |
9224 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9225 | .doit = nl80211_set_rekey_data, | |
9226 | .policy = nl80211_policy, | |
9227 | .flags = GENL_ADMIN_PERM, | |
9228 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9229 | NL80211_FLAG_NEED_RTNL, | |
9230 | }, | |
109086ce AN |
9231 | { |
9232 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9233 | .doit = nl80211_tdls_mgmt, | |
9234 | .policy = nl80211_policy, | |
9235 | .flags = GENL_ADMIN_PERM, | |
9236 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9237 | NL80211_FLAG_NEED_RTNL, | |
9238 | }, | |
9239 | { | |
9240 | .cmd = NL80211_CMD_TDLS_OPER, | |
9241 | .doit = nl80211_tdls_oper, | |
9242 | .policy = nl80211_policy, | |
9243 | .flags = GENL_ADMIN_PERM, | |
9244 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9245 | NL80211_FLAG_NEED_RTNL, | |
9246 | }, | |
28946da7 JB |
9247 | { |
9248 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9249 | .doit = nl80211_register_unexpected_frame, | |
9250 | .policy = nl80211_policy, | |
9251 | .flags = GENL_ADMIN_PERM, | |
9252 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9253 | NL80211_FLAG_NEED_RTNL, | |
9254 | }, | |
7f6cf311 JB |
9255 | { |
9256 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9257 | .doit = nl80211_probe_client, | |
9258 | .policy = nl80211_policy, | |
9259 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9260 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9261 | NL80211_FLAG_NEED_RTNL, |
9262 | }, | |
5e760230 JB |
9263 | { |
9264 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9265 | .doit = nl80211_register_beacons, | |
9266 | .policy = nl80211_policy, | |
9267 | .flags = GENL_ADMIN_PERM, | |
9268 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9269 | NL80211_FLAG_NEED_RTNL, | |
9270 | }, | |
1d9d9213 SW |
9271 | { |
9272 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9273 | .doit = nl80211_set_noack_map, | |
9274 | .policy = nl80211_policy, | |
9275 | .flags = GENL_ADMIN_PERM, | |
9276 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9277 | NL80211_FLAG_NEED_RTNL, | |
9278 | }, | |
98104fde JB |
9279 | { |
9280 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9281 | .doit = nl80211_start_p2p_device, | |
9282 | .policy = nl80211_policy, | |
9283 | .flags = GENL_ADMIN_PERM, | |
9284 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9285 | NL80211_FLAG_NEED_RTNL, | |
9286 | }, | |
9287 | { | |
9288 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9289 | .doit = nl80211_stop_p2p_device, | |
9290 | .policy = nl80211_policy, | |
9291 | .flags = GENL_ADMIN_PERM, | |
9292 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9293 | NL80211_FLAG_NEED_RTNL, | |
9294 | }, | |
f4e583c8 AQ |
9295 | { |
9296 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9297 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9298 | .policy = nl80211_policy, |
9299 | .flags = GENL_ADMIN_PERM, | |
9300 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9301 | NL80211_FLAG_NEED_RTNL, | |
9302 | }, | |
9303 | { | |
9304 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9305 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9306 | .policy = nl80211_policy, |
9307 | .flags = GENL_ADMIN_PERM, | |
9308 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9309 | NL80211_FLAG_NEED_RTNL, | |
9310 | }, | |
04f39047 SW |
9311 | { |
9312 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9313 | .doit = nl80211_start_radar_detection, | |
9314 | .policy = nl80211_policy, | |
9315 | .flags = GENL_ADMIN_PERM, | |
9316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9317 | NL80211_FLAG_NEED_RTNL, | |
9318 | }, | |
3713b4e3 JB |
9319 | { |
9320 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9321 | .doit = nl80211_get_protocol_features, | |
9322 | .policy = nl80211_policy, | |
9323 | }, | |
355199e0 JM |
9324 | { |
9325 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9326 | .doit = nl80211_update_ft_ies, | |
9327 | .policy = nl80211_policy, | |
9328 | .flags = GENL_ADMIN_PERM, | |
9329 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9330 | NL80211_FLAG_NEED_RTNL, | |
9331 | }, | |
5de17984 AS |
9332 | { |
9333 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9334 | .doit = nl80211_crit_protocol_start, | |
9335 | .policy = nl80211_policy, | |
9336 | .flags = GENL_ADMIN_PERM, | |
9337 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9338 | NL80211_FLAG_NEED_RTNL, | |
9339 | }, | |
9340 | { | |
9341 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9342 | .doit = nl80211_crit_protocol_stop, | |
9343 | .policy = nl80211_policy, | |
9344 | .flags = GENL_ADMIN_PERM, | |
9345 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9346 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9347 | }, |
9348 | { | |
9349 | .cmd = NL80211_CMD_GET_COALESCE, | |
9350 | .doit = nl80211_get_coalesce, | |
9351 | .policy = nl80211_policy, | |
9352 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9353 | NL80211_FLAG_NEED_RTNL, | |
9354 | }, | |
9355 | { | |
9356 | .cmd = NL80211_CMD_SET_COALESCE, | |
9357 | .doit = nl80211_set_coalesce, | |
9358 | .policy = nl80211_policy, | |
9359 | .flags = GENL_ADMIN_PERM, | |
9360 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9361 | NL80211_FLAG_NEED_RTNL, | |
5de17984 | 9362 | } |
55682965 | 9363 | }; |
9588bbd5 | 9364 | |
6039f6d2 JM |
9365 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
9366 | .name = "mlme", | |
9367 | }; | |
55682965 JB |
9368 | |
9369 | /* multicast groups */ | |
9370 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
9371 | .name = "config", | |
9372 | }; | |
2a519311 JB |
9373 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
9374 | .name = "scan", | |
9375 | }; | |
73d54c9e LR |
9376 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
9377 | .name = "regulatory", | |
9378 | }; | |
55682965 JB |
9379 | |
9380 | /* notification functions */ | |
9381 | ||
9382 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9383 | { | |
9384 | struct sk_buff *msg; | |
86e8cf98 | 9385 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 9386 | |
fd2120ca | 9387 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9388 | if (!msg) |
9389 | return; | |
9390 | ||
86e8cf98 | 9391 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
9392 | nlmsg_free(msg); |
9393 | return; | |
9394 | } | |
9395 | ||
463d0183 JB |
9396 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9397 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
9398 | } |
9399 | ||
362a415d JB |
9400 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9401 | struct cfg80211_registered_device *rdev) | |
9402 | { | |
9403 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9404 | struct nlattr *nest; | |
9405 | int i; | |
9406 | ||
9407 | if (WARN_ON(!req)) | |
9408 | return 0; | |
9409 | ||
9410 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9411 | if (!nest) | |
9412 | goto nla_put_failure; | |
9360ffd1 DM |
9413 | for (i = 0; i < req->n_ssids; i++) { |
9414 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9415 | goto nla_put_failure; | |
9416 | } | |
362a415d JB |
9417 | nla_nest_end(msg, nest); |
9418 | ||
9419 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9420 | if (!nest) | |
9421 | goto nla_put_failure; | |
9360ffd1 DM |
9422 | for (i = 0; i < req->n_channels; i++) { |
9423 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9424 | goto nla_put_failure; | |
9425 | } | |
362a415d JB |
9426 | nla_nest_end(msg, nest); |
9427 | ||
9360ffd1 DM |
9428 | if (req->ie && |
9429 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9430 | goto nla_put_failure; | |
362a415d | 9431 | |
ed473771 SL |
9432 | if (req->flags) |
9433 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9434 | ||
362a415d JB |
9435 | return 0; |
9436 | nla_put_failure: | |
9437 | return -ENOBUFS; | |
9438 | } | |
9439 | ||
a538e2d5 JB |
9440 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9441 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9442 | struct wireless_dev *wdev, |
15e47304 | 9443 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9444 | u32 cmd) |
2a519311 JB |
9445 | { |
9446 | void *hdr; | |
9447 | ||
15e47304 | 9448 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9449 | if (!hdr) |
9450 | return -1; | |
9451 | ||
9360ffd1 | 9452 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9453 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9454 | wdev->netdev->ifindex)) || | |
9455 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9456 | goto nla_put_failure; |
2a519311 | 9457 | |
362a415d JB |
9458 | /* ignore errors and send incomplete event anyway */ |
9459 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9460 | |
9461 | return genlmsg_end(msg, hdr); | |
9462 | ||
9463 | nla_put_failure: | |
9464 | genlmsg_cancel(msg, hdr); | |
9465 | return -EMSGSIZE; | |
9466 | } | |
9467 | ||
807f8a8c LC |
9468 | static int |
9469 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9470 | struct cfg80211_registered_device *rdev, | |
9471 | struct net_device *netdev, | |
15e47304 | 9472 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9473 | { |
9474 | void *hdr; | |
9475 | ||
15e47304 | 9476 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9477 | if (!hdr) |
9478 | return -1; | |
9479 | ||
9360ffd1 DM |
9480 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9481 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9482 | goto nla_put_failure; | |
807f8a8c LC |
9483 | |
9484 | return genlmsg_end(msg, hdr); | |
9485 | ||
9486 | nla_put_failure: | |
9487 | genlmsg_cancel(msg, hdr); | |
9488 | return -EMSGSIZE; | |
9489 | } | |
9490 | ||
a538e2d5 | 9491 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9492 | struct wireless_dev *wdev) |
a538e2d5 JB |
9493 | { |
9494 | struct sk_buff *msg; | |
9495 | ||
58050fce | 9496 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9497 | if (!msg) |
9498 | return; | |
9499 | ||
fd014284 | 9500 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9501 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9502 | nlmsg_free(msg); | |
9503 | return; | |
9504 | } | |
9505 | ||
463d0183 JB |
9506 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9507 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9508 | } |
9509 | ||
2a519311 | 9510 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9511 | struct wireless_dev *wdev) |
2a519311 JB |
9512 | { |
9513 | struct sk_buff *msg; | |
9514 | ||
fd2120ca | 9515 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9516 | if (!msg) |
9517 | return; | |
9518 | ||
fd014284 | 9519 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9520 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9521 | nlmsg_free(msg); |
9522 | return; | |
9523 | } | |
9524 | ||
463d0183 JB |
9525 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9526 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9527 | } |
9528 | ||
9529 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9530 | struct wireless_dev *wdev) |
2a519311 JB |
9531 | { |
9532 | struct sk_buff *msg; | |
9533 | ||
fd2120ca | 9534 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9535 | if (!msg) |
9536 | return; | |
9537 | ||
fd014284 | 9538 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9539 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9540 | nlmsg_free(msg); |
9541 | return; | |
9542 | } | |
9543 | ||
463d0183 JB |
9544 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9545 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9546 | } |
9547 | ||
807f8a8c LC |
9548 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9549 | struct net_device *netdev) | |
9550 | { | |
9551 | struct sk_buff *msg; | |
9552 | ||
9553 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9554 | if (!msg) | |
9555 | return; | |
9556 | ||
9557 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9558 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9559 | nlmsg_free(msg); | |
9560 | return; | |
9561 | } | |
9562 | ||
9563 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9564 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9565 | } | |
9566 | ||
9567 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9568 | struct net_device *netdev, u32 cmd) | |
9569 | { | |
9570 | struct sk_buff *msg; | |
9571 | ||
58050fce | 9572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9573 | if (!msg) |
9574 | return; | |
9575 | ||
9576 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9577 | nlmsg_free(msg); | |
9578 | return; | |
9579 | } | |
9580 | ||
9581 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9582 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9583 | } | |
9584 | ||
73d54c9e LR |
9585 | /* |
9586 | * This can happen on global regulatory changes or device specific settings | |
9587 | * based on custom world regulatory domains. | |
9588 | */ | |
9589 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9590 | { | |
9591 | struct sk_buff *msg; | |
9592 | void *hdr; | |
9593 | ||
fd2120ca | 9594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9595 | if (!msg) |
9596 | return; | |
9597 | ||
9598 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9599 | if (!hdr) { | |
9600 | nlmsg_free(msg); | |
9601 | return; | |
9602 | } | |
9603 | ||
9604 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9605 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9606 | goto nla_put_failure; | |
9607 | ||
9608 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9609 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9610 | NL80211_REGDOM_TYPE_WORLD)) | |
9611 | goto nla_put_failure; | |
9612 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9613 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9614 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9615 | goto nla_put_failure; | |
9616 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9617 | request->intersect) { | |
9618 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9619 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9620 | goto nla_put_failure; | |
9621 | } else { | |
9622 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9623 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9624 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9625 | request->alpha2)) | |
9626 | goto nla_put_failure; | |
9627 | } | |
9628 | ||
f4173766 | 9629 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9630 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9631 | goto nla_put_failure; | |
73d54c9e | 9632 | |
3b7b72ee | 9633 | genlmsg_end(msg, hdr); |
73d54c9e | 9634 | |
bc43b28c | 9635 | rcu_read_lock(); |
463d0183 | 9636 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9637 | GFP_ATOMIC); |
9638 | rcu_read_unlock(); | |
73d54c9e LR |
9639 | |
9640 | return; | |
9641 | ||
9642 | nla_put_failure: | |
9643 | genlmsg_cancel(msg, hdr); | |
9644 | nlmsg_free(msg); | |
9645 | } | |
9646 | ||
6039f6d2 JM |
9647 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9648 | struct net_device *netdev, | |
9649 | const u8 *buf, size_t len, | |
e6d6e342 | 9650 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9651 | { |
9652 | struct sk_buff *msg; | |
9653 | void *hdr; | |
9654 | ||
e6d6e342 | 9655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9656 | if (!msg) |
9657 | return; | |
9658 | ||
9659 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9660 | if (!hdr) { | |
9661 | nlmsg_free(msg); | |
9662 | return; | |
9663 | } | |
9664 | ||
9360ffd1 DM |
9665 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9666 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9667 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9668 | goto nla_put_failure; | |
6039f6d2 | 9669 | |
3b7b72ee | 9670 | genlmsg_end(msg, hdr); |
6039f6d2 | 9671 | |
463d0183 JB |
9672 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9673 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9674 | return; |
9675 | ||
9676 | nla_put_failure: | |
9677 | genlmsg_cancel(msg, hdr); | |
9678 | nlmsg_free(msg); | |
9679 | } | |
9680 | ||
9681 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9682 | struct net_device *netdev, const u8 *buf, |
9683 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9684 | { |
9685 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9686 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9687 | } |
9688 | ||
9689 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9690 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9691 | size_t len, gfp_t gfp) |
6039f6d2 | 9692 | { |
e6d6e342 JB |
9693 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9694 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9695 | } |
9696 | ||
53b46b84 | 9697 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9698 | struct net_device *netdev, const u8 *buf, |
9699 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9700 | { |
9701 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9702 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9703 | } |
9704 | ||
53b46b84 JM |
9705 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9706 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9707 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9708 | { |
9709 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9710 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9711 | } |
9712 | ||
6ff57cf8 JB |
9713 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
9714 | size_t len) | |
cf4e594e | 9715 | { |
947add36 JB |
9716 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9717 | struct wiphy *wiphy = wdev->wiphy; | |
9718 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
9719 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
9720 | u32 cmd; | |
947add36 | 9721 | |
6ff57cf8 JB |
9722 | if (WARN_ON(len < 2)) |
9723 | return; | |
cf4e594e | 9724 | |
6ff57cf8 JB |
9725 | if (ieee80211_is_deauth(mgmt->frame_control)) |
9726 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
9727 | else | |
9728 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 9729 | |
6ff57cf8 JB |
9730 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
9731 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 9732 | } |
6ff57cf8 | 9733 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 9734 | |
1b06bb40 LR |
9735 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9736 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9737 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9738 | { |
9739 | struct sk_buff *msg; | |
9740 | void *hdr; | |
9741 | ||
e6d6e342 | 9742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9743 | if (!msg) |
9744 | return; | |
9745 | ||
9746 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9747 | if (!hdr) { | |
9748 | nlmsg_free(msg); | |
9749 | return; | |
9750 | } | |
9751 | ||
9360ffd1 DM |
9752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9753 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9754 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9755 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9756 | goto nla_put_failure; | |
1965c853 | 9757 | |
3b7b72ee | 9758 | genlmsg_end(msg, hdr); |
1965c853 | 9759 | |
463d0183 JB |
9760 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9761 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9762 | return; |
9763 | ||
9764 | nla_put_failure: | |
9765 | genlmsg_cancel(msg, hdr); | |
9766 | nlmsg_free(msg); | |
9767 | } | |
9768 | ||
9769 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9770 | struct net_device *netdev, const u8 *addr, |
9771 | gfp_t gfp) | |
1965c853 JM |
9772 | { |
9773 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9774 | addr, gfp); |
1965c853 JM |
9775 | } |
9776 | ||
9777 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9778 | struct net_device *netdev, const u8 *addr, |
9779 | gfp_t gfp) | |
1965c853 | 9780 | { |
e6d6e342 JB |
9781 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9782 | addr, gfp); | |
1965c853 JM |
9783 | } |
9784 | ||
b23aa676 SO |
9785 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9786 | struct net_device *netdev, const u8 *bssid, | |
9787 | const u8 *req_ie, size_t req_ie_len, | |
9788 | const u8 *resp_ie, size_t resp_ie_len, | |
9789 | u16 status, gfp_t gfp) | |
9790 | { | |
9791 | struct sk_buff *msg; | |
9792 | void *hdr; | |
9793 | ||
58050fce | 9794 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9795 | if (!msg) |
9796 | return; | |
9797 | ||
9798 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9799 | if (!hdr) { | |
9800 | nlmsg_free(msg); | |
9801 | return; | |
9802 | } | |
9803 | ||
9360ffd1 DM |
9804 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9805 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9806 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9807 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9808 | (req_ie && | |
9809 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9810 | (resp_ie && | |
9811 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9812 | goto nla_put_failure; | |
b23aa676 | 9813 | |
3b7b72ee | 9814 | genlmsg_end(msg, hdr); |
b23aa676 | 9815 | |
463d0183 JB |
9816 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9817 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9818 | return; |
9819 | ||
9820 | nla_put_failure: | |
9821 | genlmsg_cancel(msg, hdr); | |
9822 | nlmsg_free(msg); | |
9823 | ||
9824 | } | |
9825 | ||
9826 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9827 | struct net_device *netdev, const u8 *bssid, | |
9828 | const u8 *req_ie, size_t req_ie_len, | |
9829 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9830 | { | |
9831 | struct sk_buff *msg; | |
9832 | void *hdr; | |
9833 | ||
58050fce | 9834 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9835 | if (!msg) |
9836 | return; | |
9837 | ||
9838 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9839 | if (!hdr) { | |
9840 | nlmsg_free(msg); | |
9841 | return; | |
9842 | } | |
9843 | ||
9360ffd1 DM |
9844 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9845 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9846 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9847 | (req_ie && | |
9848 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9849 | (resp_ie && | |
9850 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9851 | goto nla_put_failure; | |
b23aa676 | 9852 | |
3b7b72ee | 9853 | genlmsg_end(msg, hdr); |
b23aa676 | 9854 | |
463d0183 JB |
9855 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9856 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9857 | return; |
9858 | ||
9859 | nla_put_failure: | |
9860 | genlmsg_cancel(msg, hdr); | |
9861 | nlmsg_free(msg); | |
9862 | ||
9863 | } | |
9864 | ||
9865 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9866 | struct net_device *netdev, u16 reason, | |
667503dd | 9867 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9868 | { |
9869 | struct sk_buff *msg; | |
9870 | void *hdr; | |
9871 | ||
58050fce | 9872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9873 | if (!msg) |
9874 | return; | |
9875 | ||
9876 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9877 | if (!hdr) { | |
9878 | nlmsg_free(msg); | |
9879 | return; | |
9880 | } | |
9881 | ||
9360ffd1 DM |
9882 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9883 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9884 | (from_ap && reason && | |
9885 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9886 | (from_ap && | |
9887 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9888 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9889 | goto nla_put_failure; | |
b23aa676 | 9890 | |
3b7b72ee | 9891 | genlmsg_end(msg, hdr); |
b23aa676 | 9892 | |
463d0183 JB |
9893 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9894 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9895 | return; |
9896 | ||
9897 | nla_put_failure: | |
9898 | genlmsg_cancel(msg, hdr); | |
9899 | nlmsg_free(msg); | |
9900 | ||
9901 | } | |
9902 | ||
04a773ad JB |
9903 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9904 | struct net_device *netdev, const u8 *bssid, | |
9905 | gfp_t gfp) | |
9906 | { | |
9907 | struct sk_buff *msg; | |
9908 | void *hdr; | |
9909 | ||
fd2120ca | 9910 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9911 | if (!msg) |
9912 | return; | |
9913 | ||
9914 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9915 | if (!hdr) { | |
9916 | nlmsg_free(msg); | |
9917 | return; | |
9918 | } | |
9919 | ||
9360ffd1 DM |
9920 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9921 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9922 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9923 | goto nla_put_failure; | |
04a773ad | 9924 | |
3b7b72ee | 9925 | genlmsg_end(msg, hdr); |
04a773ad | 9926 | |
463d0183 JB |
9927 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9928 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9929 | return; |
9930 | ||
9931 | nla_put_failure: | |
9932 | genlmsg_cancel(msg, hdr); | |
9933 | nlmsg_free(msg); | |
9934 | } | |
9935 | ||
947add36 JB |
9936 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9937 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9938 | { |
947add36 JB |
9939 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9940 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9941 | struct sk_buff *msg; |
9942 | void *hdr; | |
9943 | ||
947add36 JB |
9944 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9945 | return; | |
9946 | ||
9947 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9948 | ||
c93b5e71 JC |
9949 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9950 | if (!msg) | |
9951 | return; | |
9952 | ||
9953 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9954 | if (!hdr) { | |
9955 | nlmsg_free(msg); | |
9956 | return; | |
9957 | } | |
9958 | ||
9360ffd1 | 9959 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9960 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9961 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9962 | (ie_len && ie && |
9963 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9964 | goto nla_put_failure; | |
c93b5e71 | 9965 | |
3b7b72ee | 9966 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9967 | |
9968 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9969 | nl80211_mlme_mcgrp.id, gfp); | |
9970 | return; | |
9971 | ||
9972 | nla_put_failure: | |
9973 | genlmsg_cancel(msg, hdr); | |
9974 | nlmsg_free(msg); | |
9975 | } | |
947add36 | 9976 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9977 | |
a3b8b056 JM |
9978 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9979 | struct net_device *netdev, const u8 *addr, | |
9980 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9981 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9982 | { |
9983 | struct sk_buff *msg; | |
9984 | void *hdr; | |
9985 | ||
e6d6e342 | 9986 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9987 | if (!msg) |
9988 | return; | |
9989 | ||
9990 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9991 | if (!hdr) { | |
9992 | nlmsg_free(msg); | |
9993 | return; | |
9994 | } | |
9995 | ||
9360ffd1 DM |
9996 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9997 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9998 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9999 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10000 | (key_id != -1 && | |
10001 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10002 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10003 | goto nla_put_failure; | |
a3b8b056 | 10004 | |
3b7b72ee | 10005 | genlmsg_end(msg, hdr); |
a3b8b056 | 10006 | |
463d0183 JB |
10007 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10008 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
10009 | return; |
10010 | ||
10011 | nla_put_failure: | |
10012 | genlmsg_cancel(msg, hdr); | |
10013 | nlmsg_free(msg); | |
10014 | } | |
10015 | ||
6bad8766 LR |
10016 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10017 | struct ieee80211_channel *channel_before, | |
10018 | struct ieee80211_channel *channel_after) | |
10019 | { | |
10020 | struct sk_buff *msg; | |
10021 | void *hdr; | |
10022 | struct nlattr *nl_freq; | |
10023 | ||
fd2120ca | 10024 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10025 | if (!msg) |
10026 | return; | |
10027 | ||
10028 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10029 | if (!hdr) { | |
10030 | nlmsg_free(msg); | |
10031 | return; | |
10032 | } | |
10033 | ||
10034 | /* | |
10035 | * Since we are applying the beacon hint to a wiphy we know its | |
10036 | * wiphy_idx is valid | |
10037 | */ | |
9360ffd1 DM |
10038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10039 | goto nla_put_failure; | |
6bad8766 LR |
10040 | |
10041 | /* Before */ | |
10042 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10043 | if (!nl_freq) | |
10044 | goto nla_put_failure; | |
cdc89b97 | 10045 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10046 | goto nla_put_failure; |
10047 | nla_nest_end(msg, nl_freq); | |
10048 | ||
10049 | /* After */ | |
10050 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10051 | if (!nl_freq) | |
10052 | goto nla_put_failure; | |
cdc89b97 | 10053 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10054 | goto nla_put_failure; |
10055 | nla_nest_end(msg, nl_freq); | |
10056 | ||
3b7b72ee | 10057 | genlmsg_end(msg, hdr); |
6bad8766 | 10058 | |
463d0183 JB |
10059 | rcu_read_lock(); |
10060 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
10061 | GFP_ATOMIC); | |
10062 | rcu_read_unlock(); | |
6bad8766 LR |
10063 | |
10064 | return; | |
10065 | ||
10066 | nla_put_failure: | |
10067 | genlmsg_cancel(msg, hdr); | |
10068 | nlmsg_free(msg); | |
10069 | } | |
10070 | ||
9588bbd5 JM |
10071 | static void nl80211_send_remain_on_chan_event( |
10072 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10073 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10074 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10075 | unsigned int duration, gfp_t gfp) |
10076 | { | |
10077 | struct sk_buff *msg; | |
10078 | void *hdr; | |
10079 | ||
10080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10081 | if (!msg) | |
10082 | return; | |
10083 | ||
10084 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10085 | if (!hdr) { | |
10086 | nlmsg_free(msg); | |
10087 | return; | |
10088 | } | |
10089 | ||
9360ffd1 | 10090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10091 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10092 | wdev->netdev->ifindex)) || | |
00f53350 | 10093 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10094 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10095 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10096 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10097 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10098 | goto nla_put_failure; | |
9588bbd5 | 10099 | |
9360ffd1 DM |
10100 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10101 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10102 | goto nla_put_failure; | |
9588bbd5 | 10103 | |
3b7b72ee | 10104 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
10105 | |
10106 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10107 | nl80211_mlme_mcgrp.id, gfp); | |
10108 | return; | |
10109 | ||
10110 | nla_put_failure: | |
10111 | genlmsg_cancel(msg, hdr); | |
10112 | nlmsg_free(msg); | |
10113 | } | |
10114 | ||
947add36 JB |
10115 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10116 | struct ieee80211_channel *chan, | |
10117 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10118 | { |
947add36 JB |
10119 | struct wiphy *wiphy = wdev->wiphy; |
10120 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10121 | ||
10122 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10123 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10124 | rdev, wdev, cookie, chan, |
42d97a59 | 10125 | duration, gfp); |
9588bbd5 | 10126 | } |
947add36 | 10127 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10128 | |
947add36 JB |
10129 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10130 | struct ieee80211_channel *chan, | |
10131 | gfp_t gfp) | |
9588bbd5 | 10132 | { |
947add36 JB |
10133 | struct wiphy *wiphy = wdev->wiphy; |
10134 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10135 | ||
10136 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10137 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10138 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10139 | } |
947add36 | 10140 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10141 | |
947add36 JB |
10142 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10143 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10144 | { |
947add36 JB |
10145 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10146 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
10147 | struct sk_buff *msg; |
10148 | ||
947add36 JB |
10149 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10150 | ||
58050fce | 10151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10152 | if (!msg) |
10153 | return; | |
10154 | ||
66266b3a JL |
10155 | if (nl80211_send_station(msg, 0, 0, 0, |
10156 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10157 | nlmsg_free(msg); |
10158 | return; | |
10159 | } | |
10160 | ||
10161 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10162 | nl80211_mlme_mcgrp.id, gfp); | |
10163 | } | |
947add36 | 10164 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10165 | |
947add36 | 10166 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10167 | { |
947add36 JB |
10168 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10169 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
10170 | struct sk_buff *msg; |
10171 | void *hdr; | |
10172 | ||
947add36 JB |
10173 | trace_cfg80211_del_sta(dev, mac_addr); |
10174 | ||
58050fce | 10175 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10176 | if (!msg) |
10177 | return; | |
10178 | ||
10179 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10180 | if (!hdr) { | |
10181 | nlmsg_free(msg); | |
10182 | return; | |
10183 | } | |
10184 | ||
9360ffd1 DM |
10185 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10186 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10187 | goto nla_put_failure; | |
ec15e68b | 10188 | |
3b7b72ee | 10189 | genlmsg_end(msg, hdr); |
ec15e68b JM |
10190 | |
10191 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10192 | nl80211_mlme_mcgrp.id, gfp); | |
10193 | return; | |
10194 | ||
10195 | nla_put_failure: | |
10196 | genlmsg_cancel(msg, hdr); | |
10197 | nlmsg_free(msg); | |
10198 | } | |
947add36 | 10199 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10200 | |
947add36 JB |
10201 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10202 | enum nl80211_connect_failed_reason reason, | |
10203 | gfp_t gfp) | |
ed44a951 | 10204 | { |
947add36 JB |
10205 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10206 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10207 | struct sk_buff *msg; |
10208 | void *hdr; | |
10209 | ||
10210 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10211 | if (!msg) | |
10212 | return; | |
10213 | ||
10214 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10215 | if (!hdr) { | |
10216 | nlmsg_free(msg); | |
10217 | return; | |
10218 | } | |
10219 | ||
10220 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10221 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10222 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10223 | goto nla_put_failure; | |
10224 | ||
10225 | genlmsg_end(msg, hdr); | |
10226 | ||
10227 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10228 | nl80211_mlme_mcgrp.id, gfp); | |
10229 | return; | |
10230 | ||
10231 | nla_put_failure: | |
10232 | genlmsg_cancel(msg, hdr); | |
10233 | nlmsg_free(msg); | |
10234 | } | |
947add36 | 10235 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10236 | |
b92ab5d8 JB |
10237 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10238 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10239 | { |
10240 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10241 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10242 | struct sk_buff *msg; | |
10243 | void *hdr; | |
15e47304 | 10244 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10245 | |
15e47304 | 10246 | if (!nlportid) |
28946da7 JB |
10247 | return false; |
10248 | ||
10249 | msg = nlmsg_new(100, gfp); | |
10250 | if (!msg) | |
10251 | return true; | |
10252 | ||
b92ab5d8 | 10253 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10254 | if (!hdr) { |
10255 | nlmsg_free(msg); | |
10256 | return true; | |
10257 | } | |
10258 | ||
9360ffd1 DM |
10259 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10260 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10261 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10262 | goto nla_put_failure; | |
28946da7 | 10263 | |
9c90a9f6 | 10264 | genlmsg_end(msg, hdr); |
15e47304 | 10265 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10266 | return true; |
10267 | ||
10268 | nla_put_failure: | |
10269 | genlmsg_cancel(msg, hdr); | |
10270 | nlmsg_free(msg); | |
10271 | return true; | |
10272 | } | |
10273 | ||
947add36 JB |
10274 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10275 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10276 | { |
947add36 JB |
10277 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10278 | bool ret; | |
10279 | ||
10280 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10281 | ||
10282 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10283 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10284 | trace_cfg80211_return_bool(false); | |
10285 | return false; | |
10286 | } | |
10287 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10288 | addr, gfp); | |
10289 | trace_cfg80211_return_bool(ret); | |
10290 | return ret; | |
b92ab5d8 | 10291 | } |
947add36 | 10292 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10293 | |
947add36 JB |
10294 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10295 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10296 | { |
947add36 JB |
10297 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10298 | bool ret; | |
10299 | ||
10300 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10301 | ||
10302 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10303 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10304 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10305 | trace_cfg80211_return_bool(false); | |
10306 | return false; | |
10307 | } | |
10308 | ret = __nl80211_unexpected_frame(dev, | |
10309 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10310 | addr, gfp); | |
10311 | trace_cfg80211_return_bool(ret); | |
10312 | return ret; | |
b92ab5d8 | 10313 | } |
947add36 | 10314 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10315 | |
2e161f78 | 10316 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10317 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
10318 | int freq, int sig_dbm, |
10319 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 10320 | { |
71bbc994 | 10321 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10322 | struct sk_buff *msg; |
10323 | void *hdr; | |
026331c4 JM |
10324 | |
10325 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10326 | if (!msg) | |
10327 | return -ENOMEM; | |
10328 | ||
2e161f78 | 10329 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10330 | if (!hdr) { |
10331 | nlmsg_free(msg); | |
10332 | return -ENOMEM; | |
10333 | } | |
10334 | ||
9360ffd1 | 10335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10336 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10337 | netdev->ifindex)) || | |
a838490b | 10338 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10339 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10340 | (sig_dbm && | |
10341 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10342 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10343 | goto nla_put_failure; | |
026331c4 | 10344 | |
3b7b72ee | 10345 | genlmsg_end(msg, hdr); |
026331c4 | 10346 | |
15e47304 | 10347 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10348 | |
10349 | nla_put_failure: | |
10350 | genlmsg_cancel(msg, hdr); | |
10351 | nlmsg_free(msg); | |
10352 | return -ENOBUFS; | |
10353 | } | |
10354 | ||
947add36 JB |
10355 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10356 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10357 | { |
947add36 JB |
10358 | struct wiphy *wiphy = wdev->wiphy; |
10359 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10360 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10361 | struct sk_buff *msg; |
10362 | void *hdr; | |
10363 | ||
947add36 JB |
10364 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10365 | ||
026331c4 JM |
10366 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10367 | if (!msg) | |
10368 | return; | |
10369 | ||
2e161f78 | 10370 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10371 | if (!hdr) { |
10372 | nlmsg_free(msg); | |
10373 | return; | |
10374 | } | |
10375 | ||
9360ffd1 | 10376 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10377 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10378 | netdev->ifindex)) || | |
a838490b | 10379 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10380 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10381 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10382 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10383 | goto nla_put_failure; | |
026331c4 | 10384 | |
3b7b72ee | 10385 | genlmsg_end(msg, hdr); |
026331c4 JM |
10386 | |
10387 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
10388 | return; | |
10389 | ||
10390 | nla_put_failure: | |
10391 | genlmsg_cancel(msg, hdr); | |
10392 | nlmsg_free(msg); | |
10393 | } | |
947add36 | 10394 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10395 | |
947add36 JB |
10396 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10397 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10398 | gfp_t gfp) | |
d6dc1a38 | 10399 | { |
947add36 JB |
10400 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10401 | struct wiphy *wiphy = wdev->wiphy; | |
10402 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10403 | struct sk_buff *msg; |
10404 | struct nlattr *pinfoattr; | |
10405 | void *hdr; | |
10406 | ||
947add36 JB |
10407 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10408 | ||
58050fce | 10409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10410 | if (!msg) |
10411 | return; | |
10412 | ||
10413 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10414 | if (!hdr) { | |
10415 | nlmsg_free(msg); | |
10416 | return; | |
10417 | } | |
10418 | ||
9360ffd1 | 10419 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10420 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10421 | goto nla_put_failure; |
d6dc1a38 JO |
10422 | |
10423 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10424 | if (!pinfoattr) | |
10425 | goto nla_put_failure; | |
10426 | ||
9360ffd1 DM |
10427 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10428 | rssi_event)) | |
10429 | goto nla_put_failure; | |
d6dc1a38 JO |
10430 | |
10431 | nla_nest_end(msg, pinfoattr); | |
10432 | ||
3b7b72ee | 10433 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10434 | |
10435 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10436 | nl80211_mlme_mcgrp.id, gfp); | |
10437 | return; | |
10438 | ||
10439 | nla_put_failure: | |
10440 | genlmsg_cancel(msg, hdr); | |
10441 | nlmsg_free(msg); | |
10442 | } | |
947add36 | 10443 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10444 | |
947add36 JB |
10445 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10446 | struct net_device *netdev, const u8 *bssid, | |
10447 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10448 | { |
10449 | struct sk_buff *msg; | |
10450 | struct nlattr *rekey_attr; | |
10451 | void *hdr; | |
10452 | ||
58050fce | 10453 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10454 | if (!msg) |
10455 | return; | |
10456 | ||
10457 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10458 | if (!hdr) { | |
10459 | nlmsg_free(msg); | |
10460 | return; | |
10461 | } | |
10462 | ||
9360ffd1 DM |
10463 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10464 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10465 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10466 | goto nla_put_failure; | |
e5497d76 JB |
10467 | |
10468 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10469 | if (!rekey_attr) | |
10470 | goto nla_put_failure; | |
10471 | ||
9360ffd1 DM |
10472 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10473 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10474 | goto nla_put_failure; | |
e5497d76 JB |
10475 | |
10476 | nla_nest_end(msg, rekey_attr); | |
10477 | ||
3b7b72ee | 10478 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10479 | |
10480 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10481 | nl80211_mlme_mcgrp.id, gfp); | |
10482 | return; | |
10483 | ||
10484 | nla_put_failure: | |
10485 | genlmsg_cancel(msg, hdr); | |
10486 | nlmsg_free(msg); | |
10487 | } | |
10488 | ||
947add36 JB |
10489 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10490 | const u8 *replay_ctr, gfp_t gfp) | |
10491 | { | |
10492 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10493 | struct wiphy *wiphy = wdev->wiphy; | |
10494 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10495 | ||
10496 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10497 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10498 | } | |
10499 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10500 | ||
10501 | static void | |
10502 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10503 | struct net_device *netdev, int index, | |
10504 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10505 | { |
10506 | struct sk_buff *msg; | |
10507 | struct nlattr *attr; | |
10508 | void *hdr; | |
10509 | ||
58050fce | 10510 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10511 | if (!msg) |
10512 | return; | |
10513 | ||
10514 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10515 | if (!hdr) { | |
10516 | nlmsg_free(msg); | |
10517 | return; | |
10518 | } | |
10519 | ||
9360ffd1 DM |
10520 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10521 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10522 | goto nla_put_failure; | |
c9df56b4 JM |
10523 | |
10524 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10525 | if (!attr) | |
10526 | goto nla_put_failure; | |
10527 | ||
9360ffd1 DM |
10528 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10529 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10530 | (preauth && | |
10531 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10532 | goto nla_put_failure; | |
c9df56b4 JM |
10533 | |
10534 | nla_nest_end(msg, attr); | |
10535 | ||
3b7b72ee | 10536 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10537 | |
10538 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10539 | nl80211_mlme_mcgrp.id, gfp); | |
10540 | return; | |
10541 | ||
10542 | nla_put_failure: | |
10543 | genlmsg_cancel(msg, hdr); | |
10544 | nlmsg_free(msg); | |
10545 | } | |
10546 | ||
947add36 JB |
10547 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10548 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10549 | { | |
10550 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10551 | struct wiphy *wiphy = wdev->wiphy; | |
10552 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10553 | ||
10554 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10555 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10556 | } | |
10557 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10558 | ||
10559 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10560 | struct net_device *netdev, | |
10561 | struct cfg80211_chan_def *chandef, | |
10562 | gfp_t gfp) | |
5314526b TP |
10563 | { |
10564 | struct sk_buff *msg; | |
10565 | void *hdr; | |
10566 | ||
58050fce | 10567 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10568 | if (!msg) |
10569 | return; | |
10570 | ||
10571 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10572 | if (!hdr) { | |
10573 | nlmsg_free(msg); | |
10574 | return; | |
10575 | } | |
10576 | ||
683b6d3b JB |
10577 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10578 | goto nla_put_failure; | |
10579 | ||
10580 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10581 | goto nla_put_failure; |
5314526b TP |
10582 | |
10583 | genlmsg_end(msg, hdr); | |
10584 | ||
10585 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10586 | nl80211_mlme_mcgrp.id, gfp); | |
10587 | return; | |
10588 | ||
10589 | nla_put_failure: | |
10590 | genlmsg_cancel(msg, hdr); | |
10591 | nlmsg_free(msg); | |
10592 | } | |
10593 | ||
947add36 JB |
10594 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10595 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10596 | { |
947add36 JB |
10597 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10598 | struct wiphy *wiphy = wdev->wiphy; | |
10599 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10600 | ||
10601 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10602 | ||
10603 | wdev_lock(wdev); | |
10604 | ||
10605 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10606 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10607 | goto out; | |
10608 | ||
10609 | wdev->channel = chandef->chan; | |
10610 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10611 | out: | |
10612 | wdev_unlock(wdev); | |
10613 | return; | |
10614 | } | |
10615 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10616 | ||
10617 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10618 | const u8 *peer, u32 num_packets, | |
10619 | u32 rate, u32 intvl, gfp_t gfp) | |
10620 | { | |
10621 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10622 | struct wiphy *wiphy = wdev->wiphy; | |
10623 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10624 | struct sk_buff *msg; |
10625 | struct nlattr *pinfoattr; | |
10626 | void *hdr; | |
10627 | ||
10628 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10629 | if (!msg) | |
10630 | return; | |
10631 | ||
10632 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10633 | if (!hdr) { | |
10634 | nlmsg_free(msg); | |
10635 | return; | |
10636 | } | |
10637 | ||
10638 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10639 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10640 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10641 | goto nla_put_failure; | |
10642 | ||
10643 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10644 | if (!pinfoattr) | |
10645 | goto nla_put_failure; | |
10646 | ||
10647 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10648 | goto nla_put_failure; | |
10649 | ||
10650 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10651 | goto nla_put_failure; | |
10652 | ||
10653 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10654 | goto nla_put_failure; | |
10655 | ||
10656 | nla_nest_end(msg, pinfoattr); | |
10657 | ||
10658 | genlmsg_end(msg, hdr); | |
10659 | ||
10660 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10661 | nl80211_mlme_mcgrp.id, gfp); | |
10662 | return; | |
10663 | ||
10664 | nla_put_failure: | |
10665 | genlmsg_cancel(msg, hdr); | |
10666 | nlmsg_free(msg); | |
10667 | } | |
947add36 | 10668 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10669 | |
04f39047 SW |
10670 | void |
10671 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10672 | struct cfg80211_chan_def *chandef, | |
10673 | enum nl80211_radar_event event, | |
10674 | struct net_device *netdev, gfp_t gfp) | |
10675 | { | |
10676 | struct sk_buff *msg; | |
10677 | void *hdr; | |
10678 | ||
10679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10680 | if (!msg) | |
10681 | return; | |
10682 | ||
10683 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10684 | if (!hdr) { | |
10685 | nlmsg_free(msg); | |
10686 | return; | |
10687 | } | |
10688 | ||
10689 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10690 | goto nla_put_failure; | |
10691 | ||
10692 | /* NOP and radar events don't need a netdev parameter */ | |
10693 | if (netdev) { | |
10694 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10695 | ||
10696 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10697 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10698 | goto nla_put_failure; | |
10699 | } | |
10700 | ||
10701 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10702 | goto nla_put_failure; | |
10703 | ||
10704 | if (nl80211_send_chandef(msg, chandef)) | |
10705 | goto nla_put_failure; | |
10706 | ||
9c90a9f6 | 10707 | genlmsg_end(msg, hdr); |
04f39047 SW |
10708 | |
10709 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10710 | nl80211_mlme_mcgrp.id, gfp); | |
10711 | return; | |
10712 | ||
10713 | nla_put_failure: | |
10714 | genlmsg_cancel(msg, hdr); | |
10715 | nlmsg_free(msg); | |
10716 | } | |
10717 | ||
947add36 JB |
10718 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10719 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10720 | { |
947add36 JB |
10721 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10722 | struct wiphy *wiphy = wdev->wiphy; | |
10723 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10724 | struct sk_buff *msg; |
10725 | struct nlattr *pinfoattr; | |
10726 | void *hdr; | |
10727 | ||
947add36 JB |
10728 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10729 | ||
58050fce | 10730 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10731 | if (!msg) |
10732 | return; | |
10733 | ||
10734 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10735 | if (!hdr) { | |
10736 | nlmsg_free(msg); | |
10737 | return; | |
10738 | } | |
10739 | ||
9360ffd1 | 10740 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10741 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10742 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10743 | goto nla_put_failure; | |
c063dbf5 JB |
10744 | |
10745 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10746 | if (!pinfoattr) | |
10747 | goto nla_put_failure; | |
10748 | ||
9360ffd1 DM |
10749 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10750 | goto nla_put_failure; | |
c063dbf5 JB |
10751 | |
10752 | nla_nest_end(msg, pinfoattr); | |
10753 | ||
3b7b72ee | 10754 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10755 | |
10756 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10757 | nl80211_mlme_mcgrp.id, gfp); | |
10758 | return; | |
10759 | ||
10760 | nla_put_failure: | |
10761 | genlmsg_cancel(msg, hdr); | |
10762 | nlmsg_free(msg); | |
10763 | } | |
947add36 | 10764 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10765 | |
7f6cf311 JB |
10766 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10767 | u64 cookie, bool acked, gfp_t gfp) | |
10768 | { | |
10769 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10770 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10771 | struct sk_buff *msg; | |
10772 | void *hdr; | |
7f6cf311 | 10773 | |
4ee3e063 BL |
10774 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10775 | ||
58050fce | 10776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10777 | |
7f6cf311 JB |
10778 | if (!msg) |
10779 | return; | |
10780 | ||
10781 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10782 | if (!hdr) { | |
10783 | nlmsg_free(msg); | |
10784 | return; | |
10785 | } | |
10786 | ||
9360ffd1 DM |
10787 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10788 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10789 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10790 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10791 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10792 | goto nla_put_failure; | |
7f6cf311 | 10793 | |
9c90a9f6 | 10794 | genlmsg_end(msg, hdr); |
7f6cf311 JB |
10795 | |
10796 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10797 | nl80211_mlme_mcgrp.id, gfp); | |
10798 | return; | |
10799 | ||
10800 | nla_put_failure: | |
10801 | genlmsg_cancel(msg, hdr); | |
10802 | nlmsg_free(msg); | |
10803 | } | |
10804 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10805 | ||
5e760230 JB |
10806 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10807 | const u8 *frame, size_t len, | |
37c73b5f | 10808 | int freq, int sig_dbm) |
5e760230 JB |
10809 | { |
10810 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10811 | struct sk_buff *msg; | |
10812 | void *hdr; | |
37c73b5f | 10813 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10814 | |
4ee3e063 BL |
10815 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10816 | ||
37c73b5f BG |
10817 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10818 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10819 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10820 | if (!msg) { | |
10821 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10822 | return; | |
10823 | } | |
5e760230 | 10824 | |
37c73b5f BG |
10825 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10826 | if (!hdr) | |
10827 | goto nla_put_failure; | |
5e760230 | 10828 | |
37c73b5f BG |
10829 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10830 | (freq && | |
10831 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10832 | (sig_dbm && | |
10833 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10834 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10835 | goto nla_put_failure; | |
5e760230 | 10836 | |
37c73b5f | 10837 | genlmsg_end(msg, hdr); |
5e760230 | 10838 | |
37c73b5f BG |
10839 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10840 | } | |
10841 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10842 | return; |
10843 | ||
10844 | nla_put_failure: | |
37c73b5f BG |
10845 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10846 | if (hdr) | |
10847 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10848 | nlmsg_free(msg); |
10849 | } | |
10850 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10851 | ||
cd8f7cb4 JB |
10852 | #ifdef CONFIG_PM |
10853 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10854 | struct cfg80211_wowlan_wakeup *wakeup, | |
10855 | gfp_t gfp) | |
10856 | { | |
10857 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10858 | struct sk_buff *msg; | |
10859 | void *hdr; | |
9c90a9f6 | 10860 | int size = 200; |
cd8f7cb4 JB |
10861 | |
10862 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10863 | ||
10864 | if (wakeup) | |
10865 | size += wakeup->packet_present_len; | |
10866 | ||
10867 | msg = nlmsg_new(size, gfp); | |
10868 | if (!msg) | |
10869 | return; | |
10870 | ||
10871 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10872 | if (!hdr) | |
10873 | goto free_msg; | |
10874 | ||
10875 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10876 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10877 | goto free_msg; | |
10878 | ||
10879 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10880 | wdev->netdev->ifindex)) | |
10881 | goto free_msg; | |
10882 | ||
10883 | if (wakeup) { | |
10884 | struct nlattr *reasons; | |
10885 | ||
10886 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10887 | ||
10888 | if (wakeup->disconnect && | |
10889 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10890 | goto free_msg; | |
10891 | if (wakeup->magic_pkt && | |
10892 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10893 | goto free_msg; | |
10894 | if (wakeup->gtk_rekey_failure && | |
10895 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10896 | goto free_msg; | |
10897 | if (wakeup->eap_identity_req && | |
10898 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10899 | goto free_msg; | |
10900 | if (wakeup->four_way_handshake && | |
10901 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10902 | goto free_msg; | |
10903 | if (wakeup->rfkill_release && | |
10904 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10905 | goto free_msg; | |
10906 | ||
10907 | if (wakeup->pattern_idx >= 0 && | |
10908 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10909 | wakeup->pattern_idx)) | |
10910 | goto free_msg; | |
10911 | ||
2a0e047e JB |
10912 | if (wakeup->tcp_match) |
10913 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10914 | ||
10915 | if (wakeup->tcp_connlost) | |
10916 | nla_put_flag(msg, | |
10917 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10918 | ||
10919 | if (wakeup->tcp_nomoretokens) | |
10920 | nla_put_flag(msg, | |
10921 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10922 | ||
cd8f7cb4 JB |
10923 | if (wakeup->packet) { |
10924 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10925 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10926 | ||
10927 | if (!wakeup->packet_80211) { | |
10928 | pkt_attr = | |
10929 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10930 | len_attr = | |
10931 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10932 | } | |
10933 | ||
10934 | if (wakeup->packet_len && | |
10935 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10936 | goto free_msg; | |
10937 | ||
10938 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10939 | wakeup->packet)) | |
10940 | goto free_msg; | |
10941 | } | |
10942 | ||
10943 | nla_nest_end(msg, reasons); | |
10944 | } | |
10945 | ||
9c90a9f6 | 10946 | genlmsg_end(msg, hdr); |
cd8f7cb4 JB |
10947 | |
10948 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10949 | nl80211_mlme_mcgrp.id, gfp); | |
10950 | return; | |
10951 | ||
10952 | free_msg: | |
10953 | nlmsg_free(msg); | |
10954 | } | |
10955 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10956 | #endif | |
10957 | ||
3475b094 JM |
10958 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10959 | enum nl80211_tdls_operation oper, | |
10960 | u16 reason_code, gfp_t gfp) | |
10961 | { | |
10962 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10963 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10964 | struct sk_buff *msg; | |
10965 | void *hdr; | |
3475b094 JM |
10966 | |
10967 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10968 | reason_code); | |
10969 | ||
10970 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10971 | if (!msg) | |
10972 | return; | |
10973 | ||
10974 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10975 | if (!hdr) { | |
10976 | nlmsg_free(msg); | |
10977 | return; | |
10978 | } | |
10979 | ||
10980 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10981 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10982 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10983 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10984 | (reason_code > 0 && | |
10985 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10986 | goto nla_put_failure; | |
10987 | ||
9c90a9f6 | 10988 | genlmsg_end(msg, hdr); |
3475b094 JM |
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 | } | |
10998 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10999 | ||
026331c4 JM |
11000 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11001 | unsigned long state, | |
11002 | void *_notify) | |
11003 | { | |
11004 | struct netlink_notify *notify = _notify; | |
11005 | struct cfg80211_registered_device *rdev; | |
11006 | struct wireless_dev *wdev; | |
37c73b5f | 11007 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11008 | |
11009 | if (state != NETLINK_URELEASE) | |
11010 | return NOTIFY_DONE; | |
11011 | ||
11012 | rcu_read_lock(); | |
11013 | ||
5e760230 | 11014 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 11015 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 11016 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
11017 | |
11018 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11019 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11020 | list) { | |
11021 | if (reg->nlportid == notify->portid) { | |
11022 | list_del(®->list); | |
11023 | kfree(reg); | |
11024 | break; | |
11025 | } | |
11026 | } | |
11027 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 11028 | } |
026331c4 JM |
11029 | |
11030 | rcu_read_unlock(); | |
11031 | ||
11032 | return NOTIFY_DONE; | |
11033 | } | |
11034 | ||
11035 | static struct notifier_block nl80211_netlink_notifier = { | |
11036 | .notifier_call = nl80211_netlink_notify, | |
11037 | }; | |
11038 | ||
355199e0 JM |
11039 | void cfg80211_ft_event(struct net_device *netdev, |
11040 | struct cfg80211_ft_event_params *ft_event) | |
11041 | { | |
11042 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
11043 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11044 | struct sk_buff *msg; | |
11045 | void *hdr; | |
355199e0 JM |
11046 | |
11047 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11048 | ||
11049 | if (!ft_event->target_ap) | |
11050 | return; | |
11051 | ||
11052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11053 | if (!msg) | |
11054 | return; | |
11055 | ||
11056 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
11057 | if (!hdr) { | |
11058 | nlmsg_free(msg); | |
11059 | return; | |
11060 | } | |
11061 | ||
11062 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
11063 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
11064 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
11065 | if (ft_event->ies) | |
11066 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
11067 | if (ft_event->ric_ies) | |
11068 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11069 | ft_event->ric_ies); | |
11070 | ||
9c90a9f6 | 11071 | genlmsg_end(msg, hdr); |
355199e0 JM |
11072 | |
11073 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11074 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
11075 | } | |
11076 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11077 | ||
5de17984 AS |
11078 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11079 | { | |
11080 | struct cfg80211_registered_device *rdev; | |
11081 | struct sk_buff *msg; | |
11082 | void *hdr; | |
11083 | u32 nlportid; | |
11084 | ||
11085 | rdev = wiphy_to_dev(wdev->wiphy); | |
11086 | if (!rdev->crit_proto_nlportid) | |
11087 | return; | |
11088 | ||
11089 | nlportid = rdev->crit_proto_nlportid; | |
11090 | rdev->crit_proto_nlportid = 0; | |
11091 | ||
11092 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11093 | if (!msg) | |
11094 | return; | |
11095 | ||
11096 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11097 | if (!hdr) | |
11098 | goto nla_put_failure; | |
11099 | ||
11100 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11101 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11102 | goto nla_put_failure; | |
11103 | ||
11104 | genlmsg_end(msg, hdr); | |
11105 | ||
11106 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11107 | return; | |
11108 | ||
11109 | nla_put_failure: | |
11110 | if (hdr) | |
11111 | genlmsg_cancel(msg, hdr); | |
11112 | nlmsg_free(msg); | |
11113 | ||
11114 | } | |
11115 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11116 | ||
55682965 JB |
11117 | /* initialisation/exit functions */ |
11118 | ||
11119 | int nl80211_init(void) | |
11120 | { | |
0d63cbb5 | 11121 | int err; |
55682965 | 11122 | |
0d63cbb5 MM |
11123 | err = genl_register_family_with_ops(&nl80211_fam, |
11124 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
11125 | if (err) |
11126 | return err; | |
11127 | ||
55682965 JB |
11128 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
11129 | if (err) | |
11130 | goto err_out; | |
11131 | ||
2a519311 JB |
11132 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
11133 | if (err) | |
11134 | goto err_out; | |
11135 | ||
73d54c9e LR |
11136 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
11137 | if (err) | |
11138 | goto err_out; | |
11139 | ||
6039f6d2 JM |
11140 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
11141 | if (err) | |
11142 | goto err_out; | |
11143 | ||
aff89a9b JB |
11144 | #ifdef CONFIG_NL80211_TESTMODE |
11145 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
11146 | if (err) | |
11147 | goto err_out; | |
11148 | #endif | |
11149 | ||
026331c4 JM |
11150 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11151 | if (err) | |
11152 | goto err_out; | |
11153 | ||
55682965 JB |
11154 | return 0; |
11155 | err_out: | |
11156 | genl_unregister_family(&nl80211_fam); | |
11157 | return err; | |
11158 | } | |
11159 | ||
11160 | void nl80211_exit(void) | |
11161 | { | |
026331c4 | 11162 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11163 | genl_unregister_family(&nl80211_fam); |
11164 | } |