]>
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) || | |
5677 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5678 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5679 | goto nla_put_failure; | |
2a519311 | 5680 | |
77965c97 | 5681 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5682 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5683 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5684 | goto nla_put_failure; | |
2a519311 JB |
5685 | break; |
5686 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5687 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5688 | goto nla_put_failure; | |
2a519311 JB |
5689 | break; |
5690 | default: | |
5691 | break; | |
5692 | } | |
5693 | ||
48ab905d | 5694 | switch (wdev->iftype) { |
074ac8df | 5695 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5696 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5697 | if (intbss == wdev->current_bss && |
5698 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5699 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5700 | goto nla_put_failure; | |
48ab905d JB |
5701 | break; |
5702 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5703 | if (intbss == wdev->current_bss && |
5704 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5705 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5706 | goto nla_put_failure; | |
48ab905d JB |
5707 | break; |
5708 | default: | |
5709 | break; | |
5710 | } | |
5711 | ||
2a519311 JB |
5712 | nla_nest_end(msg, bss); |
5713 | ||
5714 | return genlmsg_end(msg, hdr); | |
5715 | ||
8cef2c9d JB |
5716 | fail_unlock_rcu: |
5717 | rcu_read_unlock(); | |
2a519311 JB |
5718 | nla_put_failure: |
5719 | genlmsg_cancel(msg, hdr); | |
5720 | return -EMSGSIZE; | |
5721 | } | |
5722 | ||
97990a06 | 5723 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5724 | { |
48ab905d | 5725 | struct cfg80211_registered_device *rdev; |
2a519311 | 5726 | struct cfg80211_internal_bss *scan; |
48ab905d | 5727 | struct wireless_dev *wdev; |
97990a06 | 5728 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5729 | int err; |
5730 | ||
97990a06 | 5731 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5732 | if (err) |
5733 | return err; | |
2a519311 | 5734 | |
48ab905d JB |
5735 | wdev_lock(wdev); |
5736 | spin_lock_bh(&rdev->bss_lock); | |
5737 | cfg80211_bss_expire(rdev); | |
5738 | ||
9720bb3a JB |
5739 | cb->seq = rdev->bss_generation; |
5740 | ||
48ab905d | 5741 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5742 | if (++idx <= start) |
5743 | continue; | |
9720bb3a | 5744 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5745 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5746 | rdev, wdev, scan) < 0) { |
2a519311 | 5747 | idx--; |
67748893 | 5748 | break; |
2a519311 JB |
5749 | } |
5750 | } | |
5751 | ||
48ab905d JB |
5752 | spin_unlock_bh(&rdev->bss_lock); |
5753 | wdev_unlock(wdev); | |
2a519311 | 5754 | |
97990a06 JB |
5755 | cb->args[2] = idx; |
5756 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5757 | |
67748893 | 5758 | return skb->len; |
2a519311 JB |
5759 | } |
5760 | ||
15e47304 | 5761 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5762 | int flags, struct net_device *dev, |
5763 | struct survey_info *survey) | |
5764 | { | |
5765 | void *hdr; | |
5766 | struct nlattr *infoattr; | |
5767 | ||
15e47304 | 5768 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5769 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5770 | if (!hdr) | |
5771 | return -ENOMEM; | |
5772 | ||
9360ffd1 DM |
5773 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5774 | goto nla_put_failure; | |
61fa713c HS |
5775 | |
5776 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5777 | if (!infoattr) | |
5778 | goto nla_put_failure; | |
5779 | ||
9360ffd1 DM |
5780 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5781 | survey->channel->center_freq)) | |
5782 | goto nla_put_failure; | |
5783 | ||
5784 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5785 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5786 | goto nla_put_failure; | |
5787 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5788 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5789 | goto nla_put_failure; | |
5790 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5791 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5792 | survey->channel_time)) | |
5793 | goto nla_put_failure; | |
5794 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5795 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5796 | survey->channel_time_busy)) | |
5797 | goto nla_put_failure; | |
5798 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5799 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5800 | survey->channel_time_ext_busy)) | |
5801 | goto nla_put_failure; | |
5802 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5803 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5804 | survey->channel_time_rx)) | |
5805 | goto nla_put_failure; | |
5806 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5807 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5808 | survey->channel_time_tx)) | |
5809 | goto nla_put_failure; | |
61fa713c HS |
5810 | |
5811 | nla_nest_end(msg, infoattr); | |
5812 | ||
5813 | return genlmsg_end(msg, hdr); | |
5814 | ||
5815 | nla_put_failure: | |
5816 | genlmsg_cancel(msg, hdr); | |
5817 | return -EMSGSIZE; | |
5818 | } | |
5819 | ||
5820 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5821 | struct netlink_callback *cb) | |
5822 | { | |
5823 | struct survey_info survey; | |
5824 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5825 | struct wireless_dev *wdev; |
5826 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5827 | int res; |
5828 | ||
97990a06 | 5829 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5830 | if (res) |
5831 | return res; | |
61fa713c | 5832 | |
97990a06 JB |
5833 | if (!wdev->netdev) { |
5834 | res = -EINVAL; | |
5835 | goto out_err; | |
5836 | } | |
5837 | ||
61fa713c HS |
5838 | if (!dev->ops->dump_survey) { |
5839 | res = -EOPNOTSUPP; | |
5840 | goto out_err; | |
5841 | } | |
5842 | ||
5843 | while (1) { | |
180cdc79 LR |
5844 | struct ieee80211_channel *chan; |
5845 | ||
97990a06 | 5846 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5847 | if (res == -ENOENT) |
5848 | break; | |
5849 | if (res) | |
5850 | goto out_err; | |
5851 | ||
180cdc79 LR |
5852 | /* Survey without a channel doesn't make sense */ |
5853 | if (!survey.channel) { | |
5854 | res = -EINVAL; | |
5855 | goto out; | |
5856 | } | |
5857 | ||
5858 | chan = ieee80211_get_channel(&dev->wiphy, | |
5859 | survey.channel->center_freq); | |
5860 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5861 | survey_idx++; | |
5862 | continue; | |
5863 | } | |
5864 | ||
61fa713c | 5865 | if (nl80211_send_survey(skb, |
15e47304 | 5866 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5867 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5868 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5869 | goto out; |
5870 | survey_idx++; | |
5871 | } | |
5872 | ||
5873 | out: | |
97990a06 | 5874 | cb->args[2] = survey_idx; |
61fa713c HS |
5875 | res = skb->len; |
5876 | out_err: | |
97990a06 | 5877 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5878 | return res; |
5879 | } | |
5880 | ||
b23aa676 SO |
5881 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5882 | { | |
5883 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5884 | NL80211_WPA_VERSION_2)); | |
5885 | } | |
5886 | ||
636a5d36 JM |
5887 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5888 | { | |
4c476991 JB |
5889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5890 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5891 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5892 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5893 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5894 | enum nl80211_auth_type auth_type; |
fffd0934 | 5895 | struct key_parse key; |
d5cdfacb | 5896 | bool local_state_change; |
636a5d36 | 5897 | |
f4a11bb0 JB |
5898 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5899 | return -EINVAL; | |
5900 | ||
5901 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5902 | return -EINVAL; | |
5903 | ||
1778092e JM |
5904 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5905 | return -EINVAL; | |
5906 | ||
19957bb3 JB |
5907 | if (!info->attrs[NL80211_ATTR_SSID]) |
5908 | return -EINVAL; | |
5909 | ||
5910 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5911 | return -EINVAL; | |
5912 | ||
fffd0934 JB |
5913 | err = nl80211_parse_key(info, &key); |
5914 | if (err) | |
5915 | return err; | |
5916 | ||
5917 | if (key.idx >= 0) { | |
e31b8213 JB |
5918 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5919 | return -EINVAL; | |
fffd0934 JB |
5920 | if (!key.p.key || !key.p.key_len) |
5921 | return -EINVAL; | |
5922 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5923 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5924 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5925 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5926 | return -EINVAL; | |
5927 | if (key.idx > 4) | |
5928 | return -EINVAL; | |
5929 | } else { | |
5930 | key.p.key_len = 0; | |
5931 | key.p.key = NULL; | |
5932 | } | |
5933 | ||
afea0b7a JB |
5934 | if (key.idx >= 0) { |
5935 | int i; | |
5936 | bool ok = false; | |
5937 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5938 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5939 | ok = true; | |
5940 | break; | |
5941 | } | |
5942 | } | |
4c476991 JB |
5943 | if (!ok) |
5944 | return -EINVAL; | |
afea0b7a JB |
5945 | } |
5946 | ||
4c476991 JB |
5947 | if (!rdev->ops->auth) |
5948 | return -EOPNOTSUPP; | |
636a5d36 | 5949 | |
074ac8df | 5950 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5951 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5952 | return -EOPNOTSUPP; | |
eec60b03 | 5953 | |
19957bb3 | 5954 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5955 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5956 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5957 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5958 | return -EINVAL; | |
636a5d36 | 5959 | |
19957bb3 JB |
5960 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5961 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5962 | |
5963 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5964 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5965 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5966 | } |
5967 | ||
19957bb3 | 5968 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5969 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5970 | return -EINVAL; |
636a5d36 | 5971 | |
e39e5b5e JM |
5972 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5973 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5974 | return -EINVAL; | |
5975 | ||
5976 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5977 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5978 | return -EINVAL; | |
5979 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5980 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5981 | /* need to include at least Auth Transaction and Status Code */ | |
5982 | if (sae_data_len < 4) | |
5983 | return -EINVAL; | |
5984 | } | |
5985 | ||
d5cdfacb JM |
5986 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5987 | ||
95de817b JB |
5988 | /* |
5989 | * Since we no longer track auth state, ignore | |
5990 | * requests to only change local state. | |
5991 | */ | |
5992 | if (local_state_change) | |
5993 | return 0; | |
5994 | ||
91bf9b26 JB |
5995 | wdev_lock(dev->ieee80211_ptr); |
5996 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
5997 | ssid, ssid_len, ie, ie_len, | |
5998 | key.p.key, key.p.key_len, key.idx, | |
5999 | sae_data, sae_data_len); | |
6000 | wdev_unlock(dev->ieee80211_ptr); | |
6001 | return err; | |
636a5d36 JM |
6002 | } |
6003 | ||
c0692b8f JB |
6004 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6005 | struct genl_info *info, | |
3dc27d25 JB |
6006 | struct cfg80211_crypto_settings *settings, |
6007 | int cipher_limit) | |
b23aa676 | 6008 | { |
c0b2bbd8 JB |
6009 | memset(settings, 0, sizeof(*settings)); |
6010 | ||
b23aa676 SO |
6011 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6012 | ||
c0692b8f JB |
6013 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6014 | u16 proto; | |
6015 | proto = nla_get_u16( | |
6016 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6017 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6018 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6019 | proto != ETH_P_PAE) | |
6020 | return -EINVAL; | |
6021 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6022 | settings->control_port_no_encrypt = true; | |
6023 | } else | |
6024 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6025 | ||
b23aa676 SO |
6026 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6027 | void *data; | |
6028 | int len, i; | |
6029 | ||
6030 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6031 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6032 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6033 | ||
6034 | if (len % sizeof(u32)) | |
6035 | return -EINVAL; | |
6036 | ||
3dc27d25 | 6037 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6038 | return -EINVAL; |
6039 | ||
6040 | memcpy(settings->ciphers_pairwise, data, len); | |
6041 | ||
6042 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6043 | if (!cfg80211_supported_cipher_suite( |
6044 | &rdev->wiphy, | |
b23aa676 SO |
6045 | settings->ciphers_pairwise[i])) |
6046 | return -EINVAL; | |
6047 | } | |
6048 | ||
6049 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6050 | settings->cipher_group = | |
6051 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6052 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6053 | settings->cipher_group)) | |
b23aa676 SO |
6054 | return -EINVAL; |
6055 | } | |
6056 | ||
6057 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6058 | settings->wpa_versions = | |
6059 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6060 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6061 | return -EINVAL; | |
6062 | } | |
6063 | ||
6064 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6065 | void *data; | |
6d30240e | 6066 | int len; |
b23aa676 SO |
6067 | |
6068 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6069 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6070 | settings->n_akm_suites = len / sizeof(u32); | |
6071 | ||
6072 | if (len % sizeof(u32)) | |
6073 | return -EINVAL; | |
6074 | ||
1b9ca027 JM |
6075 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6076 | return -EINVAL; | |
6077 | ||
b23aa676 | 6078 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6079 | } |
6080 | ||
6081 | return 0; | |
6082 | } | |
6083 | ||
636a5d36 JM |
6084 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6085 | { | |
4c476991 JB |
6086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6087 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6088 | struct ieee80211_channel *chan; |
f62fab73 JB |
6089 | struct cfg80211_assoc_request req = {}; |
6090 | const u8 *bssid, *ssid; | |
6091 | int err, ssid_len = 0; | |
636a5d36 | 6092 | |
f4a11bb0 JB |
6093 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6094 | return -EINVAL; | |
6095 | ||
6096 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6097 | !info->attrs[NL80211_ATTR_SSID] || |
6098 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6099 | return -EINVAL; |
6100 | ||
4c476991 JB |
6101 | if (!rdev->ops->assoc) |
6102 | return -EOPNOTSUPP; | |
636a5d36 | 6103 | |
074ac8df | 6104 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6105 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6106 | return -EOPNOTSUPP; | |
eec60b03 | 6107 | |
19957bb3 | 6108 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6109 | |
19957bb3 JB |
6110 | chan = ieee80211_get_channel(&rdev->wiphy, |
6111 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6112 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6113 | return -EINVAL; | |
636a5d36 | 6114 | |
19957bb3 JB |
6115 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6116 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6117 | |
6118 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6119 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6120 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6121 | } |
6122 | ||
dc6382ce | 6123 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6124 | enum nl80211_mfp mfp = |
dc6382ce | 6125 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6126 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6127 | req.use_mfp = true; |
4c476991 JB |
6128 | else if (mfp != NL80211_MFP_NO) |
6129 | return -EINVAL; | |
dc6382ce JM |
6130 | } |
6131 | ||
3e5d7649 | 6132 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6133 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6134 | |
7e7c8926 | 6135 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6136 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6137 | |
6138 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6139 | memcpy(&req.ht_capa_mask, |
6140 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6141 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6142 | |
6143 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6144 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6145 | return -EINVAL; |
f62fab73 JB |
6146 | memcpy(&req.ht_capa, |
6147 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6148 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6149 | } |
6150 | ||
ee2aca34 | 6151 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6152 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6153 | |
6154 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6155 | memcpy(&req.vht_capa_mask, |
6156 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6157 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6158 | |
6159 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6160 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6161 | return -EINVAL; |
f62fab73 JB |
6162 | memcpy(&req.vht_capa, |
6163 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6164 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6165 | } |
6166 | ||
f62fab73 | 6167 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6168 | if (!err) { |
6169 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6170 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6171 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6172 | wdev_unlock(dev->ieee80211_ptr); |
6173 | } | |
636a5d36 | 6174 | |
636a5d36 JM |
6175 | return err; |
6176 | } | |
6177 | ||
6178 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6179 | { | |
4c476991 JB |
6180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6181 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6182 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6183 | int ie_len = 0, err; |
19957bb3 | 6184 | u16 reason_code; |
d5cdfacb | 6185 | bool local_state_change; |
636a5d36 | 6186 | |
f4a11bb0 JB |
6187 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6188 | return -EINVAL; | |
6189 | ||
6190 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6191 | return -EINVAL; | |
6192 | ||
6193 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6194 | return -EINVAL; | |
6195 | ||
4c476991 JB |
6196 | if (!rdev->ops->deauth) |
6197 | return -EOPNOTSUPP; | |
636a5d36 | 6198 | |
074ac8df | 6199 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6200 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6201 | return -EOPNOTSUPP; | |
eec60b03 | 6202 | |
19957bb3 | 6203 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6204 | |
19957bb3 JB |
6205 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6206 | if (reason_code == 0) { | |
f4a11bb0 | 6207 | /* Reason Code 0 is reserved */ |
4c476991 | 6208 | return -EINVAL; |
255e737e | 6209 | } |
636a5d36 JM |
6210 | |
6211 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6212 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6213 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6214 | } |
6215 | ||
d5cdfacb JM |
6216 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6217 | ||
91bf9b26 JB |
6218 | wdev_lock(dev->ieee80211_ptr); |
6219 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6220 | local_state_change); | |
6221 | wdev_unlock(dev->ieee80211_ptr); | |
6222 | return err; | |
636a5d36 JM |
6223 | } |
6224 | ||
6225 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6226 | { | |
4c476991 JB |
6227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6228 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6229 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6230 | int ie_len = 0, err; |
19957bb3 | 6231 | u16 reason_code; |
d5cdfacb | 6232 | bool local_state_change; |
636a5d36 | 6233 | |
f4a11bb0 JB |
6234 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6235 | return -EINVAL; | |
6236 | ||
6237 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6238 | return -EINVAL; | |
6239 | ||
6240 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6241 | return -EINVAL; | |
6242 | ||
4c476991 JB |
6243 | if (!rdev->ops->disassoc) |
6244 | return -EOPNOTSUPP; | |
636a5d36 | 6245 | |
074ac8df | 6246 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6247 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6248 | return -EOPNOTSUPP; | |
eec60b03 | 6249 | |
19957bb3 | 6250 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6251 | |
19957bb3 JB |
6252 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6253 | if (reason_code == 0) { | |
f4a11bb0 | 6254 | /* Reason Code 0 is reserved */ |
4c476991 | 6255 | return -EINVAL; |
255e737e | 6256 | } |
636a5d36 JM |
6257 | |
6258 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6259 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6260 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6261 | } |
6262 | ||
d5cdfacb JM |
6263 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6264 | ||
91bf9b26 JB |
6265 | wdev_lock(dev->ieee80211_ptr); |
6266 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6267 | local_state_change); | |
6268 | wdev_unlock(dev->ieee80211_ptr); | |
6269 | return err; | |
636a5d36 JM |
6270 | } |
6271 | ||
dd5b4cc7 FF |
6272 | static bool |
6273 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6274 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6275 | int rateval) | |
6276 | { | |
6277 | struct wiphy *wiphy = &rdev->wiphy; | |
6278 | bool found = false; | |
6279 | int band, i; | |
6280 | ||
6281 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6282 | struct ieee80211_supported_band *sband; | |
6283 | ||
6284 | sband = wiphy->bands[band]; | |
6285 | if (!sband) | |
6286 | continue; | |
6287 | ||
6288 | for (i = 0; i < sband->n_bitrates; i++) { | |
6289 | if (sband->bitrates[i].bitrate == rateval) { | |
6290 | mcast_rate[band] = i + 1; | |
6291 | found = true; | |
6292 | break; | |
6293 | } | |
6294 | } | |
6295 | } | |
6296 | ||
6297 | return found; | |
6298 | } | |
6299 | ||
04a773ad JB |
6300 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6301 | { | |
4c476991 JB |
6302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6303 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6304 | struct cfg80211_ibss_params ibss; |
6305 | struct wiphy *wiphy; | |
fffd0934 | 6306 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6307 | int err; |
6308 | ||
8e30bc55 JB |
6309 | memset(&ibss, 0, sizeof(ibss)); |
6310 | ||
04a773ad JB |
6311 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6312 | return -EINVAL; | |
6313 | ||
683b6d3b | 6314 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6315 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6316 | return -EINVAL; | |
6317 | ||
8e30bc55 JB |
6318 | ibss.beacon_interval = 100; |
6319 | ||
6320 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6321 | ibss.beacon_interval = | |
6322 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6323 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6324 | return -EINVAL; | |
6325 | } | |
6326 | ||
4c476991 JB |
6327 | if (!rdev->ops->join_ibss) |
6328 | return -EOPNOTSUPP; | |
04a773ad | 6329 | |
4c476991 JB |
6330 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6331 | return -EOPNOTSUPP; | |
04a773ad | 6332 | |
79c97e97 | 6333 | wiphy = &rdev->wiphy; |
04a773ad | 6334 | |
39193498 | 6335 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6336 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6337 | |
6338 | if (!is_valid_ether_addr(ibss.bssid)) | |
6339 | return -EINVAL; | |
6340 | } | |
04a773ad JB |
6341 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6342 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6343 | ||
6344 | if (info->attrs[NL80211_ATTR_IE]) { | |
6345 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6346 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6347 | } | |
6348 | ||
683b6d3b JB |
6349 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6350 | if (err) | |
6351 | return err; | |
04a773ad | 6352 | |
683b6d3b | 6353 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6354 | return -EINVAL; |
6355 | ||
2f301ab2 SW |
6356 | switch (ibss.chandef.width) { |
6357 | case NL80211_CHAN_WIDTH_20_NOHT: | |
6358 | break; | |
6359 | case NL80211_CHAN_WIDTH_20: | |
6360 | case NL80211_CHAN_WIDTH_40: | |
6361 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6362 | break; | |
6363 | default: | |
c04d6150 | 6364 | return -EINVAL; |
2f301ab2 | 6365 | } |
db9c64cf | 6366 | |
04a773ad | 6367 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6368 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6369 | ||
fbd2c8dc TP |
6370 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6371 | u8 *rates = | |
6372 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6373 | int n_rates = | |
6374 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6375 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6376 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6377 | |
34850ab2 JB |
6378 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6379 | &ibss.basic_rates); | |
6380 | if (err) | |
6381 | return err; | |
fbd2c8dc | 6382 | } |
dd5b4cc7 | 6383 | |
803768f5 SW |
6384 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6385 | memcpy(&ibss.ht_capa_mask, | |
6386 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6387 | sizeof(ibss.ht_capa_mask)); | |
6388 | ||
6389 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6390 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6391 | return -EINVAL; | |
6392 | memcpy(&ibss.ht_capa, | |
6393 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6394 | sizeof(ibss.ht_capa)); | |
6395 | } | |
6396 | ||
dd5b4cc7 FF |
6397 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6398 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6399 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6400 | return -EINVAL; | |
fbd2c8dc | 6401 | |
4c476991 | 6402 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6403 | bool no_ht = false; |
6404 | ||
4c476991 | 6405 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6406 | info->attrs[NL80211_ATTR_KEYS], |
6407 | &no_ht); | |
4c476991 JB |
6408 | if (IS_ERR(connkeys)) |
6409 | return PTR_ERR(connkeys); | |
de7044ee | 6410 | |
3d9d1d66 JB |
6411 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6412 | no_ht) { | |
de7044ee SM |
6413 | kfree(connkeys); |
6414 | return -EINVAL; | |
6415 | } | |
4c476991 | 6416 | } |
04a773ad | 6417 | |
267335d6 AQ |
6418 | ibss.control_port = |
6419 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6420 | ||
4c476991 | 6421 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6422 | if (err) |
6423 | kfree(connkeys); | |
04a773ad JB |
6424 | return err; |
6425 | } | |
6426 | ||
6427 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6428 | { | |
4c476991 JB |
6429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6430 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6431 | |
4c476991 JB |
6432 | if (!rdev->ops->leave_ibss) |
6433 | return -EOPNOTSUPP; | |
04a773ad | 6434 | |
4c476991 JB |
6435 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6436 | return -EOPNOTSUPP; | |
04a773ad | 6437 | |
4c476991 | 6438 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6439 | } |
6440 | ||
f4e583c8 AQ |
6441 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6442 | { | |
6443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6444 | struct net_device *dev = info->user_ptr[1]; | |
6445 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6446 | u32 nla_rate; | |
6447 | int err; | |
6448 | ||
6449 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6450 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6451 | return -EOPNOTSUPP; | |
6452 | ||
6453 | if (!rdev->ops->set_mcast_rate) | |
6454 | return -EOPNOTSUPP; | |
6455 | ||
6456 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6457 | ||
6458 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6459 | return -EINVAL; | |
6460 | ||
6461 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6462 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6463 | return -EINVAL; | |
6464 | ||
6465 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6466 | ||
6467 | return err; | |
6468 | } | |
6469 | ||
6470 | ||
aff89a9b JB |
6471 | #ifdef CONFIG_NL80211_TESTMODE |
6472 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6473 | .name = "testmode", | |
6474 | }; | |
6475 | ||
6476 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6477 | { | |
4c476991 | 6478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6479 | int err; |
6480 | ||
6481 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6482 | return -EINVAL; | |
6483 | ||
aff89a9b JB |
6484 | err = -EOPNOTSUPP; |
6485 | if (rdev->ops->testmode_cmd) { | |
6486 | rdev->testmode_info = info; | |
e35e4d28 | 6487 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6488 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6489 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6490 | rdev->testmode_info = NULL; | |
6491 | } | |
6492 | ||
aff89a9b JB |
6493 | return err; |
6494 | } | |
6495 | ||
71063f0e WYG |
6496 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6497 | struct netlink_callback *cb) | |
6498 | { | |
00918d33 | 6499 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6500 | int err; |
6501 | long phy_idx; | |
6502 | void *data = NULL; | |
6503 | int data_len = 0; | |
6504 | ||
5fe231e8 JB |
6505 | rtnl_lock(); |
6506 | ||
71063f0e WYG |
6507 | if (cb->args[0]) { |
6508 | /* | |
6509 | * 0 is a valid index, but not valid for args[0], | |
6510 | * so we need to offset by 1. | |
6511 | */ | |
6512 | phy_idx = cb->args[0] - 1; | |
6513 | } else { | |
6514 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6515 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6516 | nl80211_policy); | |
6517 | if (err) | |
5fe231e8 | 6518 | goto out_err; |
00918d33 | 6519 | |
2bd7e35d JB |
6520 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6521 | nl80211_fam.attrbuf); | |
6522 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6523 | err = PTR_ERR(rdev); |
6524 | goto out_err; | |
00918d33 | 6525 | } |
2bd7e35d JB |
6526 | phy_idx = rdev->wiphy_idx; |
6527 | rdev = NULL; | |
2bd7e35d | 6528 | |
71063f0e WYG |
6529 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6530 | cb->args[1] = | |
6531 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6532 | } | |
6533 | ||
6534 | if (cb->args[1]) { | |
6535 | data = nla_data((void *)cb->args[1]); | |
6536 | data_len = nla_len((void *)cb->args[1]); | |
6537 | } | |
6538 | ||
00918d33 JB |
6539 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6540 | if (!rdev) { | |
5fe231e8 JB |
6541 | err = -ENOENT; |
6542 | goto out_err; | |
71063f0e | 6543 | } |
71063f0e | 6544 | |
00918d33 | 6545 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6546 | err = -EOPNOTSUPP; |
6547 | goto out_err; | |
6548 | } | |
6549 | ||
6550 | while (1) { | |
15e47304 | 6551 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6552 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6553 | NL80211_CMD_TESTMODE); | |
6554 | struct nlattr *tmdata; | |
6555 | ||
9360ffd1 | 6556 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6557 | genlmsg_cancel(skb, hdr); |
6558 | break; | |
6559 | } | |
6560 | ||
6561 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6562 | if (!tmdata) { | |
6563 | genlmsg_cancel(skb, hdr); | |
6564 | break; | |
6565 | } | |
e35e4d28 | 6566 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6567 | nla_nest_end(skb, tmdata); |
6568 | ||
6569 | if (err == -ENOBUFS || err == -ENOENT) { | |
6570 | genlmsg_cancel(skb, hdr); | |
6571 | break; | |
6572 | } else if (err) { | |
6573 | genlmsg_cancel(skb, hdr); | |
6574 | goto out_err; | |
6575 | } | |
6576 | ||
6577 | genlmsg_end(skb, hdr); | |
6578 | } | |
6579 | ||
6580 | err = skb->len; | |
6581 | /* see above */ | |
6582 | cb->args[0] = phy_idx + 1; | |
6583 | out_err: | |
5fe231e8 | 6584 | rtnl_unlock(); |
71063f0e WYG |
6585 | return err; |
6586 | } | |
6587 | ||
aff89a9b JB |
6588 | static struct sk_buff * |
6589 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6590 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6591 | { |
6592 | struct sk_buff *skb; | |
6593 | void *hdr; | |
6594 | struct nlattr *data; | |
6595 | ||
6596 | skb = nlmsg_new(approxlen + 100, gfp); | |
6597 | if (!skb) | |
6598 | return NULL; | |
6599 | ||
15e47304 | 6600 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6601 | if (!hdr) { |
6602 | kfree_skb(skb); | |
6603 | return NULL; | |
6604 | } | |
6605 | ||
9360ffd1 DM |
6606 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6607 | goto nla_put_failure; | |
aff89a9b JB |
6608 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6609 | ||
6610 | ((void **)skb->cb)[0] = rdev; | |
6611 | ((void **)skb->cb)[1] = hdr; | |
6612 | ((void **)skb->cb)[2] = data; | |
6613 | ||
6614 | return skb; | |
6615 | ||
6616 | nla_put_failure: | |
6617 | kfree_skb(skb); | |
6618 | return NULL; | |
6619 | } | |
6620 | ||
6621 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6622 | int approxlen) | |
6623 | { | |
6624 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6625 | ||
6626 | if (WARN_ON(!rdev->testmode_info)) | |
6627 | return NULL; | |
6628 | ||
6629 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6630 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6631 | rdev->testmode_info->snd_seq, |
6632 | GFP_KERNEL); | |
6633 | } | |
6634 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6635 | ||
6636 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6637 | { | |
6638 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6639 | void *hdr = ((void **)skb->cb)[1]; | |
6640 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6641 | ||
6642 | if (WARN_ON(!rdev->testmode_info)) { | |
6643 | kfree_skb(skb); | |
6644 | return -EINVAL; | |
6645 | } | |
6646 | ||
6647 | nla_nest_end(skb, data); | |
6648 | genlmsg_end(skb, hdr); | |
6649 | return genlmsg_reply(skb, rdev->testmode_info); | |
6650 | } | |
6651 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6652 | ||
6653 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6654 | int approxlen, gfp_t gfp) | |
6655 | { | |
6656 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6657 | ||
6658 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6659 | } | |
6660 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6661 | ||
6662 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6663 | { | |
6664 | void *hdr = ((void **)skb->cb)[1]; | |
6665 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6666 | ||
6667 | nla_nest_end(skb, data); | |
6668 | genlmsg_end(skb, hdr); | |
6669 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6670 | } | |
6671 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6672 | #endif | |
6673 | ||
b23aa676 SO |
6674 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6675 | { | |
4c476991 JB |
6676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6677 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6678 | struct cfg80211_connect_params connect; |
6679 | struct wiphy *wiphy; | |
fffd0934 | 6680 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6681 | int err; |
6682 | ||
6683 | memset(&connect, 0, sizeof(connect)); | |
6684 | ||
6685 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6686 | return -EINVAL; | |
6687 | ||
6688 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6689 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6690 | return -EINVAL; | |
6691 | ||
6692 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6693 | connect.auth_type = | |
6694 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6695 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6696 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6697 | return -EINVAL; |
6698 | } else | |
6699 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6700 | ||
6701 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6702 | ||
c0692b8f | 6703 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6704 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6705 | if (err) |
6706 | return err; | |
b23aa676 | 6707 | |
074ac8df | 6708 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6709 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6710 | return -EOPNOTSUPP; | |
b23aa676 | 6711 | |
79c97e97 | 6712 | wiphy = &rdev->wiphy; |
b23aa676 | 6713 | |
4486ea98 BS |
6714 | connect.bg_scan_period = -1; |
6715 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6716 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6717 | connect.bg_scan_period = | |
6718 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6719 | } | |
6720 | ||
b23aa676 SO |
6721 | if (info->attrs[NL80211_ATTR_MAC]) |
6722 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6723 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6724 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6725 | ||
6726 | if (info->attrs[NL80211_ATTR_IE]) { | |
6727 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6728 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6729 | } | |
6730 | ||
cee00a95 JM |
6731 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6732 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6733 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6734 | connect.mfp != NL80211_MFP_NO) | |
6735 | return -EINVAL; | |
6736 | } else { | |
6737 | connect.mfp = NL80211_MFP_NO; | |
6738 | } | |
6739 | ||
b23aa676 SO |
6740 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6741 | connect.channel = | |
6742 | ieee80211_get_channel(wiphy, | |
6743 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6744 | if (!connect.channel || | |
4c476991 JB |
6745 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6746 | return -EINVAL; | |
b23aa676 SO |
6747 | } |
6748 | ||
fffd0934 JB |
6749 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6750 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6751 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6752 | if (IS_ERR(connkeys)) |
6753 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6754 | } |
6755 | ||
7e7c8926 BG |
6756 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6757 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6758 | ||
6759 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6760 | memcpy(&connect.ht_capa_mask, | |
6761 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6762 | sizeof(connect.ht_capa_mask)); | |
6763 | ||
6764 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6765 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6766 | kfree(connkeys); | |
7e7c8926 | 6767 | return -EINVAL; |
b4e4f47e | 6768 | } |
7e7c8926 BG |
6769 | memcpy(&connect.ht_capa, |
6770 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6771 | sizeof(connect.ht_capa)); | |
6772 | } | |
6773 | ||
ee2aca34 JB |
6774 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6775 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6776 | ||
6777 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6778 | memcpy(&connect.vht_capa_mask, | |
6779 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6780 | sizeof(connect.vht_capa_mask)); | |
6781 | ||
6782 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6783 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6784 | kfree(connkeys); | |
6785 | return -EINVAL; | |
6786 | } | |
6787 | memcpy(&connect.vht_capa, | |
6788 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6789 | sizeof(connect.vht_capa)); | |
6790 | } | |
6791 | ||
83739b03 JB |
6792 | wdev_lock(dev->ieee80211_ptr); |
6793 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
6794 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
6795 | if (err) |
6796 | kfree(connkeys); | |
b23aa676 SO |
6797 | return err; |
6798 | } | |
6799 | ||
6800 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6801 | { | |
4c476991 JB |
6802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6803 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 6804 | u16 reason; |
83739b03 | 6805 | int ret; |
b23aa676 SO |
6806 | |
6807 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6808 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6809 | else | |
6810 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6811 | ||
6812 | if (reason == 0) | |
6813 | return -EINVAL; | |
6814 | ||
074ac8df | 6815 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6816 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6817 | return -EOPNOTSUPP; | |
b23aa676 | 6818 | |
83739b03 JB |
6819 | wdev_lock(dev->ieee80211_ptr); |
6820 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
6821 | wdev_unlock(dev->ieee80211_ptr); | |
6822 | return ret; | |
b23aa676 SO |
6823 | } |
6824 | ||
463d0183 JB |
6825 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6826 | { | |
4c476991 | 6827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6828 | struct net *net; |
6829 | int err; | |
6830 | u32 pid; | |
6831 | ||
6832 | if (!info->attrs[NL80211_ATTR_PID]) | |
6833 | return -EINVAL; | |
6834 | ||
6835 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6836 | ||
463d0183 | 6837 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6838 | if (IS_ERR(net)) |
6839 | return PTR_ERR(net); | |
463d0183 JB |
6840 | |
6841 | err = 0; | |
6842 | ||
6843 | /* check if anything to do */ | |
4c476991 JB |
6844 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6845 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6846 | |
463d0183 | 6847 | put_net(net); |
463d0183 JB |
6848 | return err; |
6849 | } | |
6850 | ||
67fbb16b SO |
6851 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6852 | { | |
4c476991 | 6853 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6854 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6855 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6856 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6857 | struct cfg80211_pmksa pmksa; |
6858 | ||
6859 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6860 | ||
6861 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6862 | return -EINVAL; | |
6863 | ||
6864 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6865 | return -EINVAL; | |
6866 | ||
67fbb16b SO |
6867 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6868 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6869 | ||
074ac8df | 6870 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6871 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6872 | return -EOPNOTSUPP; | |
67fbb16b SO |
6873 | |
6874 | switch (info->genlhdr->cmd) { | |
6875 | case NL80211_CMD_SET_PMKSA: | |
6876 | rdev_ops = rdev->ops->set_pmksa; | |
6877 | break; | |
6878 | case NL80211_CMD_DEL_PMKSA: | |
6879 | rdev_ops = rdev->ops->del_pmksa; | |
6880 | break; | |
6881 | default: | |
6882 | WARN_ON(1); | |
6883 | break; | |
6884 | } | |
6885 | ||
4c476991 JB |
6886 | if (!rdev_ops) |
6887 | return -EOPNOTSUPP; | |
67fbb16b | 6888 | |
4c476991 | 6889 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6890 | } |
6891 | ||
6892 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6893 | { | |
4c476991 JB |
6894 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6895 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6896 | |
074ac8df | 6897 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6898 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6899 | return -EOPNOTSUPP; | |
67fbb16b | 6900 | |
4c476991 JB |
6901 | if (!rdev->ops->flush_pmksa) |
6902 | return -EOPNOTSUPP; | |
67fbb16b | 6903 | |
e35e4d28 | 6904 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6905 | } |
6906 | ||
109086ce AN |
6907 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6908 | { | |
6909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6910 | struct net_device *dev = info->user_ptr[1]; | |
6911 | u8 action_code, dialog_token; | |
6912 | u16 status_code; | |
6913 | u8 *peer; | |
6914 | ||
6915 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6916 | !rdev->ops->tdls_mgmt) | |
6917 | return -EOPNOTSUPP; | |
6918 | ||
6919 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6920 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6921 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6922 | !info->attrs[NL80211_ATTR_IE] || | |
6923 | !info->attrs[NL80211_ATTR_MAC]) | |
6924 | return -EINVAL; | |
6925 | ||
6926 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6927 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6928 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6929 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6930 | ||
e35e4d28 HG |
6931 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6932 | dialog_token, status_code, | |
6933 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6934 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6935 | } |
6936 | ||
6937 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6938 | { | |
6939 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6940 | struct net_device *dev = info->user_ptr[1]; | |
6941 | enum nl80211_tdls_operation operation; | |
6942 | u8 *peer; | |
6943 | ||
6944 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6945 | !rdev->ops->tdls_oper) | |
6946 | return -EOPNOTSUPP; | |
6947 | ||
6948 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6949 | !info->attrs[NL80211_ATTR_MAC]) | |
6950 | return -EINVAL; | |
6951 | ||
6952 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6953 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6954 | ||
e35e4d28 | 6955 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6956 | } |
6957 | ||
9588bbd5 JM |
6958 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6959 | struct genl_info *info) | |
6960 | { | |
4c476991 | 6961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6962 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6963 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6964 | struct sk_buff *msg; |
6965 | void *hdr; | |
6966 | u64 cookie; | |
683b6d3b | 6967 | u32 duration; |
9588bbd5 JM |
6968 | int err; |
6969 | ||
6970 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6971 | !info->attrs[NL80211_ATTR_DURATION]) | |
6972 | return -EINVAL; | |
6973 | ||
6974 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6975 | ||
ebf348fc JB |
6976 | if (!rdev->ops->remain_on_channel || |
6977 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6978 | return -EOPNOTSUPP; | |
6979 | ||
9588bbd5 | 6980 | /* |
ebf348fc JB |
6981 | * We should be on that channel for at least a minimum amount of |
6982 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6983 | */ |
ebf348fc | 6984 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6985 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6986 | return -EINVAL; |
6987 | ||
683b6d3b JB |
6988 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6989 | if (err) | |
6990 | return err; | |
9588bbd5 JM |
6991 | |
6992 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6993 | if (!msg) |
6994 | return -ENOMEM; | |
9588bbd5 | 6995 | |
15e47304 | 6996 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6997 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6998 | ||
6999 | if (IS_ERR(hdr)) { | |
7000 | err = PTR_ERR(hdr); | |
7001 | goto free_msg; | |
7002 | } | |
7003 | ||
683b6d3b JB |
7004 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7005 | duration, &cookie); | |
9588bbd5 JM |
7006 | |
7007 | if (err) | |
7008 | goto free_msg; | |
7009 | ||
9360ffd1 DM |
7010 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7011 | goto nla_put_failure; | |
9588bbd5 JM |
7012 | |
7013 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7014 | |
7015 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7016 | |
7017 | nla_put_failure: | |
7018 | err = -ENOBUFS; | |
7019 | free_msg: | |
7020 | nlmsg_free(msg); | |
9588bbd5 JM |
7021 | return err; |
7022 | } | |
7023 | ||
7024 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7025 | struct genl_info *info) | |
7026 | { | |
4c476991 | 7027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7028 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7029 | u64 cookie; |
9588bbd5 JM |
7030 | |
7031 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7032 | return -EINVAL; | |
7033 | ||
4c476991 JB |
7034 | if (!rdev->ops->cancel_remain_on_channel) |
7035 | return -EOPNOTSUPP; | |
9588bbd5 | 7036 | |
9588bbd5 JM |
7037 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7038 | ||
e35e4d28 | 7039 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7040 | } |
7041 | ||
13ae75b1 JM |
7042 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7043 | u8 *rates, u8 rates_len) | |
7044 | { | |
7045 | u8 i; | |
7046 | u32 mask = 0; | |
7047 | ||
7048 | for (i = 0; i < rates_len; i++) { | |
7049 | int rate = (rates[i] & 0x7f) * 5; | |
7050 | int ridx; | |
7051 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7052 | struct ieee80211_rate *srate = | |
7053 | &sband->bitrates[ridx]; | |
7054 | if (rate == srate->bitrate) { | |
7055 | mask |= 1 << ridx; | |
7056 | break; | |
7057 | } | |
7058 | } | |
7059 | if (ridx == sband->n_bitrates) | |
7060 | return 0; /* rate not found */ | |
7061 | } | |
7062 | ||
7063 | return mask; | |
7064 | } | |
7065 | ||
24db78c0 SW |
7066 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7067 | u8 *rates, u8 rates_len, | |
7068 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7069 | { | |
7070 | u8 i; | |
7071 | ||
7072 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7073 | ||
7074 | for (i = 0; i < rates_len; i++) { | |
7075 | int ridx, rbit; | |
7076 | ||
7077 | ridx = rates[i] / 8; | |
7078 | rbit = BIT(rates[i] % 8); | |
7079 | ||
7080 | /* check validity */ | |
910570b5 | 7081 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7082 | return false; |
7083 | ||
7084 | /* check availability */ | |
7085 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7086 | mcs[ridx] |= rbit; | |
7087 | else | |
7088 | return false; | |
7089 | } | |
7090 | ||
7091 | return true; | |
7092 | } | |
7093 | ||
b54452b0 | 7094 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7095 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7096 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7097 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7098 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7099 | }; |
7100 | ||
7101 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7102 | struct genl_info *info) | |
7103 | { | |
7104 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7106 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7107 | int rem, i; |
7108 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7109 | struct nlattr *tx_rates; |
7110 | struct ieee80211_supported_band *sband; | |
7111 | ||
7112 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7113 | return -EINVAL; | |
7114 | ||
4c476991 JB |
7115 | if (!rdev->ops->set_bitrate_mask) |
7116 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7117 | |
7118 | memset(&mask, 0, sizeof(mask)); | |
7119 | /* Default to all rates enabled */ | |
7120 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7121 | sband = rdev->wiphy.bands[i]; | |
7122 | mask.control[i].legacy = | |
7123 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7124 | if (sband) |
7125 | memcpy(mask.control[i].mcs, | |
7126 | sband->ht_cap.mcs.rx_mask, | |
7127 | sizeof(mask.control[i].mcs)); | |
7128 | else | |
7129 | memset(mask.control[i].mcs, 0, | |
7130 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7131 | } |
7132 | ||
7133 | /* | |
7134 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7135 | * directly to the enum ieee80211_band values used in cfg80211. | |
7136 | */ | |
24db78c0 | 7137 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7138 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7139 | { | |
7140 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7141 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7142 | return -EINVAL; | |
13ae75b1 | 7143 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7144 | if (sband == NULL) |
7145 | return -EINVAL; | |
13ae75b1 JM |
7146 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7147 | nla_len(tx_rates), nl80211_txattr_policy); | |
7148 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7149 | mask.control[band].legacy = rateset_to_mask( | |
7150 | sband, | |
7151 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7152 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7153 | if ((mask.control[band].legacy == 0) && |
7154 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7155 | return -EINVAL; | |
24db78c0 SW |
7156 | } |
7157 | if (tb[NL80211_TXRATE_MCS]) { | |
7158 | if (!ht_rateset_to_mask( | |
7159 | sband, | |
7160 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7161 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7162 | mask.control[band].mcs)) | |
7163 | return -EINVAL; | |
7164 | } | |
7165 | ||
7166 | if (mask.control[band].legacy == 0) { | |
7167 | /* don't allow empty legacy rates if HT | |
7168 | * is not even supported. */ | |
7169 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7170 | return -EINVAL; | |
7171 | ||
7172 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7173 | if (mask.control[band].mcs[i]) | |
7174 | break; | |
7175 | ||
7176 | /* legacy and mcs rates may not be both empty */ | |
7177 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7178 | return -EINVAL; |
13ae75b1 JM |
7179 | } |
7180 | } | |
7181 | ||
e35e4d28 | 7182 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7183 | } |
7184 | ||
2e161f78 | 7185 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7186 | { |
4c476991 | 7187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7188 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7189 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7190 | |
7191 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7192 | return -EINVAL; | |
7193 | ||
2e161f78 JB |
7194 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7195 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7196 | |
71bbc994 JB |
7197 | switch (wdev->iftype) { |
7198 | case NL80211_IFTYPE_STATION: | |
7199 | case NL80211_IFTYPE_ADHOC: | |
7200 | case NL80211_IFTYPE_P2P_CLIENT: | |
7201 | case NL80211_IFTYPE_AP: | |
7202 | case NL80211_IFTYPE_AP_VLAN: | |
7203 | case NL80211_IFTYPE_MESH_POINT: | |
7204 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7205 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7206 | break; |
7207 | default: | |
4c476991 | 7208 | return -EOPNOTSUPP; |
71bbc994 | 7209 | } |
026331c4 JM |
7210 | |
7211 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7212 | if (!rdev->ops->mgmt_tx) |
7213 | return -EOPNOTSUPP; | |
026331c4 | 7214 | |
15e47304 | 7215 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7216 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7217 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7218 | } |
7219 | ||
2e161f78 | 7220 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7221 | { |
4c476991 | 7222 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7223 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7224 | struct cfg80211_chan_def chandef; |
026331c4 | 7225 | int err; |
d64d373f | 7226 | void *hdr = NULL; |
026331c4 | 7227 | u64 cookie; |
e247bd90 | 7228 | struct sk_buff *msg = NULL; |
f7ca38df | 7229 | unsigned int wait = 0; |
e247bd90 JB |
7230 | bool offchan, no_cck, dont_wait_for_ack; |
7231 | ||
7232 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7233 | |
683b6d3b | 7234 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7235 | return -EINVAL; |
7236 | ||
4c476991 JB |
7237 | if (!rdev->ops->mgmt_tx) |
7238 | return -EOPNOTSUPP; | |
026331c4 | 7239 | |
71bbc994 | 7240 | switch (wdev->iftype) { |
ea141b75 AQ |
7241 | case NL80211_IFTYPE_P2P_DEVICE: |
7242 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7243 | return -EINVAL; | |
71bbc994 JB |
7244 | case NL80211_IFTYPE_STATION: |
7245 | case NL80211_IFTYPE_ADHOC: | |
7246 | case NL80211_IFTYPE_P2P_CLIENT: | |
7247 | case NL80211_IFTYPE_AP: | |
7248 | case NL80211_IFTYPE_AP_VLAN: | |
7249 | case NL80211_IFTYPE_MESH_POINT: | |
7250 | case NL80211_IFTYPE_P2P_GO: | |
7251 | break; | |
7252 | default: | |
4c476991 | 7253 | return -EOPNOTSUPP; |
71bbc994 | 7254 | } |
026331c4 | 7255 | |
f7ca38df | 7256 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7257 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7258 | return -EINVAL; |
7259 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7260 | |
7261 | /* | |
7262 | * We should wait on the channel for at least a minimum amount | |
7263 | * of time (10ms) but no longer than the driver supports. | |
7264 | */ | |
7265 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7266 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7267 | return -EINVAL; | |
7268 | ||
f7ca38df JB |
7269 | } |
7270 | ||
f7ca38df JB |
7271 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7272 | ||
7c4ef712 JB |
7273 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7274 | return -EINVAL; | |
7275 | ||
e9f935e3 RM |
7276 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7277 | ||
ea141b75 AQ |
7278 | /* get the channel if any has been specified, otherwise pass NULL to |
7279 | * the driver. The latter will use the current one | |
7280 | */ | |
7281 | chandef.chan = NULL; | |
7282 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7283 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7284 | if (err) | |
7285 | return err; | |
7286 | } | |
7287 | ||
7288 | if (!chandef.chan && offchan) | |
7289 | return -EINVAL; | |
026331c4 | 7290 | |
e247bd90 JB |
7291 | if (!dont_wait_for_ack) { |
7292 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7293 | if (!msg) | |
7294 | return -ENOMEM; | |
026331c4 | 7295 | |
15e47304 | 7296 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7297 | NL80211_CMD_FRAME); |
026331c4 | 7298 | |
e247bd90 JB |
7299 | if (IS_ERR(hdr)) { |
7300 | err = PTR_ERR(hdr); | |
7301 | goto free_msg; | |
7302 | } | |
026331c4 | 7303 | } |
e247bd90 | 7304 | |
683b6d3b | 7305 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7306 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7307 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7308 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7309 | if (err) |
7310 | goto free_msg; | |
7311 | ||
e247bd90 | 7312 | if (msg) { |
9360ffd1 DM |
7313 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7314 | goto nla_put_failure; | |
026331c4 | 7315 | |
e247bd90 JB |
7316 | genlmsg_end(msg, hdr); |
7317 | return genlmsg_reply(msg, info); | |
7318 | } | |
7319 | ||
7320 | return 0; | |
026331c4 JM |
7321 | |
7322 | nla_put_failure: | |
7323 | err = -ENOBUFS; | |
7324 | free_msg: | |
7325 | nlmsg_free(msg); | |
026331c4 JM |
7326 | return err; |
7327 | } | |
7328 | ||
f7ca38df JB |
7329 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7330 | { | |
7331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7332 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7333 | u64 cookie; |
7334 | ||
7335 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7336 | return -EINVAL; | |
7337 | ||
7338 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7339 | return -EOPNOTSUPP; | |
7340 | ||
71bbc994 JB |
7341 | switch (wdev->iftype) { |
7342 | case NL80211_IFTYPE_STATION: | |
7343 | case NL80211_IFTYPE_ADHOC: | |
7344 | case NL80211_IFTYPE_P2P_CLIENT: | |
7345 | case NL80211_IFTYPE_AP: | |
7346 | case NL80211_IFTYPE_AP_VLAN: | |
7347 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7348 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7349 | break; |
7350 | default: | |
f7ca38df | 7351 | return -EOPNOTSUPP; |
71bbc994 | 7352 | } |
f7ca38df JB |
7353 | |
7354 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7355 | ||
e35e4d28 | 7356 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7357 | } |
7358 | ||
ffb9eb3d KV |
7359 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7360 | { | |
4c476991 | 7361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7362 | struct wireless_dev *wdev; |
4c476991 | 7363 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7364 | u8 ps_state; |
7365 | bool state; | |
7366 | int err; | |
7367 | ||
4c476991 JB |
7368 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7369 | return -EINVAL; | |
ffb9eb3d KV |
7370 | |
7371 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7372 | ||
4c476991 JB |
7373 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7374 | return -EINVAL; | |
ffb9eb3d KV |
7375 | |
7376 | wdev = dev->ieee80211_ptr; | |
7377 | ||
4c476991 JB |
7378 | if (!rdev->ops->set_power_mgmt) |
7379 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7380 | |
7381 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7382 | ||
7383 | if (state == wdev->ps) | |
4c476991 | 7384 | return 0; |
ffb9eb3d | 7385 | |
e35e4d28 | 7386 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7387 | if (!err) |
7388 | wdev->ps = state; | |
ffb9eb3d KV |
7389 | return err; |
7390 | } | |
7391 | ||
7392 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7393 | { | |
4c476991 | 7394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7395 | enum nl80211_ps_state ps_state; |
7396 | struct wireless_dev *wdev; | |
4c476991 | 7397 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7398 | struct sk_buff *msg; |
7399 | void *hdr; | |
7400 | int err; | |
7401 | ||
ffb9eb3d KV |
7402 | wdev = dev->ieee80211_ptr; |
7403 | ||
4c476991 JB |
7404 | if (!rdev->ops->set_power_mgmt) |
7405 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7406 | |
7407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7408 | if (!msg) |
7409 | return -ENOMEM; | |
ffb9eb3d | 7410 | |
15e47304 | 7411 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7412 | NL80211_CMD_GET_POWER_SAVE); |
7413 | if (!hdr) { | |
4c476991 | 7414 | err = -ENOBUFS; |
ffb9eb3d KV |
7415 | goto free_msg; |
7416 | } | |
7417 | ||
7418 | if (wdev->ps) | |
7419 | ps_state = NL80211_PS_ENABLED; | |
7420 | else | |
7421 | ps_state = NL80211_PS_DISABLED; | |
7422 | ||
9360ffd1 DM |
7423 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7424 | goto nla_put_failure; | |
ffb9eb3d KV |
7425 | |
7426 | genlmsg_end(msg, hdr); | |
4c476991 | 7427 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7428 | |
4c476991 | 7429 | nla_put_failure: |
ffb9eb3d | 7430 | err = -ENOBUFS; |
4c476991 | 7431 | free_msg: |
ffb9eb3d | 7432 | nlmsg_free(msg); |
ffb9eb3d KV |
7433 | return err; |
7434 | } | |
7435 | ||
d6dc1a38 JO |
7436 | static struct nla_policy |
7437 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7438 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7439 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7440 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7441 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7442 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7443 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7444 | }; |
7445 | ||
84f10708 | 7446 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7447 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7448 | { |
7449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7450 | struct wireless_dev *wdev; | |
7451 | struct net_device *dev = info->user_ptr[1]; | |
7452 | ||
d9d8b019 | 7453 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7454 | return -EINVAL; |
7455 | ||
7456 | wdev = dev->ieee80211_ptr; | |
7457 | ||
7458 | if (!rdev->ops->set_cqm_txe_config) | |
7459 | return -EOPNOTSUPP; | |
7460 | ||
7461 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7462 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7463 | return -EOPNOTSUPP; | |
7464 | ||
e35e4d28 | 7465 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7466 | } |
7467 | ||
d6dc1a38 JO |
7468 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7469 | s32 threshold, u32 hysteresis) | |
7470 | { | |
4c476991 | 7471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7472 | struct wireless_dev *wdev; |
4c476991 | 7473 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7474 | |
7475 | if (threshold > 0) | |
7476 | return -EINVAL; | |
7477 | ||
d6dc1a38 JO |
7478 | wdev = dev->ieee80211_ptr; |
7479 | ||
4c476991 JB |
7480 | if (!rdev->ops->set_cqm_rssi_config) |
7481 | return -EOPNOTSUPP; | |
d6dc1a38 | 7482 | |
074ac8df | 7483 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7484 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7485 | return -EOPNOTSUPP; | |
d6dc1a38 | 7486 | |
e35e4d28 | 7487 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7488 | } |
7489 | ||
7490 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7491 | { | |
7492 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7493 | struct nlattr *cqm; | |
7494 | int err; | |
7495 | ||
7496 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7497 | if (!cqm) { | |
7498 | err = -EINVAL; | |
7499 | goto out; | |
7500 | } | |
7501 | ||
7502 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7503 | nl80211_attr_cqm_policy); | |
7504 | if (err) | |
7505 | goto out; | |
7506 | ||
7507 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7508 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7509 | s32 threshold; | |
7510 | u32 hysteresis; | |
7511 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7512 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7513 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7514 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7515 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7516 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7517 | u32 rate, pkts, intvl; | |
7518 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7519 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7520 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7521 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7522 | } else |
7523 | err = -EINVAL; | |
7524 | ||
7525 | out: | |
7526 | return err; | |
7527 | } | |
7528 | ||
29cbe68c JB |
7529 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7530 | { | |
7531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7532 | struct net_device *dev = info->user_ptr[1]; | |
7533 | struct mesh_config cfg; | |
c80d545d | 7534 | struct mesh_setup setup; |
29cbe68c JB |
7535 | int err; |
7536 | ||
7537 | /* start with default */ | |
7538 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7539 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7540 | |
24bdd9f4 | 7541 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7542 | /* and parse parameters if given */ |
24bdd9f4 | 7543 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7544 | if (err) |
7545 | return err; | |
7546 | } | |
7547 | ||
7548 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7549 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7550 | return -EINVAL; | |
7551 | ||
c80d545d JC |
7552 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7553 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7554 | ||
4bb62344 CYY |
7555 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7556 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7557 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7558 | return -EINVAL; | |
7559 | ||
9bdbf04d MP |
7560 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7561 | setup.beacon_interval = | |
7562 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7563 | if (setup.beacon_interval < 10 || | |
7564 | setup.beacon_interval > 10000) | |
7565 | return -EINVAL; | |
7566 | } | |
7567 | ||
7568 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7569 | setup.dtim_period = | |
7570 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7571 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7572 | return -EINVAL; | |
7573 | } | |
7574 | ||
c80d545d JC |
7575 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7576 | /* parse additional setup parameters if given */ | |
7577 | err = nl80211_parse_mesh_setup(info, &setup); | |
7578 | if (err) | |
7579 | return err; | |
7580 | } | |
7581 | ||
d37bb18a TP |
7582 | if (setup.user_mpm) |
7583 | cfg.auto_open_plinks = false; | |
7584 | ||
cc1d2806 | 7585 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7586 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7587 | if (err) | |
7588 | return err; | |
cc1d2806 JB |
7589 | } else { |
7590 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7591 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7592 | } |
7593 | ||
ffb3cf30 AN |
7594 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7595 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7596 | int n_rates = | |
7597 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7598 | struct ieee80211_supported_band *sband; | |
7599 | ||
7600 | if (!setup.chandef.chan) | |
7601 | return -EINVAL; | |
7602 | ||
7603 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
7604 | ||
7605 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
7606 | &setup.basic_rates); | |
7607 | if (err) | |
7608 | return err; | |
7609 | } | |
7610 | ||
c80d545d | 7611 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7612 | } |
7613 | ||
7614 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7615 | { | |
7616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7617 | struct net_device *dev = info->user_ptr[1]; | |
7618 | ||
7619 | return cfg80211_leave_mesh(rdev, dev); | |
7620 | } | |
7621 | ||
dfb89c56 | 7622 | #ifdef CONFIG_PM |
bb92d199 AK |
7623 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7624 | struct cfg80211_registered_device *rdev) | |
7625 | { | |
6abb9cb9 | 7626 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
7627 | struct nlattr *nl_pats, *nl_pat; |
7628 | int i, pat_len; | |
7629 | ||
6abb9cb9 | 7630 | if (!wowlan->n_patterns) |
bb92d199 AK |
7631 | return 0; |
7632 | ||
7633 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7634 | if (!nl_pats) | |
7635 | return -ENOBUFS; | |
7636 | ||
6abb9cb9 | 7637 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
7638 | nl_pat = nla_nest_start(msg, i + 1); |
7639 | if (!nl_pat) | |
7640 | return -ENOBUFS; | |
6abb9cb9 | 7641 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 7642 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 7643 | wowlan->patterns[i].mask) || |
50ac6607 AK |
7644 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
7645 | wowlan->patterns[i].pattern) || | |
7646 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 7647 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
7648 | return -ENOBUFS; |
7649 | nla_nest_end(msg, nl_pat); | |
7650 | } | |
7651 | nla_nest_end(msg, nl_pats); | |
7652 | ||
7653 | return 0; | |
7654 | } | |
7655 | ||
2a0e047e JB |
7656 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7657 | struct cfg80211_wowlan_tcp *tcp) | |
7658 | { | |
7659 | struct nlattr *nl_tcp; | |
7660 | ||
7661 | if (!tcp) | |
7662 | return 0; | |
7663 | ||
7664 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7665 | if (!nl_tcp) | |
7666 | return -ENOBUFS; | |
7667 | ||
7668 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7669 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7670 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7671 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7672 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7673 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7674 | tcp->payload_len, tcp->payload) || | |
7675 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7676 | tcp->data_interval) || | |
7677 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7678 | tcp->wake_len, tcp->wake_data) || | |
7679 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7680 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7681 | return -ENOBUFS; | |
7682 | ||
7683 | if (tcp->payload_seq.len && | |
7684 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7685 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7686 | return -ENOBUFS; | |
7687 | ||
7688 | if (tcp->payload_tok.len && | |
7689 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7690 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7691 | &tcp->payload_tok)) | |
7692 | return -ENOBUFS; | |
7693 | ||
e248ad30 JB |
7694 | nla_nest_end(msg, nl_tcp); |
7695 | ||
2a0e047e JB |
7696 | return 0; |
7697 | } | |
7698 | ||
ff1b6e69 JB |
7699 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7700 | { | |
7701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7702 | struct sk_buff *msg; | |
7703 | void *hdr; | |
2a0e047e | 7704 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7705 | |
964dc9e2 | 7706 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
7707 | return -EOPNOTSUPP; |
7708 | ||
6abb9cb9 | 7709 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 7710 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
7711 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
7712 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
7713 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
7714 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
7715 | } |
7716 | ||
7717 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7718 | if (!msg) |
7719 | return -ENOMEM; | |
7720 | ||
15e47304 | 7721 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7722 | NL80211_CMD_GET_WOWLAN); |
7723 | if (!hdr) | |
7724 | goto nla_put_failure; | |
7725 | ||
6abb9cb9 | 7726 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
7727 | struct nlattr *nl_wowlan; |
7728 | ||
7729 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7730 | if (!nl_wowlan) | |
7731 | goto nla_put_failure; | |
7732 | ||
6abb9cb9 | 7733 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 7734 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 7735 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 7736 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 7737 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 7738 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 7739 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 7740 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 7741 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 7742 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 7743 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 7744 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 7745 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
7746 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
7747 | goto nla_put_failure; | |
2a0e047e | 7748 | |
bb92d199 AK |
7749 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7750 | goto nla_put_failure; | |
2a0e047e | 7751 | |
6abb9cb9 JB |
7752 | if (nl80211_send_wowlan_tcp(msg, |
7753 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
7754 | goto nla_put_failure; |
7755 | ||
ff1b6e69 JB |
7756 | nla_nest_end(msg, nl_wowlan); |
7757 | } | |
7758 | ||
7759 | genlmsg_end(msg, hdr); | |
7760 | return genlmsg_reply(msg, info); | |
7761 | ||
7762 | nla_put_failure: | |
7763 | nlmsg_free(msg); | |
7764 | return -ENOBUFS; | |
7765 | } | |
7766 | ||
2a0e047e JB |
7767 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7768 | struct nlattr *attr, | |
7769 | struct cfg80211_wowlan *trig) | |
7770 | { | |
7771 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7772 | struct cfg80211_wowlan_tcp *cfg; | |
7773 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7774 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7775 | u32 size; | |
7776 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7777 | int err, port; | |
7778 | ||
964dc9e2 | 7779 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
7780 | return -EINVAL; |
7781 | ||
7782 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7783 | nla_data(attr), nla_len(attr), | |
7784 | nl80211_wowlan_tcp_policy); | |
7785 | if (err) | |
7786 | return err; | |
7787 | ||
7788 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7789 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7790 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7791 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7792 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7793 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7794 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7795 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7796 | return -EINVAL; | |
7797 | ||
7798 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 7799 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
7800 | return -EINVAL; |
7801 | ||
7802 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 7803 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 7804 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
7805 | return -EINVAL; |
7806 | ||
7807 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 7808 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
7809 | return -EINVAL; |
7810 | ||
7811 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7812 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7813 | return -EINVAL; | |
7814 | ||
7815 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7816 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7817 | ||
7818 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7819 | tokens_size = tokln - sizeof(*tok); | |
7820 | ||
7821 | if (!tok->len || tokens_size % tok->len) | |
7822 | return -EINVAL; | |
964dc9e2 | 7823 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 7824 | return -EINVAL; |
964dc9e2 | 7825 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 7826 | return -EINVAL; |
964dc9e2 | 7827 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 7828 | return -EINVAL; |
964dc9e2 | 7829 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
7830 | return -EINVAL; |
7831 | if (tok->offset + tok->len > data_size) | |
7832 | return -EINVAL; | |
7833 | } | |
7834 | ||
7835 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7836 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 7837 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
7838 | return -EINVAL; |
7839 | if (seq->len == 0 || seq->len > 4) | |
7840 | return -EINVAL; | |
7841 | if (seq->len + seq->offset > data_size) | |
7842 | return -EINVAL; | |
7843 | } | |
7844 | ||
7845 | size = sizeof(*cfg); | |
7846 | size += data_size; | |
7847 | size += wake_size + wake_mask_size; | |
7848 | size += tokens_size; | |
7849 | ||
7850 | cfg = kzalloc(size, GFP_KERNEL); | |
7851 | if (!cfg) | |
7852 | return -ENOMEM; | |
7853 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7854 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7855 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7856 | ETH_ALEN); | |
7857 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7858 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7859 | else | |
7860 | port = 0; | |
7861 | #ifdef CONFIG_INET | |
7862 | /* allocate a socket and port for it and use it */ | |
7863 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7864 | IPPROTO_TCP, &cfg->sock, 1); | |
7865 | if (err) { | |
7866 | kfree(cfg); | |
7867 | return err; | |
7868 | } | |
7869 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7870 | sock_release(cfg->sock); | |
7871 | kfree(cfg); | |
7872 | return -EADDRINUSE; | |
7873 | } | |
7874 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7875 | #else | |
7876 | if (!port) { | |
7877 | kfree(cfg); | |
7878 | return -EINVAL; | |
7879 | } | |
7880 | cfg->src_port = port; | |
7881 | #endif | |
7882 | ||
7883 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7884 | cfg->payload_len = data_size; | |
7885 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7886 | memcpy((void *)cfg->payload, | |
7887 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7888 | data_size); | |
7889 | if (seq) | |
7890 | cfg->payload_seq = *seq; | |
7891 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7892 | cfg->wake_len = wake_size; | |
7893 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7894 | memcpy((void *)cfg->wake_data, | |
7895 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7896 | wake_size); | |
7897 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7898 | data_size + wake_size; | |
7899 | memcpy((void *)cfg->wake_mask, | |
7900 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7901 | wake_mask_size); | |
7902 | if (tok) { | |
7903 | cfg->tokens_size = tokens_size; | |
7904 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7905 | } | |
7906 | ||
7907 | trig->tcp = cfg; | |
7908 | ||
7909 | return 0; | |
7910 | } | |
7911 | ||
ff1b6e69 JB |
7912 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7913 | { | |
7914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7915 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7916 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7917 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 7918 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 7919 | int err, i; |
6abb9cb9 | 7920 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 7921 | |
964dc9e2 | 7922 | if (!wowlan) |
ff1b6e69 JB |
7923 | return -EOPNOTSUPP; |
7924 | ||
ae33bd81 JB |
7925 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7926 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 7927 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
7928 | goto set_wakeup; |
7929 | } | |
ff1b6e69 JB |
7930 | |
7931 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7932 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7933 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7934 | nl80211_wowlan_policy); | |
7935 | if (err) | |
7936 | return err; | |
7937 | ||
7938 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7939 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7940 | return -EINVAL; | |
7941 | new_triggers.any = true; | |
7942 | } | |
7943 | ||
7944 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7945 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7946 | return -EINVAL; | |
7947 | new_triggers.disconnect = true; | |
7948 | } | |
7949 | ||
7950 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7951 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7952 | return -EINVAL; | |
7953 | new_triggers.magic_pkt = true; | |
7954 | } | |
7955 | ||
77dbbb13 JB |
7956 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7957 | return -EINVAL; | |
7958 | ||
7959 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7960 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7961 | return -EINVAL; | |
7962 | new_triggers.gtk_rekey_failure = true; | |
7963 | } | |
7964 | ||
7965 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7966 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7967 | return -EINVAL; | |
7968 | new_triggers.eap_identity_req = true; | |
7969 | } | |
7970 | ||
7971 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7972 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7973 | return -EINVAL; | |
7974 | new_triggers.four_way_handshake = true; | |
7975 | } | |
7976 | ||
7977 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7978 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7979 | return -EINVAL; | |
7980 | new_triggers.rfkill_release = true; | |
7981 | } | |
7982 | ||
ff1b6e69 JB |
7983 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7984 | struct nlattr *pat; | |
7985 | int n_patterns = 0; | |
bb92d199 | 7986 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 7987 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
7988 | |
7989 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7990 | rem) | |
7991 | n_patterns++; | |
7992 | if (n_patterns > wowlan->n_patterns) | |
7993 | return -EINVAL; | |
7994 | ||
7995 | new_triggers.patterns = kcalloc(n_patterns, | |
7996 | sizeof(new_triggers.patterns[0]), | |
7997 | GFP_KERNEL); | |
7998 | if (!new_triggers.patterns) | |
7999 | return -ENOMEM; | |
8000 | ||
8001 | new_triggers.n_patterns = n_patterns; | |
8002 | i = 0; | |
8003 | ||
8004 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8005 | rem) { | |
50ac6607 AK |
8006 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8007 | nla_len(pat), NULL); | |
ff1b6e69 | 8008 | err = -EINVAL; |
50ac6607 AK |
8009 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8010 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8011 | goto error; |
50ac6607 | 8012 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8013 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8014 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8015 | goto error; |
8016 | if (pat_len > wowlan->pattern_max_len || | |
8017 | pat_len < wowlan->pattern_min_len) | |
8018 | goto error; | |
8019 | ||
50ac6607 | 8020 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8021 | pkt_offset = 0; |
8022 | else | |
8023 | pkt_offset = nla_get_u32( | |
50ac6607 | 8024 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8025 | if (pkt_offset > wowlan->max_pkt_offset) |
8026 | goto error; | |
8027 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8028 | ||
ff1b6e69 JB |
8029 | new_triggers.patterns[i].mask = |
8030 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8031 | if (!new_triggers.patterns[i].mask) { | |
8032 | err = -ENOMEM; | |
8033 | goto error; | |
8034 | } | |
8035 | new_triggers.patterns[i].pattern = | |
8036 | new_triggers.patterns[i].mask + mask_len; | |
8037 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8038 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8039 | mask_len); |
8040 | new_triggers.patterns[i].pattern_len = pat_len; | |
8041 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8042 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8043 | pat_len); |
8044 | i++; | |
8045 | } | |
8046 | } | |
8047 | ||
2a0e047e JB |
8048 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8049 | err = nl80211_parse_wowlan_tcp( | |
8050 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8051 | &new_triggers); | |
8052 | if (err) | |
8053 | goto error; | |
8054 | } | |
8055 | ||
ae33bd81 JB |
8056 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8057 | if (!ntrig) { | |
8058 | err = -ENOMEM; | |
8059 | goto error; | |
ff1b6e69 | 8060 | } |
ae33bd81 | 8061 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8062 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8063 | |
ae33bd81 | 8064 | set_wakeup: |
6abb9cb9 JB |
8065 | if (rdev->ops->set_wakeup && |
8066 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8067 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8068 | |
ff1b6e69 JB |
8069 | return 0; |
8070 | error: | |
8071 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8072 | kfree(new_triggers.patterns[i].mask); | |
8073 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8074 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8075 | sock_release(new_triggers.tcp->sock); | |
8076 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8077 | return err; |
8078 | } | |
dfb89c56 | 8079 | #endif |
ff1b6e69 | 8080 | |
be29b99a AK |
8081 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8082 | struct cfg80211_registered_device *rdev) | |
8083 | { | |
8084 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8085 | int i, j, pat_len; | |
8086 | struct cfg80211_coalesce_rules *rule; | |
8087 | ||
8088 | if (!rdev->coalesce->n_rules) | |
8089 | return 0; | |
8090 | ||
8091 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8092 | if (!nl_rules) | |
8093 | return -ENOBUFS; | |
8094 | ||
8095 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8096 | nl_rule = nla_nest_start(msg, i + 1); | |
8097 | if (!nl_rule) | |
8098 | return -ENOBUFS; | |
8099 | ||
8100 | rule = &rdev->coalesce->rules[i]; | |
8101 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8102 | rule->delay)) | |
8103 | return -ENOBUFS; | |
8104 | ||
8105 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8106 | rule->condition)) | |
8107 | return -ENOBUFS; | |
8108 | ||
8109 | nl_pats = nla_nest_start(msg, | |
8110 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8111 | if (!nl_pats) | |
8112 | return -ENOBUFS; | |
8113 | ||
8114 | for (j = 0; j < rule->n_patterns; j++) { | |
8115 | nl_pat = nla_nest_start(msg, j + 1); | |
8116 | if (!nl_pat) | |
8117 | return -ENOBUFS; | |
8118 | pat_len = rule->patterns[j].pattern_len; | |
8119 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8120 | DIV_ROUND_UP(pat_len, 8), | |
8121 | rule->patterns[j].mask) || | |
8122 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8123 | rule->patterns[j].pattern) || | |
8124 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8125 | rule->patterns[j].pkt_offset)) | |
8126 | return -ENOBUFS; | |
8127 | nla_nest_end(msg, nl_pat); | |
8128 | } | |
8129 | nla_nest_end(msg, nl_pats); | |
8130 | nla_nest_end(msg, nl_rule); | |
8131 | } | |
8132 | nla_nest_end(msg, nl_rules); | |
8133 | ||
8134 | return 0; | |
8135 | } | |
8136 | ||
8137 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8138 | { | |
8139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8140 | struct sk_buff *msg; | |
8141 | void *hdr; | |
8142 | ||
8143 | if (!rdev->wiphy.coalesce) | |
8144 | return -EOPNOTSUPP; | |
8145 | ||
8146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8147 | if (!msg) | |
8148 | return -ENOMEM; | |
8149 | ||
8150 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8151 | NL80211_CMD_GET_COALESCE); | |
8152 | if (!hdr) | |
8153 | goto nla_put_failure; | |
8154 | ||
8155 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8156 | goto nla_put_failure; | |
8157 | ||
8158 | genlmsg_end(msg, hdr); | |
8159 | return genlmsg_reply(msg, info); | |
8160 | ||
8161 | nla_put_failure: | |
8162 | nlmsg_free(msg); | |
8163 | return -ENOBUFS; | |
8164 | } | |
8165 | ||
8166 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8167 | { | |
8168 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8169 | int i, j; | |
8170 | struct cfg80211_coalesce_rules *rule; | |
8171 | ||
8172 | if (!coalesce) | |
8173 | return; | |
8174 | ||
8175 | for (i = 0; i < coalesce->n_rules; i++) { | |
8176 | rule = &coalesce->rules[i]; | |
8177 | for (j = 0; j < rule->n_patterns; j++) | |
8178 | kfree(rule->patterns[j].mask); | |
8179 | kfree(rule->patterns); | |
8180 | } | |
8181 | kfree(coalesce->rules); | |
8182 | kfree(coalesce); | |
8183 | rdev->coalesce = NULL; | |
8184 | } | |
8185 | ||
8186 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8187 | struct nlattr *rule, | |
8188 | struct cfg80211_coalesce_rules *new_rule) | |
8189 | { | |
8190 | int err, i; | |
8191 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8192 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8193 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8194 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8195 | ||
8196 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8197 | nla_len(rule), nl80211_coalesce_policy); | |
8198 | if (err) | |
8199 | return err; | |
8200 | ||
8201 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8202 | new_rule->delay = | |
8203 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8204 | if (new_rule->delay > coalesce->max_delay) | |
8205 | return -EINVAL; | |
8206 | ||
8207 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8208 | new_rule->condition = | |
8209 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8210 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8211 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8212 | return -EINVAL; | |
8213 | ||
8214 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8215 | return -EINVAL; | |
8216 | ||
8217 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8218 | rem) | |
8219 | n_patterns++; | |
8220 | if (n_patterns > coalesce->n_patterns) | |
8221 | return -EINVAL; | |
8222 | ||
8223 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8224 | GFP_KERNEL); | |
8225 | if (!new_rule->patterns) | |
8226 | return -ENOMEM; | |
8227 | ||
8228 | new_rule->n_patterns = n_patterns; | |
8229 | i = 0; | |
8230 | ||
8231 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8232 | rem) { | |
8233 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8234 | nla_len(pat), NULL); | |
8235 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8236 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8237 | return -EINVAL; | |
8238 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8239 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8240 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8241 | return -EINVAL; | |
8242 | if (pat_len > coalesce->pattern_max_len || | |
8243 | pat_len < coalesce->pattern_min_len) | |
8244 | return -EINVAL; | |
8245 | ||
8246 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8247 | pkt_offset = 0; | |
8248 | else | |
8249 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8250 | if (pkt_offset > coalesce->max_pkt_offset) | |
8251 | return -EINVAL; | |
8252 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8253 | ||
8254 | new_rule->patterns[i].mask = | |
8255 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8256 | if (!new_rule->patterns[i].mask) | |
8257 | return -ENOMEM; | |
8258 | new_rule->patterns[i].pattern = | |
8259 | new_rule->patterns[i].mask + mask_len; | |
8260 | memcpy(new_rule->patterns[i].mask, | |
8261 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8262 | new_rule->patterns[i].pattern_len = pat_len; | |
8263 | memcpy(new_rule->patterns[i].pattern, | |
8264 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8265 | i++; | |
8266 | } | |
8267 | ||
8268 | return 0; | |
8269 | } | |
8270 | ||
8271 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8272 | { | |
8273 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8274 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8275 | struct cfg80211_coalesce new_coalesce = {}; | |
8276 | struct cfg80211_coalesce *n_coalesce; | |
8277 | int err, rem_rule, n_rules = 0, i, j; | |
8278 | struct nlattr *rule; | |
8279 | struct cfg80211_coalesce_rules *tmp_rule; | |
8280 | ||
8281 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8282 | return -EOPNOTSUPP; | |
8283 | ||
8284 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8285 | cfg80211_rdev_free_coalesce(rdev); | |
8286 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8287 | return 0; | |
8288 | } | |
8289 | ||
8290 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8291 | rem_rule) | |
8292 | n_rules++; | |
8293 | if (n_rules > coalesce->n_rules) | |
8294 | return -EINVAL; | |
8295 | ||
8296 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8297 | GFP_KERNEL); | |
8298 | if (!new_coalesce.rules) | |
8299 | return -ENOMEM; | |
8300 | ||
8301 | new_coalesce.n_rules = n_rules; | |
8302 | i = 0; | |
8303 | ||
8304 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8305 | rem_rule) { | |
8306 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8307 | &new_coalesce.rules[i]); | |
8308 | if (err) | |
8309 | goto error; | |
8310 | ||
8311 | i++; | |
8312 | } | |
8313 | ||
8314 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8315 | if (err) | |
8316 | goto error; | |
8317 | ||
8318 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8319 | if (!n_coalesce) { | |
8320 | err = -ENOMEM; | |
8321 | goto error; | |
8322 | } | |
8323 | cfg80211_rdev_free_coalesce(rdev); | |
8324 | rdev->coalesce = n_coalesce; | |
8325 | ||
8326 | return 0; | |
8327 | error: | |
8328 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8329 | tmp_rule = &new_coalesce.rules[i]; | |
8330 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8331 | kfree(tmp_rule->patterns[j].mask); | |
8332 | kfree(tmp_rule->patterns); | |
8333 | } | |
8334 | kfree(new_coalesce.rules); | |
8335 | ||
8336 | return err; | |
8337 | } | |
8338 | ||
e5497d76 JB |
8339 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8340 | { | |
8341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8342 | struct net_device *dev = info->user_ptr[1]; | |
8343 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8344 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8345 | struct cfg80211_gtk_rekey_data rekey_data; | |
8346 | int err; | |
8347 | ||
8348 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8349 | return -EINVAL; | |
8350 | ||
8351 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8352 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8353 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8354 | nl80211_rekey_policy); | |
8355 | if (err) | |
8356 | return err; | |
8357 | ||
8358 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8359 | return -ERANGE; | |
8360 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8361 | return -ERANGE; | |
8362 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8363 | return -ERANGE; | |
8364 | ||
8365 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8366 | NL80211_KEK_LEN); | |
8367 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8368 | NL80211_KCK_LEN); | |
8369 | memcpy(rekey_data.replay_ctr, | |
8370 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8371 | NL80211_REPLAY_CTR_LEN); | |
8372 | ||
8373 | wdev_lock(wdev); | |
8374 | if (!wdev->current_bss) { | |
8375 | err = -ENOTCONN; | |
8376 | goto out; | |
8377 | } | |
8378 | ||
8379 | if (!rdev->ops->set_rekey_data) { | |
8380 | err = -EOPNOTSUPP; | |
8381 | goto out; | |
8382 | } | |
8383 | ||
e35e4d28 | 8384 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8385 | out: |
8386 | wdev_unlock(wdev); | |
8387 | return err; | |
8388 | } | |
8389 | ||
28946da7 JB |
8390 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8391 | struct genl_info *info) | |
8392 | { | |
8393 | struct net_device *dev = info->user_ptr[1]; | |
8394 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8395 | ||
8396 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8397 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8398 | return -EINVAL; | |
8399 | ||
15e47304 | 8400 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8401 | return -EBUSY; |
8402 | ||
15e47304 | 8403 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8404 | return 0; |
8405 | } | |
8406 | ||
7f6cf311 JB |
8407 | static int nl80211_probe_client(struct sk_buff *skb, |
8408 | struct genl_info *info) | |
8409 | { | |
8410 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8411 | struct net_device *dev = info->user_ptr[1]; | |
8412 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8413 | struct sk_buff *msg; | |
8414 | void *hdr; | |
8415 | const u8 *addr; | |
8416 | u64 cookie; | |
8417 | int err; | |
8418 | ||
8419 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8420 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8421 | return -EOPNOTSUPP; | |
8422 | ||
8423 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8424 | return -EINVAL; | |
8425 | ||
8426 | if (!rdev->ops->probe_client) | |
8427 | return -EOPNOTSUPP; | |
8428 | ||
8429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8430 | if (!msg) | |
8431 | return -ENOMEM; | |
8432 | ||
15e47304 | 8433 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8434 | NL80211_CMD_PROBE_CLIENT); |
8435 | ||
8436 | if (IS_ERR(hdr)) { | |
8437 | err = PTR_ERR(hdr); | |
8438 | goto free_msg; | |
8439 | } | |
8440 | ||
8441 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8442 | ||
e35e4d28 | 8443 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8444 | if (err) |
8445 | goto free_msg; | |
8446 | ||
9360ffd1 DM |
8447 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8448 | goto nla_put_failure; | |
7f6cf311 JB |
8449 | |
8450 | genlmsg_end(msg, hdr); | |
8451 | ||
8452 | return genlmsg_reply(msg, info); | |
8453 | ||
8454 | nla_put_failure: | |
8455 | err = -ENOBUFS; | |
8456 | free_msg: | |
8457 | nlmsg_free(msg); | |
8458 | return err; | |
8459 | } | |
8460 | ||
5e760230 JB |
8461 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8462 | { | |
8463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8464 | struct cfg80211_beacon_registration *reg, *nreg; |
8465 | int rv; | |
5e760230 JB |
8466 | |
8467 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8468 | return -EOPNOTSUPP; | |
8469 | ||
37c73b5f BG |
8470 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8471 | if (!nreg) | |
8472 | return -ENOMEM; | |
8473 | ||
8474 | /* First, check if already registered. */ | |
8475 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8476 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8477 | if (reg->nlportid == info->snd_portid) { | |
8478 | rv = -EALREADY; | |
8479 | goto out_err; | |
8480 | } | |
8481 | } | |
8482 | /* Add it to the list */ | |
8483 | nreg->nlportid = info->snd_portid; | |
8484 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8485 | |
37c73b5f | 8486 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8487 | |
8488 | return 0; | |
37c73b5f BG |
8489 | out_err: |
8490 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8491 | kfree(nreg); | |
8492 | return rv; | |
5e760230 JB |
8493 | } |
8494 | ||
98104fde JB |
8495 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8496 | { | |
8497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8498 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8499 | int err; | |
8500 | ||
8501 | if (!rdev->ops->start_p2p_device) | |
8502 | return -EOPNOTSUPP; | |
8503 | ||
8504 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8505 | return -EOPNOTSUPP; | |
8506 | ||
8507 | if (wdev->p2p_started) | |
8508 | return 0; | |
8509 | ||
98104fde | 8510 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8511 | if (err) |
8512 | return err; | |
8513 | ||
eeb126e9 | 8514 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8515 | if (err) |
8516 | return err; | |
8517 | ||
8518 | wdev->p2p_started = true; | |
98104fde | 8519 | rdev->opencount++; |
98104fde JB |
8520 | |
8521 | return 0; | |
8522 | } | |
8523 | ||
8524 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8525 | { | |
8526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8527 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8528 | ||
8529 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8530 | return -EOPNOTSUPP; | |
8531 | ||
8532 | if (!rdev->ops->stop_p2p_device) | |
8533 | return -EOPNOTSUPP; | |
8534 | ||
f9f47529 | 8535 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8536 | |
8537 | return 0; | |
8538 | } | |
8539 | ||
3713b4e3 JB |
8540 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8541 | struct genl_info *info) | |
8542 | { | |
8543 | void *hdr; | |
8544 | struct sk_buff *msg; | |
8545 | ||
8546 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8547 | if (!msg) | |
8548 | return -ENOMEM; | |
8549 | ||
8550 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8551 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8552 | if (!hdr) | |
8553 | goto nla_put_failure; | |
8554 | ||
8555 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8556 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8557 | goto nla_put_failure; | |
8558 | ||
8559 | genlmsg_end(msg, hdr); | |
8560 | return genlmsg_reply(msg, info); | |
8561 | ||
8562 | nla_put_failure: | |
8563 | kfree_skb(msg); | |
8564 | return -ENOBUFS; | |
8565 | } | |
8566 | ||
355199e0 JM |
8567 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8568 | { | |
8569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8570 | struct cfg80211_update_ft_ies_params ft_params; | |
8571 | struct net_device *dev = info->user_ptr[1]; | |
8572 | ||
8573 | if (!rdev->ops->update_ft_ies) | |
8574 | return -EOPNOTSUPP; | |
8575 | ||
8576 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8577 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8578 | return -EINVAL; | |
8579 | ||
8580 | memset(&ft_params, 0, sizeof(ft_params)); | |
8581 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8582 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8583 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8584 | ||
8585 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8586 | } | |
8587 | ||
5de17984 AS |
8588 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8589 | struct genl_info *info) | |
8590 | { | |
8591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8592 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8593 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8594 | u16 duration; | |
8595 | int ret; | |
8596 | ||
8597 | if (!rdev->ops->crit_proto_start) | |
8598 | return -EOPNOTSUPP; | |
8599 | ||
8600 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8601 | return -EINVAL; | |
8602 | ||
8603 | if (rdev->crit_proto_nlportid) | |
8604 | return -EBUSY; | |
8605 | ||
8606 | /* determine protocol if provided */ | |
8607 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8608 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8609 | ||
8610 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8611 | return -EINVAL; | |
8612 | ||
8613 | /* timeout must be provided */ | |
8614 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8615 | return -EINVAL; | |
8616 | ||
8617 | duration = | |
8618 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8619 | ||
8620 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8621 | return -ERANGE; | |
8622 | ||
8623 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8624 | if (!ret) | |
8625 | rdev->crit_proto_nlportid = info->snd_portid; | |
8626 | ||
8627 | return ret; | |
8628 | } | |
8629 | ||
8630 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8631 | struct genl_info *info) | |
8632 | { | |
8633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8634 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8635 | ||
8636 | if (!rdev->ops->crit_proto_stop) | |
8637 | return -EOPNOTSUPP; | |
8638 | ||
8639 | if (rdev->crit_proto_nlportid) { | |
8640 | rdev->crit_proto_nlportid = 0; | |
8641 | rdev_crit_proto_stop(rdev, wdev); | |
8642 | } | |
8643 | return 0; | |
8644 | } | |
8645 | ||
4c476991 JB |
8646 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8647 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8648 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8649 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8650 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8651 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8652 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8653 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8654 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8655 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8656 | |
8657 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8658 | struct genl_info *info) | |
8659 | { | |
8660 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8661 | struct wireless_dev *wdev; |
4c476991 | 8662 | struct net_device *dev; |
4c476991 JB |
8663 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8664 | ||
8665 | if (rtnl) | |
8666 | rtnl_lock(); | |
8667 | ||
8668 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8669 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8670 | if (IS_ERR(rdev)) { |
8671 | if (rtnl) | |
8672 | rtnl_unlock(); | |
8673 | return PTR_ERR(rdev); | |
8674 | } | |
8675 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8676 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8677 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
8678 | ASSERT_RTNL(); |
8679 | ||
89a54e48 JB |
8680 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
8681 | info->attrs); | |
8682 | if (IS_ERR(wdev)) { | |
4c476991 JB |
8683 | if (rtnl) |
8684 | rtnl_unlock(); | |
89a54e48 | 8685 | return PTR_ERR(wdev); |
4c476991 | 8686 | } |
89a54e48 | 8687 | |
89a54e48 JB |
8688 | dev = wdev->netdev; |
8689 | rdev = wiphy_to_dev(wdev->wiphy); | |
8690 | ||
1bf614ef JB |
8691 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8692 | if (!dev) { | |
1bf614ef JB |
8693 | if (rtnl) |
8694 | rtnl_unlock(); | |
8695 | return -EINVAL; | |
8696 | } | |
8697 | ||
8698 | info->user_ptr[1] = dev; | |
8699 | } else { | |
8700 | info->user_ptr[1] = wdev; | |
41265714 | 8701 | } |
1bf614ef JB |
8702 | |
8703 | if (dev) { | |
8704 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8705 | !netif_running(dev)) { | |
1bf614ef JB |
8706 | if (rtnl) |
8707 | rtnl_unlock(); | |
8708 | return -ENETDOWN; | |
8709 | } | |
8710 | ||
8711 | dev_hold(dev); | |
98104fde JB |
8712 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8713 | if (!wdev->p2p_started) { | |
98104fde JB |
8714 | if (rtnl) |
8715 | rtnl_unlock(); | |
8716 | return -ENETDOWN; | |
8717 | } | |
41265714 | 8718 | } |
89a54e48 | 8719 | |
4c476991 | 8720 | info->user_ptr[0] = rdev; |
4c476991 JB |
8721 | } |
8722 | ||
8723 | return 0; | |
8724 | } | |
8725 | ||
8726 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8727 | struct genl_info *info) | |
8728 | { | |
1bf614ef JB |
8729 | if (info->user_ptr[1]) { |
8730 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8731 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8732 | ||
8733 | if (wdev->netdev) | |
8734 | dev_put(wdev->netdev); | |
8735 | } else { | |
8736 | dev_put(info->user_ptr[1]); | |
8737 | } | |
8738 | } | |
4c476991 JB |
8739 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8740 | rtnl_unlock(); | |
8741 | } | |
8742 | ||
55682965 JB |
8743 | static struct genl_ops nl80211_ops[] = { |
8744 | { | |
8745 | .cmd = NL80211_CMD_GET_WIPHY, | |
8746 | .doit = nl80211_get_wiphy, | |
8747 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 8748 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
8749 | .policy = nl80211_policy, |
8750 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8751 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8752 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8753 | }, |
8754 | { | |
8755 | .cmd = NL80211_CMD_SET_WIPHY, | |
8756 | .doit = nl80211_set_wiphy, | |
8757 | .policy = nl80211_policy, | |
8758 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8759 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8760 | }, |
8761 | { | |
8762 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8763 | .doit = nl80211_get_interface, | |
8764 | .dumpit = nl80211_dump_interface, | |
8765 | .policy = nl80211_policy, | |
8766 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8767 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
8768 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8769 | }, |
8770 | { | |
8771 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8772 | .doit = nl80211_set_interface, | |
8773 | .policy = nl80211_policy, | |
8774 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8775 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8776 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8777 | }, |
8778 | { | |
8779 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8780 | .doit = nl80211_new_interface, | |
8781 | .policy = nl80211_policy, | |
8782 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8783 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8784 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8785 | }, |
8786 | { | |
8787 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8788 | .doit = nl80211_del_interface, | |
8789 | .policy = nl80211_policy, | |
41ade00f | 8790 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8791 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8792 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8793 | }, |
8794 | { | |
8795 | .cmd = NL80211_CMD_GET_KEY, | |
8796 | .doit = nl80211_get_key, | |
8797 | .policy = nl80211_policy, | |
8798 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8800 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8801 | }, |
8802 | { | |
8803 | .cmd = NL80211_CMD_SET_KEY, | |
8804 | .doit = nl80211_set_key, | |
8805 | .policy = nl80211_policy, | |
8806 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8807 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8808 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8809 | }, |
8810 | { | |
8811 | .cmd = NL80211_CMD_NEW_KEY, | |
8812 | .doit = nl80211_new_key, | |
8813 | .policy = nl80211_policy, | |
8814 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8815 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8816 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8817 | }, |
8818 | { | |
8819 | .cmd = NL80211_CMD_DEL_KEY, | |
8820 | .doit = nl80211_del_key, | |
8821 | .policy = nl80211_policy, | |
55682965 | 8822 | .flags = GENL_ADMIN_PERM, |
41265714 | 8823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8824 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8825 | }, |
ed1b6cc7 JB |
8826 | { |
8827 | .cmd = NL80211_CMD_SET_BEACON, | |
8828 | .policy = nl80211_policy, | |
8829 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8830 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8832 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8833 | }, |
8834 | { | |
8860020e | 8835 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8836 | .policy = nl80211_policy, |
8837 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8838 | .doit = nl80211_start_ap, |
2b5f8b0b | 8839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8840 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8841 | }, |
8842 | { | |
8860020e | 8843 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8844 | .policy = nl80211_policy, |
8845 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8846 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8847 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8848 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8849 | }, |
5727ef1b JB |
8850 | { |
8851 | .cmd = NL80211_CMD_GET_STATION, | |
8852 | .doit = nl80211_get_station, | |
2ec600d6 | 8853 | .dumpit = nl80211_dump_station, |
5727ef1b | 8854 | .policy = nl80211_policy, |
4c476991 JB |
8855 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8856 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8857 | }, |
8858 | { | |
8859 | .cmd = NL80211_CMD_SET_STATION, | |
8860 | .doit = nl80211_set_station, | |
8861 | .policy = nl80211_policy, | |
8862 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8864 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8865 | }, |
8866 | { | |
8867 | .cmd = NL80211_CMD_NEW_STATION, | |
8868 | .doit = nl80211_new_station, | |
8869 | .policy = nl80211_policy, | |
8870 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8871 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8872 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8873 | }, |
8874 | { | |
8875 | .cmd = NL80211_CMD_DEL_STATION, | |
8876 | .doit = nl80211_del_station, | |
8877 | .policy = nl80211_policy, | |
2ec600d6 | 8878 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8879 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8880 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8881 | }, |
8882 | { | |
8883 | .cmd = NL80211_CMD_GET_MPATH, | |
8884 | .doit = nl80211_get_mpath, | |
8885 | .dumpit = nl80211_dump_mpath, | |
8886 | .policy = nl80211_policy, | |
8887 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8888 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8889 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8890 | }, |
8891 | { | |
8892 | .cmd = NL80211_CMD_SET_MPATH, | |
8893 | .doit = nl80211_set_mpath, | |
8894 | .policy = nl80211_policy, | |
8895 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8896 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8897 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8898 | }, |
8899 | { | |
8900 | .cmd = NL80211_CMD_NEW_MPATH, | |
8901 | .doit = nl80211_new_mpath, | |
8902 | .policy = nl80211_policy, | |
8903 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8904 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8905 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8906 | }, |
8907 | { | |
8908 | .cmd = NL80211_CMD_DEL_MPATH, | |
8909 | .doit = nl80211_del_mpath, | |
8910 | .policy = nl80211_policy, | |
9f1ba906 | 8911 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8912 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8913 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8914 | }, |
8915 | { | |
8916 | .cmd = NL80211_CMD_SET_BSS, | |
8917 | .doit = nl80211_set_bss, | |
8918 | .policy = nl80211_policy, | |
b2e1b302 | 8919 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8920 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8921 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8922 | }, |
f130347c LR |
8923 | { |
8924 | .cmd = NL80211_CMD_GET_REG, | |
8925 | .doit = nl80211_get_reg, | |
8926 | .policy = nl80211_policy, | |
5fe231e8 | 8927 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
8928 | /* can be retrieved by unprivileged users */ |
8929 | }, | |
b2e1b302 LR |
8930 | { |
8931 | .cmd = NL80211_CMD_SET_REG, | |
8932 | .doit = nl80211_set_reg, | |
8933 | .policy = nl80211_policy, | |
8934 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 8935 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
8936 | }, |
8937 | { | |
8938 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8939 | .doit = nl80211_req_set_reg, | |
8940 | .policy = nl80211_policy, | |
93da9cc1 | 8941 | .flags = GENL_ADMIN_PERM, |
8942 | }, | |
8943 | { | |
24bdd9f4 JC |
8944 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8945 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8946 | .policy = nl80211_policy, |
8947 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8949 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8950 | }, |
8951 | { | |
24bdd9f4 JC |
8952 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8953 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8954 | .policy = nl80211_policy, |
9aed3cc1 | 8955 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8956 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8957 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8958 | }, |
2a519311 JB |
8959 | { |
8960 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8961 | .doit = nl80211_trigger_scan, | |
8962 | .policy = nl80211_policy, | |
8963 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8964 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8965 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8966 | }, |
8967 | { | |
8968 | .cmd = NL80211_CMD_GET_SCAN, | |
8969 | .policy = nl80211_policy, | |
8970 | .dumpit = nl80211_dump_scan, | |
8971 | }, | |
807f8a8c LC |
8972 | { |
8973 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8974 | .doit = nl80211_start_sched_scan, | |
8975 | .policy = nl80211_policy, | |
8976 | .flags = GENL_ADMIN_PERM, | |
8977 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8978 | NL80211_FLAG_NEED_RTNL, | |
8979 | }, | |
8980 | { | |
8981 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8982 | .doit = nl80211_stop_sched_scan, | |
8983 | .policy = nl80211_policy, | |
8984 | .flags = GENL_ADMIN_PERM, | |
8985 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8986 | NL80211_FLAG_NEED_RTNL, | |
8987 | }, | |
636a5d36 JM |
8988 | { |
8989 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8990 | .doit = nl80211_authenticate, | |
8991 | .policy = nl80211_policy, | |
8992 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8994 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8995 | }, |
8996 | { | |
8997 | .cmd = NL80211_CMD_ASSOCIATE, | |
8998 | .doit = nl80211_associate, | |
8999 | .policy = nl80211_policy, | |
9000 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9001 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9002 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9003 | }, |
9004 | { | |
9005 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9006 | .doit = nl80211_deauthenticate, | |
9007 | .policy = nl80211_policy, | |
9008 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9009 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9010 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9011 | }, |
9012 | { | |
9013 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9014 | .doit = nl80211_disassociate, | |
9015 | .policy = nl80211_policy, | |
9016 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9017 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9018 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9019 | }, |
04a773ad JB |
9020 | { |
9021 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9022 | .doit = nl80211_join_ibss, | |
9023 | .policy = nl80211_policy, | |
9024 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9025 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9026 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9027 | }, |
9028 | { | |
9029 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9030 | .doit = nl80211_leave_ibss, | |
9031 | .policy = nl80211_policy, | |
9032 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9033 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9034 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9035 | }, |
aff89a9b JB |
9036 | #ifdef CONFIG_NL80211_TESTMODE |
9037 | { | |
9038 | .cmd = NL80211_CMD_TESTMODE, | |
9039 | .doit = nl80211_testmode_do, | |
71063f0e | 9040 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9041 | .policy = nl80211_policy, |
9042 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9043 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9044 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9045 | }, |
9046 | #endif | |
b23aa676 SO |
9047 | { |
9048 | .cmd = NL80211_CMD_CONNECT, | |
9049 | .doit = nl80211_connect, | |
9050 | .policy = nl80211_policy, | |
9051 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9052 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9053 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9054 | }, |
9055 | { | |
9056 | .cmd = NL80211_CMD_DISCONNECT, | |
9057 | .doit = nl80211_disconnect, | |
9058 | .policy = nl80211_policy, | |
9059 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9060 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9061 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9062 | }, |
463d0183 JB |
9063 | { |
9064 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9065 | .doit = nl80211_wiphy_netns, | |
9066 | .policy = nl80211_policy, | |
9067 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9068 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9069 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9070 | }, |
61fa713c HS |
9071 | { |
9072 | .cmd = NL80211_CMD_GET_SURVEY, | |
9073 | .policy = nl80211_policy, | |
9074 | .dumpit = nl80211_dump_survey, | |
9075 | }, | |
67fbb16b SO |
9076 | { |
9077 | .cmd = NL80211_CMD_SET_PMKSA, | |
9078 | .doit = nl80211_setdel_pmksa, | |
9079 | .policy = nl80211_policy, | |
9080 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9081 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9082 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9083 | }, |
9084 | { | |
9085 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9086 | .doit = nl80211_setdel_pmksa, | |
9087 | .policy = nl80211_policy, | |
9088 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9089 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9090 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9091 | }, |
9092 | { | |
9093 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9094 | .doit = nl80211_flush_pmksa, | |
9095 | .policy = nl80211_policy, | |
9096 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9097 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9098 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9099 | }, |
9588bbd5 JM |
9100 | { |
9101 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9102 | .doit = nl80211_remain_on_channel, | |
9103 | .policy = nl80211_policy, | |
9104 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9105 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9106 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9107 | }, |
9108 | { | |
9109 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9110 | .doit = nl80211_cancel_remain_on_channel, | |
9111 | .policy = nl80211_policy, | |
9112 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9113 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9114 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9115 | }, |
13ae75b1 JM |
9116 | { |
9117 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9118 | .doit = nl80211_set_tx_bitrate_mask, | |
9119 | .policy = nl80211_policy, | |
9120 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9121 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9122 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9123 | }, |
026331c4 | 9124 | { |
2e161f78 JB |
9125 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9126 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9127 | .policy = nl80211_policy, |
9128 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9129 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9130 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9131 | }, |
9132 | { | |
2e161f78 JB |
9133 | .cmd = NL80211_CMD_FRAME, |
9134 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9135 | .policy = nl80211_policy, |
f7ca38df | 9136 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9137 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9138 | NL80211_FLAG_NEED_RTNL, |
9139 | }, | |
9140 | { | |
9141 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9142 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9143 | .policy = nl80211_policy, | |
026331c4 | 9144 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9145 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9146 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9147 | }, |
ffb9eb3d KV |
9148 | { |
9149 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9150 | .doit = nl80211_set_power_save, | |
9151 | .policy = nl80211_policy, | |
9152 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9153 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9154 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9155 | }, |
9156 | { | |
9157 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9158 | .doit = nl80211_get_power_save, | |
9159 | .policy = nl80211_policy, | |
9160 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9161 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9162 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9163 | }, |
d6dc1a38 JO |
9164 | { |
9165 | .cmd = NL80211_CMD_SET_CQM, | |
9166 | .doit = nl80211_set_cqm, | |
9167 | .policy = nl80211_policy, | |
9168 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9169 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9170 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9171 | }, |
f444de05 JB |
9172 | { |
9173 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9174 | .doit = nl80211_set_channel, | |
9175 | .policy = nl80211_policy, | |
9176 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9177 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9178 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9179 | }, |
e8347eba BJ |
9180 | { |
9181 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9182 | .doit = nl80211_set_wds_peer, | |
9183 | .policy = nl80211_policy, | |
9184 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9185 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9186 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9187 | }, |
29cbe68c JB |
9188 | { |
9189 | .cmd = NL80211_CMD_JOIN_MESH, | |
9190 | .doit = nl80211_join_mesh, | |
9191 | .policy = nl80211_policy, | |
9192 | .flags = GENL_ADMIN_PERM, | |
9193 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9194 | NL80211_FLAG_NEED_RTNL, | |
9195 | }, | |
9196 | { | |
9197 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9198 | .doit = nl80211_leave_mesh, | |
9199 | .policy = nl80211_policy, | |
9200 | .flags = GENL_ADMIN_PERM, | |
9201 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9202 | NL80211_FLAG_NEED_RTNL, | |
9203 | }, | |
dfb89c56 | 9204 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9205 | { |
9206 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9207 | .doit = nl80211_get_wowlan, | |
9208 | .policy = nl80211_policy, | |
9209 | /* can be retrieved by unprivileged users */ | |
9210 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9211 | NL80211_FLAG_NEED_RTNL, | |
9212 | }, | |
9213 | { | |
9214 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9215 | .doit = nl80211_set_wowlan, | |
9216 | .policy = nl80211_policy, | |
9217 | .flags = GENL_ADMIN_PERM, | |
9218 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9219 | NL80211_FLAG_NEED_RTNL, | |
9220 | }, | |
dfb89c56 | 9221 | #endif |
e5497d76 JB |
9222 | { |
9223 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9224 | .doit = nl80211_set_rekey_data, | |
9225 | .policy = nl80211_policy, | |
9226 | .flags = GENL_ADMIN_PERM, | |
9227 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9228 | NL80211_FLAG_NEED_RTNL, | |
9229 | }, | |
109086ce AN |
9230 | { |
9231 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9232 | .doit = nl80211_tdls_mgmt, | |
9233 | .policy = nl80211_policy, | |
9234 | .flags = GENL_ADMIN_PERM, | |
9235 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9236 | NL80211_FLAG_NEED_RTNL, | |
9237 | }, | |
9238 | { | |
9239 | .cmd = NL80211_CMD_TDLS_OPER, | |
9240 | .doit = nl80211_tdls_oper, | |
9241 | .policy = nl80211_policy, | |
9242 | .flags = GENL_ADMIN_PERM, | |
9243 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9244 | NL80211_FLAG_NEED_RTNL, | |
9245 | }, | |
28946da7 JB |
9246 | { |
9247 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9248 | .doit = nl80211_register_unexpected_frame, | |
9249 | .policy = nl80211_policy, | |
9250 | .flags = GENL_ADMIN_PERM, | |
9251 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9252 | NL80211_FLAG_NEED_RTNL, | |
9253 | }, | |
7f6cf311 JB |
9254 | { |
9255 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9256 | .doit = nl80211_probe_client, | |
9257 | .policy = nl80211_policy, | |
9258 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9259 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9260 | NL80211_FLAG_NEED_RTNL, |
9261 | }, | |
5e760230 JB |
9262 | { |
9263 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9264 | .doit = nl80211_register_beacons, | |
9265 | .policy = nl80211_policy, | |
9266 | .flags = GENL_ADMIN_PERM, | |
9267 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9268 | NL80211_FLAG_NEED_RTNL, | |
9269 | }, | |
1d9d9213 SW |
9270 | { |
9271 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9272 | .doit = nl80211_set_noack_map, | |
9273 | .policy = nl80211_policy, | |
9274 | .flags = GENL_ADMIN_PERM, | |
9275 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9276 | NL80211_FLAG_NEED_RTNL, | |
9277 | }, | |
98104fde JB |
9278 | { |
9279 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9280 | .doit = nl80211_start_p2p_device, | |
9281 | .policy = nl80211_policy, | |
9282 | .flags = GENL_ADMIN_PERM, | |
9283 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9284 | NL80211_FLAG_NEED_RTNL, | |
9285 | }, | |
9286 | { | |
9287 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9288 | .doit = nl80211_stop_p2p_device, | |
9289 | .policy = nl80211_policy, | |
9290 | .flags = GENL_ADMIN_PERM, | |
9291 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9292 | NL80211_FLAG_NEED_RTNL, | |
9293 | }, | |
f4e583c8 AQ |
9294 | { |
9295 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9296 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9297 | .policy = nl80211_policy, |
9298 | .flags = GENL_ADMIN_PERM, | |
9299 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9300 | NL80211_FLAG_NEED_RTNL, | |
9301 | }, | |
9302 | { | |
9303 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9304 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9305 | .policy = nl80211_policy, |
9306 | .flags = GENL_ADMIN_PERM, | |
9307 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9308 | NL80211_FLAG_NEED_RTNL, | |
9309 | }, | |
04f39047 SW |
9310 | { |
9311 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9312 | .doit = nl80211_start_radar_detection, | |
9313 | .policy = nl80211_policy, | |
9314 | .flags = GENL_ADMIN_PERM, | |
9315 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9316 | NL80211_FLAG_NEED_RTNL, | |
9317 | }, | |
3713b4e3 JB |
9318 | { |
9319 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9320 | .doit = nl80211_get_protocol_features, | |
9321 | .policy = nl80211_policy, | |
9322 | }, | |
355199e0 JM |
9323 | { |
9324 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9325 | .doit = nl80211_update_ft_ies, | |
9326 | .policy = nl80211_policy, | |
9327 | .flags = GENL_ADMIN_PERM, | |
9328 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9329 | NL80211_FLAG_NEED_RTNL, | |
9330 | }, | |
5de17984 AS |
9331 | { |
9332 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9333 | .doit = nl80211_crit_protocol_start, | |
9334 | .policy = nl80211_policy, | |
9335 | .flags = GENL_ADMIN_PERM, | |
9336 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9337 | NL80211_FLAG_NEED_RTNL, | |
9338 | }, | |
9339 | { | |
9340 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9341 | .doit = nl80211_crit_protocol_stop, | |
9342 | .policy = nl80211_policy, | |
9343 | .flags = GENL_ADMIN_PERM, | |
9344 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9345 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9346 | }, |
9347 | { | |
9348 | .cmd = NL80211_CMD_GET_COALESCE, | |
9349 | .doit = nl80211_get_coalesce, | |
9350 | .policy = nl80211_policy, | |
9351 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9352 | NL80211_FLAG_NEED_RTNL, | |
9353 | }, | |
9354 | { | |
9355 | .cmd = NL80211_CMD_SET_COALESCE, | |
9356 | .doit = nl80211_set_coalesce, | |
9357 | .policy = nl80211_policy, | |
9358 | .flags = GENL_ADMIN_PERM, | |
9359 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9360 | NL80211_FLAG_NEED_RTNL, | |
5de17984 | 9361 | } |
55682965 | 9362 | }; |
9588bbd5 | 9363 | |
6039f6d2 JM |
9364 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
9365 | .name = "mlme", | |
9366 | }; | |
55682965 JB |
9367 | |
9368 | /* multicast groups */ | |
9369 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
9370 | .name = "config", | |
9371 | }; | |
2a519311 JB |
9372 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
9373 | .name = "scan", | |
9374 | }; | |
73d54c9e LR |
9375 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
9376 | .name = "regulatory", | |
9377 | }; | |
55682965 JB |
9378 | |
9379 | /* notification functions */ | |
9380 | ||
9381 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9382 | { | |
9383 | struct sk_buff *msg; | |
86e8cf98 | 9384 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 9385 | |
fd2120ca | 9386 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9387 | if (!msg) |
9388 | return; | |
9389 | ||
86e8cf98 | 9390 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
9391 | nlmsg_free(msg); |
9392 | return; | |
9393 | } | |
9394 | ||
463d0183 JB |
9395 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9396 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
9397 | } |
9398 | ||
362a415d JB |
9399 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9400 | struct cfg80211_registered_device *rdev) | |
9401 | { | |
9402 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9403 | struct nlattr *nest; | |
9404 | int i; | |
9405 | ||
9406 | if (WARN_ON(!req)) | |
9407 | return 0; | |
9408 | ||
9409 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9410 | if (!nest) | |
9411 | goto nla_put_failure; | |
9360ffd1 DM |
9412 | for (i = 0; i < req->n_ssids; i++) { |
9413 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9414 | goto nla_put_failure; | |
9415 | } | |
362a415d JB |
9416 | nla_nest_end(msg, nest); |
9417 | ||
9418 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9419 | if (!nest) | |
9420 | goto nla_put_failure; | |
9360ffd1 DM |
9421 | for (i = 0; i < req->n_channels; i++) { |
9422 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9423 | goto nla_put_failure; | |
9424 | } | |
362a415d JB |
9425 | nla_nest_end(msg, nest); |
9426 | ||
9360ffd1 DM |
9427 | if (req->ie && |
9428 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9429 | goto nla_put_failure; | |
362a415d | 9430 | |
ed473771 SL |
9431 | if (req->flags) |
9432 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9433 | ||
362a415d JB |
9434 | return 0; |
9435 | nla_put_failure: | |
9436 | return -ENOBUFS; | |
9437 | } | |
9438 | ||
a538e2d5 JB |
9439 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9440 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9441 | struct wireless_dev *wdev, |
15e47304 | 9442 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9443 | u32 cmd) |
2a519311 JB |
9444 | { |
9445 | void *hdr; | |
9446 | ||
15e47304 | 9447 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9448 | if (!hdr) |
9449 | return -1; | |
9450 | ||
9360ffd1 | 9451 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9452 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9453 | wdev->netdev->ifindex)) || | |
9454 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9455 | goto nla_put_failure; |
2a519311 | 9456 | |
362a415d JB |
9457 | /* ignore errors and send incomplete event anyway */ |
9458 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9459 | |
9460 | return genlmsg_end(msg, hdr); | |
9461 | ||
9462 | nla_put_failure: | |
9463 | genlmsg_cancel(msg, hdr); | |
9464 | return -EMSGSIZE; | |
9465 | } | |
9466 | ||
807f8a8c LC |
9467 | static int |
9468 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9469 | struct cfg80211_registered_device *rdev, | |
9470 | struct net_device *netdev, | |
15e47304 | 9471 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9472 | { |
9473 | void *hdr; | |
9474 | ||
15e47304 | 9475 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9476 | if (!hdr) |
9477 | return -1; | |
9478 | ||
9360ffd1 DM |
9479 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9480 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9481 | goto nla_put_failure; | |
807f8a8c LC |
9482 | |
9483 | return genlmsg_end(msg, hdr); | |
9484 | ||
9485 | nla_put_failure: | |
9486 | genlmsg_cancel(msg, hdr); | |
9487 | return -EMSGSIZE; | |
9488 | } | |
9489 | ||
a538e2d5 | 9490 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9491 | struct wireless_dev *wdev) |
a538e2d5 JB |
9492 | { |
9493 | struct sk_buff *msg; | |
9494 | ||
58050fce | 9495 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9496 | if (!msg) |
9497 | return; | |
9498 | ||
fd014284 | 9499 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9500 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9501 | nlmsg_free(msg); | |
9502 | return; | |
9503 | } | |
9504 | ||
463d0183 JB |
9505 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9506 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9507 | } |
9508 | ||
2a519311 | 9509 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9510 | struct wireless_dev *wdev) |
2a519311 JB |
9511 | { |
9512 | struct sk_buff *msg; | |
9513 | ||
fd2120ca | 9514 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9515 | if (!msg) |
9516 | return; | |
9517 | ||
fd014284 | 9518 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9519 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9520 | nlmsg_free(msg); |
9521 | return; | |
9522 | } | |
9523 | ||
463d0183 JB |
9524 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9525 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9526 | } |
9527 | ||
9528 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9529 | struct wireless_dev *wdev) |
2a519311 JB |
9530 | { |
9531 | struct sk_buff *msg; | |
9532 | ||
fd2120ca | 9533 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9534 | if (!msg) |
9535 | return; | |
9536 | ||
fd014284 | 9537 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9538 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9539 | nlmsg_free(msg); |
9540 | return; | |
9541 | } | |
9542 | ||
463d0183 JB |
9543 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9544 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9545 | } |
9546 | ||
807f8a8c LC |
9547 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9548 | struct net_device *netdev) | |
9549 | { | |
9550 | struct sk_buff *msg; | |
9551 | ||
9552 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9553 | if (!msg) | |
9554 | return; | |
9555 | ||
9556 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9557 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9558 | nlmsg_free(msg); | |
9559 | return; | |
9560 | } | |
9561 | ||
9562 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9563 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9564 | } | |
9565 | ||
9566 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9567 | struct net_device *netdev, u32 cmd) | |
9568 | { | |
9569 | struct sk_buff *msg; | |
9570 | ||
58050fce | 9571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9572 | if (!msg) |
9573 | return; | |
9574 | ||
9575 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9576 | nlmsg_free(msg); | |
9577 | return; | |
9578 | } | |
9579 | ||
9580 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9581 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9582 | } | |
9583 | ||
73d54c9e LR |
9584 | /* |
9585 | * This can happen on global regulatory changes or device specific settings | |
9586 | * based on custom world regulatory domains. | |
9587 | */ | |
9588 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9589 | { | |
9590 | struct sk_buff *msg; | |
9591 | void *hdr; | |
9592 | ||
fd2120ca | 9593 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9594 | if (!msg) |
9595 | return; | |
9596 | ||
9597 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9598 | if (!hdr) { | |
9599 | nlmsg_free(msg); | |
9600 | return; | |
9601 | } | |
9602 | ||
9603 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9604 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9605 | goto nla_put_failure; | |
9606 | ||
9607 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9608 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9609 | NL80211_REGDOM_TYPE_WORLD)) | |
9610 | goto nla_put_failure; | |
9611 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9612 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9613 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9614 | goto nla_put_failure; | |
9615 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9616 | request->intersect) { | |
9617 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9618 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9619 | goto nla_put_failure; | |
9620 | } else { | |
9621 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9622 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9623 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9624 | request->alpha2)) | |
9625 | goto nla_put_failure; | |
9626 | } | |
9627 | ||
f4173766 | 9628 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9629 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9630 | goto nla_put_failure; | |
73d54c9e | 9631 | |
3b7b72ee | 9632 | genlmsg_end(msg, hdr); |
73d54c9e | 9633 | |
bc43b28c | 9634 | rcu_read_lock(); |
463d0183 | 9635 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9636 | GFP_ATOMIC); |
9637 | rcu_read_unlock(); | |
73d54c9e LR |
9638 | |
9639 | return; | |
9640 | ||
9641 | nla_put_failure: | |
9642 | genlmsg_cancel(msg, hdr); | |
9643 | nlmsg_free(msg); | |
9644 | } | |
9645 | ||
6039f6d2 JM |
9646 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9647 | struct net_device *netdev, | |
9648 | const u8 *buf, size_t len, | |
e6d6e342 | 9649 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9650 | { |
9651 | struct sk_buff *msg; | |
9652 | void *hdr; | |
9653 | ||
e6d6e342 | 9654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9655 | if (!msg) |
9656 | return; | |
9657 | ||
9658 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9659 | if (!hdr) { | |
9660 | nlmsg_free(msg); | |
9661 | return; | |
9662 | } | |
9663 | ||
9360ffd1 DM |
9664 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9665 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9666 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9667 | goto nla_put_failure; | |
6039f6d2 | 9668 | |
3b7b72ee | 9669 | genlmsg_end(msg, hdr); |
6039f6d2 | 9670 | |
463d0183 JB |
9671 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9672 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9673 | return; |
9674 | ||
9675 | nla_put_failure: | |
9676 | genlmsg_cancel(msg, hdr); | |
9677 | nlmsg_free(msg); | |
9678 | } | |
9679 | ||
9680 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9681 | struct net_device *netdev, const u8 *buf, |
9682 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9683 | { |
9684 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9685 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9686 | } |
9687 | ||
9688 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9689 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9690 | size_t len, gfp_t gfp) |
6039f6d2 | 9691 | { |
e6d6e342 JB |
9692 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9693 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9694 | } |
9695 | ||
53b46b84 | 9696 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9697 | struct net_device *netdev, const u8 *buf, |
9698 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9699 | { |
9700 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9701 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9702 | } |
9703 | ||
53b46b84 JM |
9704 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9705 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9706 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9707 | { |
9708 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9709 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9710 | } |
9711 | ||
6ff57cf8 JB |
9712 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
9713 | size_t len) | |
cf4e594e | 9714 | { |
947add36 JB |
9715 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9716 | struct wiphy *wiphy = wdev->wiphy; | |
9717 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
9718 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
9719 | u32 cmd; | |
947add36 | 9720 | |
6ff57cf8 JB |
9721 | if (WARN_ON(len < 2)) |
9722 | return; | |
cf4e594e | 9723 | |
6ff57cf8 JB |
9724 | if (ieee80211_is_deauth(mgmt->frame_control)) |
9725 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
9726 | else | |
9727 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 9728 | |
6ff57cf8 JB |
9729 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
9730 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 9731 | } |
6ff57cf8 | 9732 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 9733 | |
1b06bb40 LR |
9734 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9735 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9736 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9737 | { |
9738 | struct sk_buff *msg; | |
9739 | void *hdr; | |
9740 | ||
e6d6e342 | 9741 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9742 | if (!msg) |
9743 | return; | |
9744 | ||
9745 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9746 | if (!hdr) { | |
9747 | nlmsg_free(msg); | |
9748 | return; | |
9749 | } | |
9750 | ||
9360ffd1 DM |
9751 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9752 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9753 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9754 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9755 | goto nla_put_failure; | |
1965c853 | 9756 | |
3b7b72ee | 9757 | genlmsg_end(msg, hdr); |
1965c853 | 9758 | |
463d0183 JB |
9759 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9760 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9761 | return; |
9762 | ||
9763 | nla_put_failure: | |
9764 | genlmsg_cancel(msg, hdr); | |
9765 | nlmsg_free(msg); | |
9766 | } | |
9767 | ||
9768 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9769 | struct net_device *netdev, const u8 *addr, |
9770 | gfp_t gfp) | |
1965c853 JM |
9771 | { |
9772 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9773 | addr, gfp); |
1965c853 JM |
9774 | } |
9775 | ||
9776 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9777 | struct net_device *netdev, const u8 *addr, |
9778 | gfp_t gfp) | |
1965c853 | 9779 | { |
e6d6e342 JB |
9780 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9781 | addr, gfp); | |
1965c853 JM |
9782 | } |
9783 | ||
b23aa676 SO |
9784 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9785 | struct net_device *netdev, const u8 *bssid, | |
9786 | const u8 *req_ie, size_t req_ie_len, | |
9787 | const u8 *resp_ie, size_t resp_ie_len, | |
9788 | u16 status, gfp_t gfp) | |
9789 | { | |
9790 | struct sk_buff *msg; | |
9791 | void *hdr; | |
9792 | ||
58050fce | 9793 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9794 | if (!msg) |
9795 | return; | |
9796 | ||
9797 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9798 | if (!hdr) { | |
9799 | nlmsg_free(msg); | |
9800 | return; | |
9801 | } | |
9802 | ||
9360ffd1 DM |
9803 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9804 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9805 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9806 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9807 | (req_ie && | |
9808 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9809 | (resp_ie && | |
9810 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9811 | goto nla_put_failure; | |
b23aa676 | 9812 | |
3b7b72ee | 9813 | genlmsg_end(msg, hdr); |
b23aa676 | 9814 | |
463d0183 JB |
9815 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9816 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9817 | return; |
9818 | ||
9819 | nla_put_failure: | |
9820 | genlmsg_cancel(msg, hdr); | |
9821 | nlmsg_free(msg); | |
9822 | ||
9823 | } | |
9824 | ||
9825 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9826 | struct net_device *netdev, const u8 *bssid, | |
9827 | const u8 *req_ie, size_t req_ie_len, | |
9828 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9829 | { | |
9830 | struct sk_buff *msg; | |
9831 | void *hdr; | |
9832 | ||
58050fce | 9833 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9834 | if (!msg) |
9835 | return; | |
9836 | ||
9837 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9838 | if (!hdr) { | |
9839 | nlmsg_free(msg); | |
9840 | return; | |
9841 | } | |
9842 | ||
9360ffd1 DM |
9843 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9844 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9845 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9846 | (req_ie && | |
9847 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9848 | (resp_ie && | |
9849 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9850 | goto nla_put_failure; | |
b23aa676 | 9851 | |
3b7b72ee | 9852 | genlmsg_end(msg, hdr); |
b23aa676 | 9853 | |
463d0183 JB |
9854 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9855 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9856 | return; |
9857 | ||
9858 | nla_put_failure: | |
9859 | genlmsg_cancel(msg, hdr); | |
9860 | nlmsg_free(msg); | |
9861 | ||
9862 | } | |
9863 | ||
9864 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9865 | struct net_device *netdev, u16 reason, | |
667503dd | 9866 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9867 | { |
9868 | struct sk_buff *msg; | |
9869 | void *hdr; | |
9870 | ||
58050fce | 9871 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9872 | if (!msg) |
9873 | return; | |
9874 | ||
9875 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9876 | if (!hdr) { | |
9877 | nlmsg_free(msg); | |
9878 | return; | |
9879 | } | |
9880 | ||
9360ffd1 DM |
9881 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9882 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9883 | (from_ap && reason && | |
9884 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9885 | (from_ap && | |
9886 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9887 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9888 | goto nla_put_failure; | |
b23aa676 | 9889 | |
3b7b72ee | 9890 | genlmsg_end(msg, hdr); |
b23aa676 | 9891 | |
463d0183 JB |
9892 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9893 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9894 | return; |
9895 | ||
9896 | nla_put_failure: | |
9897 | genlmsg_cancel(msg, hdr); | |
9898 | nlmsg_free(msg); | |
9899 | ||
9900 | } | |
9901 | ||
04a773ad JB |
9902 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9903 | struct net_device *netdev, const u8 *bssid, | |
9904 | gfp_t gfp) | |
9905 | { | |
9906 | struct sk_buff *msg; | |
9907 | void *hdr; | |
9908 | ||
fd2120ca | 9909 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9910 | if (!msg) |
9911 | return; | |
9912 | ||
9913 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9914 | if (!hdr) { | |
9915 | nlmsg_free(msg); | |
9916 | return; | |
9917 | } | |
9918 | ||
9360ffd1 DM |
9919 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9920 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9921 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9922 | goto nla_put_failure; | |
04a773ad | 9923 | |
3b7b72ee | 9924 | genlmsg_end(msg, hdr); |
04a773ad | 9925 | |
463d0183 JB |
9926 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9927 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9928 | return; |
9929 | ||
9930 | nla_put_failure: | |
9931 | genlmsg_cancel(msg, hdr); | |
9932 | nlmsg_free(msg); | |
9933 | } | |
9934 | ||
947add36 JB |
9935 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9936 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9937 | { |
947add36 JB |
9938 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9939 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9940 | struct sk_buff *msg; |
9941 | void *hdr; | |
9942 | ||
947add36 JB |
9943 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9944 | return; | |
9945 | ||
9946 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9947 | ||
c93b5e71 JC |
9948 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9949 | if (!msg) | |
9950 | return; | |
9951 | ||
9952 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9953 | if (!hdr) { | |
9954 | nlmsg_free(msg); | |
9955 | return; | |
9956 | } | |
9957 | ||
9360ffd1 | 9958 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9959 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9960 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9961 | (ie_len && ie && |
9962 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9963 | goto nla_put_failure; | |
c93b5e71 | 9964 | |
3b7b72ee | 9965 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9966 | |
9967 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9968 | nl80211_mlme_mcgrp.id, gfp); | |
9969 | return; | |
9970 | ||
9971 | nla_put_failure: | |
9972 | genlmsg_cancel(msg, hdr); | |
9973 | nlmsg_free(msg); | |
9974 | } | |
947add36 | 9975 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9976 | |
a3b8b056 JM |
9977 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9978 | struct net_device *netdev, const u8 *addr, | |
9979 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9980 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9981 | { |
9982 | struct sk_buff *msg; | |
9983 | void *hdr; | |
9984 | ||
e6d6e342 | 9985 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9986 | if (!msg) |
9987 | return; | |
9988 | ||
9989 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9990 | if (!hdr) { | |
9991 | nlmsg_free(msg); | |
9992 | return; | |
9993 | } | |
9994 | ||
9360ffd1 DM |
9995 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9996 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9997 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9998 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9999 | (key_id != -1 && | |
10000 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10001 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10002 | goto nla_put_failure; | |
a3b8b056 | 10003 | |
3b7b72ee | 10004 | genlmsg_end(msg, hdr); |
a3b8b056 | 10005 | |
463d0183 JB |
10006 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10007 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
10008 | return; |
10009 | ||
10010 | nla_put_failure: | |
10011 | genlmsg_cancel(msg, hdr); | |
10012 | nlmsg_free(msg); | |
10013 | } | |
10014 | ||
6bad8766 LR |
10015 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10016 | struct ieee80211_channel *channel_before, | |
10017 | struct ieee80211_channel *channel_after) | |
10018 | { | |
10019 | struct sk_buff *msg; | |
10020 | void *hdr; | |
10021 | struct nlattr *nl_freq; | |
10022 | ||
fd2120ca | 10023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10024 | if (!msg) |
10025 | return; | |
10026 | ||
10027 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10028 | if (!hdr) { | |
10029 | nlmsg_free(msg); | |
10030 | return; | |
10031 | } | |
10032 | ||
10033 | /* | |
10034 | * Since we are applying the beacon hint to a wiphy we know its | |
10035 | * wiphy_idx is valid | |
10036 | */ | |
9360ffd1 DM |
10037 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10038 | goto nla_put_failure; | |
6bad8766 LR |
10039 | |
10040 | /* Before */ | |
10041 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10042 | if (!nl_freq) | |
10043 | goto nla_put_failure; | |
cdc89b97 | 10044 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10045 | goto nla_put_failure; |
10046 | nla_nest_end(msg, nl_freq); | |
10047 | ||
10048 | /* After */ | |
10049 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10050 | if (!nl_freq) | |
10051 | goto nla_put_failure; | |
cdc89b97 | 10052 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10053 | goto nla_put_failure; |
10054 | nla_nest_end(msg, nl_freq); | |
10055 | ||
3b7b72ee | 10056 | genlmsg_end(msg, hdr); |
6bad8766 | 10057 | |
463d0183 JB |
10058 | rcu_read_lock(); |
10059 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
10060 | GFP_ATOMIC); | |
10061 | rcu_read_unlock(); | |
6bad8766 LR |
10062 | |
10063 | return; | |
10064 | ||
10065 | nla_put_failure: | |
10066 | genlmsg_cancel(msg, hdr); | |
10067 | nlmsg_free(msg); | |
10068 | } | |
10069 | ||
9588bbd5 JM |
10070 | static void nl80211_send_remain_on_chan_event( |
10071 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10072 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10073 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10074 | unsigned int duration, gfp_t gfp) |
10075 | { | |
10076 | struct sk_buff *msg; | |
10077 | void *hdr; | |
10078 | ||
10079 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10080 | if (!msg) | |
10081 | return; | |
10082 | ||
10083 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10084 | if (!hdr) { | |
10085 | nlmsg_free(msg); | |
10086 | return; | |
10087 | } | |
10088 | ||
9360ffd1 | 10089 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10090 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10091 | wdev->netdev->ifindex)) || | |
00f53350 | 10092 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10093 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10094 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10095 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10096 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10097 | goto nla_put_failure; | |
9588bbd5 | 10098 | |
9360ffd1 DM |
10099 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10100 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10101 | goto nla_put_failure; | |
9588bbd5 | 10102 | |
3b7b72ee | 10103 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
10104 | |
10105 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10106 | nl80211_mlme_mcgrp.id, gfp); | |
10107 | return; | |
10108 | ||
10109 | nla_put_failure: | |
10110 | genlmsg_cancel(msg, hdr); | |
10111 | nlmsg_free(msg); | |
10112 | } | |
10113 | ||
947add36 JB |
10114 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10115 | struct ieee80211_channel *chan, | |
10116 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10117 | { |
947add36 JB |
10118 | struct wiphy *wiphy = wdev->wiphy; |
10119 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10120 | ||
10121 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10122 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10123 | rdev, wdev, cookie, chan, |
42d97a59 | 10124 | duration, gfp); |
9588bbd5 | 10125 | } |
947add36 | 10126 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10127 | |
947add36 JB |
10128 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10129 | struct ieee80211_channel *chan, | |
10130 | gfp_t gfp) | |
9588bbd5 | 10131 | { |
947add36 JB |
10132 | struct wiphy *wiphy = wdev->wiphy; |
10133 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10134 | ||
10135 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10136 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10137 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10138 | } |
947add36 | 10139 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10140 | |
947add36 JB |
10141 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10142 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10143 | { |
947add36 JB |
10144 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10145 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
10146 | struct sk_buff *msg; |
10147 | ||
947add36 JB |
10148 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10149 | ||
58050fce | 10150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10151 | if (!msg) |
10152 | return; | |
10153 | ||
66266b3a JL |
10154 | if (nl80211_send_station(msg, 0, 0, 0, |
10155 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10156 | nlmsg_free(msg); |
10157 | return; | |
10158 | } | |
10159 | ||
10160 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10161 | nl80211_mlme_mcgrp.id, gfp); | |
10162 | } | |
947add36 | 10163 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10164 | |
947add36 | 10165 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10166 | { |
947add36 JB |
10167 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10168 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
10169 | struct sk_buff *msg; |
10170 | void *hdr; | |
10171 | ||
947add36 JB |
10172 | trace_cfg80211_del_sta(dev, mac_addr); |
10173 | ||
58050fce | 10174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10175 | if (!msg) |
10176 | return; | |
10177 | ||
10178 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10179 | if (!hdr) { | |
10180 | nlmsg_free(msg); | |
10181 | return; | |
10182 | } | |
10183 | ||
9360ffd1 DM |
10184 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10185 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10186 | goto nla_put_failure; | |
ec15e68b | 10187 | |
3b7b72ee | 10188 | genlmsg_end(msg, hdr); |
ec15e68b JM |
10189 | |
10190 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10191 | nl80211_mlme_mcgrp.id, gfp); | |
10192 | return; | |
10193 | ||
10194 | nla_put_failure: | |
10195 | genlmsg_cancel(msg, hdr); | |
10196 | nlmsg_free(msg); | |
10197 | } | |
947add36 | 10198 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10199 | |
947add36 JB |
10200 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10201 | enum nl80211_connect_failed_reason reason, | |
10202 | gfp_t gfp) | |
ed44a951 | 10203 | { |
947add36 JB |
10204 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10205 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10206 | struct sk_buff *msg; |
10207 | void *hdr; | |
10208 | ||
10209 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10210 | if (!msg) | |
10211 | return; | |
10212 | ||
10213 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10214 | if (!hdr) { | |
10215 | nlmsg_free(msg); | |
10216 | return; | |
10217 | } | |
10218 | ||
10219 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10220 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10221 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10222 | goto nla_put_failure; | |
10223 | ||
10224 | genlmsg_end(msg, hdr); | |
10225 | ||
10226 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10227 | nl80211_mlme_mcgrp.id, gfp); | |
10228 | return; | |
10229 | ||
10230 | nla_put_failure: | |
10231 | genlmsg_cancel(msg, hdr); | |
10232 | nlmsg_free(msg); | |
10233 | } | |
947add36 | 10234 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10235 | |
b92ab5d8 JB |
10236 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10237 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10238 | { |
10239 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10240 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10241 | struct sk_buff *msg; | |
10242 | void *hdr; | |
15e47304 | 10243 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10244 | |
15e47304 | 10245 | if (!nlportid) |
28946da7 JB |
10246 | return false; |
10247 | ||
10248 | msg = nlmsg_new(100, gfp); | |
10249 | if (!msg) | |
10250 | return true; | |
10251 | ||
b92ab5d8 | 10252 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10253 | if (!hdr) { |
10254 | nlmsg_free(msg); | |
10255 | return true; | |
10256 | } | |
10257 | ||
9360ffd1 DM |
10258 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10259 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10260 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10261 | goto nla_put_failure; | |
28946da7 | 10262 | |
9c90a9f6 | 10263 | genlmsg_end(msg, hdr); |
15e47304 | 10264 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10265 | return true; |
10266 | ||
10267 | nla_put_failure: | |
10268 | genlmsg_cancel(msg, hdr); | |
10269 | nlmsg_free(msg); | |
10270 | return true; | |
10271 | } | |
10272 | ||
947add36 JB |
10273 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10274 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10275 | { |
947add36 JB |
10276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10277 | bool ret; | |
10278 | ||
10279 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10280 | ||
10281 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10282 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10283 | trace_cfg80211_return_bool(false); | |
10284 | return false; | |
10285 | } | |
10286 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10287 | addr, gfp); | |
10288 | trace_cfg80211_return_bool(ret); | |
10289 | return ret; | |
b92ab5d8 | 10290 | } |
947add36 | 10291 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10292 | |
947add36 JB |
10293 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10294 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10295 | { |
947add36 JB |
10296 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10297 | bool ret; | |
10298 | ||
10299 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10300 | ||
10301 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10302 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10303 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10304 | trace_cfg80211_return_bool(false); | |
10305 | return false; | |
10306 | } | |
10307 | ret = __nl80211_unexpected_frame(dev, | |
10308 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10309 | addr, gfp); | |
10310 | trace_cfg80211_return_bool(ret); | |
10311 | return ret; | |
b92ab5d8 | 10312 | } |
947add36 | 10313 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10314 | |
2e161f78 | 10315 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10316 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
10317 | int freq, int sig_dbm, |
10318 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 10319 | { |
71bbc994 | 10320 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10321 | struct sk_buff *msg; |
10322 | void *hdr; | |
026331c4 JM |
10323 | |
10324 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10325 | if (!msg) | |
10326 | return -ENOMEM; | |
10327 | ||
2e161f78 | 10328 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10329 | if (!hdr) { |
10330 | nlmsg_free(msg); | |
10331 | return -ENOMEM; | |
10332 | } | |
10333 | ||
9360ffd1 | 10334 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10335 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10336 | netdev->ifindex)) || | |
a838490b | 10337 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10338 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10339 | (sig_dbm && | |
10340 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10341 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10342 | goto nla_put_failure; | |
026331c4 | 10343 | |
3b7b72ee | 10344 | genlmsg_end(msg, hdr); |
026331c4 | 10345 | |
15e47304 | 10346 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10347 | |
10348 | nla_put_failure: | |
10349 | genlmsg_cancel(msg, hdr); | |
10350 | nlmsg_free(msg); | |
10351 | return -ENOBUFS; | |
10352 | } | |
10353 | ||
947add36 JB |
10354 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10355 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10356 | { |
947add36 JB |
10357 | struct wiphy *wiphy = wdev->wiphy; |
10358 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10359 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10360 | struct sk_buff *msg; |
10361 | void *hdr; | |
10362 | ||
947add36 JB |
10363 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10364 | ||
026331c4 JM |
10365 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10366 | if (!msg) | |
10367 | return; | |
10368 | ||
2e161f78 | 10369 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10370 | if (!hdr) { |
10371 | nlmsg_free(msg); | |
10372 | return; | |
10373 | } | |
10374 | ||
9360ffd1 | 10375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10376 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10377 | netdev->ifindex)) || | |
a838490b | 10378 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10379 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10380 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10381 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10382 | goto nla_put_failure; | |
026331c4 | 10383 | |
3b7b72ee | 10384 | genlmsg_end(msg, hdr); |
026331c4 JM |
10385 | |
10386 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
10387 | return; | |
10388 | ||
10389 | nla_put_failure: | |
10390 | genlmsg_cancel(msg, hdr); | |
10391 | nlmsg_free(msg); | |
10392 | } | |
947add36 | 10393 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10394 | |
947add36 JB |
10395 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10396 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10397 | gfp_t gfp) | |
d6dc1a38 | 10398 | { |
947add36 JB |
10399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10400 | struct wiphy *wiphy = wdev->wiphy; | |
10401 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10402 | struct sk_buff *msg; |
10403 | struct nlattr *pinfoattr; | |
10404 | void *hdr; | |
10405 | ||
947add36 JB |
10406 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10407 | ||
58050fce | 10408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10409 | if (!msg) |
10410 | return; | |
10411 | ||
10412 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10413 | if (!hdr) { | |
10414 | nlmsg_free(msg); | |
10415 | return; | |
10416 | } | |
10417 | ||
9360ffd1 | 10418 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10419 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10420 | goto nla_put_failure; |
d6dc1a38 JO |
10421 | |
10422 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10423 | if (!pinfoattr) | |
10424 | goto nla_put_failure; | |
10425 | ||
9360ffd1 DM |
10426 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10427 | rssi_event)) | |
10428 | goto nla_put_failure; | |
d6dc1a38 JO |
10429 | |
10430 | nla_nest_end(msg, pinfoattr); | |
10431 | ||
3b7b72ee | 10432 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10433 | |
10434 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10435 | nl80211_mlme_mcgrp.id, gfp); | |
10436 | return; | |
10437 | ||
10438 | nla_put_failure: | |
10439 | genlmsg_cancel(msg, hdr); | |
10440 | nlmsg_free(msg); | |
10441 | } | |
947add36 | 10442 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10443 | |
947add36 JB |
10444 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10445 | struct net_device *netdev, const u8 *bssid, | |
10446 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10447 | { |
10448 | struct sk_buff *msg; | |
10449 | struct nlattr *rekey_attr; | |
10450 | void *hdr; | |
10451 | ||
58050fce | 10452 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10453 | if (!msg) |
10454 | return; | |
10455 | ||
10456 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10457 | if (!hdr) { | |
10458 | nlmsg_free(msg); | |
10459 | return; | |
10460 | } | |
10461 | ||
9360ffd1 DM |
10462 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10463 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10465 | goto nla_put_failure; | |
e5497d76 JB |
10466 | |
10467 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10468 | if (!rekey_attr) | |
10469 | goto nla_put_failure; | |
10470 | ||
9360ffd1 DM |
10471 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10472 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10473 | goto nla_put_failure; | |
e5497d76 JB |
10474 | |
10475 | nla_nest_end(msg, rekey_attr); | |
10476 | ||
3b7b72ee | 10477 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10478 | |
10479 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10480 | nl80211_mlme_mcgrp.id, gfp); | |
10481 | return; | |
10482 | ||
10483 | nla_put_failure: | |
10484 | genlmsg_cancel(msg, hdr); | |
10485 | nlmsg_free(msg); | |
10486 | } | |
10487 | ||
947add36 JB |
10488 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10489 | const u8 *replay_ctr, gfp_t gfp) | |
10490 | { | |
10491 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10492 | struct wiphy *wiphy = wdev->wiphy; | |
10493 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10494 | ||
10495 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10496 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10497 | } | |
10498 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10499 | ||
10500 | static void | |
10501 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10502 | struct net_device *netdev, int index, | |
10503 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10504 | { |
10505 | struct sk_buff *msg; | |
10506 | struct nlattr *attr; | |
10507 | void *hdr; | |
10508 | ||
58050fce | 10509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10510 | if (!msg) |
10511 | return; | |
10512 | ||
10513 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10514 | if (!hdr) { | |
10515 | nlmsg_free(msg); | |
10516 | return; | |
10517 | } | |
10518 | ||
9360ffd1 DM |
10519 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10520 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10521 | goto nla_put_failure; | |
c9df56b4 JM |
10522 | |
10523 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10524 | if (!attr) | |
10525 | goto nla_put_failure; | |
10526 | ||
9360ffd1 DM |
10527 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10528 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10529 | (preauth && | |
10530 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10531 | goto nla_put_failure; | |
c9df56b4 JM |
10532 | |
10533 | nla_nest_end(msg, attr); | |
10534 | ||
3b7b72ee | 10535 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10536 | |
10537 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10538 | nl80211_mlme_mcgrp.id, gfp); | |
10539 | return; | |
10540 | ||
10541 | nla_put_failure: | |
10542 | genlmsg_cancel(msg, hdr); | |
10543 | nlmsg_free(msg); | |
10544 | } | |
10545 | ||
947add36 JB |
10546 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10547 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10548 | { | |
10549 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10550 | struct wiphy *wiphy = wdev->wiphy; | |
10551 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10552 | ||
10553 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10554 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10555 | } | |
10556 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10557 | ||
10558 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10559 | struct net_device *netdev, | |
10560 | struct cfg80211_chan_def *chandef, | |
10561 | gfp_t gfp) | |
5314526b TP |
10562 | { |
10563 | struct sk_buff *msg; | |
10564 | void *hdr; | |
10565 | ||
58050fce | 10566 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10567 | if (!msg) |
10568 | return; | |
10569 | ||
10570 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10571 | if (!hdr) { | |
10572 | nlmsg_free(msg); | |
10573 | return; | |
10574 | } | |
10575 | ||
683b6d3b JB |
10576 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10577 | goto nla_put_failure; | |
10578 | ||
10579 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10580 | goto nla_put_failure; |
5314526b TP |
10581 | |
10582 | genlmsg_end(msg, hdr); | |
10583 | ||
10584 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10585 | nl80211_mlme_mcgrp.id, gfp); | |
10586 | return; | |
10587 | ||
10588 | nla_put_failure: | |
10589 | genlmsg_cancel(msg, hdr); | |
10590 | nlmsg_free(msg); | |
10591 | } | |
10592 | ||
947add36 JB |
10593 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10594 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10595 | { |
947add36 JB |
10596 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10597 | struct wiphy *wiphy = wdev->wiphy; | |
10598 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10599 | ||
10600 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10601 | ||
10602 | wdev_lock(wdev); | |
10603 | ||
10604 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10605 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10606 | goto out; | |
10607 | ||
10608 | wdev->channel = chandef->chan; | |
10609 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10610 | out: | |
10611 | wdev_unlock(wdev); | |
10612 | return; | |
10613 | } | |
10614 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10615 | ||
10616 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10617 | const u8 *peer, u32 num_packets, | |
10618 | u32 rate, u32 intvl, gfp_t gfp) | |
10619 | { | |
10620 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10621 | struct wiphy *wiphy = wdev->wiphy; | |
10622 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10623 | struct sk_buff *msg; |
10624 | struct nlattr *pinfoattr; | |
10625 | void *hdr; | |
10626 | ||
10627 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10628 | if (!msg) | |
10629 | return; | |
10630 | ||
10631 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10632 | if (!hdr) { | |
10633 | nlmsg_free(msg); | |
10634 | return; | |
10635 | } | |
10636 | ||
10637 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10638 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10639 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10640 | goto nla_put_failure; | |
10641 | ||
10642 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10643 | if (!pinfoattr) | |
10644 | goto nla_put_failure; | |
10645 | ||
10646 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10647 | goto nla_put_failure; | |
10648 | ||
10649 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10650 | goto nla_put_failure; | |
10651 | ||
10652 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10653 | goto nla_put_failure; | |
10654 | ||
10655 | nla_nest_end(msg, pinfoattr); | |
10656 | ||
10657 | genlmsg_end(msg, hdr); | |
10658 | ||
10659 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10660 | nl80211_mlme_mcgrp.id, gfp); | |
10661 | return; | |
10662 | ||
10663 | nla_put_failure: | |
10664 | genlmsg_cancel(msg, hdr); | |
10665 | nlmsg_free(msg); | |
10666 | } | |
947add36 | 10667 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10668 | |
04f39047 SW |
10669 | void |
10670 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10671 | struct cfg80211_chan_def *chandef, | |
10672 | enum nl80211_radar_event event, | |
10673 | struct net_device *netdev, gfp_t gfp) | |
10674 | { | |
10675 | struct sk_buff *msg; | |
10676 | void *hdr; | |
10677 | ||
10678 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10679 | if (!msg) | |
10680 | return; | |
10681 | ||
10682 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10683 | if (!hdr) { | |
10684 | nlmsg_free(msg); | |
10685 | return; | |
10686 | } | |
10687 | ||
10688 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10689 | goto nla_put_failure; | |
10690 | ||
10691 | /* NOP and radar events don't need a netdev parameter */ | |
10692 | if (netdev) { | |
10693 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10694 | ||
10695 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10696 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10697 | goto nla_put_failure; | |
10698 | } | |
10699 | ||
10700 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10701 | goto nla_put_failure; | |
10702 | ||
10703 | if (nl80211_send_chandef(msg, chandef)) | |
10704 | goto nla_put_failure; | |
10705 | ||
9c90a9f6 | 10706 | genlmsg_end(msg, hdr); |
04f39047 SW |
10707 | |
10708 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10709 | nl80211_mlme_mcgrp.id, gfp); | |
10710 | return; | |
10711 | ||
10712 | nla_put_failure: | |
10713 | genlmsg_cancel(msg, hdr); | |
10714 | nlmsg_free(msg); | |
10715 | } | |
10716 | ||
947add36 JB |
10717 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10718 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10719 | { |
947add36 JB |
10720 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10721 | struct wiphy *wiphy = wdev->wiphy; | |
10722 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10723 | struct sk_buff *msg; |
10724 | struct nlattr *pinfoattr; | |
10725 | void *hdr; | |
10726 | ||
947add36 JB |
10727 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10728 | ||
58050fce | 10729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10730 | if (!msg) |
10731 | return; | |
10732 | ||
10733 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10734 | if (!hdr) { | |
10735 | nlmsg_free(msg); | |
10736 | return; | |
10737 | } | |
10738 | ||
9360ffd1 | 10739 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10740 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10741 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10742 | goto nla_put_failure; | |
c063dbf5 JB |
10743 | |
10744 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10745 | if (!pinfoattr) | |
10746 | goto nla_put_failure; | |
10747 | ||
9360ffd1 DM |
10748 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10749 | goto nla_put_failure; | |
c063dbf5 JB |
10750 | |
10751 | nla_nest_end(msg, pinfoattr); | |
10752 | ||
3b7b72ee | 10753 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10754 | |
10755 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10756 | nl80211_mlme_mcgrp.id, gfp); | |
10757 | return; | |
10758 | ||
10759 | nla_put_failure: | |
10760 | genlmsg_cancel(msg, hdr); | |
10761 | nlmsg_free(msg); | |
10762 | } | |
947add36 | 10763 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10764 | |
7f6cf311 JB |
10765 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10766 | u64 cookie, bool acked, gfp_t gfp) | |
10767 | { | |
10768 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10769 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10770 | struct sk_buff *msg; | |
10771 | void *hdr; | |
7f6cf311 | 10772 | |
4ee3e063 BL |
10773 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10774 | ||
58050fce | 10775 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10776 | |
7f6cf311 JB |
10777 | if (!msg) |
10778 | return; | |
10779 | ||
10780 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10781 | if (!hdr) { | |
10782 | nlmsg_free(msg); | |
10783 | return; | |
10784 | } | |
10785 | ||
9360ffd1 DM |
10786 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10787 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10788 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10789 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10790 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10791 | goto nla_put_failure; | |
7f6cf311 | 10792 | |
9c90a9f6 | 10793 | genlmsg_end(msg, hdr); |
7f6cf311 JB |
10794 | |
10795 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10796 | nl80211_mlme_mcgrp.id, gfp); | |
10797 | return; | |
10798 | ||
10799 | nla_put_failure: | |
10800 | genlmsg_cancel(msg, hdr); | |
10801 | nlmsg_free(msg); | |
10802 | } | |
10803 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10804 | ||
5e760230 JB |
10805 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10806 | const u8 *frame, size_t len, | |
37c73b5f | 10807 | int freq, int sig_dbm) |
5e760230 JB |
10808 | { |
10809 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10810 | struct sk_buff *msg; | |
10811 | void *hdr; | |
37c73b5f | 10812 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10813 | |
4ee3e063 BL |
10814 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10815 | ||
37c73b5f BG |
10816 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10817 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10818 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10819 | if (!msg) { | |
10820 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10821 | return; | |
10822 | } | |
5e760230 | 10823 | |
37c73b5f BG |
10824 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10825 | if (!hdr) | |
10826 | goto nla_put_failure; | |
5e760230 | 10827 | |
37c73b5f BG |
10828 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10829 | (freq && | |
10830 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10831 | (sig_dbm && | |
10832 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10833 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10834 | goto nla_put_failure; | |
5e760230 | 10835 | |
37c73b5f | 10836 | genlmsg_end(msg, hdr); |
5e760230 | 10837 | |
37c73b5f BG |
10838 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10839 | } | |
10840 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10841 | return; |
10842 | ||
10843 | nla_put_failure: | |
37c73b5f BG |
10844 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10845 | if (hdr) | |
10846 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10847 | nlmsg_free(msg); |
10848 | } | |
10849 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10850 | ||
cd8f7cb4 JB |
10851 | #ifdef CONFIG_PM |
10852 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10853 | struct cfg80211_wowlan_wakeup *wakeup, | |
10854 | gfp_t gfp) | |
10855 | { | |
10856 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10857 | struct sk_buff *msg; | |
10858 | void *hdr; | |
9c90a9f6 | 10859 | int size = 200; |
cd8f7cb4 JB |
10860 | |
10861 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10862 | ||
10863 | if (wakeup) | |
10864 | size += wakeup->packet_present_len; | |
10865 | ||
10866 | msg = nlmsg_new(size, gfp); | |
10867 | if (!msg) | |
10868 | return; | |
10869 | ||
10870 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10871 | if (!hdr) | |
10872 | goto free_msg; | |
10873 | ||
10874 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10875 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10876 | goto free_msg; | |
10877 | ||
10878 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10879 | wdev->netdev->ifindex)) | |
10880 | goto free_msg; | |
10881 | ||
10882 | if (wakeup) { | |
10883 | struct nlattr *reasons; | |
10884 | ||
10885 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10886 | ||
10887 | if (wakeup->disconnect && | |
10888 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10889 | goto free_msg; | |
10890 | if (wakeup->magic_pkt && | |
10891 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10892 | goto free_msg; | |
10893 | if (wakeup->gtk_rekey_failure && | |
10894 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10895 | goto free_msg; | |
10896 | if (wakeup->eap_identity_req && | |
10897 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10898 | goto free_msg; | |
10899 | if (wakeup->four_way_handshake && | |
10900 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10901 | goto free_msg; | |
10902 | if (wakeup->rfkill_release && | |
10903 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10904 | goto free_msg; | |
10905 | ||
10906 | if (wakeup->pattern_idx >= 0 && | |
10907 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10908 | wakeup->pattern_idx)) | |
10909 | goto free_msg; | |
10910 | ||
2a0e047e JB |
10911 | if (wakeup->tcp_match) |
10912 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10913 | ||
10914 | if (wakeup->tcp_connlost) | |
10915 | nla_put_flag(msg, | |
10916 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10917 | ||
10918 | if (wakeup->tcp_nomoretokens) | |
10919 | nla_put_flag(msg, | |
10920 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10921 | ||
cd8f7cb4 JB |
10922 | if (wakeup->packet) { |
10923 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10924 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10925 | ||
10926 | if (!wakeup->packet_80211) { | |
10927 | pkt_attr = | |
10928 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10929 | len_attr = | |
10930 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10931 | } | |
10932 | ||
10933 | if (wakeup->packet_len && | |
10934 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10935 | goto free_msg; | |
10936 | ||
10937 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10938 | wakeup->packet)) | |
10939 | goto free_msg; | |
10940 | } | |
10941 | ||
10942 | nla_nest_end(msg, reasons); | |
10943 | } | |
10944 | ||
9c90a9f6 | 10945 | genlmsg_end(msg, hdr); |
cd8f7cb4 JB |
10946 | |
10947 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10948 | nl80211_mlme_mcgrp.id, gfp); | |
10949 | return; | |
10950 | ||
10951 | free_msg: | |
10952 | nlmsg_free(msg); | |
10953 | } | |
10954 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10955 | #endif | |
10956 | ||
3475b094 JM |
10957 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10958 | enum nl80211_tdls_operation oper, | |
10959 | u16 reason_code, gfp_t gfp) | |
10960 | { | |
10961 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10962 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10963 | struct sk_buff *msg; | |
10964 | void *hdr; | |
3475b094 JM |
10965 | |
10966 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10967 | reason_code); | |
10968 | ||
10969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10970 | if (!msg) | |
10971 | return; | |
10972 | ||
10973 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10974 | if (!hdr) { | |
10975 | nlmsg_free(msg); | |
10976 | return; | |
10977 | } | |
10978 | ||
10979 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10980 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10981 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10982 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10983 | (reason_code > 0 && | |
10984 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10985 | goto nla_put_failure; | |
10986 | ||
9c90a9f6 | 10987 | genlmsg_end(msg, hdr); |
3475b094 JM |
10988 | |
10989 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10990 | nl80211_mlme_mcgrp.id, gfp); | |
10991 | return; | |
10992 | ||
10993 | nla_put_failure: | |
10994 | genlmsg_cancel(msg, hdr); | |
10995 | nlmsg_free(msg); | |
10996 | } | |
10997 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10998 | ||
026331c4 JM |
10999 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11000 | unsigned long state, | |
11001 | void *_notify) | |
11002 | { | |
11003 | struct netlink_notify *notify = _notify; | |
11004 | struct cfg80211_registered_device *rdev; | |
11005 | struct wireless_dev *wdev; | |
37c73b5f | 11006 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11007 | |
11008 | if (state != NETLINK_URELEASE) | |
11009 | return NOTIFY_DONE; | |
11010 | ||
11011 | rcu_read_lock(); | |
11012 | ||
5e760230 | 11013 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 11014 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 11015 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
11016 | |
11017 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11018 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11019 | list) { | |
11020 | if (reg->nlportid == notify->portid) { | |
11021 | list_del(®->list); | |
11022 | kfree(reg); | |
11023 | break; | |
11024 | } | |
11025 | } | |
11026 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 11027 | } |
026331c4 JM |
11028 | |
11029 | rcu_read_unlock(); | |
11030 | ||
11031 | return NOTIFY_DONE; | |
11032 | } | |
11033 | ||
11034 | static struct notifier_block nl80211_netlink_notifier = { | |
11035 | .notifier_call = nl80211_netlink_notify, | |
11036 | }; | |
11037 | ||
355199e0 JM |
11038 | void cfg80211_ft_event(struct net_device *netdev, |
11039 | struct cfg80211_ft_event_params *ft_event) | |
11040 | { | |
11041 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
11042 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11043 | struct sk_buff *msg; | |
11044 | void *hdr; | |
355199e0 JM |
11045 | |
11046 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11047 | ||
11048 | if (!ft_event->target_ap) | |
11049 | return; | |
11050 | ||
11051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11052 | if (!msg) | |
11053 | return; | |
11054 | ||
11055 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
11056 | if (!hdr) { | |
11057 | nlmsg_free(msg); | |
11058 | return; | |
11059 | } | |
11060 | ||
11061 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
11062 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
11063 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
11064 | if (ft_event->ies) | |
11065 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
11066 | if (ft_event->ric_ies) | |
11067 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11068 | ft_event->ric_ies); | |
11069 | ||
9c90a9f6 | 11070 | genlmsg_end(msg, hdr); |
355199e0 JM |
11071 | |
11072 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11073 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
11074 | } | |
11075 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11076 | ||
5de17984 AS |
11077 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11078 | { | |
11079 | struct cfg80211_registered_device *rdev; | |
11080 | struct sk_buff *msg; | |
11081 | void *hdr; | |
11082 | u32 nlportid; | |
11083 | ||
11084 | rdev = wiphy_to_dev(wdev->wiphy); | |
11085 | if (!rdev->crit_proto_nlportid) | |
11086 | return; | |
11087 | ||
11088 | nlportid = rdev->crit_proto_nlportid; | |
11089 | rdev->crit_proto_nlportid = 0; | |
11090 | ||
11091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11092 | if (!msg) | |
11093 | return; | |
11094 | ||
11095 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11096 | if (!hdr) | |
11097 | goto nla_put_failure; | |
11098 | ||
11099 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11100 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11101 | goto nla_put_failure; | |
11102 | ||
11103 | genlmsg_end(msg, hdr); | |
11104 | ||
11105 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11106 | return; | |
11107 | ||
11108 | nla_put_failure: | |
11109 | if (hdr) | |
11110 | genlmsg_cancel(msg, hdr); | |
11111 | nlmsg_free(msg); | |
11112 | ||
11113 | } | |
11114 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11115 | ||
55682965 JB |
11116 | /* initialisation/exit functions */ |
11117 | ||
11118 | int nl80211_init(void) | |
11119 | { | |
0d63cbb5 | 11120 | int err; |
55682965 | 11121 | |
0d63cbb5 MM |
11122 | err = genl_register_family_with_ops(&nl80211_fam, |
11123 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
11124 | if (err) |
11125 | return err; | |
11126 | ||
55682965 JB |
11127 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
11128 | if (err) | |
11129 | goto err_out; | |
11130 | ||
2a519311 JB |
11131 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
11132 | if (err) | |
11133 | goto err_out; | |
11134 | ||
73d54c9e LR |
11135 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
11136 | if (err) | |
11137 | goto err_out; | |
11138 | ||
6039f6d2 JM |
11139 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
11140 | if (err) | |
11141 | goto err_out; | |
11142 | ||
aff89a9b JB |
11143 | #ifdef CONFIG_NL80211_TESTMODE |
11144 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
11145 | if (err) | |
11146 | goto err_out; | |
11147 | #endif | |
11148 | ||
026331c4 JM |
11149 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11150 | if (err) | |
11151 | goto err_out; | |
11152 | ||
55682965 JB |
11153 | return 0; |
11154 | err_out: | |
11155 | genl_unregister_family(&nl80211_fam); | |
11156 | return err; | |
11157 | } | |
11158 | ||
11159 | void nl80211_exit(void) | |
11160 | { | |
026331c4 | 11161 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11162 | genl_unregister_family(&nl80211_fam); |
11163 | } |