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 | ||
e5497d76 JB |
406 | /* policy for GTK rekey offload attributes */ |
407 | static const struct nla_policy | |
408 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
409 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
410 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
411 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
412 | }; | |
413 | ||
a1f1c21c LC |
414 | static const struct nla_policy |
415 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 416 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 417 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 418 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
419 | }; |
420 | ||
97990a06 JB |
421 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
422 | struct netlink_callback *cb, | |
423 | struct cfg80211_registered_device **rdev, | |
424 | struct wireless_dev **wdev) | |
a043897a | 425 | { |
97990a06 | 426 | int err; |
a043897a | 427 | |
97990a06 | 428 | rtnl_lock(); |
a043897a | 429 | |
97990a06 JB |
430 | if (!cb->args[0]) { |
431 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
432 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
433 | nl80211_policy); | |
434 | if (err) | |
435 | goto out_unlock; | |
67748893 | 436 | |
97990a06 JB |
437 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
438 | nl80211_fam.attrbuf); | |
439 | if (IS_ERR(*wdev)) { | |
440 | err = PTR_ERR(*wdev); | |
441 | goto out_unlock; | |
442 | } | |
443 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
444 | cb->args[0] = (*rdev)->wiphy_idx; | |
445 | cb->args[1] = (*wdev)->identifier; | |
446 | } else { | |
447 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); | |
448 | struct wireless_dev *tmp; | |
67748893 | 449 | |
97990a06 JB |
450 | if (!wiphy) { |
451 | err = -ENODEV; | |
452 | goto out_unlock; | |
453 | } | |
454 | *rdev = wiphy_to_dev(wiphy); | |
455 | *wdev = NULL; | |
67748893 | 456 | |
97990a06 JB |
457 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
458 | if (tmp->identifier == cb->args[1]) { | |
459 | *wdev = tmp; | |
460 | break; | |
461 | } | |
462 | } | |
67748893 | 463 | |
97990a06 JB |
464 | if (!*wdev) { |
465 | err = -ENODEV; | |
466 | goto out_unlock; | |
467 | } | |
67748893 JB |
468 | } |
469 | ||
67748893 | 470 | return 0; |
97990a06 | 471 | out_unlock: |
67748893 JB |
472 | rtnl_unlock(); |
473 | return err; | |
474 | } | |
475 | ||
97990a06 | 476 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 477 | { |
67748893 JB |
478 | rtnl_unlock(); |
479 | } | |
480 | ||
f4a11bb0 JB |
481 | /* IE validation */ |
482 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
483 | { | |
484 | const u8 *pos; | |
485 | int len; | |
486 | ||
487 | if (!attr) | |
488 | return true; | |
489 | ||
490 | pos = nla_data(attr); | |
491 | len = nla_len(attr); | |
492 | ||
493 | while (len) { | |
494 | u8 elemlen; | |
495 | ||
496 | if (len < 2) | |
497 | return false; | |
498 | len -= 2; | |
499 | ||
500 | elemlen = pos[1]; | |
501 | if (elemlen > len) | |
502 | return false; | |
503 | ||
504 | len -= elemlen; | |
505 | pos += 2 + elemlen; | |
506 | } | |
507 | ||
508 | return true; | |
509 | } | |
510 | ||
55682965 | 511 | /* message building helper */ |
15e47304 | 512 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
513 | int flags, u8 cmd) |
514 | { | |
515 | /* since there is no private header just add the generic one */ | |
15e47304 | 516 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
517 | } |
518 | ||
5dab3b8a | 519 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
520 | struct ieee80211_channel *chan, |
521 | bool large) | |
5dab3b8a | 522 | { |
9360ffd1 DM |
523 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
524 | chan->center_freq)) | |
525 | goto nla_put_failure; | |
5dab3b8a | 526 | |
9360ffd1 DM |
527 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
529 | goto nla_put_failure; | |
530 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
532 | goto nla_put_failure; | |
533 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
534 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
535 | goto nla_put_failure; | |
cdc89b97 JB |
536 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
537 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
538 | goto nla_put_failure; | |
539 | if (large) { | |
540 | u32 time; | |
541 | ||
542 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
543 | ||
544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
545 | chan->dfs_state)) | |
546 | goto nla_put_failure; | |
547 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
548 | time)) | |
549 | goto nla_put_failure; | |
550 | } | |
551 | } | |
5dab3b8a | 552 | |
fe1abafd JB |
553 | if (large) { |
554 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
556 | goto nla_put_failure; | |
557 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
559 | goto nla_put_failure; | |
560 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
562 | goto nla_put_failure; | |
563 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
565 | goto nla_put_failure; | |
566 | } | |
567 | ||
9360ffd1 DM |
568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
569 | DBM_TO_MBM(chan->max_power))) | |
570 | goto nla_put_failure; | |
5dab3b8a LR |
571 | |
572 | return 0; | |
573 | ||
574 | nla_put_failure: | |
575 | return -ENOBUFS; | |
576 | } | |
577 | ||
55682965 JB |
578 | /* netlink command implementations */ |
579 | ||
b9454e83 JB |
580 | struct key_parse { |
581 | struct key_params p; | |
582 | int idx; | |
e31b8213 | 583 | int type; |
b9454e83 | 584 | bool def, defmgmt; |
dbd2fd65 | 585 | bool def_uni, def_multi; |
b9454e83 JB |
586 | }; |
587 | ||
588 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
589 | { | |
590 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
591 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
592 | nl80211_key_policy); | |
593 | if (err) | |
594 | return err; | |
595 | ||
596 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
597 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
598 | ||
dbd2fd65 JB |
599 | if (k->def) { |
600 | k->def_uni = true; | |
601 | k->def_multi = true; | |
602 | } | |
603 | if (k->defmgmt) | |
604 | k->def_multi = true; | |
605 | ||
b9454e83 JB |
606 | if (tb[NL80211_KEY_IDX]) |
607 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
608 | ||
609 | if (tb[NL80211_KEY_DATA]) { | |
610 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
611 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
612 | } | |
613 | ||
614 | if (tb[NL80211_KEY_SEQ]) { | |
615 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
616 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
617 | } | |
618 | ||
619 | if (tb[NL80211_KEY_CIPHER]) | |
620 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
621 | ||
e31b8213 JB |
622 | if (tb[NL80211_KEY_TYPE]) { |
623 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
624 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
625 | return -EINVAL; | |
626 | } | |
627 | ||
dbd2fd65 JB |
628 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
629 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
630 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
631 | tb[NL80211_KEY_DEFAULT_TYPES], | |
632 | nl80211_key_default_policy); | |
dbd2fd65 JB |
633 | if (err) |
634 | return err; | |
635 | ||
636 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
637 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
638 | } | |
639 | ||
b9454e83 JB |
640 | return 0; |
641 | } | |
642 | ||
643 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
644 | { | |
645 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
646 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
647 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
648 | } | |
649 | ||
650 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
651 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
652 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
653 | } | |
654 | ||
655 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
656 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
657 | ||
658 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
659 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
660 | ||
661 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
662 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
663 | ||
dbd2fd65 JB |
664 | if (k->def) { |
665 | k->def_uni = true; | |
666 | k->def_multi = true; | |
667 | } | |
668 | if (k->defmgmt) | |
669 | k->def_multi = true; | |
670 | ||
e31b8213 JB |
671 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
672 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
673 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
674 | return -EINVAL; | |
675 | } | |
676 | ||
dbd2fd65 JB |
677 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
678 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
679 | int err = nla_parse_nested( | |
680 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
681 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
682 | nl80211_key_default_policy); | |
683 | if (err) | |
684 | return err; | |
685 | ||
686 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
687 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
688 | } | |
689 | ||
b9454e83 JB |
690 | return 0; |
691 | } | |
692 | ||
693 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
694 | { | |
695 | int err; | |
696 | ||
697 | memset(k, 0, sizeof(*k)); | |
698 | k->idx = -1; | |
e31b8213 | 699 | k->type = -1; |
b9454e83 JB |
700 | |
701 | if (info->attrs[NL80211_ATTR_KEY]) | |
702 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
703 | else | |
704 | err = nl80211_parse_key_old(info, k); | |
705 | ||
706 | if (err) | |
707 | return err; | |
708 | ||
709 | if (k->def && k->defmgmt) | |
710 | return -EINVAL; | |
711 | ||
dbd2fd65 JB |
712 | if (k->defmgmt) { |
713 | if (k->def_uni || !k->def_multi) | |
714 | return -EINVAL; | |
715 | } | |
716 | ||
b9454e83 JB |
717 | if (k->idx != -1) { |
718 | if (k->defmgmt) { | |
719 | if (k->idx < 4 || k->idx > 5) | |
720 | return -EINVAL; | |
721 | } else if (k->def) { | |
722 | if (k->idx < 0 || k->idx > 3) | |
723 | return -EINVAL; | |
724 | } else { | |
725 | if (k->idx < 0 || k->idx > 5) | |
726 | return -EINVAL; | |
727 | } | |
728 | } | |
729 | ||
730 | return 0; | |
731 | } | |
732 | ||
fffd0934 JB |
733 | static struct cfg80211_cached_keys * |
734 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 735 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
736 | { |
737 | struct key_parse parse; | |
738 | struct nlattr *key; | |
739 | struct cfg80211_cached_keys *result; | |
740 | int rem, err, def = 0; | |
741 | ||
742 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
743 | if (!result) | |
744 | return ERR_PTR(-ENOMEM); | |
745 | ||
746 | result->def = -1; | |
747 | result->defmgmt = -1; | |
748 | ||
749 | nla_for_each_nested(key, keys, rem) { | |
750 | memset(&parse, 0, sizeof(parse)); | |
751 | parse.idx = -1; | |
752 | ||
753 | err = nl80211_parse_key_new(key, &parse); | |
754 | if (err) | |
755 | goto error; | |
756 | err = -EINVAL; | |
757 | if (!parse.p.key) | |
758 | goto error; | |
759 | if (parse.idx < 0 || parse.idx > 4) | |
760 | goto error; | |
761 | if (parse.def) { | |
762 | if (def) | |
763 | goto error; | |
764 | def = 1; | |
765 | result->def = parse.idx; | |
dbd2fd65 JB |
766 | if (!parse.def_uni || !parse.def_multi) |
767 | goto error; | |
fffd0934 JB |
768 | } else if (parse.defmgmt) |
769 | goto error; | |
770 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 771 | parse.idx, false, NULL); |
fffd0934 JB |
772 | if (err) |
773 | goto error; | |
774 | result->params[parse.idx].cipher = parse.p.cipher; | |
775 | result->params[parse.idx].key_len = parse.p.key_len; | |
776 | result->params[parse.idx].key = result->data[parse.idx]; | |
777 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
778 | |
779 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
780 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
781 | if (no_ht) | |
782 | *no_ht = true; | |
783 | } | |
fffd0934 JB |
784 | } |
785 | ||
786 | return result; | |
787 | error: | |
788 | kfree(result); | |
789 | return ERR_PTR(err); | |
790 | } | |
791 | ||
792 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
793 | { | |
794 | ASSERT_WDEV_LOCK(wdev); | |
795 | ||
fffd0934 JB |
796 | switch (wdev->iftype) { |
797 | case NL80211_IFTYPE_AP: | |
798 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 799 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 800 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
801 | break; |
802 | case NL80211_IFTYPE_ADHOC: | |
803 | if (!wdev->current_bss) | |
804 | return -ENOLINK; | |
805 | break; | |
806 | case NL80211_IFTYPE_STATION: | |
074ac8df | 807 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
808 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
809 | return -ENOLINK; | |
810 | break; | |
811 | default: | |
812 | return -EINVAL; | |
813 | } | |
814 | ||
815 | return 0; | |
816 | } | |
817 | ||
7527a782 JB |
818 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
819 | { | |
820 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
821 | int i; | |
822 | ||
823 | if (!nl_modes) | |
824 | goto nla_put_failure; | |
825 | ||
826 | i = 0; | |
827 | while (ifmodes) { | |
9360ffd1 DM |
828 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
829 | goto nla_put_failure; | |
7527a782 JB |
830 | ifmodes >>= 1; |
831 | i++; | |
832 | } | |
833 | ||
834 | nla_nest_end(msg, nl_modes); | |
835 | return 0; | |
836 | ||
837 | nla_put_failure: | |
838 | return -ENOBUFS; | |
839 | } | |
840 | ||
841 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
842 | struct sk_buff *msg, |
843 | bool large) | |
7527a782 JB |
844 | { |
845 | struct nlattr *nl_combis; | |
846 | int i, j; | |
847 | ||
848 | nl_combis = nla_nest_start(msg, | |
849 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
850 | if (!nl_combis) | |
851 | goto nla_put_failure; | |
852 | ||
853 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
854 | const struct ieee80211_iface_combination *c; | |
855 | struct nlattr *nl_combi, *nl_limits; | |
856 | ||
857 | c = &wiphy->iface_combinations[i]; | |
858 | ||
859 | nl_combi = nla_nest_start(msg, i + 1); | |
860 | if (!nl_combi) | |
861 | goto nla_put_failure; | |
862 | ||
863 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
864 | if (!nl_limits) | |
865 | goto nla_put_failure; | |
866 | ||
867 | for (j = 0; j < c->n_limits; j++) { | |
868 | struct nlattr *nl_limit; | |
869 | ||
870 | nl_limit = nla_nest_start(msg, j + 1); | |
871 | if (!nl_limit) | |
872 | goto nla_put_failure; | |
9360ffd1 DM |
873 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
874 | c->limits[j].max)) | |
875 | goto nla_put_failure; | |
7527a782 JB |
876 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
877 | c->limits[j].types)) | |
878 | goto nla_put_failure; | |
879 | nla_nest_end(msg, nl_limit); | |
880 | } | |
881 | ||
882 | nla_nest_end(msg, nl_limits); | |
883 | ||
9360ffd1 DM |
884 | if (c->beacon_int_infra_match && |
885 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
886 | goto nla_put_failure; | |
887 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
888 | c->num_different_channels) || | |
889 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
890 | c->max_interfaces)) | |
891 | goto nla_put_failure; | |
cdc89b97 JB |
892 | if (large && |
893 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
894 | c->radar_detect_widths)) | |
895 | goto nla_put_failure; | |
7527a782 JB |
896 | |
897 | nla_nest_end(msg, nl_combi); | |
898 | } | |
899 | ||
900 | nla_nest_end(msg, nl_combis); | |
901 | ||
902 | return 0; | |
903 | nla_put_failure: | |
904 | return -ENOBUFS; | |
905 | } | |
906 | ||
3713b4e3 | 907 | #ifdef CONFIG_PM |
b56cf720 JB |
908 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
909 | struct sk_buff *msg) | |
910 | { | |
911 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; | |
912 | struct nlattr *nl_tcp; | |
913 | ||
914 | if (!tcp) | |
915 | return 0; | |
916 | ||
917 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
918 | if (!nl_tcp) | |
919 | return -ENOBUFS; | |
920 | ||
921 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
922 | tcp->data_payload_max)) | |
923 | return -ENOBUFS; | |
924 | ||
925 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
926 | tcp->data_payload_max)) | |
927 | return -ENOBUFS; | |
928 | ||
929 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
930 | return -ENOBUFS; | |
931 | ||
932 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
933 | sizeof(*tcp->tok), tcp->tok)) | |
934 | return -ENOBUFS; | |
935 | ||
936 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
937 | tcp->data_interval_max)) | |
938 | return -ENOBUFS; | |
939 | ||
940 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
941 | tcp->wake_payload_max)) | |
942 | return -ENOBUFS; | |
943 | ||
944 | nla_nest_end(msg, nl_tcp); | |
945 | return 0; | |
946 | } | |
947 | ||
3713b4e3 | 948 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
949 | struct cfg80211_registered_device *dev, |
950 | bool large) | |
55682965 | 951 | { |
3713b4e3 | 952 | struct nlattr *nl_wowlan; |
55682965 | 953 | |
3713b4e3 JB |
954 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
955 | return 0; | |
55682965 | 956 | |
3713b4e3 JB |
957 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
958 | if (!nl_wowlan) | |
959 | return -ENOBUFS; | |
9360ffd1 | 960 | |
3713b4e3 JB |
961 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
962 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
963 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
964 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
965 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
966 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
967 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
968 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
969 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
970 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
971 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
972 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
973 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
974 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
975 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
977 | return -ENOBUFS; | |
9360ffd1 | 978 | |
3713b4e3 JB |
979 | if (dev->wiphy.wowlan.n_patterns) { |
980 | struct nl80211_wowlan_pattern_support pat = { | |
981 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
982 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, | |
983 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, | |
984 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, | |
985 | }; | |
9360ffd1 | 986 | |
3713b4e3 JB |
987 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
988 | sizeof(pat), &pat)) | |
989 | return -ENOBUFS; | |
990 | } | |
9360ffd1 | 991 | |
b56cf720 JB |
992 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
993 | return -ENOBUFS; | |
994 | ||
3713b4e3 | 995 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 996 | |
3713b4e3 JB |
997 | return 0; |
998 | } | |
999 | #endif | |
9360ffd1 | 1000 | |
3713b4e3 JB |
1001 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1002 | struct ieee80211_supported_band *sband) | |
1003 | { | |
1004 | struct nlattr *nl_rates, *nl_rate; | |
1005 | struct ieee80211_rate *rate; | |
1006 | int i; | |
87bbbe22 | 1007 | |
3713b4e3 JB |
1008 | /* add HT info */ |
1009 | if (sband->ht_cap.ht_supported && | |
1010 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1011 | sizeof(sband->ht_cap.mcs), | |
1012 | &sband->ht_cap.mcs) || | |
1013 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1014 | sband->ht_cap.cap) || | |
1015 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1016 | sband->ht_cap.ampdu_factor) || | |
1017 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1018 | sband->ht_cap.ampdu_density))) | |
1019 | return -ENOBUFS; | |
afe0cbf8 | 1020 | |
3713b4e3 JB |
1021 | /* add VHT info */ |
1022 | if (sband->vht_cap.vht_supported && | |
1023 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1024 | sizeof(sband->vht_cap.vht_mcs), | |
1025 | &sband->vht_cap.vht_mcs) || | |
1026 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1027 | sband->vht_cap.cap))) | |
1028 | return -ENOBUFS; | |
f59ac048 | 1029 | |
3713b4e3 JB |
1030 | /* add bitrates */ |
1031 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1032 | if (!nl_rates) | |
1033 | return -ENOBUFS; | |
ee688b00 | 1034 | |
3713b4e3 JB |
1035 | for (i = 0; i < sband->n_bitrates; i++) { |
1036 | nl_rate = nla_nest_start(msg, i); | |
1037 | if (!nl_rate) | |
1038 | return -ENOBUFS; | |
ee688b00 | 1039 | |
3713b4e3 JB |
1040 | rate = &sband->bitrates[i]; |
1041 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1042 | rate->bitrate)) | |
1043 | return -ENOBUFS; | |
1044 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1045 | nla_put_flag(msg, | |
1046 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1047 | return -ENOBUFS; | |
ee688b00 | 1048 | |
3713b4e3 JB |
1049 | nla_nest_end(msg, nl_rate); |
1050 | } | |
d51626df | 1051 | |
3713b4e3 | 1052 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1053 | |
3713b4e3 JB |
1054 | return 0; |
1055 | } | |
ee688b00 | 1056 | |
3713b4e3 JB |
1057 | static int |
1058 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1059 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1060 | { | |
1061 | u16 stypes; | |
1062 | struct nlattr *nl_ftypes, *nl_ifs; | |
1063 | enum nl80211_iftype ift; | |
1064 | int i; | |
ee688b00 | 1065 | |
3713b4e3 JB |
1066 | if (!mgmt_stypes) |
1067 | return 0; | |
5dab3b8a | 1068 | |
3713b4e3 JB |
1069 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1070 | if (!nl_ifs) | |
1071 | return -ENOBUFS; | |
e2f367f2 | 1072 | |
3713b4e3 JB |
1073 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1074 | nl_ftypes = nla_nest_start(msg, ift); | |
1075 | if (!nl_ftypes) | |
1076 | return -ENOBUFS; | |
1077 | i = 0; | |
1078 | stypes = mgmt_stypes[ift].tx; | |
1079 | while (stypes) { | |
1080 | if ((stypes & 1) && | |
1081 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1082 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1083 | return -ENOBUFS; | |
1084 | stypes >>= 1; | |
1085 | i++; | |
ee688b00 | 1086 | } |
3713b4e3 JB |
1087 | nla_nest_end(msg, nl_ftypes); |
1088 | } | |
ee688b00 | 1089 | |
3713b4e3 | 1090 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1091 | |
3713b4e3 JB |
1092 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1093 | if (!nl_ifs) | |
1094 | return -ENOBUFS; | |
ee688b00 | 1095 | |
3713b4e3 JB |
1096 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1097 | nl_ftypes = nla_nest_start(msg, ift); | |
1098 | if (!nl_ftypes) | |
1099 | return -ENOBUFS; | |
1100 | i = 0; | |
1101 | stypes = mgmt_stypes[ift].rx; | |
1102 | while (stypes) { | |
1103 | if ((stypes & 1) && | |
1104 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1105 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1106 | return -ENOBUFS; | |
1107 | stypes >>= 1; | |
1108 | i++; | |
1109 | } | |
1110 | nla_nest_end(msg, nl_ftypes); | |
1111 | } | |
1112 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1113 | |
3713b4e3 JB |
1114 | return 0; |
1115 | } | |
ee688b00 | 1116 | |
3713b4e3 JB |
1117 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1118 | struct sk_buff *msg, u32 portid, u32 seq, | |
1119 | int flags, bool split, long *split_start, | |
1120 | long *band_start, long *chan_start) | |
1121 | { | |
1122 | void *hdr; | |
1123 | struct nlattr *nl_bands, *nl_band; | |
1124 | struct nlattr *nl_freqs, *nl_freq; | |
1125 | struct nlattr *nl_cmds; | |
1126 | enum ieee80211_band band; | |
1127 | struct ieee80211_channel *chan; | |
1128 | int i; | |
1129 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1130 | dev->wiphy.mgmt_stypes; | |
1131 | long start = 0, start_chan = 0, start_band = 0; | |
fe1abafd | 1132 | u32 features; |
ee688b00 | 1133 | |
3713b4e3 JB |
1134 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1135 | if (!hdr) | |
1136 | return -ENOBUFS; | |
ee688b00 | 1137 | |
3713b4e3 JB |
1138 | /* allow always using the variables */ |
1139 | if (!split) { | |
1140 | split_start = &start; | |
1141 | band_start = &start_band; | |
1142 | chan_start = &start_chan; | |
ee688b00 | 1143 | } |
ee688b00 | 1144 | |
3713b4e3 JB |
1145 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1146 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1147 | wiphy_name(&dev->wiphy)) || | |
1148 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1149 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1150 | goto nla_put_failure; |
1151 | ||
3713b4e3 JB |
1152 | switch (*split_start) { |
1153 | case 0: | |
1154 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1155 | dev->wiphy.retry_short) || | |
1156 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1157 | dev->wiphy.retry_long) || | |
1158 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1159 | dev->wiphy.frag_threshold) || | |
1160 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1161 | dev->wiphy.rts_threshold) || | |
1162 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1163 | dev->wiphy.coverage_class) || | |
1164 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1165 | dev->wiphy.max_scan_ssids) || | |
1166 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1167 | dev->wiphy.max_sched_scan_ssids) || | |
1168 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1169 | dev->wiphy.max_scan_ie_len) || | |
1170 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1171 | dev->wiphy.max_sched_scan_ie_len) || | |
1172 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1173 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1174 | goto nla_put_failure; |
3713b4e3 JB |
1175 | |
1176 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1177 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1178 | goto nla_put_failure; |
3713b4e3 JB |
1179 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1180 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1181 | goto nla_put_failure; | |
1182 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1183 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1184 | goto nla_put_failure; | |
1185 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1186 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1187 | goto nla_put_failure; | |
1188 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1189 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1190 | goto nla_put_failure; | |
1191 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1192 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1193 | goto nla_put_failure; |
8fdc621d | 1194 | |
3713b4e3 JB |
1195 | (*split_start)++; |
1196 | if (split) | |
1197 | break; | |
1198 | case 1: | |
1199 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1200 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1201 | dev->wiphy.cipher_suites)) | |
1202 | goto nla_put_failure; | |
4745fc09 | 1203 | |
3713b4e3 JB |
1204 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1205 | dev->wiphy.max_num_pmkids)) | |
1206 | goto nla_put_failure; | |
b23aa676 | 1207 | |
3713b4e3 JB |
1208 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1209 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1210 | goto nla_put_failure; |
b23aa676 | 1211 | |
3713b4e3 JB |
1212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1213 | dev->wiphy.available_antennas_tx) || | |
1214 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1215 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1216 | goto nla_put_failure; |
b23aa676 | 1217 | |
3713b4e3 JB |
1218 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1219 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1220 | dev->wiphy.probe_resp_offload)) | |
1221 | goto nla_put_failure; | |
8fdc621d | 1222 | |
3713b4e3 JB |
1223 | if ((dev->wiphy.available_antennas_tx || |
1224 | dev->wiphy.available_antennas_rx) && | |
1225 | dev->ops->get_antenna) { | |
1226 | u32 tx_ant = 0, rx_ant = 0; | |
1227 | int res; | |
1228 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1229 | if (!res) { | |
1230 | if (nla_put_u32(msg, | |
1231 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1232 | tx_ant) || | |
1233 | nla_put_u32(msg, | |
1234 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1235 | rx_ant)) | |
1236 | goto nla_put_failure; | |
1237 | } | |
1238 | } | |
a293911d | 1239 | |
3713b4e3 JB |
1240 | (*split_start)++; |
1241 | if (split) | |
1242 | break; | |
1243 | case 2: | |
1244 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1245 | dev->wiphy.interface_modes)) | |
1246 | goto nla_put_failure; | |
1247 | (*split_start)++; | |
1248 | if (split) | |
1249 | break; | |
1250 | case 3: | |
1251 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1252 | if (!nl_bands) | |
1253 | goto nla_put_failure; | |
f7ca38df | 1254 | |
3713b4e3 JB |
1255 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
1256 | struct ieee80211_supported_band *sband; | |
2e161f78 | 1257 | |
3713b4e3 | 1258 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1259 | |
3713b4e3 JB |
1260 | if (!sband) |
1261 | continue; | |
1262 | ||
1263 | nl_band = nla_nest_start(msg, band); | |
1264 | if (!nl_band) | |
2e161f78 | 1265 | goto nla_put_failure; |
3713b4e3 JB |
1266 | |
1267 | switch (*chan_start) { | |
1268 | case 0: | |
1269 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1270 | goto nla_put_failure; |
3713b4e3 JB |
1271 | (*chan_start)++; |
1272 | if (split) | |
1273 | break; | |
1274 | default: | |
1275 | /* add frequencies */ | |
1276 | nl_freqs = nla_nest_start( | |
1277 | msg, NL80211_BAND_ATTR_FREQS); | |
1278 | if (!nl_freqs) | |
1279 | goto nla_put_failure; | |
1280 | ||
1281 | for (i = *chan_start - 1; | |
1282 | i < sband->n_channels; | |
1283 | i++) { | |
1284 | nl_freq = nla_nest_start(msg, i); | |
1285 | if (!nl_freq) | |
1286 | goto nla_put_failure; | |
1287 | ||
1288 | chan = &sband->channels[i]; | |
1289 | ||
cdc89b97 JB |
1290 | if (nl80211_msg_put_channel(msg, chan, |
1291 | split)) | |
3713b4e3 JB |
1292 | goto nla_put_failure; |
1293 | ||
1294 | nla_nest_end(msg, nl_freq); | |
1295 | if (split) | |
1296 | break; | |
1297 | } | |
1298 | if (i < sband->n_channels) | |
1299 | *chan_start = i + 2; | |
1300 | else | |
1301 | *chan_start = 0; | |
1302 | nla_nest_end(msg, nl_freqs); | |
1303 | } | |
1304 | ||
1305 | nla_nest_end(msg, nl_band); | |
1306 | ||
1307 | if (split) { | |
1308 | /* start again here */ | |
1309 | if (*chan_start) | |
1310 | band--; | |
1311 | break; | |
2e161f78 | 1312 | } |
2e161f78 | 1313 | } |
3713b4e3 | 1314 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1315 | |
3713b4e3 JB |
1316 | if (band < IEEE80211_NUM_BANDS) |
1317 | *band_start = band + 1; | |
1318 | else | |
1319 | *band_start = 0; | |
74b70a4e | 1320 | |
3713b4e3 JB |
1321 | /* if bands & channels are done, continue outside */ |
1322 | if (*band_start == 0 && *chan_start == 0) | |
1323 | (*split_start)++; | |
1324 | if (split) | |
1325 | break; | |
1326 | case 4: | |
1327 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1328 | if (!nl_cmds) | |
2e161f78 JB |
1329 | goto nla_put_failure; |
1330 | ||
3713b4e3 JB |
1331 | i = 0; |
1332 | #define CMD(op, n) \ | |
1333 | do { \ | |
1334 | if (dev->ops->op) { \ | |
1335 | i++; \ | |
1336 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1337 | goto nla_put_failure; \ | |
1338 | } \ | |
1339 | } while (0) | |
1340 | ||
1341 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1342 | CMD(change_virtual_intf, SET_INTERFACE); | |
1343 | CMD(add_key, NEW_KEY); | |
1344 | CMD(start_ap, START_AP); | |
1345 | CMD(add_station, NEW_STATION); | |
1346 | CMD(add_mpath, NEW_MPATH); | |
1347 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1348 | CMD(change_bss, SET_BSS); | |
1349 | CMD(auth, AUTHENTICATE); | |
1350 | CMD(assoc, ASSOCIATE); | |
1351 | CMD(deauth, DEAUTHENTICATE); | |
1352 | CMD(disassoc, DISASSOCIATE); | |
1353 | CMD(join_ibss, JOIN_IBSS); | |
1354 | CMD(join_mesh, JOIN_MESH); | |
1355 | CMD(set_pmksa, SET_PMKSA); | |
1356 | CMD(del_pmksa, DEL_PMKSA); | |
1357 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1358 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1359 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1360 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1361 | CMD(mgmt_tx, FRAME); | |
1362 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1363 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1364 | i++; | |
1365 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1366 | goto nla_put_failure; |
2e161f78 | 1367 | } |
3713b4e3 JB |
1368 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1369 | dev->ops->join_mesh) { | |
1370 | i++; | |
1371 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1372 | goto nla_put_failure; | |
1373 | } | |
1374 | CMD(set_wds_peer, SET_WDS_PEER); | |
1375 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1376 | CMD(tdls_mgmt, TDLS_MGMT); | |
1377 | CMD(tdls_oper, TDLS_OPER); | |
1378 | } | |
1379 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1380 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1381 | CMD(probe_client, PROBE_CLIENT); | |
1382 | CMD(set_noack_map, SET_NOACK_MAP); | |
1383 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1384 | i++; | |
1385 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1386 | goto nla_put_failure; | |
1387 | } | |
1388 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1389 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
5de17984 AS |
1390 | if (split) { |
1391 | CMD(crit_proto_start, CRIT_PROTOCOL_START); | |
1392 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1393 | } | |
2e161f78 | 1394 | |
3713b4e3 JB |
1395 | #ifdef CONFIG_NL80211_TESTMODE |
1396 | CMD(testmode_cmd, TESTMODE); | |
1397 | #endif | |
ff1b6e69 | 1398 | |
3713b4e3 | 1399 | #undef CMD |
ff1b6e69 | 1400 | |
3713b4e3 JB |
1401 | if (dev->ops->connect || dev->ops->auth) { |
1402 | i++; | |
1403 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1404 | goto nla_put_failure; |
ff1b6e69 JB |
1405 | } |
1406 | ||
3713b4e3 JB |
1407 | if (dev->ops->disconnect || dev->ops->deauth) { |
1408 | i++; | |
1409 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1410 | goto nla_put_failure; | |
1411 | } | |
1412 | ||
1413 | nla_nest_end(msg, nl_cmds); | |
1414 | (*split_start)++; | |
1415 | if (split) | |
1416 | break; | |
1417 | case 5: | |
1418 | if (dev->ops->remain_on_channel && | |
1419 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1420 | nla_put_u32(msg, | |
1421 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1422 | dev->wiphy.max_remain_on_channel_duration)) | |
1423 | goto nla_put_failure; | |
1424 | ||
1425 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1426 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1427 | goto nla_put_failure; | |
1428 | ||
1429 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1430 | goto nla_put_failure; | |
1431 | (*split_start)++; | |
1432 | if (split) | |
1433 | break; | |
1434 | case 6: | |
1435 | #ifdef CONFIG_PM | |
b56cf720 | 1436 | if (nl80211_send_wowlan(msg, dev, split)) |
3713b4e3 JB |
1437 | goto nla_put_failure; |
1438 | (*split_start)++; | |
1439 | if (split) | |
1440 | break; | |
1441 | #else | |
1442 | (*split_start)++; | |
dfb89c56 | 1443 | #endif |
3713b4e3 JB |
1444 | case 7: |
1445 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1446 | dev->wiphy.software_iftypes)) | |
1447 | goto nla_put_failure; | |
ff1b6e69 | 1448 | |
cdc89b97 | 1449 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
3713b4e3 | 1450 | goto nla_put_failure; |
7527a782 | 1451 | |
3713b4e3 JB |
1452 | (*split_start)++; |
1453 | if (split) | |
1454 | break; | |
1455 | case 8: | |
1456 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1457 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1458 | dev->wiphy.ap_sme_capa)) | |
1459 | goto nla_put_failure; | |
7527a782 | 1460 | |
fe1abafd JB |
1461 | features = dev->wiphy.features; |
1462 | /* | |
1463 | * We can only add the per-channel limit information if the | |
1464 | * dump is split, otherwise it makes it too big. Therefore | |
1465 | * only advertise it in that case. | |
1466 | */ | |
1467 | if (split) | |
1468 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | |
1469 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1470 | goto nla_put_failure; |
562a7480 | 1471 | |
3713b4e3 JB |
1472 | if (dev->wiphy.ht_capa_mod_mask && |
1473 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1474 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1475 | dev->wiphy.ht_capa_mod_mask)) | |
1476 | goto nla_put_failure; | |
1f074bd8 | 1477 | |
3713b4e3 JB |
1478 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1479 | dev->wiphy.max_acl_mac_addrs && | |
1480 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1481 | dev->wiphy.max_acl_mac_addrs)) | |
1482 | goto nla_put_failure; | |
7e7c8926 | 1483 | |
3713b4e3 JB |
1484 | /* |
1485 | * Any information below this point is only available to | |
1486 | * applications that can deal with it being split. This | |
1487 | * helps ensure that newly added capabilities don't break | |
1488 | * older tools by overrunning their buffers. | |
1489 | * | |
1490 | * We still increment split_start so that in the split | |
1491 | * case we'll continue with more data in the next round, | |
1492 | * but break unconditionally so unsplit data stops here. | |
1493 | */ | |
1494 | (*split_start)++; | |
1495 | break; | |
1496 | case 9: | |
fe1abafd JB |
1497 | if (dev->wiphy.extended_capabilities && |
1498 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1499 | dev->wiphy.extended_capabilities_len, | |
1500 | dev->wiphy.extended_capabilities) || | |
1501 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1502 | dev->wiphy.extended_capabilities_len, | |
1503 | dev->wiphy.extended_capabilities_mask))) | |
1504 | goto nla_put_failure; | |
a50df0c4 | 1505 | |
ee2aca34 JB |
1506 | if (dev->wiphy.vht_capa_mod_mask && |
1507 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1508 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1509 | dev->wiphy.vht_capa_mod_mask)) | |
1510 | goto nla_put_failure; | |
1511 | ||
3713b4e3 JB |
1512 | /* done */ |
1513 | *split_start = 0; | |
1514 | break; | |
1515 | } | |
55682965 JB |
1516 | return genlmsg_end(msg, hdr); |
1517 | ||
1518 | nla_put_failure: | |
bc3ed28c TG |
1519 | genlmsg_cancel(msg, hdr); |
1520 | return -EMSGSIZE; | |
55682965 JB |
1521 | } |
1522 | ||
1523 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1524 | { | |
645e77de | 1525 | int idx = 0, ret; |
55682965 JB |
1526 | int start = cb->args[0]; |
1527 | struct cfg80211_registered_device *dev; | |
3713b4e3 JB |
1528 | s64 filter_wiphy = -1; |
1529 | bool split = false; | |
1530 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1531 | int res; | |
55682965 | 1532 | |
5fe231e8 | 1533 | rtnl_lock(); |
3713b4e3 JB |
1534 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
1535 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1536 | if (res == 0) { | |
1537 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1538 | if (tb[NL80211_ATTR_WIPHY]) | |
1539 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1540 | if (tb[NL80211_ATTR_WDEV]) | |
1541 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1542 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1543 | struct net_device *netdev; | |
1544 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1545 | ||
1546 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
5fe231e8 | 1547 | if (!netdev) |
3713b4e3 | 1548 | return -ENODEV; |
3713b4e3 JB |
1549 | if (netdev->ieee80211_ptr) { |
1550 | dev = wiphy_to_dev( | |
1551 | netdev->ieee80211_ptr->wiphy); | |
1552 | filter_wiphy = dev->wiphy_idx; | |
1553 | } | |
1554 | dev_put(netdev); | |
1555 | } | |
1556 | } | |
1557 | ||
79c97e97 | 1558 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1559 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1560 | continue; | |
b4637271 | 1561 | if (++idx <= start) |
55682965 | 1562 | continue; |
3713b4e3 JB |
1563 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
1564 | continue; | |
1565 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1566 | do { | |
1567 | ret = nl80211_send_wiphy(dev, skb, | |
1568 | NETLINK_CB(cb->skb).portid, | |
1569 | cb->nlh->nlmsg_seq, | |
1570 | NLM_F_MULTI, | |
1571 | split, &cb->args[1], | |
1572 | &cb->args[2], | |
1573 | &cb->args[3]); | |
1574 | if (ret < 0) { | |
1575 | /* | |
1576 | * If sending the wiphy data didn't fit (ENOBUFS | |
1577 | * or EMSGSIZE returned), this SKB is still | |
1578 | * empty (so it's not too big because another | |
1579 | * wiphy dataset is already in the skb) and | |
1580 | * we've not tried to adjust the dump allocation | |
1581 | * yet ... then adjust the alloc size to be | |
1582 | * bigger, and return 1 but with the empty skb. | |
1583 | * This results in an empty message being RX'ed | |
1584 | * in userspace, but that is ignored. | |
1585 | * | |
1586 | * We can then retry with the larger buffer. | |
1587 | */ | |
1588 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1589 | !skb->len && | |
1590 | cb->min_dump_alloc < 4096) { | |
1591 | cb->min_dump_alloc = 4096; | |
3713b4e3 JB |
1592 | return 1; |
1593 | } | |
1594 | idx--; | |
1595 | break; | |
645e77de | 1596 | } |
3713b4e3 JB |
1597 | } while (cb->args[1] > 0); |
1598 | break; | |
55682965 | 1599 | } |
5fe231e8 | 1600 | rtnl_unlock(); |
55682965 JB |
1601 | |
1602 | cb->args[0] = idx; | |
1603 | ||
1604 | return skb->len; | |
1605 | } | |
1606 | ||
1607 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1608 | { | |
1609 | struct sk_buff *msg; | |
4c476991 | 1610 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1611 | |
645e77de | 1612 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1613 | if (!msg) |
4c476991 | 1614 | return -ENOMEM; |
55682965 | 1615 | |
3713b4e3 JB |
1616 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
1617 | false, NULL, NULL, NULL) < 0) { | |
4c476991 JB |
1618 | nlmsg_free(msg); |
1619 | return -ENOBUFS; | |
1620 | } | |
55682965 | 1621 | |
134e6375 | 1622 | return genlmsg_reply(msg, info); |
55682965 JB |
1623 | } |
1624 | ||
31888487 JM |
1625 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1626 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1627 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1628 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1629 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1630 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1631 | }; | |
1632 | ||
1633 | static int parse_txq_params(struct nlattr *tb[], | |
1634 | struct ieee80211_txq_params *txq_params) | |
1635 | { | |
a3304b0a | 1636 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1637 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1638 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1639 | return -EINVAL; | |
1640 | ||
a3304b0a | 1641 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1642 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1643 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1644 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1645 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1646 | ||
a3304b0a JB |
1647 | if (txq_params->ac >= NL80211_NUM_ACS) |
1648 | return -EINVAL; | |
1649 | ||
31888487 JM |
1650 | return 0; |
1651 | } | |
1652 | ||
f444de05 JB |
1653 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1654 | { | |
1655 | /* | |
cc1d2806 JB |
1656 | * You can only set the channel explicitly for WDS interfaces, |
1657 | * all others have their channel managed via their respective | |
1658 | * "establish a connection" command (connect, join, ...) | |
1659 | * | |
1660 | * For AP/GO and mesh mode, the channel can be set with the | |
1661 | * channel userspace API, but is only stored and passed to the | |
1662 | * low-level driver when the AP starts or the mesh is joined. | |
1663 | * This is for backward compatibility, userspace can also give | |
1664 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1665 | * |
1666 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1667 | * whatever else is going on, so they have their own special |
1668 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1669 | */ |
1670 | return !wdev || | |
1671 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1672 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1673 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1674 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1675 | } |
1676 | ||
683b6d3b JB |
1677 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1678 | struct genl_info *info, | |
1679 | struct cfg80211_chan_def *chandef) | |
1680 | { | |
dbeca2ea | 1681 | u32 control_freq; |
683b6d3b JB |
1682 | |
1683 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1684 | return -EINVAL; | |
1685 | ||
1686 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1687 | ||
1688 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1689 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1690 | chandef->center_freq1 = control_freq; | |
1691 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1692 | |
1693 | /* Primary channel not allowed */ | |
1694 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1695 | return -EINVAL; | |
1696 | ||
3d9d1d66 JB |
1697 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1698 | enum nl80211_channel_type chantype; | |
1699 | ||
1700 | chantype = nla_get_u32( | |
1701 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1702 | ||
1703 | switch (chantype) { | |
1704 | case NL80211_CHAN_NO_HT: | |
1705 | case NL80211_CHAN_HT20: | |
1706 | case NL80211_CHAN_HT40PLUS: | |
1707 | case NL80211_CHAN_HT40MINUS: | |
1708 | cfg80211_chandef_create(chandef, chandef->chan, | |
1709 | chantype); | |
1710 | break; | |
1711 | default: | |
1712 | return -EINVAL; | |
1713 | } | |
1714 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1715 | chandef->width = | |
1716 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1717 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1718 | chandef->center_freq1 = | |
1719 | nla_get_u32( | |
1720 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1721 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1722 | chandef->center_freq2 = | |
1723 | nla_get_u32( | |
1724 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1725 | } | |
1726 | ||
9f5e8f6e | 1727 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1728 | return -EINVAL; |
1729 | ||
9f5e8f6e JB |
1730 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1731 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1732 | return -EINVAL; |
1733 | ||
683b6d3b JB |
1734 | return 0; |
1735 | } | |
1736 | ||
f444de05 JB |
1737 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1738 | struct wireless_dev *wdev, | |
1739 | struct genl_info *info) | |
1740 | { | |
683b6d3b | 1741 | struct cfg80211_chan_def chandef; |
f444de05 | 1742 | int result; |
e8c9bd5b JB |
1743 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1744 | ||
1745 | if (wdev) | |
1746 | iftype = wdev->iftype; | |
f444de05 | 1747 | |
f444de05 JB |
1748 | if (!nl80211_can_set_dev_channel(wdev)) |
1749 | return -EOPNOTSUPP; | |
1750 | ||
683b6d3b JB |
1751 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1752 | if (result) | |
1753 | return result; | |
f444de05 | 1754 | |
e8c9bd5b | 1755 | switch (iftype) { |
aa430da4 JB |
1756 | case NL80211_IFTYPE_AP: |
1757 | case NL80211_IFTYPE_P2P_GO: | |
1758 | if (wdev->beacon_interval) { | |
1759 | result = -EBUSY; | |
1760 | break; | |
1761 | } | |
683b6d3b | 1762 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1763 | result = -EINVAL; |
1764 | break; | |
1765 | } | |
683b6d3b | 1766 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1767 | result = 0; |
1768 | break; | |
cc1d2806 | 1769 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1770 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1771 | break; |
e8c9bd5b | 1772 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1773 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1774 | break; |
aa430da4 | 1775 | default: |
e8c9bd5b | 1776 | result = -EINVAL; |
f444de05 | 1777 | } |
f444de05 JB |
1778 | |
1779 | return result; | |
1780 | } | |
1781 | ||
1782 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1783 | { | |
4c476991 JB |
1784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1785 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1786 | |
4c476991 | 1787 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1788 | } |
1789 | ||
e8347eba BJ |
1790 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1791 | { | |
43b19952 JB |
1792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1793 | struct net_device *dev = info->user_ptr[1]; | |
1794 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1795 | const u8 *bssid; |
e8347eba BJ |
1796 | |
1797 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1798 | return -EINVAL; | |
1799 | ||
43b19952 JB |
1800 | if (netif_running(dev)) |
1801 | return -EBUSY; | |
e8347eba | 1802 | |
43b19952 JB |
1803 | if (!rdev->ops->set_wds_peer) |
1804 | return -EOPNOTSUPP; | |
e8347eba | 1805 | |
43b19952 JB |
1806 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1807 | return -EOPNOTSUPP; | |
e8347eba BJ |
1808 | |
1809 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1810 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1811 | } |
1812 | ||
1813 | ||
55682965 JB |
1814 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1815 | { | |
1816 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1817 | struct net_device *netdev = NULL; |
1818 | struct wireless_dev *wdev; | |
a1e567c8 | 1819 | int result = 0, rem_txq_params = 0; |
31888487 | 1820 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1821 | u32 changed; |
1822 | u8 retry_short = 0, retry_long = 0; | |
1823 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1824 | u8 coverage_class = 0; |
55682965 | 1825 | |
5fe231e8 JB |
1826 | ASSERT_RTNL(); |
1827 | ||
f444de05 JB |
1828 | /* |
1829 | * Try to find the wiphy and netdev. Normally this | |
1830 | * function shouldn't need the netdev, but this is | |
1831 | * done for backward compatibility -- previously | |
1832 | * setting the channel was done per wiphy, but now | |
1833 | * it is per netdev. Previous userland like hostapd | |
1834 | * also passed a netdev to set_wiphy, so that it is | |
1835 | * possible to let that go to the right netdev! | |
1836 | */ | |
4bbf4d56 | 1837 | |
f444de05 JB |
1838 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1839 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1840 | ||
1841 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
5fe231e8 | 1842 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 1843 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 1844 | else |
f444de05 | 1845 | netdev = NULL; |
4bbf4d56 JB |
1846 | } |
1847 | ||
f444de05 | 1848 | if (!netdev) { |
878d9ec7 JB |
1849 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1850 | info->attrs); | |
5fe231e8 | 1851 | if (IS_ERR(rdev)) |
4c476991 | 1852 | return PTR_ERR(rdev); |
f444de05 JB |
1853 | wdev = NULL; |
1854 | netdev = NULL; | |
1855 | result = 0; | |
71fe96bf | 1856 | } else |
f444de05 | 1857 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1858 | |
1859 | /* | |
1860 | * end workaround code, by now the rdev is available | |
1861 | * and locked, and wdev may or may not be NULL. | |
1862 | */ | |
4bbf4d56 JB |
1863 | |
1864 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1865 | result = cfg80211_dev_rename( |
1866 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 1867 | |
4bbf4d56 JB |
1868 | if (result) |
1869 | goto bad_res; | |
31888487 JM |
1870 | |
1871 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1872 | struct ieee80211_txq_params txq_params; | |
1873 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1874 | ||
1875 | if (!rdev->ops->set_txq_params) { | |
1876 | result = -EOPNOTSUPP; | |
1877 | goto bad_res; | |
1878 | } | |
1879 | ||
f70f01c2 EP |
1880 | if (!netdev) { |
1881 | result = -EINVAL; | |
1882 | goto bad_res; | |
1883 | } | |
1884 | ||
133a3ff2 JB |
1885 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1886 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1887 | result = -EINVAL; | |
1888 | goto bad_res; | |
1889 | } | |
1890 | ||
2b5f8b0b JB |
1891 | if (!netif_running(netdev)) { |
1892 | result = -ENETDOWN; | |
1893 | goto bad_res; | |
1894 | } | |
1895 | ||
31888487 JM |
1896 | nla_for_each_nested(nl_txq_params, |
1897 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1898 | rem_txq_params) { | |
1899 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1900 | nla_data(nl_txq_params), | |
1901 | nla_len(nl_txq_params), | |
1902 | txq_params_policy); | |
1903 | result = parse_txq_params(tb, &txq_params); | |
1904 | if (result) | |
1905 | goto bad_res; | |
1906 | ||
e35e4d28 HG |
1907 | result = rdev_set_txq_params(rdev, netdev, |
1908 | &txq_params); | |
31888487 JM |
1909 | if (result) |
1910 | goto bad_res; | |
1911 | } | |
1912 | } | |
55682965 | 1913 | |
72bdcf34 | 1914 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1915 | result = __nl80211_set_channel(rdev, |
1916 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1917 | info); | |
72bdcf34 JM |
1918 | if (result) |
1919 | goto bad_res; | |
1920 | } | |
1921 | ||
98d2ff8b | 1922 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1923 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1924 | enum nl80211_tx_power_setting type; |
1925 | int idx, mbm = 0; | |
1926 | ||
c8442118 JB |
1927 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
1928 | txp_wdev = NULL; | |
1929 | ||
98d2ff8b | 1930 | if (!rdev->ops->set_tx_power) { |
60ea385f | 1931 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1932 | goto bad_res; |
1933 | } | |
1934 | ||
1935 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1936 | type = nla_get_u32(info->attrs[idx]); | |
1937 | ||
1938 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1939 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1940 | result = -EINVAL; | |
1941 | goto bad_res; | |
1942 | } | |
1943 | ||
1944 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1945 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1946 | mbm = nla_get_u32(info->attrs[idx]); | |
1947 | } | |
1948 | ||
c8442118 | 1949 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
1950 | if (result) |
1951 | goto bad_res; | |
1952 | } | |
1953 | ||
afe0cbf8 BR |
1954 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1955 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1956 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1957 | if ((!rdev->wiphy.available_antennas_tx && |
1958 | !rdev->wiphy.available_antennas_rx) || | |
1959 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1960 | result = -EOPNOTSUPP; |
1961 | goto bad_res; | |
1962 | } | |
1963 | ||
1964 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1965 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
1966 | ||
a7ffac95 | 1967 | /* reject antenna configurations which don't match the |
7f531e03 BR |
1968 | * available antenna masks, except for the "all" mask */ |
1969 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
1970 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
1971 | result = -EINVAL; |
1972 | goto bad_res; | |
1973 | } | |
1974 | ||
7f531e03 BR |
1975 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
1976 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 1977 | |
e35e4d28 | 1978 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
1979 | if (result) |
1980 | goto bad_res; | |
1981 | } | |
1982 | ||
b9a5f8ca JM |
1983 | changed = 0; |
1984 | ||
1985 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
1986 | retry_short = nla_get_u8( | |
1987 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
1988 | if (retry_short == 0) { | |
1989 | result = -EINVAL; | |
1990 | goto bad_res; | |
1991 | } | |
1992 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
1993 | } | |
1994 | ||
1995 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
1996 | retry_long = nla_get_u8( | |
1997 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
1998 | if (retry_long == 0) { | |
1999 | result = -EINVAL; | |
2000 | goto bad_res; | |
2001 | } | |
2002 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2003 | } | |
2004 | ||
2005 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2006 | frag_threshold = nla_get_u32( | |
2007 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2008 | if (frag_threshold < 256) { | |
2009 | result = -EINVAL; | |
2010 | goto bad_res; | |
2011 | } | |
2012 | if (frag_threshold != (u32) -1) { | |
2013 | /* | |
2014 | * Fragments (apart from the last one) are required to | |
2015 | * have even length. Make the fragmentation code | |
2016 | * simpler by stripping LSB should someone try to use | |
2017 | * odd threshold value. | |
2018 | */ | |
2019 | frag_threshold &= ~0x1; | |
2020 | } | |
2021 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2022 | } | |
2023 | ||
2024 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2025 | rts_threshold = nla_get_u32( | |
2026 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2027 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2028 | } | |
2029 | ||
81077e82 LT |
2030 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2031 | coverage_class = nla_get_u8( | |
2032 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2033 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2034 | } | |
2035 | ||
b9a5f8ca JM |
2036 | if (changed) { |
2037 | u8 old_retry_short, old_retry_long; | |
2038 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2039 | u8 old_coverage_class; |
b9a5f8ca JM |
2040 | |
2041 | if (!rdev->ops->set_wiphy_params) { | |
2042 | result = -EOPNOTSUPP; | |
2043 | goto bad_res; | |
2044 | } | |
2045 | ||
2046 | old_retry_short = rdev->wiphy.retry_short; | |
2047 | old_retry_long = rdev->wiphy.retry_long; | |
2048 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2049 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2050 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2051 | |
2052 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2053 | rdev->wiphy.retry_short = retry_short; | |
2054 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2055 | rdev->wiphy.retry_long = retry_long; | |
2056 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2057 | rdev->wiphy.frag_threshold = frag_threshold; | |
2058 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2059 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2060 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2061 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2062 | |
e35e4d28 | 2063 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2064 | if (result) { |
2065 | rdev->wiphy.retry_short = old_retry_short; | |
2066 | rdev->wiphy.retry_long = old_retry_long; | |
2067 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2068 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2069 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2070 | } |
2071 | } | |
72bdcf34 | 2072 | |
306d6112 | 2073 | bad_res: |
f444de05 JB |
2074 | if (netdev) |
2075 | dev_put(netdev); | |
55682965 JB |
2076 | return result; |
2077 | } | |
2078 | ||
71bbc994 JB |
2079 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2080 | { | |
2081 | return (u64)wdev->identifier | | |
2082 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2083 | } | |
55682965 | 2084 | |
683b6d3b JB |
2085 | static int nl80211_send_chandef(struct sk_buff *msg, |
2086 | struct cfg80211_chan_def *chandef) | |
2087 | { | |
9f5e8f6e | 2088 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2089 | |
683b6d3b JB |
2090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2091 | chandef->chan->center_freq)) | |
2092 | return -ENOBUFS; | |
3d9d1d66 JB |
2093 | switch (chandef->width) { |
2094 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2095 | case NL80211_CHAN_WIDTH_20: | |
2096 | case NL80211_CHAN_WIDTH_40: | |
2097 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2098 | cfg80211_get_chandef_type(chandef))) | |
2099 | return -ENOBUFS; | |
2100 | break; | |
2101 | default: | |
2102 | break; | |
2103 | } | |
2104 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2105 | return -ENOBUFS; | |
2106 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2107 | return -ENOBUFS; | |
2108 | if (chandef->center_freq2 && | |
2109 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2110 | return -ENOBUFS; |
2111 | return 0; | |
2112 | } | |
2113 | ||
15e47304 | 2114 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2115 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2116 | struct wireless_dev *wdev) |
55682965 | 2117 | { |
72fb2abc | 2118 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2119 | void *hdr; |
2120 | ||
15e47304 | 2121 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2122 | if (!hdr) |
2123 | return -1; | |
2124 | ||
72fb2abc JB |
2125 | if (dev && |
2126 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2127 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2128 | goto nla_put_failure; |
2129 | ||
2130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2131 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2132 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2133 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2134 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2135 | rdev->devlist_generation ^ | |
2136 | (cfg80211_rdev_list_generation << 2))) | |
2137 | goto nla_put_failure; | |
f5ea9120 | 2138 | |
5b7ccaf3 | 2139 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2140 | int ret; |
2141 | struct cfg80211_chan_def chandef; | |
2142 | ||
2143 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2144 | if (ret == 0) { | |
2145 | if (nl80211_send_chandef(msg, &chandef)) | |
2146 | goto nla_put_failure; | |
2147 | } | |
d91df0e3 PF |
2148 | } |
2149 | ||
b84e7a05 AQ |
2150 | if (wdev->ssid_len) { |
2151 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2152 | goto nla_put_failure; | |
2153 | } | |
2154 | ||
55682965 JB |
2155 | return genlmsg_end(msg, hdr); |
2156 | ||
2157 | nla_put_failure: | |
bc3ed28c TG |
2158 | genlmsg_cancel(msg, hdr); |
2159 | return -EMSGSIZE; | |
55682965 JB |
2160 | } |
2161 | ||
2162 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2163 | { | |
2164 | int wp_idx = 0; | |
2165 | int if_idx = 0; | |
2166 | int wp_start = cb->args[0]; | |
2167 | int if_start = cb->args[1]; | |
f5ea9120 | 2168 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2169 | struct wireless_dev *wdev; |
2170 | ||
5fe231e8 | 2171 | rtnl_lock(); |
f5ea9120 JB |
2172 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2173 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2174 | continue; |
bba95fef JB |
2175 | if (wp_idx < wp_start) { |
2176 | wp_idx++; | |
55682965 | 2177 | continue; |
bba95fef | 2178 | } |
55682965 JB |
2179 | if_idx = 0; |
2180 | ||
89a54e48 | 2181 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2182 | if (if_idx < if_start) { |
2183 | if_idx++; | |
55682965 | 2184 | continue; |
bba95fef | 2185 | } |
15e47304 | 2186 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2187 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2188 | rdev, wdev) < 0) { |
bba95fef JB |
2189 | goto out; |
2190 | } | |
2191 | if_idx++; | |
55682965 | 2192 | } |
bba95fef JB |
2193 | |
2194 | wp_idx++; | |
55682965 | 2195 | } |
bba95fef | 2196 | out: |
5fe231e8 | 2197 | rtnl_unlock(); |
55682965 JB |
2198 | |
2199 | cb->args[0] = wp_idx; | |
2200 | cb->args[1] = if_idx; | |
2201 | ||
2202 | return skb->len; | |
2203 | } | |
2204 | ||
2205 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2206 | { | |
2207 | struct sk_buff *msg; | |
4c476991 | 2208 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2209 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2210 | |
fd2120ca | 2211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2212 | if (!msg) |
4c476991 | 2213 | return -ENOMEM; |
55682965 | 2214 | |
15e47304 | 2215 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2216 | dev, wdev) < 0) { |
4c476991 JB |
2217 | nlmsg_free(msg); |
2218 | return -ENOBUFS; | |
2219 | } | |
55682965 | 2220 | |
134e6375 | 2221 | return genlmsg_reply(msg, info); |
55682965 JB |
2222 | } |
2223 | ||
66f7ac50 MW |
2224 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2225 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2226 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2227 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2228 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2229 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
2230 | }; | |
2231 | ||
2232 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2233 | { | |
2234 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2235 | int flag; | |
2236 | ||
2237 | *mntrflags = 0; | |
2238 | ||
2239 | if (!nla) | |
2240 | return -EINVAL; | |
2241 | ||
2242 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2243 | nla, mntr_flags_policy)) | |
2244 | return -EINVAL; | |
2245 | ||
2246 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2247 | if (flags[flag]) | |
2248 | *mntrflags |= (1<<flag); | |
2249 | ||
2250 | return 0; | |
2251 | } | |
2252 | ||
9bc383de | 2253 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2254 | struct net_device *netdev, u8 use_4addr, |
2255 | enum nl80211_iftype iftype) | |
9bc383de | 2256 | { |
ad4bb6f8 | 2257 | if (!use_4addr) { |
f350a0a8 | 2258 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2259 | return -EBUSY; |
9bc383de | 2260 | return 0; |
ad4bb6f8 | 2261 | } |
9bc383de JB |
2262 | |
2263 | switch (iftype) { | |
2264 | case NL80211_IFTYPE_AP_VLAN: | |
2265 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2266 | return 0; | |
2267 | break; | |
2268 | case NL80211_IFTYPE_STATION: | |
2269 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2270 | return 0; | |
2271 | break; | |
2272 | default: | |
2273 | break; | |
2274 | } | |
2275 | ||
2276 | return -EOPNOTSUPP; | |
2277 | } | |
2278 | ||
55682965 JB |
2279 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2280 | { | |
4c476991 | 2281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2282 | struct vif_params params; |
e36d56b6 | 2283 | int err; |
04a773ad | 2284 | enum nl80211_iftype otype, ntype; |
4c476991 | 2285 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2286 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2287 | bool change = false; |
55682965 | 2288 | |
2ec600d6 LCC |
2289 | memset(¶ms, 0, sizeof(params)); |
2290 | ||
04a773ad | 2291 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2292 | |
723b038d | 2293 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2294 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2295 | if (otype != ntype) |
ac7f9cfa | 2296 | change = true; |
4c476991 JB |
2297 | if (ntype > NL80211_IFTYPE_MAX) |
2298 | return -EINVAL; | |
723b038d JB |
2299 | } |
2300 | ||
92ffe055 | 2301 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2302 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2303 | ||
4c476991 JB |
2304 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2305 | return -EINVAL; | |
29cbe68c JB |
2306 | if (netif_running(dev)) |
2307 | return -EBUSY; | |
2308 | ||
2309 | wdev_lock(wdev); | |
2310 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2311 | IEEE80211_MAX_MESH_ID_LEN); | |
2312 | wdev->mesh_id_up_len = | |
2313 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2314 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2315 | wdev->mesh_id_up_len); | |
2316 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2317 | } |
2318 | ||
8b787643 FF |
2319 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2320 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2321 | change = true; | |
ad4bb6f8 | 2322 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2323 | if (err) |
4c476991 | 2324 | return err; |
8b787643 FF |
2325 | } else { |
2326 | params.use_4addr = -1; | |
2327 | } | |
2328 | ||
92ffe055 | 2329 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2330 | if (ntype != NL80211_IFTYPE_MONITOR) |
2331 | return -EINVAL; | |
92ffe055 JB |
2332 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2333 | &_flags); | |
ac7f9cfa | 2334 | if (err) |
4c476991 | 2335 | return err; |
ac7f9cfa JB |
2336 | |
2337 | flags = &_flags; | |
2338 | change = true; | |
92ffe055 | 2339 | } |
3b85875a | 2340 | |
ac7f9cfa | 2341 | if (change) |
3d54d255 | 2342 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2343 | else |
2344 | err = 0; | |
60719ffd | 2345 | |
9bc383de JB |
2346 | if (!err && params.use_4addr != -1) |
2347 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2348 | ||
55682965 JB |
2349 | return err; |
2350 | } | |
2351 | ||
2352 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2353 | { | |
4c476991 | 2354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2355 | struct vif_params params; |
84efbb84 | 2356 | struct wireless_dev *wdev; |
1c90f9d4 | 2357 | struct sk_buff *msg; |
55682965 JB |
2358 | int err; |
2359 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2360 | u32 flags; |
55682965 | 2361 | |
2ec600d6 LCC |
2362 | memset(¶ms, 0, sizeof(params)); |
2363 | ||
55682965 JB |
2364 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2365 | return -EINVAL; | |
2366 | ||
2367 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2368 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2369 | if (type > NL80211_IFTYPE_MAX) | |
2370 | return -EINVAL; | |
2371 | } | |
2372 | ||
79c97e97 | 2373 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2374 | !(rdev->wiphy.interface_modes & (1 << type))) |
2375 | return -EOPNOTSUPP; | |
55682965 | 2376 | |
1c18f145 AS |
2377 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2378 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2379 | ETH_ALEN); | |
2380 | if (!is_valid_ether_addr(params.macaddr)) | |
2381 | return -EADDRNOTAVAIL; | |
2382 | } | |
2383 | ||
9bc383de | 2384 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2385 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2386 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2387 | if (err) |
4c476991 | 2388 | return err; |
9bc383de | 2389 | } |
8b787643 | 2390 | |
1c90f9d4 JB |
2391 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2392 | if (!msg) | |
2393 | return -ENOMEM; | |
2394 | ||
66f7ac50 MW |
2395 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2396 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2397 | &flags); | |
e35e4d28 HG |
2398 | wdev = rdev_add_virtual_intf(rdev, |
2399 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2400 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2401 | if (IS_ERR(wdev)) { |
2402 | nlmsg_free(msg); | |
84efbb84 | 2403 | return PTR_ERR(wdev); |
1c90f9d4 | 2404 | } |
2ec600d6 | 2405 | |
98104fde JB |
2406 | switch (type) { |
2407 | case NL80211_IFTYPE_MESH_POINT: | |
2408 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2409 | break; | |
29cbe68c JB |
2410 | wdev_lock(wdev); |
2411 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2412 | IEEE80211_MAX_MESH_ID_LEN); | |
2413 | wdev->mesh_id_up_len = | |
2414 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2415 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2416 | wdev->mesh_id_up_len); | |
2417 | wdev_unlock(wdev); | |
98104fde JB |
2418 | break; |
2419 | case NL80211_IFTYPE_P2P_DEVICE: | |
2420 | /* | |
2421 | * P2P Device doesn't have a netdev, so doesn't go | |
2422 | * through the netdev notifier and must be added here | |
2423 | */ | |
2424 | mutex_init(&wdev->mtx); | |
2425 | INIT_LIST_HEAD(&wdev->event_list); | |
2426 | spin_lock_init(&wdev->event_lock); | |
2427 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2428 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2429 | ||
98104fde JB |
2430 | wdev->identifier = ++rdev->wdev_id; |
2431 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2432 | rdev->devlist_generation++; | |
98104fde JB |
2433 | break; |
2434 | default: | |
2435 | break; | |
29cbe68c JB |
2436 | } |
2437 | ||
15e47304 | 2438 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2439 | rdev, wdev) < 0) { |
2440 | nlmsg_free(msg); | |
2441 | return -ENOBUFS; | |
2442 | } | |
2443 | ||
2444 | return genlmsg_reply(msg, info); | |
55682965 JB |
2445 | } |
2446 | ||
2447 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2448 | { | |
4c476991 | 2449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2450 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2451 | |
4c476991 JB |
2452 | if (!rdev->ops->del_virtual_intf) |
2453 | return -EOPNOTSUPP; | |
55682965 | 2454 | |
84efbb84 JB |
2455 | /* |
2456 | * If we remove a wireless device without a netdev then clear | |
2457 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2458 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2459 | * since the wdev has been freed, unlike with a netdev where | |
2460 | * we need the dev_put() for the netdev to really be freed. | |
2461 | */ | |
2462 | if (!wdev->netdev) | |
2463 | info->user_ptr[1] = NULL; | |
2464 | ||
e35e4d28 | 2465 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2466 | } |
2467 | ||
1d9d9213 SW |
2468 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2469 | { | |
2470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2471 | struct net_device *dev = info->user_ptr[1]; | |
2472 | u16 noack_map; | |
2473 | ||
2474 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2475 | return -EINVAL; | |
2476 | ||
2477 | if (!rdev->ops->set_noack_map) | |
2478 | return -EOPNOTSUPP; | |
2479 | ||
2480 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2481 | ||
e35e4d28 | 2482 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2483 | } |
2484 | ||
41ade00f JB |
2485 | struct get_key_cookie { |
2486 | struct sk_buff *msg; | |
2487 | int error; | |
b9454e83 | 2488 | int idx; |
41ade00f JB |
2489 | }; |
2490 | ||
2491 | static void get_key_callback(void *c, struct key_params *params) | |
2492 | { | |
b9454e83 | 2493 | struct nlattr *key; |
41ade00f JB |
2494 | struct get_key_cookie *cookie = c; |
2495 | ||
9360ffd1 DM |
2496 | if ((params->key && |
2497 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2498 | params->key_len, params->key)) || | |
2499 | (params->seq && | |
2500 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2501 | params->seq_len, params->seq)) || | |
2502 | (params->cipher && | |
2503 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2504 | params->cipher))) | |
2505 | goto nla_put_failure; | |
41ade00f | 2506 | |
b9454e83 JB |
2507 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2508 | if (!key) | |
2509 | goto nla_put_failure; | |
2510 | ||
9360ffd1 DM |
2511 | if ((params->key && |
2512 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2513 | params->key_len, params->key)) || | |
2514 | (params->seq && | |
2515 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2516 | params->seq_len, params->seq)) || | |
2517 | (params->cipher && | |
2518 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2519 | params->cipher))) | |
2520 | goto nla_put_failure; | |
b9454e83 | 2521 | |
9360ffd1 DM |
2522 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2523 | goto nla_put_failure; | |
b9454e83 JB |
2524 | |
2525 | nla_nest_end(cookie->msg, key); | |
2526 | ||
41ade00f JB |
2527 | return; |
2528 | nla_put_failure: | |
2529 | cookie->error = 1; | |
2530 | } | |
2531 | ||
2532 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2533 | { | |
4c476991 | 2534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2535 | int err; |
4c476991 | 2536 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2537 | u8 key_idx = 0; |
e31b8213 JB |
2538 | const u8 *mac_addr = NULL; |
2539 | bool pairwise; | |
41ade00f JB |
2540 | struct get_key_cookie cookie = { |
2541 | .error = 0, | |
2542 | }; | |
2543 | void *hdr; | |
2544 | struct sk_buff *msg; | |
2545 | ||
2546 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2547 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2548 | ||
3cfcf6ac | 2549 | if (key_idx > 5) |
41ade00f JB |
2550 | return -EINVAL; |
2551 | ||
2552 | if (info->attrs[NL80211_ATTR_MAC]) | |
2553 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2554 | ||
e31b8213 JB |
2555 | pairwise = !!mac_addr; |
2556 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2557 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2558 | if (kt >= NUM_NL80211_KEYTYPES) | |
2559 | return -EINVAL; | |
2560 | if (kt != NL80211_KEYTYPE_GROUP && | |
2561 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2562 | return -EINVAL; | |
2563 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2564 | } | |
2565 | ||
4c476991 JB |
2566 | if (!rdev->ops->get_key) |
2567 | return -EOPNOTSUPP; | |
41ade00f | 2568 | |
fd2120ca | 2569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2570 | if (!msg) |
2571 | return -ENOMEM; | |
41ade00f | 2572 | |
15e47304 | 2573 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2574 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2575 | if (IS_ERR(hdr)) |
2576 | return PTR_ERR(hdr); | |
41ade00f JB |
2577 | |
2578 | cookie.msg = msg; | |
b9454e83 | 2579 | cookie.idx = key_idx; |
41ade00f | 2580 | |
9360ffd1 DM |
2581 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2582 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2583 | goto nla_put_failure; | |
2584 | if (mac_addr && | |
2585 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2586 | goto nla_put_failure; | |
41ade00f | 2587 | |
e31b8213 JB |
2588 | if (pairwise && mac_addr && |
2589 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2590 | return -ENOENT; | |
2591 | ||
e35e4d28 HG |
2592 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2593 | get_key_callback); | |
41ade00f JB |
2594 | |
2595 | if (err) | |
6c95e2a2 | 2596 | goto free_msg; |
41ade00f JB |
2597 | |
2598 | if (cookie.error) | |
2599 | goto nla_put_failure; | |
2600 | ||
2601 | genlmsg_end(msg, hdr); | |
4c476991 | 2602 | return genlmsg_reply(msg, info); |
41ade00f JB |
2603 | |
2604 | nla_put_failure: | |
2605 | err = -ENOBUFS; | |
6c95e2a2 | 2606 | free_msg: |
41ade00f | 2607 | nlmsg_free(msg); |
41ade00f JB |
2608 | return err; |
2609 | } | |
2610 | ||
2611 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2612 | { | |
4c476991 | 2613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2614 | struct key_parse key; |
41ade00f | 2615 | int err; |
4c476991 | 2616 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2617 | |
b9454e83 JB |
2618 | err = nl80211_parse_key(info, &key); |
2619 | if (err) | |
2620 | return err; | |
41ade00f | 2621 | |
b9454e83 | 2622 | if (key.idx < 0) |
41ade00f JB |
2623 | return -EINVAL; |
2624 | ||
b9454e83 JB |
2625 | /* only support setting default key */ |
2626 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2627 | return -EINVAL; |
2628 | ||
dbd2fd65 | 2629 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2630 | |
dbd2fd65 JB |
2631 | if (key.def) { |
2632 | if (!rdev->ops->set_default_key) { | |
2633 | err = -EOPNOTSUPP; | |
2634 | goto out; | |
2635 | } | |
41ade00f | 2636 | |
dbd2fd65 JB |
2637 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2638 | if (err) | |
2639 | goto out; | |
2640 | ||
e35e4d28 | 2641 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2642 | key.def_uni, key.def_multi); |
2643 | ||
2644 | if (err) | |
2645 | goto out; | |
fffd0934 | 2646 | |
3d23e349 | 2647 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2648 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2649 | #endif | |
2650 | } else { | |
2651 | if (key.def_uni || !key.def_multi) { | |
2652 | err = -EINVAL; | |
2653 | goto out; | |
2654 | } | |
2655 | ||
2656 | if (!rdev->ops->set_default_mgmt_key) { | |
2657 | err = -EOPNOTSUPP; | |
2658 | goto out; | |
2659 | } | |
2660 | ||
2661 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2662 | if (err) | |
2663 | goto out; | |
2664 | ||
e35e4d28 | 2665 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2666 | if (err) |
2667 | goto out; | |
2668 | ||
2669 | #ifdef CONFIG_CFG80211_WEXT | |
2670 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2671 | #endif |
dbd2fd65 JB |
2672 | } |
2673 | ||
2674 | out: | |
fffd0934 | 2675 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2676 | |
41ade00f JB |
2677 | return err; |
2678 | } | |
2679 | ||
2680 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2681 | { | |
4c476991 | 2682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2683 | int err; |
4c476991 | 2684 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2685 | struct key_parse key; |
e31b8213 | 2686 | const u8 *mac_addr = NULL; |
41ade00f | 2687 | |
b9454e83 JB |
2688 | err = nl80211_parse_key(info, &key); |
2689 | if (err) | |
2690 | return err; | |
41ade00f | 2691 | |
b9454e83 | 2692 | if (!key.p.key) |
41ade00f JB |
2693 | return -EINVAL; |
2694 | ||
41ade00f JB |
2695 | if (info->attrs[NL80211_ATTR_MAC]) |
2696 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2697 | ||
e31b8213 JB |
2698 | if (key.type == -1) { |
2699 | if (mac_addr) | |
2700 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2701 | else | |
2702 | key.type = NL80211_KEYTYPE_GROUP; | |
2703 | } | |
2704 | ||
2705 | /* for now */ | |
2706 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2707 | key.type != NL80211_KEYTYPE_GROUP) | |
2708 | return -EINVAL; | |
2709 | ||
4c476991 JB |
2710 | if (!rdev->ops->add_key) |
2711 | return -EOPNOTSUPP; | |
25e47c18 | 2712 | |
e31b8213 JB |
2713 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2714 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2715 | mac_addr)) | |
4c476991 | 2716 | return -EINVAL; |
41ade00f | 2717 | |
fffd0934 JB |
2718 | wdev_lock(dev->ieee80211_ptr); |
2719 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2720 | if (!err) | |
e35e4d28 HG |
2721 | err = rdev_add_key(rdev, dev, key.idx, |
2722 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2723 | mac_addr, &key.p); | |
fffd0934 | 2724 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2725 | |
41ade00f JB |
2726 | return err; |
2727 | } | |
2728 | ||
2729 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2730 | { | |
4c476991 | 2731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2732 | int err; |
4c476991 | 2733 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2734 | u8 *mac_addr = NULL; |
b9454e83 | 2735 | struct key_parse key; |
41ade00f | 2736 | |
b9454e83 JB |
2737 | err = nl80211_parse_key(info, &key); |
2738 | if (err) | |
2739 | return err; | |
41ade00f JB |
2740 | |
2741 | if (info->attrs[NL80211_ATTR_MAC]) | |
2742 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2743 | ||
e31b8213 JB |
2744 | if (key.type == -1) { |
2745 | if (mac_addr) | |
2746 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2747 | else | |
2748 | key.type = NL80211_KEYTYPE_GROUP; | |
2749 | } | |
2750 | ||
2751 | /* for now */ | |
2752 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2753 | key.type != NL80211_KEYTYPE_GROUP) | |
2754 | return -EINVAL; | |
2755 | ||
4c476991 JB |
2756 | if (!rdev->ops->del_key) |
2757 | return -EOPNOTSUPP; | |
41ade00f | 2758 | |
fffd0934 JB |
2759 | wdev_lock(dev->ieee80211_ptr); |
2760 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2761 | |
2762 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2763 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2764 | err = -ENOENT; | |
2765 | ||
fffd0934 | 2766 | if (!err) |
e35e4d28 HG |
2767 | err = rdev_del_key(rdev, dev, key.idx, |
2768 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2769 | mac_addr); | |
41ade00f | 2770 | |
3d23e349 | 2771 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2772 | if (!err) { |
b9454e83 | 2773 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2774 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2775 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2776 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2777 | } | |
2778 | #endif | |
fffd0934 | 2779 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2780 | |
41ade00f JB |
2781 | return err; |
2782 | } | |
2783 | ||
77765eaf VT |
2784 | /* This function returns an error or the number of nested attributes */ |
2785 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2786 | { | |
2787 | struct nlattr *attr; | |
2788 | int n_entries = 0, tmp; | |
2789 | ||
2790 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2791 | if (nla_len(attr) != ETH_ALEN) | |
2792 | return -EINVAL; | |
2793 | ||
2794 | n_entries++; | |
2795 | } | |
2796 | ||
2797 | return n_entries; | |
2798 | } | |
2799 | ||
2800 | /* | |
2801 | * This function parses ACL information and allocates memory for ACL data. | |
2802 | * On successful return, the calling function is responsible to free the | |
2803 | * ACL buffer returned by this function. | |
2804 | */ | |
2805 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2806 | struct genl_info *info) | |
2807 | { | |
2808 | enum nl80211_acl_policy acl_policy; | |
2809 | struct nlattr *attr; | |
2810 | struct cfg80211_acl_data *acl; | |
2811 | int i = 0, n_entries, tmp; | |
2812 | ||
2813 | if (!wiphy->max_acl_mac_addrs) | |
2814 | return ERR_PTR(-EOPNOTSUPP); | |
2815 | ||
2816 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2817 | return ERR_PTR(-EINVAL); | |
2818 | ||
2819 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2820 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2821 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2822 | return ERR_PTR(-EINVAL); | |
2823 | ||
2824 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2825 | return ERR_PTR(-EINVAL); | |
2826 | ||
2827 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2828 | if (n_entries < 0) | |
2829 | return ERR_PTR(n_entries); | |
2830 | ||
2831 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2832 | return ERR_PTR(-ENOTSUPP); | |
2833 | ||
2834 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2835 | GFP_KERNEL); | |
2836 | if (!acl) | |
2837 | return ERR_PTR(-ENOMEM); | |
2838 | ||
2839 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2840 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2841 | i++; | |
2842 | } | |
2843 | ||
2844 | acl->n_acl_entries = n_entries; | |
2845 | acl->acl_policy = acl_policy; | |
2846 | ||
2847 | return acl; | |
2848 | } | |
2849 | ||
2850 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2851 | { | |
2852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2853 | struct net_device *dev = info->user_ptr[1]; | |
2854 | struct cfg80211_acl_data *acl; | |
2855 | int err; | |
2856 | ||
2857 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2858 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2859 | return -EOPNOTSUPP; | |
2860 | ||
2861 | if (!dev->ieee80211_ptr->beacon_interval) | |
2862 | return -EINVAL; | |
2863 | ||
2864 | acl = parse_acl_data(&rdev->wiphy, info); | |
2865 | if (IS_ERR(acl)) | |
2866 | return PTR_ERR(acl); | |
2867 | ||
2868 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2869 | ||
2870 | kfree(acl); | |
2871 | ||
2872 | return err; | |
2873 | } | |
2874 | ||
8860020e JB |
2875 | static int nl80211_parse_beacon(struct genl_info *info, |
2876 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2877 | { |
8860020e | 2878 | bool haveinfo = false; |
ed1b6cc7 | 2879 | |
9946ecfb JM |
2880 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2881 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2882 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2883 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2884 | return -EINVAL; |
2885 | ||
8860020e | 2886 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2887 | |
ed1b6cc7 | 2888 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2889 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2890 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2891 | if (!bcn->head_len) | |
2892 | return -EINVAL; | |
2893 | haveinfo = true; | |
ed1b6cc7 JB |
2894 | } |
2895 | ||
2896 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2897 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2898 | bcn->tail_len = | |
ed1b6cc7 | 2899 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2900 | haveinfo = true; |
ed1b6cc7 JB |
2901 | } |
2902 | ||
4c476991 JB |
2903 | if (!haveinfo) |
2904 | return -EINVAL; | |
3b85875a | 2905 | |
9946ecfb | 2906 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2907 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2908 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2909 | } |
2910 | ||
2911 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2912 | bcn->proberesp_ies = |
9946ecfb | 2913 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2914 | bcn->proberesp_ies_len = |
9946ecfb JM |
2915 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2916 | } | |
2917 | ||
2918 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2919 | bcn->assocresp_ies = |
9946ecfb | 2920 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2921 | bcn->assocresp_ies_len = |
9946ecfb JM |
2922 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2923 | } | |
2924 | ||
00f740e1 | 2925 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2926 | bcn->probe_resp = |
00f740e1 | 2927 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2928 | bcn->probe_resp_len = |
00f740e1 AN |
2929 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2930 | } | |
2931 | ||
8860020e JB |
2932 | return 0; |
2933 | } | |
2934 | ||
46c1dd0c FF |
2935 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2936 | struct cfg80211_ap_settings *params) | |
2937 | { | |
2938 | struct wireless_dev *wdev; | |
2939 | bool ret = false; | |
2940 | ||
89a54e48 | 2941 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
2942 | if (wdev->iftype != NL80211_IFTYPE_AP && |
2943 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2944 | continue; | |
2945 | ||
683b6d3b | 2946 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
2947 | continue; |
2948 | ||
683b6d3b | 2949 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
2950 | ret = true; |
2951 | break; | |
2952 | } | |
2953 | ||
46c1dd0c FF |
2954 | return ret; |
2955 | } | |
2956 | ||
e39e5b5e JM |
2957 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
2958 | enum nl80211_auth_type auth_type, | |
2959 | enum nl80211_commands cmd) | |
2960 | { | |
2961 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
2962 | return false; | |
2963 | ||
2964 | switch (cmd) { | |
2965 | case NL80211_CMD_AUTHENTICATE: | |
2966 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
2967 | auth_type == NL80211_AUTHTYPE_SAE) | |
2968 | return false; | |
2969 | return true; | |
2970 | case NL80211_CMD_CONNECT: | |
2971 | case NL80211_CMD_START_AP: | |
2972 | /* SAE not supported yet */ | |
2973 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
2974 | return false; | |
2975 | return true; | |
2976 | default: | |
2977 | return false; | |
2978 | } | |
2979 | } | |
2980 | ||
8860020e JB |
2981 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
2982 | { | |
2983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2984 | struct net_device *dev = info->user_ptr[1]; | |
2985 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2986 | struct cfg80211_ap_settings params; | |
2987 | int err; | |
04f39047 | 2988 | u8 radar_detect_width = 0; |
8860020e JB |
2989 | |
2990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2992 | return -EOPNOTSUPP; | |
2993 | ||
2994 | if (!rdev->ops->start_ap) | |
2995 | return -EOPNOTSUPP; | |
2996 | ||
2997 | if (wdev->beacon_interval) | |
2998 | return -EALREADY; | |
2999 | ||
3000 | memset(¶ms, 0, sizeof(params)); | |
3001 | ||
3002 | /* these are required for START_AP */ | |
3003 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3004 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3005 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3006 | return -EINVAL; | |
3007 | ||
3008 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
3009 | if (err) | |
3010 | return err; | |
3011 | ||
3012 | params.beacon_interval = | |
3013 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3014 | params.dtim_period = | |
3015 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3016 | ||
3017 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3018 | if (err) | |
3019 | return err; | |
3020 | ||
3021 | /* | |
3022 | * In theory, some of these attributes should be required here | |
3023 | * but since they were not used when the command was originally | |
3024 | * added, keep them optional for old user space programs to let | |
3025 | * them continue to work with drivers that do not need the | |
3026 | * additional information -- drivers must check! | |
3027 | */ | |
3028 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3029 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3030 | params.ssid_len = | |
3031 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3032 | if (params.ssid_len == 0 || | |
3033 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3034 | return -EINVAL; | |
3035 | } | |
3036 | ||
3037 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3038 | params.hidden_ssid = nla_get_u32( | |
3039 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3040 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3041 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3042 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3043 | return -EINVAL; | |
3044 | } | |
3045 | ||
3046 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3047 | ||
3048 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3049 | params.auth_type = nla_get_u32( | |
3050 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3051 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3052 | NL80211_CMD_START_AP)) | |
8860020e JB |
3053 | return -EINVAL; |
3054 | } else | |
3055 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3056 | ||
3057 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3058 | NL80211_MAX_NR_CIPHER_SUITES); | |
3059 | if (err) | |
3060 | return err; | |
3061 | ||
1b658f11 VT |
3062 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3063 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3064 | return -EOPNOTSUPP; | |
3065 | params.inactivity_timeout = nla_get_u16( | |
3066 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3067 | } | |
3068 | ||
53cabad7 JB |
3069 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3070 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3071 | return -EINVAL; | |
3072 | params.p2p_ctwindow = | |
3073 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3074 | if (params.p2p_ctwindow > 127) | |
3075 | return -EINVAL; | |
3076 | if (params.p2p_ctwindow != 0 && | |
3077 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3078 | return -EINVAL; | |
3079 | } | |
3080 | ||
3081 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3082 | u8 tmp; | |
3083 | ||
3084 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3085 | return -EINVAL; | |
3086 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3087 | if (tmp > 1) | |
3088 | return -EINVAL; | |
3089 | params.p2p_opp_ps = tmp; | |
3090 | if (params.p2p_opp_ps != 0 && | |
3091 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3092 | return -EINVAL; | |
3093 | } | |
3094 | ||
aa430da4 | 3095 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3096 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3097 | if (err) | |
3098 | return err; | |
3099 | } else if (wdev->preset_chandef.chan) { | |
3100 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3101 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3102 | return -EINVAL; |
3103 | ||
683b6d3b | 3104 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3105 | return -EINVAL; |
3106 | ||
04f39047 SW |
3107 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3108 | if (err < 0) | |
3109 | return err; | |
3110 | if (err) { | |
3111 | radar_detect_width = BIT(params.chandef.width); | |
3112 | params.radar_required = true; | |
3113 | } | |
3114 | ||
04f39047 SW |
3115 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3116 | params.chandef.chan, | |
3117 | CHAN_MODE_SHARED, | |
3118 | radar_detect_width); | |
e4e32459 MK |
3119 | if (err) |
3120 | return err; | |
3121 | ||
77765eaf VT |
3122 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3123 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3124 | if (IS_ERR(params.acl)) | |
3125 | return PTR_ERR(params.acl); | |
3126 | } | |
3127 | ||
e35e4d28 | 3128 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3129 | if (!err) { |
683b6d3b | 3130 | wdev->preset_chandef = params.chandef; |
8860020e | 3131 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3132 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3133 | wdev->ssid_len = params.ssid_len; |
3134 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3135 | } |
77765eaf VT |
3136 | |
3137 | kfree(params.acl); | |
3138 | ||
56d1893d | 3139 | return err; |
ed1b6cc7 JB |
3140 | } |
3141 | ||
8860020e JB |
3142 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3143 | { | |
3144 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3145 | struct net_device *dev = info->user_ptr[1]; | |
3146 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3147 | struct cfg80211_beacon_data params; | |
3148 | int err; | |
3149 | ||
3150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3151 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3152 | return -EOPNOTSUPP; | |
3153 | ||
3154 | if (!rdev->ops->change_beacon) | |
3155 | return -EOPNOTSUPP; | |
3156 | ||
3157 | if (!wdev->beacon_interval) | |
3158 | return -EINVAL; | |
3159 | ||
3160 | err = nl80211_parse_beacon(info, ¶ms); | |
3161 | if (err) | |
3162 | return err; | |
3163 | ||
e35e4d28 | 3164 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3165 | } |
3166 | ||
3167 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3168 | { |
4c476991 JB |
3169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3170 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3171 | |
60771780 | 3172 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3173 | } |
3174 | ||
5727ef1b JB |
3175 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3176 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3177 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3178 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3179 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3180 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3181 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3182 | }; |
3183 | ||
eccb8e8f | 3184 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3185 | enum nl80211_iftype iftype, |
eccb8e8f | 3186 | struct station_parameters *params) |
5727ef1b JB |
3187 | { |
3188 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3189 | struct nlattr *nla; |
5727ef1b JB |
3190 | int flag; |
3191 | ||
eccb8e8f JB |
3192 | /* |
3193 | * Try parsing the new attribute first so userspace | |
3194 | * can specify both for older kernels. | |
3195 | */ | |
3196 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3197 | if (nla) { | |
3198 | struct nl80211_sta_flag_update *sta_flags; | |
3199 | ||
3200 | sta_flags = nla_data(nla); | |
3201 | params->sta_flags_mask = sta_flags->mask; | |
3202 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3203 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3204 | if ((params->sta_flags_mask | |
3205 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3206 | return -EINVAL; | |
3207 | return 0; | |
3208 | } | |
3209 | ||
3210 | /* if present, parse the old attribute */ | |
5727ef1b | 3211 | |
eccb8e8f | 3212 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3213 | if (!nla) |
3214 | return 0; | |
3215 | ||
3216 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3217 | nla, sta_flags_policy)) | |
3218 | return -EINVAL; | |
3219 | ||
bdd3ae3d JB |
3220 | /* |
3221 | * Only allow certain flags for interface types so that | |
3222 | * other attributes are silently ignored. Remember that | |
3223 | * this is backward compatibility code with old userspace | |
3224 | * and shouldn't be hit in other cases anyway. | |
3225 | */ | |
3226 | switch (iftype) { | |
3227 | case NL80211_IFTYPE_AP: | |
3228 | case NL80211_IFTYPE_AP_VLAN: | |
3229 | case NL80211_IFTYPE_P2P_GO: | |
3230 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3231 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3232 | BIT(NL80211_STA_FLAG_WME) | | |
3233 | BIT(NL80211_STA_FLAG_MFP); | |
3234 | break; | |
3235 | case NL80211_IFTYPE_P2P_CLIENT: | |
3236 | case NL80211_IFTYPE_STATION: | |
3237 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3238 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3239 | break; | |
3240 | case NL80211_IFTYPE_MESH_POINT: | |
3241 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3242 | BIT(NL80211_STA_FLAG_MFP) | | |
3243 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3244 | default: | |
3245 | return -EINVAL; | |
3246 | } | |
5727ef1b | 3247 | |
3383b5a6 JB |
3248 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3249 | if (flags[flag]) { | |
eccb8e8f | 3250 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3251 | |
3383b5a6 JB |
3252 | /* no longer support new API additions in old API */ |
3253 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3254 | return -EINVAL; | |
3255 | } | |
3256 | } | |
3257 | ||
5727ef1b JB |
3258 | return 0; |
3259 | } | |
3260 | ||
c8dcfd8a FF |
3261 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3262 | int attr) | |
3263 | { | |
3264 | struct nlattr *rate; | |
8eb41c8d VK |
3265 | u32 bitrate; |
3266 | u16 bitrate_compat; | |
c8dcfd8a FF |
3267 | |
3268 | rate = nla_nest_start(msg, attr); | |
3269 | if (!rate) | |
db9c64cf | 3270 | return false; |
c8dcfd8a FF |
3271 | |
3272 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3273 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3274 | /* report 16-bit bitrate only if we can */ |
3275 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3276 | if (bitrate > 0 && |
3277 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3278 | return false; | |
3279 | if (bitrate_compat > 0 && | |
3280 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3281 | return false; | |
3282 | ||
3283 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3284 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3285 | return false; | |
3286 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3287 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3288 | return false; | |
3289 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3290 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3291 | return false; | |
3292 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3293 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3294 | return false; | |
3295 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3296 | return false; | |
3297 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3298 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3299 | return false; | |
3300 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3301 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3302 | return false; | |
3303 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3304 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3305 | return false; | |
3306 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3307 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3308 | return false; | |
3309 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3310 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3311 | return false; | |
3312 | } | |
c8dcfd8a FF |
3313 | |
3314 | nla_nest_end(msg, rate); | |
3315 | return true; | |
c8dcfd8a FF |
3316 | } |
3317 | ||
119363c7 FF |
3318 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3319 | int id) | |
3320 | { | |
3321 | void *attr; | |
3322 | int i = 0; | |
3323 | ||
3324 | if (!mask) | |
3325 | return true; | |
3326 | ||
3327 | attr = nla_nest_start(msg, id); | |
3328 | if (!attr) | |
3329 | return false; | |
3330 | ||
3331 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3332 | if (!(mask & BIT(i))) | |
3333 | continue; | |
3334 | ||
3335 | if (nla_put_u8(msg, i, signal[i])) | |
3336 | return false; | |
3337 | } | |
3338 | ||
3339 | nla_nest_end(msg, attr); | |
3340 | ||
3341 | return true; | |
3342 | } | |
3343 | ||
15e47304 | 3344 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3345 | int flags, |
3346 | struct cfg80211_registered_device *rdev, | |
3347 | struct net_device *dev, | |
98b62183 | 3348 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3349 | { |
3350 | void *hdr; | |
f4263c98 | 3351 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3352 | |
15e47304 | 3353 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3354 | if (!hdr) |
3355 | return -1; | |
3356 | ||
9360ffd1 DM |
3357 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3358 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3359 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3360 | goto nla_put_failure; | |
f5ea9120 | 3361 | |
2ec600d6 LCC |
3362 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3363 | if (!sinfoattr) | |
fd5b74dc | 3364 | goto nla_put_failure; |
9360ffd1 DM |
3365 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3366 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3367 | sinfo->connected_time)) | |
3368 | goto nla_put_failure; | |
3369 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3370 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3371 | sinfo->inactive_time)) | |
3372 | goto nla_put_failure; | |
42745e03 VK |
3373 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3374 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3375 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3376 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3377 | goto nla_put_failure; |
42745e03 | 3378 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3379 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3380 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3381 | (u32)sinfo->tx_bytes)) |
3382 | goto nla_put_failure; | |
3383 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3384 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3385 | sinfo->rx_bytes)) | |
3386 | goto nla_put_failure; | |
3387 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3388 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3389 | sinfo->tx_bytes)) |
3390 | goto nla_put_failure; | |
3391 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3392 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3393 | goto nla_put_failure; | |
3394 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3395 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3396 | goto nla_put_failure; | |
3397 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3398 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3399 | sinfo->plink_state)) | |
3400 | goto nla_put_failure; | |
66266b3a JL |
3401 | switch (rdev->wiphy.signal_type) { |
3402 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3403 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3404 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3405 | sinfo->signal)) | |
3406 | goto nla_put_failure; | |
3407 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3408 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3409 | sinfo->signal_avg)) | |
3410 | goto nla_put_failure; | |
66266b3a JL |
3411 | break; |
3412 | default: | |
3413 | break; | |
3414 | } | |
119363c7 FF |
3415 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3416 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3417 | sinfo->chain_signal, | |
3418 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3419 | goto nla_put_failure; | |
3420 | } | |
3421 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3422 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3423 | sinfo->chain_signal_avg, | |
3424 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3425 | goto nla_put_failure; | |
3426 | } | |
420e7fab | 3427 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3428 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3429 | NL80211_STA_INFO_TX_BITRATE)) | |
3430 | goto nla_put_failure; | |
3431 | } | |
3432 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3433 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3434 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3435 | goto nla_put_failure; |
420e7fab | 3436 | } |
9360ffd1 DM |
3437 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3438 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3439 | sinfo->rx_packets)) | |
3440 | goto nla_put_failure; | |
3441 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3442 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3443 | sinfo->tx_packets)) | |
3444 | goto nla_put_failure; | |
3445 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3446 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3447 | sinfo->tx_retries)) | |
3448 | goto nla_put_failure; | |
3449 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3450 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3451 | sinfo->tx_failed)) | |
3452 | goto nla_put_failure; | |
3453 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3454 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3455 | sinfo->beacon_loss_count)) | |
3456 | goto nla_put_failure; | |
3b1c5a53 MP |
3457 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3458 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3459 | sinfo->local_pm)) | |
3460 | goto nla_put_failure; | |
3461 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3462 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3463 | sinfo->peer_pm)) | |
3464 | goto nla_put_failure; | |
3465 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3466 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3467 | sinfo->nonpeer_pm)) | |
3468 | goto nla_put_failure; | |
f4263c98 PS |
3469 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3470 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3471 | if (!bss_param) | |
3472 | goto nla_put_failure; | |
3473 | ||
9360ffd1 DM |
3474 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3475 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3476 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3477 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3478 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3479 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3480 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3481 | sinfo->bss_param.dtim_period) || | |
3482 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3483 | sinfo->bss_param.beacon_interval)) | |
3484 | goto nla_put_failure; | |
f4263c98 PS |
3485 | |
3486 | nla_nest_end(msg, bss_param); | |
3487 | } | |
9360ffd1 DM |
3488 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3489 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3490 | sizeof(struct nl80211_sta_flag_update), | |
3491 | &sinfo->sta_flags)) | |
3492 | goto nla_put_failure; | |
7eab0f64 JL |
3493 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3494 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3495 | sinfo->t_offset)) | |
3496 | goto nla_put_failure; | |
2ec600d6 | 3497 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3498 | |
9360ffd1 DM |
3499 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3500 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3501 | sinfo->assoc_req_ies)) | |
3502 | goto nla_put_failure; | |
50d3dfb7 | 3503 | |
fd5b74dc JB |
3504 | return genlmsg_end(msg, hdr); |
3505 | ||
3506 | nla_put_failure: | |
bc3ed28c TG |
3507 | genlmsg_cancel(msg, hdr); |
3508 | return -EMSGSIZE; | |
fd5b74dc JB |
3509 | } |
3510 | ||
2ec600d6 | 3511 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3512 | struct netlink_callback *cb) |
2ec600d6 | 3513 | { |
2ec600d6 LCC |
3514 | struct station_info sinfo; |
3515 | struct cfg80211_registered_device *dev; | |
97990a06 | 3516 | struct wireless_dev *wdev; |
2ec600d6 | 3517 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3518 | int sta_idx = cb->args[2]; |
2ec600d6 | 3519 | int err; |
2ec600d6 | 3520 | |
97990a06 | 3521 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3522 | if (err) |
3523 | return err; | |
bba95fef | 3524 | |
97990a06 JB |
3525 | if (!wdev->netdev) { |
3526 | err = -EINVAL; | |
3527 | goto out_err; | |
3528 | } | |
3529 | ||
bba95fef | 3530 | if (!dev->ops->dump_station) { |
eec60b03 | 3531 | err = -EOPNOTSUPP; |
bba95fef JB |
3532 | goto out_err; |
3533 | } | |
3534 | ||
bba95fef | 3535 | while (1) { |
f612cedf | 3536 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3537 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3538 | mac_addr, &sinfo); |
bba95fef JB |
3539 | if (err == -ENOENT) |
3540 | break; | |
3541 | if (err) | |
3b85875a | 3542 | goto out_err; |
bba95fef JB |
3543 | |
3544 | if (nl80211_send_station(skb, | |
15e47304 | 3545 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3546 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3547 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3548 | &sinfo) < 0) |
3549 | goto out; | |
3550 | ||
3551 | sta_idx++; | |
3552 | } | |
3553 | ||
3554 | ||
3555 | out: | |
97990a06 | 3556 | cb->args[2] = sta_idx; |
bba95fef | 3557 | err = skb->len; |
bba95fef | 3558 | out_err: |
97990a06 | 3559 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3560 | |
3561 | return err; | |
2ec600d6 | 3562 | } |
fd5b74dc | 3563 | |
5727ef1b JB |
3564 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3565 | { | |
4c476991 JB |
3566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3567 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3568 | struct station_info sinfo; |
fd5b74dc JB |
3569 | struct sk_buff *msg; |
3570 | u8 *mac_addr = NULL; | |
4c476991 | 3571 | int err; |
fd5b74dc | 3572 | |
2ec600d6 | 3573 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3574 | |
3575 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3576 | return -EINVAL; | |
3577 | ||
3578 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3579 | ||
4c476991 JB |
3580 | if (!rdev->ops->get_station) |
3581 | return -EOPNOTSUPP; | |
3b85875a | 3582 | |
e35e4d28 | 3583 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3584 | if (err) |
4c476991 | 3585 | return err; |
2ec600d6 | 3586 | |
fd2120ca | 3587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3588 | if (!msg) |
4c476991 | 3589 | return -ENOMEM; |
fd5b74dc | 3590 | |
15e47304 | 3591 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3592 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3593 | nlmsg_free(msg); |
3594 | return -ENOBUFS; | |
3595 | } | |
3b85875a | 3596 | |
4c476991 | 3597 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3598 | } |
3599 | ||
77ee7c89 JB |
3600 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3601 | struct station_parameters *params, | |
3602 | enum cfg80211_station_type statype) | |
3603 | { | |
3604 | if (params->listen_interval != -1) | |
3605 | return -EINVAL; | |
3606 | if (params->aid) | |
3607 | return -EINVAL; | |
3608 | ||
3609 | /* When you run into this, adjust the code below for the new flag */ | |
3610 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3611 | ||
3612 | switch (statype) { | |
eef941e6 TP |
3613 | case CFG80211_STA_MESH_PEER_KERNEL: |
3614 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3615 | /* |
3616 | * No ignoring the TDLS flag here -- the userspace mesh | |
3617 | * code doesn't have the bug of including TDLS in the | |
3618 | * mask everywhere. | |
3619 | */ | |
3620 | if (params->sta_flags_mask & | |
3621 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3622 | BIT(NL80211_STA_FLAG_MFP) | | |
3623 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3624 | return -EINVAL; | |
3625 | break; | |
3626 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3627 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3628 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3629 | return -EINVAL; | |
3630 | /* ignore since it can't change */ | |
3631 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3632 | break; | |
3633 | default: | |
3634 | /* disallow mesh-specific things */ | |
3635 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3636 | return -EINVAL; | |
3637 | if (params->local_pm) | |
3638 | return -EINVAL; | |
3639 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3640 | return -EINVAL; | |
3641 | } | |
3642 | ||
3643 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3644 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3645 | /* TDLS can't be set, ... */ | |
3646 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3647 | return -EINVAL; | |
3648 | /* | |
3649 | * ... but don't bother the driver with it. This works around | |
3650 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3651 | * TLDS_PEER flag in the mask even for AP mode. | |
3652 | */ | |
3653 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3654 | } | |
3655 | ||
3656 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3657 | /* reject other things that can't change */ | |
3658 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3659 | return -EINVAL; | |
3660 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3661 | return -EINVAL; | |
3662 | if (params->supported_rates) | |
3663 | return -EINVAL; | |
3664 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3665 | return -EINVAL; | |
3666 | } | |
3667 | ||
3668 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3669 | if (params->vlan) | |
3670 | return -EINVAL; | |
3671 | } | |
3672 | ||
3673 | switch (statype) { | |
3674 | case CFG80211_STA_AP_MLME_CLIENT: | |
3675 | /* Use this only for authorizing/unauthorizing a station */ | |
3676 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3677 | return -EOPNOTSUPP; | |
3678 | break; | |
3679 | case CFG80211_STA_AP_CLIENT: | |
3680 | /* accept only the listed bits */ | |
3681 | if (params->sta_flags_mask & | |
3682 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3683 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3684 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3685 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3686 | BIT(NL80211_STA_FLAG_WME) | | |
3687 | BIT(NL80211_STA_FLAG_MFP))) | |
3688 | return -EINVAL; | |
3689 | ||
3690 | /* but authenticated/associated only if driver handles it */ | |
3691 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3692 | params->sta_flags_mask & | |
3693 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3694 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3695 | return -EINVAL; | |
3696 | break; | |
3697 | case CFG80211_STA_IBSS: | |
3698 | case CFG80211_STA_AP_STA: | |
3699 | /* reject any changes other than AUTHORIZED */ | |
3700 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3701 | return -EINVAL; | |
3702 | break; | |
3703 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3704 | /* reject any changes other than AUTHORIZED or WME */ | |
3705 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3706 | BIT(NL80211_STA_FLAG_WME))) | |
3707 | return -EINVAL; | |
3708 | /* force (at least) rates when authorizing */ | |
3709 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3710 | !params->supported_rates) | |
3711 | return -EINVAL; | |
3712 | break; | |
3713 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3714 | /* reject any changes */ | |
3715 | return -EINVAL; | |
eef941e6 | 3716 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3717 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3718 | return -EINVAL; | |
3719 | break; | |
eef941e6 | 3720 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3721 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3722 | return -EINVAL; | |
3723 | break; | |
3724 | } | |
3725 | ||
3726 | return 0; | |
3727 | } | |
3728 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3729 | ||
5727ef1b | 3730 | /* |
c258d2de | 3731 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3732 | */ |
80b99899 JB |
3733 | static struct net_device *get_vlan(struct genl_info *info, |
3734 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3735 | { |
463d0183 | 3736 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3737 | struct net_device *v; |
3738 | int ret; | |
3739 | ||
3740 | if (!vlanattr) | |
3741 | return NULL; | |
3742 | ||
3743 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3744 | if (!v) | |
3745 | return ERR_PTR(-ENODEV); | |
3746 | ||
3747 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3748 | ret = -EINVAL; | |
3749 | goto error; | |
5727ef1b | 3750 | } |
80b99899 | 3751 | |
77ee7c89 JB |
3752 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3753 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3754 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3755 | ret = -EINVAL; | |
3756 | goto error; | |
3757 | } | |
3758 | ||
80b99899 JB |
3759 | if (!netif_running(v)) { |
3760 | ret = -ENETDOWN; | |
3761 | goto error; | |
3762 | } | |
3763 | ||
3764 | return v; | |
3765 | error: | |
3766 | dev_put(v); | |
3767 | return ERR_PTR(ret); | |
5727ef1b JB |
3768 | } |
3769 | ||
df881293 JM |
3770 | static struct nla_policy |
3771 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3772 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3773 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3774 | }; | |
3775 | ||
ff276691 JB |
3776 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3777 | struct station_parameters *params) | |
df881293 | 3778 | { |
df881293 JM |
3779 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3780 | struct nlattr *nla; | |
3781 | int err; | |
3782 | ||
df881293 JM |
3783 | /* parse WME attributes if present */ |
3784 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3785 | return 0; | |
3786 | ||
3787 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3788 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3789 | nl80211_sta_wme_policy); | |
3790 | if (err) | |
3791 | return err; | |
3792 | ||
3793 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3794 | params->uapsd_queues = nla_get_u8( | |
3795 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3796 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3797 | return -EINVAL; | |
3798 | ||
3799 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3800 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3801 | ||
3802 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3803 | return -EINVAL; | |
3804 | ||
3805 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3806 | ||
3807 | return 0; | |
3808 | } | |
3809 | ||
ff276691 JB |
3810 | static int nl80211_set_station_tdls(struct genl_info *info, |
3811 | struct station_parameters *params) | |
3812 | { | |
3813 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
5e4b6f56 JM |
3814 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
3815 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
3816 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3817 | params->ht_capa = | |
3818 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3819 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3820 | params->vht_capa = | |
3821 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3822 | ||
3823 | return nl80211_parse_sta_wme(info, params); | |
3824 | } | |
3825 | ||
5727ef1b JB |
3826 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3827 | { | |
4c476991 | 3828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3829 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3830 | struct station_parameters params; |
77ee7c89 JB |
3831 | u8 *mac_addr; |
3832 | int err; | |
5727ef1b JB |
3833 | |
3834 | memset(¶ms, 0, sizeof(params)); | |
3835 | ||
3836 | params.listen_interval = -1; | |
3837 | ||
77ee7c89 JB |
3838 | if (!rdev->ops->change_station) |
3839 | return -EOPNOTSUPP; | |
3840 | ||
5727ef1b JB |
3841 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3842 | return -EINVAL; | |
3843 | ||
3844 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3845 | return -EINVAL; | |
3846 | ||
3847 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3848 | ||
3849 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3850 | params.supported_rates = | |
3851 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3852 | params.supported_rates_len = | |
3853 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3854 | } | |
3855 | ||
9d62a986 JM |
3856 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3857 | params.capability = | |
3858 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3859 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3860 | } | |
3861 | ||
3862 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3863 | params.ext_capab = | |
3864 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3865 | params.ext_capab_len = | |
3866 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3867 | } | |
3868 | ||
df881293 | 3869 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3870 | return -EINVAL; |
36aedc90 | 3871 | |
bdd3ae3d | 3872 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3873 | return -EINVAL; |
3874 | ||
f8bacc21 | 3875 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3876 | params.plink_action = |
f8bacc21 JB |
3877 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3878 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3879 | return -EINVAL; | |
3880 | } | |
2ec600d6 | 3881 | |
f8bacc21 | 3882 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3883 | params.plink_state = |
f8bacc21 JB |
3884 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3885 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3886 | return -EINVAL; | |
3887 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3888 | } | |
9c3990aa | 3889 | |
3b1c5a53 MP |
3890 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3891 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3892 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3893 | ||
3894 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3895 | pm > NL80211_MESH_POWER_MAX) | |
3896 | return -EINVAL; | |
3897 | ||
3898 | params.local_pm = pm; | |
3899 | } | |
3900 | ||
77ee7c89 JB |
3901 | /* Include parameters for TDLS peer (will check later) */ |
3902 | err = nl80211_set_station_tdls(info, ¶ms); | |
3903 | if (err) | |
3904 | return err; | |
3905 | ||
3906 | params.vlan = get_vlan(info, rdev); | |
3907 | if (IS_ERR(params.vlan)) | |
3908 | return PTR_ERR(params.vlan); | |
3909 | ||
a97f4424 JB |
3910 | switch (dev->ieee80211_ptr->iftype) { |
3911 | case NL80211_IFTYPE_AP: | |
3912 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3913 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3914 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3915 | case NL80211_IFTYPE_STATION: |
267335d6 | 3916 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3917 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3918 | break; |
3919 | default: | |
77ee7c89 JB |
3920 | err = -EOPNOTSUPP; |
3921 | goto out_put_vlan; | |
034d655e JB |
3922 | } |
3923 | ||
77ee7c89 | 3924 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 3925 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3926 | |
77ee7c89 | 3927 | out_put_vlan: |
5727ef1b JB |
3928 | if (params.vlan) |
3929 | dev_put(params.vlan); | |
3b85875a | 3930 | |
5727ef1b JB |
3931 | return err; |
3932 | } | |
3933 | ||
3934 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
3935 | { | |
4c476991 | 3936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3937 | int err; |
4c476991 | 3938 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3939 | struct station_parameters params; |
3940 | u8 *mac_addr = NULL; | |
3941 | ||
3942 | memset(¶ms, 0, sizeof(params)); | |
3943 | ||
984c311b JB |
3944 | if (!rdev->ops->add_station) |
3945 | return -EOPNOTSUPP; | |
3946 | ||
5727ef1b JB |
3947 | if (!info->attrs[NL80211_ATTR_MAC]) |
3948 | return -EINVAL; | |
3949 | ||
5727ef1b JB |
3950 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3951 | return -EINVAL; | |
3952 | ||
3953 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3954 | return -EINVAL; | |
3955 | ||
5e4b6f56 JM |
3956 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
3957 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
3958 | return -EINVAL; |
3959 | ||
5727ef1b JB |
3960 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3961 | params.supported_rates = | |
3962 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3963 | params.supported_rates_len = | |
3964 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3965 | params.listen_interval = | |
3966 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3967 | |
5e4b6f56 JM |
3968 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3969 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
3970 | else | |
3971 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
0e956c13 TLSC |
3972 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
3973 | return -EINVAL; | |
51b50fbe | 3974 | |
9d62a986 JM |
3975 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3976 | params.capability = | |
3977 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3978 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3979 | } | |
3980 | ||
3981 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3982 | params.ext_capab = | |
3983 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3984 | params.ext_capab_len = | |
3985 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3986 | } | |
3987 | ||
36aedc90 JM |
3988 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3989 | params.ht_capa = | |
3990 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 3991 | |
f461be3e MP |
3992 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
3993 | params.vht_capa = | |
3994 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3995 | ||
f8bacc21 | 3996 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 3997 | params.plink_action = |
f8bacc21 JB |
3998 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3999 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4000 | return -EINVAL; | |
4001 | } | |
96b78dff | 4002 | |
ff276691 JB |
4003 | err = nl80211_parse_sta_wme(info, ¶ms); |
4004 | if (err) | |
4005 | return err; | |
bdd90d5e | 4006 | |
bdd3ae3d | 4007 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4008 | return -EINVAL; |
4009 | ||
77ee7c89 JB |
4010 | /* When you run into this, adjust the code below for the new flag */ |
4011 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4012 | ||
bdd90d5e JB |
4013 | switch (dev->ieee80211_ptr->iftype) { |
4014 | case NL80211_IFTYPE_AP: | |
4015 | case NL80211_IFTYPE_AP_VLAN: | |
4016 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4017 | /* ignore WME attributes if iface/sta is not capable */ |
4018 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4019 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4020 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4021 | |
bdd90d5e JB |
4022 | /* TDLS peers cannot be added */ |
4023 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 4024 | return -EINVAL; |
bdd90d5e JB |
4025 | /* but don't bother the driver with it */ |
4026 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4027 | |
d582cffb JB |
4028 | /* allow authenticated/associated only if driver handles it */ |
4029 | if (!(rdev->wiphy.features & | |
4030 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4031 | params.sta_flags_mask & | |
4032 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4033 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4034 | return -EINVAL; | |
4035 | ||
bdd90d5e JB |
4036 | /* must be last in here for error handling */ |
4037 | params.vlan = get_vlan(info, rdev); | |
4038 | if (IS_ERR(params.vlan)) | |
4039 | return PTR_ERR(params.vlan); | |
4040 | break; | |
4041 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4042 | /* ignore uAPSD data */ |
4043 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4044 | ||
d582cffb JB |
4045 | /* associated is disallowed */ |
4046 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4047 | return -EINVAL; | |
bdd90d5e JB |
4048 | /* TDLS peers cannot be added */ |
4049 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4050 | return -EINVAL; | |
4051 | break; | |
4052 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4053 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4054 | /* ignore uAPSD data */ |
4055 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4056 | ||
77ee7c89 JB |
4057 | /* these are disallowed */ |
4058 | if (params.sta_flags_mask & | |
4059 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4060 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4061 | return -EINVAL; |
bdd90d5e JB |
4062 | /* Only TDLS peers can be added */ |
4063 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4064 | return -EINVAL; | |
4065 | /* Can only add if TDLS ... */ | |
4066 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4067 | return -EOPNOTSUPP; | |
4068 | /* ... with external setup is supported */ | |
4069 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4070 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4071 | /* |
4072 | * Older wpa_supplicant versions always mark the TDLS peer | |
4073 | * as authorized, but it shouldn't yet be. | |
4074 | */ | |
4075 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4076 | break; |
4077 | default: | |
4078 | return -EOPNOTSUPP; | |
c75786c9 EP |
4079 | } |
4080 | ||
bdd90d5e | 4081 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4082 | |
e35e4d28 | 4083 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4084 | |
5727ef1b JB |
4085 | if (params.vlan) |
4086 | dev_put(params.vlan); | |
5727ef1b JB |
4087 | return err; |
4088 | } | |
4089 | ||
4090 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4091 | { | |
4c476991 JB |
4092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4093 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4094 | u8 *mac_addr = NULL; |
4095 | ||
4096 | if (info->attrs[NL80211_ATTR_MAC]) | |
4097 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4098 | ||
e80cf853 | 4099 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4100 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4103 | return -EINVAL; | |
5727ef1b | 4104 | |
4c476991 JB |
4105 | if (!rdev->ops->del_station) |
4106 | return -EOPNOTSUPP; | |
3b85875a | 4107 | |
e35e4d28 | 4108 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4109 | } |
4110 | ||
15e47304 | 4111 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4112 | int flags, struct net_device *dev, |
4113 | u8 *dst, u8 *next_hop, | |
4114 | struct mpath_info *pinfo) | |
4115 | { | |
4116 | void *hdr; | |
4117 | struct nlattr *pinfoattr; | |
4118 | ||
15e47304 | 4119 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4120 | if (!hdr) |
4121 | return -1; | |
4122 | ||
9360ffd1 DM |
4123 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4124 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4125 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4126 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4127 | goto nla_put_failure; | |
f5ea9120 | 4128 | |
2ec600d6 LCC |
4129 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4130 | if (!pinfoattr) | |
4131 | goto nla_put_failure; | |
9360ffd1 DM |
4132 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4133 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4134 | pinfo->frame_qlen)) | |
4135 | goto nla_put_failure; | |
4136 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4137 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4138 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4139 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4140 | pinfo->metric)) || | |
4141 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4142 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4143 | pinfo->exptime)) || | |
4144 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4145 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4146 | pinfo->flags)) || | |
4147 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4148 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4149 | pinfo->discovery_timeout)) || | |
4150 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4151 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4152 | pinfo->discovery_retries))) | |
4153 | goto nla_put_failure; | |
2ec600d6 LCC |
4154 | |
4155 | nla_nest_end(msg, pinfoattr); | |
4156 | ||
4157 | return genlmsg_end(msg, hdr); | |
4158 | ||
4159 | nla_put_failure: | |
bc3ed28c TG |
4160 | genlmsg_cancel(msg, hdr); |
4161 | return -EMSGSIZE; | |
2ec600d6 LCC |
4162 | } |
4163 | ||
4164 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4165 | struct netlink_callback *cb) |
2ec600d6 | 4166 | { |
2ec600d6 LCC |
4167 | struct mpath_info pinfo; |
4168 | struct cfg80211_registered_device *dev; | |
97990a06 | 4169 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4170 | u8 dst[ETH_ALEN]; |
4171 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4172 | int path_idx = cb->args[2]; |
2ec600d6 | 4173 | int err; |
2ec600d6 | 4174 | |
97990a06 | 4175 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4176 | if (err) |
4177 | return err; | |
bba95fef JB |
4178 | |
4179 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4180 | err = -EOPNOTSUPP; |
bba95fef JB |
4181 | goto out_err; |
4182 | } | |
4183 | ||
97990a06 | 4184 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4185 | err = -EOPNOTSUPP; |
0448b5fc | 4186 | goto out_err; |
eec60b03 JM |
4187 | } |
4188 | ||
bba95fef | 4189 | while (1) { |
97990a06 JB |
4190 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4191 | next_hop, &pinfo); | |
bba95fef | 4192 | if (err == -ENOENT) |
2ec600d6 | 4193 | break; |
bba95fef | 4194 | if (err) |
3b85875a | 4195 | goto out_err; |
2ec600d6 | 4196 | |
15e47304 | 4197 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4198 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4199 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4200 | &pinfo) < 0) |
4201 | goto out; | |
2ec600d6 | 4202 | |
bba95fef | 4203 | path_idx++; |
2ec600d6 | 4204 | } |
2ec600d6 | 4205 | |
2ec600d6 | 4206 | |
bba95fef | 4207 | out: |
97990a06 | 4208 | cb->args[2] = path_idx; |
bba95fef | 4209 | err = skb->len; |
bba95fef | 4210 | out_err: |
97990a06 | 4211 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4212 | return err; |
2ec600d6 LCC |
4213 | } |
4214 | ||
4215 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4216 | { | |
4c476991 | 4217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4218 | int err; |
4c476991 | 4219 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4220 | struct mpath_info pinfo; |
4221 | struct sk_buff *msg; | |
4222 | u8 *dst = NULL; | |
4223 | u8 next_hop[ETH_ALEN]; | |
4224 | ||
4225 | memset(&pinfo, 0, sizeof(pinfo)); | |
4226 | ||
4227 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4228 | return -EINVAL; | |
4229 | ||
4230 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4231 | ||
4c476991 JB |
4232 | if (!rdev->ops->get_mpath) |
4233 | return -EOPNOTSUPP; | |
2ec600d6 | 4234 | |
4c476991 JB |
4235 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4236 | return -EOPNOTSUPP; | |
eec60b03 | 4237 | |
e35e4d28 | 4238 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4239 | if (err) |
4c476991 | 4240 | return err; |
2ec600d6 | 4241 | |
fd2120ca | 4242 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4243 | if (!msg) |
4c476991 | 4244 | return -ENOMEM; |
2ec600d6 | 4245 | |
15e47304 | 4246 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4247 | dev, dst, next_hop, &pinfo) < 0) { |
4248 | nlmsg_free(msg); | |
4249 | return -ENOBUFS; | |
4250 | } | |
3b85875a | 4251 | |
4c476991 | 4252 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4253 | } |
4254 | ||
4255 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4256 | { | |
4c476991 JB |
4257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4258 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4259 | u8 *dst = NULL; |
4260 | u8 *next_hop = NULL; | |
4261 | ||
4262 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4263 | return -EINVAL; | |
4264 | ||
4265 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4266 | return -EINVAL; | |
4267 | ||
4268 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4269 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4270 | ||
4c476991 JB |
4271 | if (!rdev->ops->change_mpath) |
4272 | return -EOPNOTSUPP; | |
35a8efe1 | 4273 | |
4c476991 JB |
4274 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4275 | return -EOPNOTSUPP; | |
2ec600d6 | 4276 | |
e35e4d28 | 4277 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4278 | } |
4c476991 | 4279 | |
2ec600d6 LCC |
4280 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4281 | { | |
4c476991 JB |
4282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4283 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4284 | u8 *dst = NULL; |
4285 | u8 *next_hop = NULL; | |
4286 | ||
4287 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4288 | return -EINVAL; | |
4289 | ||
4290 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4291 | return -EINVAL; | |
4292 | ||
4293 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4294 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4295 | ||
4c476991 JB |
4296 | if (!rdev->ops->add_mpath) |
4297 | return -EOPNOTSUPP; | |
35a8efe1 | 4298 | |
4c476991 JB |
4299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4300 | return -EOPNOTSUPP; | |
2ec600d6 | 4301 | |
e35e4d28 | 4302 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4303 | } |
4304 | ||
4305 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4306 | { | |
4c476991 JB |
4307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4308 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4309 | u8 *dst = NULL; |
4310 | ||
4311 | if (info->attrs[NL80211_ATTR_MAC]) | |
4312 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4313 | ||
4c476991 JB |
4314 | if (!rdev->ops->del_mpath) |
4315 | return -EOPNOTSUPP; | |
3b85875a | 4316 | |
e35e4d28 | 4317 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4318 | } |
4319 | ||
9f1ba906 JM |
4320 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4321 | { | |
4c476991 JB |
4322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4323 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4324 | struct bss_parameters params; |
4325 | ||
4326 | memset(¶ms, 0, sizeof(params)); | |
4327 | /* default to not changing parameters */ | |
4328 | params.use_cts_prot = -1; | |
4329 | params.use_short_preamble = -1; | |
4330 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4331 | params.ap_isolate = -1; |
50b12f59 | 4332 | params.ht_opmode = -1; |
53cabad7 JB |
4333 | params.p2p_ctwindow = -1; |
4334 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4335 | |
4336 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4337 | params.use_cts_prot = | |
4338 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4339 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4340 | params.use_short_preamble = | |
4341 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4342 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4343 | params.use_short_slot_time = | |
4344 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4345 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4346 | params.basic_rates = | |
4347 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4348 | params.basic_rates_len = | |
4349 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4350 | } | |
fd8aaaf3 FF |
4351 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4352 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4353 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4354 | params.ht_opmode = | |
4355 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4356 | |
53cabad7 JB |
4357 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4358 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4359 | return -EINVAL; | |
4360 | params.p2p_ctwindow = | |
4361 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4362 | if (params.p2p_ctwindow < 0) | |
4363 | return -EINVAL; | |
4364 | if (params.p2p_ctwindow != 0 && | |
4365 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4366 | return -EINVAL; | |
4367 | } | |
4368 | ||
4369 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4370 | u8 tmp; | |
4371 | ||
4372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4373 | return -EINVAL; | |
4374 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4375 | if (tmp > 1) | |
4376 | return -EINVAL; | |
4377 | params.p2p_opp_ps = tmp; | |
4378 | if (params.p2p_opp_ps && | |
4379 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4380 | return -EINVAL; | |
4381 | } | |
4382 | ||
4c476991 JB |
4383 | if (!rdev->ops->change_bss) |
4384 | return -EOPNOTSUPP; | |
9f1ba906 | 4385 | |
074ac8df | 4386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4387 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4388 | return -EOPNOTSUPP; | |
3b85875a | 4389 | |
e35e4d28 | 4390 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4391 | } |
4392 | ||
b54452b0 | 4393 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4394 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4395 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4396 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4397 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4398 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4399 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4400 | }; | |
4401 | ||
4402 | static int parse_reg_rule(struct nlattr *tb[], | |
4403 | struct ieee80211_reg_rule *reg_rule) | |
4404 | { | |
4405 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4406 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4407 | ||
4408 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4409 | return -EINVAL; | |
4410 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4411 | return -EINVAL; | |
4412 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4413 | return -EINVAL; | |
4414 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4415 | return -EINVAL; | |
4416 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4417 | return -EINVAL; | |
4418 | ||
4419 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4420 | ||
4421 | freq_range->start_freq_khz = | |
4422 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4423 | freq_range->end_freq_khz = | |
4424 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4425 | freq_range->max_bandwidth_khz = | |
4426 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4427 | ||
4428 | power_rule->max_eirp = | |
4429 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4430 | ||
4431 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4432 | power_rule->max_antenna_gain = | |
4433 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4434 | ||
4435 | return 0; | |
4436 | } | |
4437 | ||
4438 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4439 | { | |
4440 | int r; | |
4441 | char *data = NULL; | |
57b5ce07 | 4442 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4443 | |
80778f18 LR |
4444 | /* |
4445 | * You should only get this when cfg80211 hasn't yet initialized | |
4446 | * completely when built-in to the kernel right between the time | |
4447 | * window between nl80211_init() and regulatory_init(), if that is | |
4448 | * even possible. | |
4449 | */ | |
458f4f9e | 4450 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4451 | return -EINPROGRESS; |
80778f18 | 4452 | |
fe33eb39 LR |
4453 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4454 | return -EINVAL; | |
b2e1b302 LR |
4455 | |
4456 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4457 | ||
57b5ce07 LR |
4458 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4459 | user_reg_hint_type = | |
4460 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4461 | else | |
4462 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4463 | ||
4464 | switch (user_reg_hint_type) { | |
4465 | case NL80211_USER_REG_HINT_USER: | |
4466 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4467 | break; | |
4468 | default: | |
4469 | return -EINVAL; | |
4470 | } | |
4471 | ||
4472 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4473 | |
b2e1b302 LR |
4474 | return r; |
4475 | } | |
4476 | ||
24bdd9f4 | 4477 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4478 | struct genl_info *info) |
93da9cc1 | 4479 | { |
4c476991 | 4480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4481 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4482 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4483 | struct mesh_config cur_params; | |
4484 | int err = 0; | |
93da9cc1 | 4485 | void *hdr; |
4486 | struct nlattr *pinfoattr; | |
4487 | struct sk_buff *msg; | |
4488 | ||
29cbe68c JB |
4489 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4490 | return -EOPNOTSUPP; | |
4491 | ||
24bdd9f4 | 4492 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4493 | return -EOPNOTSUPP; |
f3f92586 | 4494 | |
29cbe68c JB |
4495 | wdev_lock(wdev); |
4496 | /* If not connected, get default parameters */ | |
4497 | if (!wdev->mesh_id_len) | |
4498 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4499 | else | |
e35e4d28 | 4500 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4501 | wdev_unlock(wdev); |
4502 | ||
93da9cc1 | 4503 | if (err) |
4c476991 | 4504 | return err; |
93da9cc1 | 4505 | |
4506 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4507 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4508 | if (!msg) |
4509 | return -ENOMEM; | |
15e47304 | 4510 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4511 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4512 | if (!hdr) |
efe1cf0c | 4513 | goto out; |
24bdd9f4 | 4514 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4515 | if (!pinfoattr) |
4516 | goto nla_put_failure; | |
9360ffd1 DM |
4517 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4518 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4519 | cur_params.dot11MeshRetryTimeout) || | |
4520 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4521 | cur_params.dot11MeshConfirmTimeout) || | |
4522 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4523 | cur_params.dot11MeshHoldingTimeout) || | |
4524 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4525 | cur_params.dot11MeshMaxPeerLinks) || | |
4526 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4527 | cur_params.dot11MeshMaxRetries) || | |
4528 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4529 | cur_params.dot11MeshTTL) || | |
4530 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4531 | cur_params.element_ttl) || | |
4532 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4533 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4534 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4535 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4536 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4537 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4538 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4539 | cur_params.path_refresh_time) || | |
4540 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4541 | cur_params.min_discovery_timeout) || | |
4542 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4543 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4544 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4545 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4546 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4547 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4548 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4549 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4550 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4551 | cur_params.dot11MeshHWMPRootMode) || | |
4552 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4553 | cur_params.dot11MeshHWMPRannInterval) || | |
4554 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4555 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4556 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4557 | cur_params.dot11MeshForwarding) || | |
4558 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4559 | cur_params.rssi_threshold) || |
4560 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4561 | cur_params.ht_opmode) || |
4562 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4563 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4564 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4565 | cur_params.dot11MeshHWMProotInterval) || |
4566 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4567 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4568 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4569 | cur_params.power_mode) || | |
4570 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
4571 | cur_params.dot11MeshAwakeWindowDuration)) | |
9360ffd1 | 4572 | goto nla_put_failure; |
93da9cc1 | 4573 | nla_nest_end(msg, pinfoattr); |
4574 | genlmsg_end(msg, hdr); | |
4c476991 | 4575 | return genlmsg_reply(msg, info); |
93da9cc1 | 4576 | |
3b85875a | 4577 | nla_put_failure: |
93da9cc1 | 4578 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4579 | out: |
d080e275 | 4580 | nlmsg_free(msg); |
4c476991 | 4581 | return -ENOBUFS; |
93da9cc1 | 4582 | } |
4583 | ||
b54452b0 | 4584 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4585 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4586 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4587 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4588 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4589 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4590 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4591 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4592 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4593 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4594 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4595 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4596 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4597 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4598 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4599 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4600 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4601 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4602 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4603 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4604 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4605 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4606 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4607 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4608 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4609 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4610 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4611 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
93da9cc1 | 4612 | }; |
4613 | ||
c80d545d JC |
4614 | static const struct nla_policy |
4615 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4616 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4617 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4618 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4619 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4620 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4621 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4622 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4623 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4624 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4625 | }; |
4626 | ||
24bdd9f4 | 4627 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4628 | struct mesh_config *cfg, |
4629 | u32 *mask_out) | |
93da9cc1 | 4630 | { |
93da9cc1 | 4631 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4632 | u32 mask = 0; |
93da9cc1 | 4633 | |
ea54fba2 MP |
4634 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4635 | do { \ | |
4636 | if (tb[attr]) { \ | |
4637 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4638 | return -EINVAL; \ | |
4639 | cfg->param = fn(tb[attr]); \ | |
4640 | mask |= (1 << (attr - 1)); \ | |
4641 | } \ | |
4642 | } while (0) | |
bd90fdcc JB |
4643 | |
4644 | ||
24bdd9f4 | 4645 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4646 | return -EINVAL; |
4647 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4648 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4649 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4650 | return -EINVAL; |
4651 | ||
93da9cc1 | 4652 | /* This makes sure that there aren't more than 32 mesh config |
4653 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4654 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4655 | ||
4656 | /* Fill in the params struct */ | |
ea54fba2 | 4657 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4658 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4659 | nla_get_u16); | |
ea54fba2 | 4660 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4661 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4662 | nla_get_u16); | |
ea54fba2 | 4663 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4664 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4665 | nla_get_u16); | |
ea54fba2 | 4666 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4667 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4668 | nla_get_u16); | |
ea54fba2 | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4670 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4671 | nla_get_u8); | |
ea54fba2 | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4673 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4674 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4675 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4676 | nla_get_u8); | |
ea54fba2 | 4677 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4678 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4679 | nla_get_u8); | |
ea54fba2 MP |
4680 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4681 | 1, 255, mask, | |
a4f606ea CYY |
4682 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4683 | nla_get_u32); | |
ea54fba2 | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4685 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4686 | nla_get_u8); | |
ea54fba2 | 4687 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4688 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4689 | nla_get_u32); | |
ea54fba2 | 4690 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4691 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4692 | nla_get_u16); | |
ea54fba2 MP |
4693 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4694 | 1, 65535, mask, | |
a4f606ea CYY |
4695 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4696 | nla_get_u32); | |
93da9cc1 | 4697 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4698 | 1, 65535, mask, |
4699 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4700 | nla_get_u16); |
dca7e943 | 4701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4702 | 1, 65535, mask, |
4703 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4704 | nla_get_u16); |
93da9cc1 | 4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4706 | dot11MeshHWMPnetDiameterTraversalTime, |
4707 | 1, 65535, mask, | |
a4f606ea CYY |
4708 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4709 | nla_get_u16); | |
ea54fba2 MP |
4710 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4711 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4712 | nla_get_u8); | |
4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4714 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4715 | nla_get_u16); |
63c5723b | 4716 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4717 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4718 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4719 | nla_get_u8); |
ea54fba2 | 4720 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4721 | mask, NL80211_MESHCONF_FORWARDING, |
4722 | nla_get_u8); | |
ea54fba2 | 4723 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4724 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4725 | nla_get_u32); | |
ea54fba2 | 4726 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4727 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4728 | nla_get_u16); |
4729 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4730 | 1, 65535, mask, |
ac1073a6 CYY |
4731 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4732 | nla_get_u32); | |
ea54fba2 | 4733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4734 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4735 | nla_get_u16); |
4736 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4737 | dot11MeshHWMPconfirmationInterval, |
4738 | 1, 65535, mask, | |
728b19e5 | 4739 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4740 | nla_get_u16); |
3b1c5a53 MP |
4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4742 | NL80211_MESH_POWER_ACTIVE, | |
4743 | NL80211_MESH_POWER_MAX, | |
4744 | mask, NL80211_MESHCONF_POWER_MODE, | |
4745 | nla_get_u32); | |
4746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4747 | 0, 65535, mask, | |
4748 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
bd90fdcc JB |
4749 | if (mask_out) |
4750 | *mask_out = mask; | |
c80d545d | 4751 | |
bd90fdcc JB |
4752 | return 0; |
4753 | ||
4754 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4755 | } | |
4756 | ||
c80d545d JC |
4757 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4758 | struct mesh_setup *setup) | |
4759 | { | |
bb2798d4 | 4760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4761 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4762 | ||
4763 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4764 | return -EINVAL; | |
4765 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4766 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4767 | nl80211_mesh_setup_params_policy)) | |
4768 | return -EINVAL; | |
4769 | ||
d299a1f2 JC |
4770 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4771 | setup->sync_method = | |
4772 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4773 | IEEE80211_SYNC_METHOD_VENDOR : | |
4774 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4775 | ||
c80d545d JC |
4776 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4777 | setup->path_sel_proto = | |
4778 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4779 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4780 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4781 | ||
4782 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4783 | setup->path_metric = | |
4784 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4785 | IEEE80211_PATH_METRIC_VENDOR : | |
4786 | IEEE80211_PATH_METRIC_AIRTIME; | |
4787 | ||
581a8b0f JC |
4788 | |
4789 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4790 | struct nlattr *ieattr = |
581a8b0f | 4791 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4792 | if (!is_valid_ie_attr(ieattr)) |
4793 | return -EINVAL; | |
581a8b0f JC |
4794 | setup->ie = nla_data(ieattr); |
4795 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4796 | } |
bb2798d4 TP |
4797 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4798 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4799 | return -EINVAL; | |
4800 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4801 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4802 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4803 | if (setup->is_secure) |
4804 | setup->user_mpm = true; | |
c80d545d | 4805 | |
6e16d90b CT |
4806 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
4807 | if (!setup->user_mpm) | |
4808 | return -EINVAL; | |
4809 | setup->auth_id = | |
4810 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
4811 | } | |
4812 | ||
c80d545d JC |
4813 | return 0; |
4814 | } | |
4815 | ||
24bdd9f4 | 4816 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4817 | struct genl_info *info) |
bd90fdcc JB |
4818 | { |
4819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4820 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4821 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4822 | struct mesh_config cfg; |
4823 | u32 mask; | |
4824 | int err; | |
4825 | ||
29cbe68c JB |
4826 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4827 | return -EOPNOTSUPP; | |
4828 | ||
24bdd9f4 | 4829 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4830 | return -EOPNOTSUPP; |
4831 | ||
24bdd9f4 | 4832 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4833 | if (err) |
4834 | return err; | |
4835 | ||
29cbe68c JB |
4836 | wdev_lock(wdev); |
4837 | if (!wdev->mesh_id_len) | |
4838 | err = -ENOLINK; | |
4839 | ||
4840 | if (!err) | |
e35e4d28 | 4841 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4842 | |
4843 | wdev_unlock(wdev); | |
4844 | ||
4845 | return err; | |
93da9cc1 | 4846 | } |
4847 | ||
f130347c LR |
4848 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4849 | { | |
458f4f9e | 4850 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4851 | struct sk_buff *msg; |
4852 | void *hdr = NULL; | |
4853 | struct nlattr *nl_reg_rules; | |
4854 | unsigned int i; | |
f130347c LR |
4855 | |
4856 | if (!cfg80211_regdomain) | |
5fe231e8 | 4857 | return -EINVAL; |
f130347c | 4858 | |
fd2120ca | 4859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
4860 | if (!msg) |
4861 | return -ENOBUFS; | |
f130347c | 4862 | |
15e47304 | 4863 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4864 | NL80211_CMD_GET_REG); |
4865 | if (!hdr) | |
efe1cf0c | 4866 | goto put_failure; |
f130347c | 4867 | |
57b5ce07 LR |
4868 | if (reg_last_request_cell_base() && |
4869 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4870 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4871 | goto nla_put_failure; | |
4872 | ||
458f4f9e JB |
4873 | rcu_read_lock(); |
4874 | regdom = rcu_dereference(cfg80211_regdomain); | |
4875 | ||
4876 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4877 | (regdom->dfs_region && | |
4878 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4879 | goto nla_put_failure_rcu; | |
4880 | ||
f130347c LR |
4881 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4882 | if (!nl_reg_rules) | |
458f4f9e | 4883 | goto nla_put_failure_rcu; |
f130347c | 4884 | |
458f4f9e | 4885 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4886 | struct nlattr *nl_reg_rule; |
4887 | const struct ieee80211_reg_rule *reg_rule; | |
4888 | const struct ieee80211_freq_range *freq_range; | |
4889 | const struct ieee80211_power_rule *power_rule; | |
4890 | ||
458f4f9e | 4891 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4892 | freq_range = ®_rule->freq_range; |
4893 | power_rule = ®_rule->power_rule; | |
4894 | ||
4895 | nl_reg_rule = nla_nest_start(msg, i); | |
4896 | if (!nl_reg_rule) | |
458f4f9e | 4897 | goto nla_put_failure_rcu; |
f130347c | 4898 | |
9360ffd1 DM |
4899 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4900 | reg_rule->flags) || | |
4901 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4902 | freq_range->start_freq_khz) || | |
4903 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4904 | freq_range->end_freq_khz) || | |
4905 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4906 | freq_range->max_bandwidth_khz) || | |
4907 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4908 | power_rule->max_antenna_gain) || | |
4909 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4910 | power_rule->max_eirp)) | |
458f4f9e | 4911 | goto nla_put_failure_rcu; |
f130347c LR |
4912 | |
4913 | nla_nest_end(msg, nl_reg_rule); | |
4914 | } | |
458f4f9e | 4915 | rcu_read_unlock(); |
f130347c LR |
4916 | |
4917 | nla_nest_end(msg, nl_reg_rules); | |
4918 | ||
4919 | genlmsg_end(msg, hdr); | |
5fe231e8 | 4920 | return genlmsg_reply(msg, info); |
f130347c | 4921 | |
458f4f9e JB |
4922 | nla_put_failure_rcu: |
4923 | rcu_read_unlock(); | |
f130347c LR |
4924 | nla_put_failure: |
4925 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4926 | put_failure: |
d080e275 | 4927 | nlmsg_free(msg); |
5fe231e8 | 4928 | return -EMSGSIZE; |
f130347c LR |
4929 | } |
4930 | ||
b2e1b302 LR |
4931 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
4932 | { | |
4933 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
4934 | struct nlattr *nl_reg_rule; | |
4935 | char *alpha2 = NULL; | |
4936 | int rem_reg_rules = 0, r = 0; | |
4937 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 4938 | u8 dfs_region = 0; |
b2e1b302 LR |
4939 | struct ieee80211_regdomain *rd = NULL; |
4940 | ||
4941 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
4942 | return -EINVAL; | |
4943 | ||
4944 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
4945 | return -EINVAL; | |
4946 | ||
4947 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4948 | ||
8b60b078 LR |
4949 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
4950 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
4951 | ||
b2e1b302 | 4952 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4953 | rem_reg_rules) { |
b2e1b302 LR |
4954 | num_rules++; |
4955 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 4956 | return -EINVAL; |
b2e1b302 LR |
4957 | } |
4958 | ||
b2e1b302 | 4959 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 4960 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
4961 | |
4962 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
4963 | if (!rd) |
4964 | return -ENOMEM; | |
b2e1b302 LR |
4965 | |
4966 | rd->n_reg_rules = num_rules; | |
4967 | rd->alpha2[0] = alpha2[0]; | |
4968 | rd->alpha2[1] = alpha2[1]; | |
4969 | ||
8b60b078 LR |
4970 | /* |
4971 | * Disable DFS master mode if the DFS region was | |
4972 | * not supported or known on this kernel. | |
4973 | */ | |
4974 | if (reg_supported_dfs_region(dfs_region)) | |
4975 | rd->dfs_region = dfs_region; | |
4976 | ||
b2e1b302 | 4977 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4978 | rem_reg_rules) { |
b2e1b302 | 4979 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
4980 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
4981 | reg_rule_policy); | |
b2e1b302 LR |
4982 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
4983 | if (r) | |
4984 | goto bad_reg; | |
4985 | ||
4986 | rule_idx++; | |
4987 | ||
d0e18f83 LR |
4988 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
4989 | r = -EINVAL; | |
b2e1b302 | 4990 | goto bad_reg; |
d0e18f83 | 4991 | } |
b2e1b302 LR |
4992 | } |
4993 | ||
b2e1b302 | 4994 | r = set_regdom(rd); |
6913b49a | 4995 | /* set_regdom took ownership */ |
1a919318 | 4996 | rd = NULL; |
b2e1b302 | 4997 | |
d2372b31 | 4998 | bad_reg: |
b2e1b302 | 4999 | kfree(rd); |
d0e18f83 | 5000 | return r; |
b2e1b302 LR |
5001 | } |
5002 | ||
83f5e2cf JB |
5003 | static int validate_scan_freqs(struct nlattr *freqs) |
5004 | { | |
5005 | struct nlattr *attr1, *attr2; | |
5006 | int n_channels = 0, tmp1, tmp2; | |
5007 | ||
5008 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5009 | n_channels++; | |
5010 | /* | |
5011 | * Some hardware has a limited channel list for | |
5012 | * scanning, and it is pretty much nonsensical | |
5013 | * to scan for a channel twice, so disallow that | |
5014 | * and don't require drivers to check that the | |
5015 | * channel list they get isn't longer than what | |
5016 | * they can scan, as long as they can scan all | |
5017 | * the channels they registered at once. | |
5018 | */ | |
5019 | nla_for_each_nested(attr2, freqs, tmp2) | |
5020 | if (attr1 != attr2 && | |
5021 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5022 | return 0; | |
5023 | } | |
5024 | ||
5025 | return n_channels; | |
5026 | } | |
5027 | ||
2a519311 JB |
5028 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5029 | { | |
4c476991 | 5030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5031 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5032 | struct cfg80211_scan_request *request; |
2a519311 JB |
5033 | struct nlattr *attr; |
5034 | struct wiphy *wiphy; | |
83f5e2cf | 5035 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5036 | size_t ie_len; |
2a519311 | 5037 | |
f4a11bb0 JB |
5038 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5039 | return -EINVAL; | |
5040 | ||
79c97e97 | 5041 | wiphy = &rdev->wiphy; |
2a519311 | 5042 | |
4c476991 JB |
5043 | if (!rdev->ops->scan) |
5044 | return -EOPNOTSUPP; | |
2a519311 | 5045 | |
f9f47529 JB |
5046 | if (rdev->scan_req) { |
5047 | err = -EBUSY; | |
5048 | goto unlock; | |
5049 | } | |
2a519311 JB |
5050 | |
5051 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5052 | n_channels = validate_scan_freqs( |
5053 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5054 | if (!n_channels) { |
5055 | err = -EINVAL; | |
5056 | goto unlock; | |
5057 | } | |
2a519311 | 5058 | } else { |
34850ab2 | 5059 | enum ieee80211_band band; |
83f5e2cf JB |
5060 | n_channels = 0; |
5061 | ||
2a519311 JB |
5062 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5063 | if (wiphy->bands[band]) | |
5064 | n_channels += wiphy->bands[band]->n_channels; | |
5065 | } | |
5066 | ||
5067 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5068 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5069 | n_ssids++; | |
5070 | ||
f9f47529 JB |
5071 | if (n_ssids > wiphy->max_scan_ssids) { |
5072 | err = -EINVAL; | |
5073 | goto unlock; | |
5074 | } | |
2a519311 | 5075 | |
70692ad2 JM |
5076 | if (info->attrs[NL80211_ATTR_IE]) |
5077 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5078 | else | |
5079 | ie_len = 0; | |
5080 | ||
f9f47529 JB |
5081 | if (ie_len > wiphy->max_scan_ie_len) { |
5082 | err = -EINVAL; | |
5083 | goto unlock; | |
5084 | } | |
18a83659 | 5085 | |
2a519311 | 5086 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5087 | + sizeof(*request->ssids) * n_ssids |
5088 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5089 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5090 | if (!request) { |
5091 | err = -ENOMEM; | |
5092 | goto unlock; | |
5093 | } | |
2a519311 | 5094 | |
2a519311 | 5095 | if (n_ssids) |
5ba63533 | 5096 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5097 | request->n_ssids = n_ssids; |
70692ad2 JM |
5098 | if (ie_len) { |
5099 | if (request->ssids) | |
5100 | request->ie = (void *)(request->ssids + n_ssids); | |
5101 | else | |
5102 | request->ie = (void *)(request->channels + n_channels); | |
5103 | } | |
2a519311 | 5104 | |
584991dc | 5105 | i = 0; |
2a519311 JB |
5106 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5107 | /* user specified, bail out if channel not found */ | |
2a519311 | 5108 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5109 | struct ieee80211_channel *chan; |
5110 | ||
5111 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5112 | ||
5113 | if (!chan) { | |
2a519311 JB |
5114 | err = -EINVAL; |
5115 | goto out_free; | |
5116 | } | |
584991dc JB |
5117 | |
5118 | /* ignore disabled channels */ | |
5119 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5120 | continue; | |
5121 | ||
5122 | request->channels[i] = chan; | |
2a519311 JB |
5123 | i++; |
5124 | } | |
5125 | } else { | |
34850ab2 JB |
5126 | enum ieee80211_band band; |
5127 | ||
2a519311 | 5128 | /* all channels */ |
2a519311 JB |
5129 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5130 | int j; | |
5131 | if (!wiphy->bands[band]) | |
5132 | continue; | |
5133 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5134 | struct ieee80211_channel *chan; |
5135 | ||
5136 | chan = &wiphy->bands[band]->channels[j]; | |
5137 | ||
5138 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5139 | continue; | |
5140 | ||
5141 | request->channels[i] = chan; | |
2a519311 JB |
5142 | i++; |
5143 | } | |
5144 | } | |
5145 | } | |
5146 | ||
584991dc JB |
5147 | if (!i) { |
5148 | err = -EINVAL; | |
5149 | goto out_free; | |
5150 | } | |
5151 | ||
5152 | request->n_channels = i; | |
5153 | ||
2a519311 JB |
5154 | i = 0; |
5155 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5156 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5157 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5158 | err = -EINVAL; |
5159 | goto out_free; | |
5160 | } | |
57a27e1d | 5161 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5162 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5163 | i++; |
5164 | } | |
5165 | } | |
5166 | ||
70692ad2 JM |
5167 | if (info->attrs[NL80211_ATTR_IE]) { |
5168 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5169 | memcpy((void *)request->ie, |
5170 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5171 | request->ie_len); |
5172 | } | |
5173 | ||
34850ab2 | 5174 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5175 | if (wiphy->bands[i]) |
5176 | request->rates[i] = | |
5177 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5178 | |
5179 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5180 | nla_for_each_nested(attr, | |
5181 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5182 | tmp) { | |
5183 | enum ieee80211_band band = nla_type(attr); | |
5184 | ||
84404623 | 5185 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5186 | err = -EINVAL; |
5187 | goto out_free; | |
5188 | } | |
5189 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5190 | nla_data(attr), | |
5191 | nla_len(attr), | |
5192 | &request->rates[band]); | |
5193 | if (err) | |
5194 | goto out_free; | |
5195 | } | |
5196 | } | |
5197 | ||
46856bbf | 5198 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5199 | request->flags = nla_get_u32( |
5200 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5201 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5202 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5203 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5204 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5205 | err = -EOPNOTSUPP; |
5206 | goto out_free; | |
5207 | } | |
5208 | } | |
ed473771 | 5209 | |
e9f935e3 RM |
5210 | request->no_cck = |
5211 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5212 | ||
fd014284 | 5213 | request->wdev = wdev; |
79c97e97 | 5214 | request->wiphy = &rdev->wiphy; |
15d6030b | 5215 | request->scan_start = jiffies; |
2a519311 | 5216 | |
79c97e97 | 5217 | rdev->scan_req = request; |
e35e4d28 | 5218 | err = rdev_scan(rdev, request); |
2a519311 | 5219 | |
463d0183 | 5220 | if (!err) { |
fd014284 JB |
5221 | nl80211_send_scan_start(rdev, wdev); |
5222 | if (wdev->netdev) | |
5223 | dev_hold(wdev->netdev); | |
4c476991 | 5224 | } else { |
2a519311 | 5225 | out_free: |
79c97e97 | 5226 | rdev->scan_req = NULL; |
2a519311 JB |
5227 | kfree(request); |
5228 | } | |
3b85875a | 5229 | |
f9f47529 | 5230 | unlock: |
2a519311 JB |
5231 | return err; |
5232 | } | |
5233 | ||
807f8a8c LC |
5234 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5235 | struct genl_info *info) | |
5236 | { | |
5237 | struct cfg80211_sched_scan_request *request; | |
5238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5239 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5240 | struct nlattr *attr; |
5241 | struct wiphy *wiphy; | |
a1f1c21c | 5242 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5243 | u32 interval; |
807f8a8c LC |
5244 | enum ieee80211_band band; |
5245 | size_t ie_len; | |
a1f1c21c | 5246 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5247 | |
5248 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5249 | !rdev->ops->sched_scan_start) | |
5250 | return -EOPNOTSUPP; | |
5251 | ||
5252 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5253 | return -EINVAL; | |
5254 | ||
bbe6ad6d LC |
5255 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5256 | return -EINVAL; | |
5257 | ||
5258 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5259 | if (interval == 0) | |
5260 | return -EINVAL; | |
5261 | ||
807f8a8c LC |
5262 | wiphy = &rdev->wiphy; |
5263 | ||
5264 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5265 | n_channels = validate_scan_freqs( | |
5266 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5267 | if (!n_channels) | |
5268 | return -EINVAL; | |
5269 | } else { | |
5270 | n_channels = 0; | |
5271 | ||
5272 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5273 | if (wiphy->bands[band]) | |
5274 | n_channels += wiphy->bands[band]->n_channels; | |
5275 | } | |
5276 | ||
5277 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5278 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5279 | tmp) | |
5280 | n_ssids++; | |
5281 | ||
93b6aa69 | 5282 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5283 | return -EINVAL; |
5284 | ||
a1f1c21c LC |
5285 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5286 | nla_for_each_nested(attr, | |
5287 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5288 | tmp) | |
5289 | n_match_sets++; | |
5290 | ||
5291 | if (n_match_sets > wiphy->max_match_sets) | |
5292 | return -EINVAL; | |
5293 | ||
807f8a8c LC |
5294 | if (info->attrs[NL80211_ATTR_IE]) |
5295 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5296 | else | |
5297 | ie_len = 0; | |
5298 | ||
5a865bad | 5299 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5300 | return -EINVAL; |
5301 | ||
c10841ca LC |
5302 | if (rdev->sched_scan_req) { |
5303 | err = -EINPROGRESS; | |
5304 | goto out; | |
5305 | } | |
5306 | ||
807f8a8c | 5307 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5308 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5309 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5310 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5311 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5312 | if (!request) { |
5313 | err = -ENOMEM; | |
5314 | goto out; | |
5315 | } | |
807f8a8c LC |
5316 | |
5317 | if (n_ssids) | |
5318 | request->ssids = (void *)&request->channels[n_channels]; | |
5319 | request->n_ssids = n_ssids; | |
5320 | if (ie_len) { | |
5321 | if (request->ssids) | |
5322 | request->ie = (void *)(request->ssids + n_ssids); | |
5323 | else | |
5324 | request->ie = (void *)(request->channels + n_channels); | |
5325 | } | |
5326 | ||
a1f1c21c LC |
5327 | if (n_match_sets) { |
5328 | if (request->ie) | |
5329 | request->match_sets = (void *)(request->ie + ie_len); | |
5330 | else if (request->ssids) | |
5331 | request->match_sets = | |
5332 | (void *)(request->ssids + n_ssids); | |
5333 | else | |
5334 | request->match_sets = | |
5335 | (void *)(request->channels + n_channels); | |
5336 | } | |
5337 | request->n_match_sets = n_match_sets; | |
5338 | ||
807f8a8c LC |
5339 | i = 0; |
5340 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5341 | /* user specified, bail out if channel not found */ | |
5342 | nla_for_each_nested(attr, | |
5343 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5344 | tmp) { | |
5345 | struct ieee80211_channel *chan; | |
5346 | ||
5347 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5348 | ||
5349 | if (!chan) { | |
5350 | err = -EINVAL; | |
5351 | goto out_free; | |
5352 | } | |
5353 | ||
5354 | /* ignore disabled channels */ | |
5355 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5356 | continue; | |
5357 | ||
5358 | request->channels[i] = chan; | |
5359 | i++; | |
5360 | } | |
5361 | } else { | |
5362 | /* all channels */ | |
5363 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5364 | int j; | |
5365 | if (!wiphy->bands[band]) | |
5366 | continue; | |
5367 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5368 | struct ieee80211_channel *chan; | |
5369 | ||
5370 | chan = &wiphy->bands[band]->channels[j]; | |
5371 | ||
5372 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5373 | continue; | |
5374 | ||
5375 | request->channels[i] = chan; | |
5376 | i++; | |
5377 | } | |
5378 | } | |
5379 | } | |
5380 | ||
5381 | if (!i) { | |
5382 | err = -EINVAL; | |
5383 | goto out_free; | |
5384 | } | |
5385 | ||
5386 | request->n_channels = i; | |
5387 | ||
5388 | i = 0; | |
5389 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5390 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5391 | tmp) { | |
57a27e1d | 5392 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5393 | err = -EINVAL; |
5394 | goto out_free; | |
5395 | } | |
57a27e1d | 5396 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5397 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5398 | nla_len(attr)); | |
807f8a8c LC |
5399 | i++; |
5400 | } | |
5401 | } | |
5402 | ||
a1f1c21c LC |
5403 | i = 0; |
5404 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5405 | nla_for_each_nested(attr, | |
5406 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5407 | tmp) { | |
88e920b4 | 5408 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5409 | |
5410 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5411 | nla_data(attr), nla_len(attr), | |
5412 | nl80211_match_policy); | |
4a4ab0d7 | 5413 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5414 | if (ssid) { |
5415 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5416 | err = -EINVAL; | |
5417 | goto out_free; | |
5418 | } | |
5419 | memcpy(request->match_sets[i].ssid.ssid, | |
5420 | nla_data(ssid), nla_len(ssid)); | |
5421 | request->match_sets[i].ssid.ssid_len = | |
5422 | nla_len(ssid); | |
5423 | } | |
88e920b4 TP |
5424 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5425 | if (rssi) | |
5426 | request->rssi_thold = nla_get_u32(rssi); | |
5427 | else | |
5428 | request->rssi_thold = | |
5429 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5430 | i++; |
5431 | } | |
5432 | } | |
5433 | ||
807f8a8c LC |
5434 | if (info->attrs[NL80211_ATTR_IE]) { |
5435 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5436 | memcpy((void *)request->ie, | |
5437 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5438 | request->ie_len); | |
5439 | } | |
5440 | ||
46856bbf | 5441 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5442 | request->flags = nla_get_u32( |
5443 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5444 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5445 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5446 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5447 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5448 | err = -EOPNOTSUPP; |
5449 | goto out_free; | |
5450 | } | |
5451 | } | |
ed473771 | 5452 | |
807f8a8c LC |
5453 | request->dev = dev; |
5454 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5455 | request->interval = interval; |
15d6030b | 5456 | request->scan_start = jiffies; |
807f8a8c | 5457 | |
e35e4d28 | 5458 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5459 | if (!err) { |
5460 | rdev->sched_scan_req = request; | |
5461 | nl80211_send_sched_scan(rdev, dev, | |
5462 | NL80211_CMD_START_SCHED_SCAN); | |
5463 | goto out; | |
5464 | } | |
5465 | ||
5466 | out_free: | |
5467 | kfree(request); | |
5468 | out: | |
5469 | return err; | |
5470 | } | |
5471 | ||
5472 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5473 | struct genl_info *info) | |
5474 | { | |
5475 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5476 | ||
5477 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5478 | !rdev->ops->sched_scan_stop) | |
5479 | return -EOPNOTSUPP; | |
5480 | ||
5fe231e8 | 5481 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5482 | } |
5483 | ||
04f39047 SW |
5484 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5485 | struct genl_info *info) | |
5486 | { | |
5487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5488 | struct net_device *dev = info->user_ptr[1]; | |
5489 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5490 | struct cfg80211_chan_def chandef; | |
5491 | int err; | |
5492 | ||
5493 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5494 | if (err) | |
5495 | return err; | |
5496 | ||
5497 | if (wdev->cac_started) | |
5498 | return -EBUSY; | |
5499 | ||
5500 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5501 | if (err < 0) | |
5502 | return err; | |
5503 | ||
5504 | if (err == 0) | |
5505 | return -EINVAL; | |
5506 | ||
5507 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5508 | return -EINVAL; | |
5509 | ||
5510 | if (!rdev->ops->start_radar_detection) | |
5511 | return -EOPNOTSUPP; | |
5512 | ||
04f39047 SW |
5513 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5514 | chandef.chan, CHAN_MODE_SHARED, | |
5515 | BIT(chandef.width)); | |
5516 | if (err) | |
5fe231e8 | 5517 | return err; |
04f39047 SW |
5518 | |
5519 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5520 | if (!err) { | |
5521 | wdev->channel = chandef.chan; | |
5522 | wdev->cac_started = true; | |
5523 | wdev->cac_start_time = jiffies; | |
5524 | } | |
04f39047 SW |
5525 | return err; |
5526 | } | |
5527 | ||
9720bb3a JB |
5528 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5529 | u32 seq, int flags, | |
2a519311 | 5530 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5531 | struct wireless_dev *wdev, |
5532 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5533 | { |
48ab905d | 5534 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5535 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5536 | void *hdr; |
5537 | struct nlattr *bss; | |
8cef2c9d | 5538 | bool tsf = false; |
48ab905d JB |
5539 | |
5540 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5541 | |
15e47304 | 5542 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5543 | NL80211_CMD_NEW_SCAN_RESULTS); |
5544 | if (!hdr) | |
5545 | return -1; | |
5546 | ||
9720bb3a JB |
5547 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5548 | ||
97990a06 JB |
5549 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5550 | goto nla_put_failure; | |
5551 | if (wdev->netdev && | |
9360ffd1 DM |
5552 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5553 | goto nla_put_failure; | |
97990a06 JB |
5554 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5555 | goto nla_put_failure; | |
2a519311 JB |
5556 | |
5557 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5558 | if (!bss) | |
5559 | goto nla_put_failure; | |
9360ffd1 | 5560 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5561 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5562 | goto nla_put_failure; |
9caf0364 JB |
5563 | |
5564 | rcu_read_lock(); | |
5565 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5566 | if (ies) { |
5567 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5568 | goto fail_unlock_rcu; | |
5569 | tsf = true; | |
5570 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5571 | ies->len, ies->data)) | |
5572 | goto fail_unlock_rcu; | |
9caf0364 JB |
5573 | } |
5574 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5575 | if (ies) { |
5576 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5577 | goto fail_unlock_rcu; | |
5578 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5579 | ies->len, ies->data)) | |
5580 | goto fail_unlock_rcu; | |
9caf0364 JB |
5581 | } |
5582 | rcu_read_unlock(); | |
5583 | ||
9360ffd1 DM |
5584 | if (res->beacon_interval && |
5585 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5586 | goto nla_put_failure; | |
5587 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5588 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5589 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5590 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5591 | goto nla_put_failure; | |
2a519311 | 5592 | |
77965c97 | 5593 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5594 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5595 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5596 | goto nla_put_failure; | |
2a519311 JB |
5597 | break; |
5598 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5599 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5600 | goto nla_put_failure; | |
2a519311 JB |
5601 | break; |
5602 | default: | |
5603 | break; | |
5604 | } | |
5605 | ||
48ab905d | 5606 | switch (wdev->iftype) { |
074ac8df | 5607 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5608 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5609 | if (intbss == wdev->current_bss && |
5610 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5611 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5612 | goto nla_put_failure; | |
48ab905d JB |
5613 | break; |
5614 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5615 | if (intbss == wdev->current_bss && |
5616 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5617 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5618 | goto nla_put_failure; | |
48ab905d JB |
5619 | break; |
5620 | default: | |
5621 | break; | |
5622 | } | |
5623 | ||
2a519311 JB |
5624 | nla_nest_end(msg, bss); |
5625 | ||
5626 | return genlmsg_end(msg, hdr); | |
5627 | ||
8cef2c9d JB |
5628 | fail_unlock_rcu: |
5629 | rcu_read_unlock(); | |
2a519311 JB |
5630 | nla_put_failure: |
5631 | genlmsg_cancel(msg, hdr); | |
5632 | return -EMSGSIZE; | |
5633 | } | |
5634 | ||
97990a06 | 5635 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5636 | { |
48ab905d | 5637 | struct cfg80211_registered_device *rdev; |
2a519311 | 5638 | struct cfg80211_internal_bss *scan; |
48ab905d | 5639 | struct wireless_dev *wdev; |
97990a06 | 5640 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5641 | int err; |
5642 | ||
97990a06 | 5643 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5644 | if (err) |
5645 | return err; | |
2a519311 | 5646 | |
48ab905d JB |
5647 | wdev_lock(wdev); |
5648 | spin_lock_bh(&rdev->bss_lock); | |
5649 | cfg80211_bss_expire(rdev); | |
5650 | ||
9720bb3a JB |
5651 | cb->seq = rdev->bss_generation; |
5652 | ||
48ab905d | 5653 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5654 | if (++idx <= start) |
5655 | continue; | |
9720bb3a | 5656 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5657 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5658 | rdev, wdev, scan) < 0) { |
2a519311 | 5659 | idx--; |
67748893 | 5660 | break; |
2a519311 JB |
5661 | } |
5662 | } | |
5663 | ||
48ab905d JB |
5664 | spin_unlock_bh(&rdev->bss_lock); |
5665 | wdev_unlock(wdev); | |
2a519311 | 5666 | |
97990a06 JB |
5667 | cb->args[2] = idx; |
5668 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5669 | |
67748893 | 5670 | return skb->len; |
2a519311 JB |
5671 | } |
5672 | ||
15e47304 | 5673 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5674 | int flags, struct net_device *dev, |
5675 | struct survey_info *survey) | |
5676 | { | |
5677 | void *hdr; | |
5678 | struct nlattr *infoattr; | |
5679 | ||
15e47304 | 5680 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5681 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5682 | if (!hdr) | |
5683 | return -ENOMEM; | |
5684 | ||
9360ffd1 DM |
5685 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5686 | goto nla_put_failure; | |
61fa713c HS |
5687 | |
5688 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5689 | if (!infoattr) | |
5690 | goto nla_put_failure; | |
5691 | ||
9360ffd1 DM |
5692 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5693 | survey->channel->center_freq)) | |
5694 | goto nla_put_failure; | |
5695 | ||
5696 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5697 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5698 | goto nla_put_failure; | |
5699 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5700 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5701 | goto nla_put_failure; | |
5702 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5703 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5704 | survey->channel_time)) | |
5705 | goto nla_put_failure; | |
5706 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5707 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5708 | survey->channel_time_busy)) | |
5709 | goto nla_put_failure; | |
5710 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5711 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5712 | survey->channel_time_ext_busy)) | |
5713 | goto nla_put_failure; | |
5714 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5715 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5716 | survey->channel_time_rx)) | |
5717 | goto nla_put_failure; | |
5718 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5719 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5720 | survey->channel_time_tx)) | |
5721 | goto nla_put_failure; | |
61fa713c HS |
5722 | |
5723 | nla_nest_end(msg, infoattr); | |
5724 | ||
5725 | return genlmsg_end(msg, hdr); | |
5726 | ||
5727 | nla_put_failure: | |
5728 | genlmsg_cancel(msg, hdr); | |
5729 | return -EMSGSIZE; | |
5730 | } | |
5731 | ||
5732 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5733 | struct netlink_callback *cb) | |
5734 | { | |
5735 | struct survey_info survey; | |
5736 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5737 | struct wireless_dev *wdev; |
5738 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5739 | int res; |
5740 | ||
97990a06 | 5741 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5742 | if (res) |
5743 | return res; | |
61fa713c | 5744 | |
97990a06 JB |
5745 | if (!wdev->netdev) { |
5746 | res = -EINVAL; | |
5747 | goto out_err; | |
5748 | } | |
5749 | ||
61fa713c HS |
5750 | if (!dev->ops->dump_survey) { |
5751 | res = -EOPNOTSUPP; | |
5752 | goto out_err; | |
5753 | } | |
5754 | ||
5755 | while (1) { | |
180cdc79 LR |
5756 | struct ieee80211_channel *chan; |
5757 | ||
97990a06 | 5758 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5759 | if (res == -ENOENT) |
5760 | break; | |
5761 | if (res) | |
5762 | goto out_err; | |
5763 | ||
180cdc79 LR |
5764 | /* Survey without a channel doesn't make sense */ |
5765 | if (!survey.channel) { | |
5766 | res = -EINVAL; | |
5767 | goto out; | |
5768 | } | |
5769 | ||
5770 | chan = ieee80211_get_channel(&dev->wiphy, | |
5771 | survey.channel->center_freq); | |
5772 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5773 | survey_idx++; | |
5774 | continue; | |
5775 | } | |
5776 | ||
61fa713c | 5777 | if (nl80211_send_survey(skb, |
15e47304 | 5778 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5779 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5780 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5781 | goto out; |
5782 | survey_idx++; | |
5783 | } | |
5784 | ||
5785 | out: | |
97990a06 | 5786 | cb->args[2] = survey_idx; |
61fa713c HS |
5787 | res = skb->len; |
5788 | out_err: | |
97990a06 | 5789 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5790 | return res; |
5791 | } | |
5792 | ||
b23aa676 SO |
5793 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5794 | { | |
5795 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5796 | NL80211_WPA_VERSION_2)); | |
5797 | } | |
5798 | ||
636a5d36 JM |
5799 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5800 | { | |
4c476991 JB |
5801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5802 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5803 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5804 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5805 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5806 | enum nl80211_auth_type auth_type; |
fffd0934 | 5807 | struct key_parse key; |
d5cdfacb | 5808 | bool local_state_change; |
636a5d36 | 5809 | |
f4a11bb0 JB |
5810 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5811 | return -EINVAL; | |
5812 | ||
5813 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5814 | return -EINVAL; | |
5815 | ||
1778092e JM |
5816 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5817 | return -EINVAL; | |
5818 | ||
19957bb3 JB |
5819 | if (!info->attrs[NL80211_ATTR_SSID]) |
5820 | return -EINVAL; | |
5821 | ||
5822 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5823 | return -EINVAL; | |
5824 | ||
fffd0934 JB |
5825 | err = nl80211_parse_key(info, &key); |
5826 | if (err) | |
5827 | return err; | |
5828 | ||
5829 | if (key.idx >= 0) { | |
e31b8213 JB |
5830 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5831 | return -EINVAL; | |
fffd0934 JB |
5832 | if (!key.p.key || !key.p.key_len) |
5833 | return -EINVAL; | |
5834 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5835 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5836 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5837 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5838 | return -EINVAL; | |
5839 | if (key.idx > 4) | |
5840 | return -EINVAL; | |
5841 | } else { | |
5842 | key.p.key_len = 0; | |
5843 | key.p.key = NULL; | |
5844 | } | |
5845 | ||
afea0b7a JB |
5846 | if (key.idx >= 0) { |
5847 | int i; | |
5848 | bool ok = false; | |
5849 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5850 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5851 | ok = true; | |
5852 | break; | |
5853 | } | |
5854 | } | |
4c476991 JB |
5855 | if (!ok) |
5856 | return -EINVAL; | |
afea0b7a JB |
5857 | } |
5858 | ||
4c476991 JB |
5859 | if (!rdev->ops->auth) |
5860 | return -EOPNOTSUPP; | |
636a5d36 | 5861 | |
074ac8df | 5862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5863 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5864 | return -EOPNOTSUPP; | |
eec60b03 | 5865 | |
19957bb3 | 5866 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5867 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5868 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5869 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5870 | return -EINVAL; | |
636a5d36 | 5871 | |
19957bb3 JB |
5872 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5873 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5874 | |
5875 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5876 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5877 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5878 | } |
5879 | ||
19957bb3 | 5880 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5881 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5882 | return -EINVAL; |
636a5d36 | 5883 | |
e39e5b5e JM |
5884 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5885 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5886 | return -EINVAL; | |
5887 | ||
5888 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5889 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5890 | return -EINVAL; | |
5891 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5892 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5893 | /* need to include at least Auth Transaction and Status Code */ | |
5894 | if (sae_data_len < 4) | |
5895 | return -EINVAL; | |
5896 | } | |
5897 | ||
d5cdfacb JM |
5898 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5899 | ||
95de817b JB |
5900 | /* |
5901 | * Since we no longer track auth state, ignore | |
5902 | * requests to only change local state. | |
5903 | */ | |
5904 | if (local_state_change) | |
5905 | return 0; | |
5906 | ||
4c476991 JB |
5907 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
5908 | ssid, ssid_len, ie, ie_len, | |
e39e5b5e JM |
5909 | key.p.key, key.p.key_len, key.idx, |
5910 | sae_data, sae_data_len); | |
636a5d36 JM |
5911 | } |
5912 | ||
c0692b8f JB |
5913 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
5914 | struct genl_info *info, | |
3dc27d25 JB |
5915 | struct cfg80211_crypto_settings *settings, |
5916 | int cipher_limit) | |
b23aa676 | 5917 | { |
c0b2bbd8 JB |
5918 | memset(settings, 0, sizeof(*settings)); |
5919 | ||
b23aa676 SO |
5920 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
5921 | ||
c0692b8f JB |
5922 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
5923 | u16 proto; | |
5924 | proto = nla_get_u16( | |
5925 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
5926 | settings->control_port_ethertype = cpu_to_be16(proto); | |
5927 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
5928 | proto != ETH_P_PAE) | |
5929 | return -EINVAL; | |
5930 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
5931 | settings->control_port_no_encrypt = true; | |
5932 | } else | |
5933 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
5934 | ||
b23aa676 SO |
5935 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
5936 | void *data; | |
5937 | int len, i; | |
5938 | ||
5939 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5940 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5941 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
5942 | ||
5943 | if (len % sizeof(u32)) | |
5944 | return -EINVAL; | |
5945 | ||
3dc27d25 | 5946 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
5947 | return -EINVAL; |
5948 | ||
5949 | memcpy(settings->ciphers_pairwise, data, len); | |
5950 | ||
5951 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
5952 | if (!cfg80211_supported_cipher_suite( |
5953 | &rdev->wiphy, | |
b23aa676 SO |
5954 | settings->ciphers_pairwise[i])) |
5955 | return -EINVAL; | |
5956 | } | |
5957 | ||
5958 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
5959 | settings->cipher_group = | |
5960 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
5961 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
5962 | settings->cipher_group)) | |
b23aa676 SO |
5963 | return -EINVAL; |
5964 | } | |
5965 | ||
5966 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
5967 | settings->wpa_versions = | |
5968 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
5969 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
5970 | return -EINVAL; | |
5971 | } | |
5972 | ||
5973 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
5974 | void *data; | |
6d30240e | 5975 | int len; |
b23aa676 SO |
5976 | |
5977 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5978 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
5979 | settings->n_akm_suites = len / sizeof(u32); | |
5980 | ||
5981 | if (len % sizeof(u32)) | |
5982 | return -EINVAL; | |
5983 | ||
1b9ca027 JM |
5984 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
5985 | return -EINVAL; | |
5986 | ||
b23aa676 | 5987 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
5988 | } |
5989 | ||
5990 | return 0; | |
5991 | } | |
5992 | ||
636a5d36 JM |
5993 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
5994 | { | |
4c476991 JB |
5995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5996 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 5997 | struct ieee80211_channel *chan; |
f62fab73 JB |
5998 | struct cfg80211_assoc_request req = {}; |
5999 | const u8 *bssid, *ssid; | |
6000 | int err, ssid_len = 0; | |
636a5d36 | 6001 | |
f4a11bb0 JB |
6002 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6003 | return -EINVAL; | |
6004 | ||
6005 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6006 | !info->attrs[NL80211_ATTR_SSID] || |
6007 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6008 | return -EINVAL; |
6009 | ||
4c476991 JB |
6010 | if (!rdev->ops->assoc) |
6011 | return -EOPNOTSUPP; | |
636a5d36 | 6012 | |
074ac8df | 6013 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6014 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6015 | return -EOPNOTSUPP; | |
eec60b03 | 6016 | |
19957bb3 | 6017 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6018 | |
19957bb3 JB |
6019 | chan = ieee80211_get_channel(&rdev->wiphy, |
6020 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6021 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6022 | return -EINVAL; | |
636a5d36 | 6023 | |
19957bb3 JB |
6024 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6025 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6026 | |
6027 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6028 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6029 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6030 | } |
6031 | ||
dc6382ce | 6032 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6033 | enum nl80211_mfp mfp = |
dc6382ce | 6034 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6035 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6036 | req.use_mfp = true; |
4c476991 JB |
6037 | else if (mfp != NL80211_MFP_NO) |
6038 | return -EINVAL; | |
dc6382ce JM |
6039 | } |
6040 | ||
3e5d7649 | 6041 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6042 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6043 | |
7e7c8926 | 6044 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6045 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6046 | |
6047 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6048 | memcpy(&req.ht_capa_mask, |
6049 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6050 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6051 | |
6052 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6053 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6054 | return -EINVAL; |
f62fab73 JB |
6055 | memcpy(&req.ht_capa, |
6056 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6057 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6058 | } |
6059 | ||
ee2aca34 | 6060 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6061 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6062 | |
6063 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6064 | memcpy(&req.vht_capa_mask, |
6065 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6066 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6067 | |
6068 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6069 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6070 | return -EINVAL; |
f62fab73 JB |
6071 | memcpy(&req.vht_capa, |
6072 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6073 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6074 | } |
6075 | ||
f62fab73 | 6076 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
b23aa676 | 6077 | if (!err) |
f62fab73 JB |
6078 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6079 | ssid, ssid_len, &req); | |
636a5d36 | 6080 | |
636a5d36 JM |
6081 | return err; |
6082 | } | |
6083 | ||
6084 | static int nl80211_deauthenticate(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]; | |
19957bb3 | 6088 | const u8 *ie = NULL, *bssid; |
4c476991 | 6089 | int ie_len = 0; |
19957bb3 | 6090 | u16 reason_code; |
d5cdfacb | 6091 | bool local_state_change; |
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]) | |
6097 | return -EINVAL; | |
6098 | ||
6099 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6100 | return -EINVAL; | |
6101 | ||
4c476991 JB |
6102 | if (!rdev->ops->deauth) |
6103 | return -EOPNOTSUPP; | |
636a5d36 | 6104 | |
074ac8df | 6105 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6106 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6107 | return -EOPNOTSUPP; | |
eec60b03 | 6108 | |
19957bb3 | 6109 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6110 | |
19957bb3 JB |
6111 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6112 | if (reason_code == 0) { | |
f4a11bb0 | 6113 | /* Reason Code 0 is reserved */ |
4c476991 | 6114 | return -EINVAL; |
255e737e | 6115 | } |
636a5d36 JM |
6116 | |
6117 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6118 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6119 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6120 | } |
6121 | ||
d5cdfacb JM |
6122 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6123 | ||
4c476991 JB |
6124 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
6125 | local_state_change); | |
636a5d36 JM |
6126 | } |
6127 | ||
6128 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6129 | { | |
4c476991 JB |
6130 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6131 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6132 | const u8 *ie = NULL, *bssid; |
4c476991 | 6133 | int ie_len = 0; |
19957bb3 | 6134 | u16 reason_code; |
d5cdfacb | 6135 | bool local_state_change; |
636a5d36 | 6136 | |
f4a11bb0 JB |
6137 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6138 | return -EINVAL; | |
6139 | ||
6140 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6141 | return -EINVAL; | |
6142 | ||
6143 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6144 | return -EINVAL; | |
6145 | ||
4c476991 JB |
6146 | if (!rdev->ops->disassoc) |
6147 | return -EOPNOTSUPP; | |
636a5d36 | 6148 | |
074ac8df | 6149 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6150 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6151 | return -EOPNOTSUPP; | |
eec60b03 | 6152 | |
19957bb3 | 6153 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6154 | |
19957bb3 JB |
6155 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6156 | if (reason_code == 0) { | |
f4a11bb0 | 6157 | /* Reason Code 0 is reserved */ |
4c476991 | 6158 | return -EINVAL; |
255e737e | 6159 | } |
636a5d36 JM |
6160 | |
6161 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6162 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6163 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6164 | } |
6165 | ||
d5cdfacb JM |
6166 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6167 | ||
4c476991 JB |
6168 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
6169 | local_state_change); | |
636a5d36 JM |
6170 | } |
6171 | ||
dd5b4cc7 FF |
6172 | static bool |
6173 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6174 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6175 | int rateval) | |
6176 | { | |
6177 | struct wiphy *wiphy = &rdev->wiphy; | |
6178 | bool found = false; | |
6179 | int band, i; | |
6180 | ||
6181 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6182 | struct ieee80211_supported_band *sband; | |
6183 | ||
6184 | sband = wiphy->bands[band]; | |
6185 | if (!sband) | |
6186 | continue; | |
6187 | ||
6188 | for (i = 0; i < sband->n_bitrates; i++) { | |
6189 | if (sband->bitrates[i].bitrate == rateval) { | |
6190 | mcast_rate[band] = i + 1; | |
6191 | found = true; | |
6192 | break; | |
6193 | } | |
6194 | } | |
6195 | } | |
6196 | ||
6197 | return found; | |
6198 | } | |
6199 | ||
04a773ad JB |
6200 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6201 | { | |
4c476991 JB |
6202 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6203 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6204 | struct cfg80211_ibss_params ibss; |
6205 | struct wiphy *wiphy; | |
fffd0934 | 6206 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6207 | int err; |
6208 | ||
8e30bc55 JB |
6209 | memset(&ibss, 0, sizeof(ibss)); |
6210 | ||
04a773ad JB |
6211 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6212 | return -EINVAL; | |
6213 | ||
683b6d3b | 6214 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6215 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6216 | return -EINVAL; | |
6217 | ||
8e30bc55 JB |
6218 | ibss.beacon_interval = 100; |
6219 | ||
6220 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6221 | ibss.beacon_interval = | |
6222 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6223 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6224 | return -EINVAL; | |
6225 | } | |
6226 | ||
4c476991 JB |
6227 | if (!rdev->ops->join_ibss) |
6228 | return -EOPNOTSUPP; | |
04a773ad | 6229 | |
4c476991 JB |
6230 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6231 | return -EOPNOTSUPP; | |
04a773ad | 6232 | |
79c97e97 | 6233 | wiphy = &rdev->wiphy; |
04a773ad | 6234 | |
39193498 | 6235 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6236 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6237 | |
6238 | if (!is_valid_ether_addr(ibss.bssid)) | |
6239 | return -EINVAL; | |
6240 | } | |
04a773ad JB |
6241 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6242 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6243 | ||
6244 | if (info->attrs[NL80211_ATTR_IE]) { | |
6245 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6246 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6247 | } | |
6248 | ||
683b6d3b JB |
6249 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6250 | if (err) | |
6251 | return err; | |
04a773ad | 6252 | |
683b6d3b | 6253 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6254 | return -EINVAL; |
6255 | ||
db9c64cf JB |
6256 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
6257 | return -EINVAL; | |
6258 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
6259 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
c04d6150 | 6260 | return -EINVAL; |
db9c64cf | 6261 | |
04a773ad | 6262 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6263 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6264 | ||
fbd2c8dc TP |
6265 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6266 | u8 *rates = | |
6267 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6268 | int n_rates = | |
6269 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6270 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6271 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6272 | |
34850ab2 JB |
6273 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6274 | &ibss.basic_rates); | |
6275 | if (err) | |
6276 | return err; | |
fbd2c8dc | 6277 | } |
dd5b4cc7 FF |
6278 | |
6279 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
6280 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6281 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6282 | return -EINVAL; | |
fbd2c8dc | 6283 | |
4c476991 | 6284 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6285 | bool no_ht = false; |
6286 | ||
4c476991 | 6287 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6288 | info->attrs[NL80211_ATTR_KEYS], |
6289 | &no_ht); | |
4c476991 JB |
6290 | if (IS_ERR(connkeys)) |
6291 | return PTR_ERR(connkeys); | |
de7044ee | 6292 | |
3d9d1d66 JB |
6293 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6294 | no_ht) { | |
de7044ee SM |
6295 | kfree(connkeys); |
6296 | return -EINVAL; | |
6297 | } | |
4c476991 | 6298 | } |
04a773ad | 6299 | |
267335d6 AQ |
6300 | ibss.control_port = |
6301 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6302 | ||
4c476991 | 6303 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6304 | if (err) |
6305 | kfree(connkeys); | |
04a773ad JB |
6306 | return err; |
6307 | } | |
6308 | ||
6309 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6310 | { | |
4c476991 JB |
6311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6312 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6313 | |
4c476991 JB |
6314 | if (!rdev->ops->leave_ibss) |
6315 | return -EOPNOTSUPP; | |
04a773ad | 6316 | |
4c476991 JB |
6317 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6318 | return -EOPNOTSUPP; | |
04a773ad | 6319 | |
4c476991 | 6320 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6321 | } |
6322 | ||
f4e583c8 AQ |
6323 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6324 | { | |
6325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6326 | struct net_device *dev = info->user_ptr[1]; | |
6327 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6328 | u32 nla_rate; | |
6329 | int err; | |
6330 | ||
6331 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6332 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6333 | return -EOPNOTSUPP; | |
6334 | ||
6335 | if (!rdev->ops->set_mcast_rate) | |
6336 | return -EOPNOTSUPP; | |
6337 | ||
6338 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6339 | ||
6340 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6341 | return -EINVAL; | |
6342 | ||
6343 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6344 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6345 | return -EINVAL; | |
6346 | ||
6347 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6348 | ||
6349 | return err; | |
6350 | } | |
6351 | ||
6352 | ||
aff89a9b JB |
6353 | #ifdef CONFIG_NL80211_TESTMODE |
6354 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6355 | .name = "testmode", | |
6356 | }; | |
6357 | ||
6358 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6359 | { | |
4c476991 | 6360 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6361 | int err; |
6362 | ||
6363 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6364 | return -EINVAL; | |
6365 | ||
aff89a9b JB |
6366 | err = -EOPNOTSUPP; |
6367 | if (rdev->ops->testmode_cmd) { | |
6368 | rdev->testmode_info = info; | |
e35e4d28 | 6369 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6370 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6371 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6372 | rdev->testmode_info = NULL; | |
6373 | } | |
6374 | ||
aff89a9b JB |
6375 | return err; |
6376 | } | |
6377 | ||
71063f0e WYG |
6378 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6379 | struct netlink_callback *cb) | |
6380 | { | |
00918d33 | 6381 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6382 | int err; |
6383 | long phy_idx; | |
6384 | void *data = NULL; | |
6385 | int data_len = 0; | |
6386 | ||
5fe231e8 JB |
6387 | rtnl_lock(); |
6388 | ||
71063f0e WYG |
6389 | if (cb->args[0]) { |
6390 | /* | |
6391 | * 0 is a valid index, but not valid for args[0], | |
6392 | * so we need to offset by 1. | |
6393 | */ | |
6394 | phy_idx = cb->args[0] - 1; | |
6395 | } else { | |
6396 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6397 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6398 | nl80211_policy); | |
6399 | if (err) | |
5fe231e8 | 6400 | goto out_err; |
00918d33 | 6401 | |
2bd7e35d JB |
6402 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6403 | nl80211_fam.attrbuf); | |
6404 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6405 | err = PTR_ERR(rdev); |
6406 | goto out_err; | |
00918d33 | 6407 | } |
2bd7e35d JB |
6408 | phy_idx = rdev->wiphy_idx; |
6409 | rdev = NULL; | |
2bd7e35d | 6410 | |
71063f0e WYG |
6411 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6412 | cb->args[1] = | |
6413 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6414 | } | |
6415 | ||
6416 | if (cb->args[1]) { | |
6417 | data = nla_data((void *)cb->args[1]); | |
6418 | data_len = nla_len((void *)cb->args[1]); | |
6419 | } | |
6420 | ||
00918d33 JB |
6421 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6422 | if (!rdev) { | |
5fe231e8 JB |
6423 | err = -ENOENT; |
6424 | goto out_err; | |
71063f0e | 6425 | } |
71063f0e | 6426 | |
00918d33 | 6427 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6428 | err = -EOPNOTSUPP; |
6429 | goto out_err; | |
6430 | } | |
6431 | ||
6432 | while (1) { | |
15e47304 | 6433 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6434 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6435 | NL80211_CMD_TESTMODE); | |
6436 | struct nlattr *tmdata; | |
6437 | ||
9360ffd1 | 6438 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6439 | genlmsg_cancel(skb, hdr); |
6440 | break; | |
6441 | } | |
6442 | ||
6443 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6444 | if (!tmdata) { | |
6445 | genlmsg_cancel(skb, hdr); | |
6446 | break; | |
6447 | } | |
e35e4d28 | 6448 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6449 | nla_nest_end(skb, tmdata); |
6450 | ||
6451 | if (err == -ENOBUFS || err == -ENOENT) { | |
6452 | genlmsg_cancel(skb, hdr); | |
6453 | break; | |
6454 | } else if (err) { | |
6455 | genlmsg_cancel(skb, hdr); | |
6456 | goto out_err; | |
6457 | } | |
6458 | ||
6459 | genlmsg_end(skb, hdr); | |
6460 | } | |
6461 | ||
6462 | err = skb->len; | |
6463 | /* see above */ | |
6464 | cb->args[0] = phy_idx + 1; | |
6465 | out_err: | |
5fe231e8 | 6466 | rtnl_unlock(); |
71063f0e WYG |
6467 | return err; |
6468 | } | |
6469 | ||
aff89a9b JB |
6470 | static struct sk_buff * |
6471 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6472 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6473 | { |
6474 | struct sk_buff *skb; | |
6475 | void *hdr; | |
6476 | struct nlattr *data; | |
6477 | ||
6478 | skb = nlmsg_new(approxlen + 100, gfp); | |
6479 | if (!skb) | |
6480 | return NULL; | |
6481 | ||
15e47304 | 6482 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6483 | if (!hdr) { |
6484 | kfree_skb(skb); | |
6485 | return NULL; | |
6486 | } | |
6487 | ||
9360ffd1 DM |
6488 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6489 | goto nla_put_failure; | |
aff89a9b JB |
6490 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6491 | ||
6492 | ((void **)skb->cb)[0] = rdev; | |
6493 | ((void **)skb->cb)[1] = hdr; | |
6494 | ((void **)skb->cb)[2] = data; | |
6495 | ||
6496 | return skb; | |
6497 | ||
6498 | nla_put_failure: | |
6499 | kfree_skb(skb); | |
6500 | return NULL; | |
6501 | } | |
6502 | ||
6503 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6504 | int approxlen) | |
6505 | { | |
6506 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6507 | ||
6508 | if (WARN_ON(!rdev->testmode_info)) | |
6509 | return NULL; | |
6510 | ||
6511 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6512 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6513 | rdev->testmode_info->snd_seq, |
6514 | GFP_KERNEL); | |
6515 | } | |
6516 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6517 | ||
6518 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6519 | { | |
6520 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6521 | void *hdr = ((void **)skb->cb)[1]; | |
6522 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6523 | ||
6524 | if (WARN_ON(!rdev->testmode_info)) { | |
6525 | kfree_skb(skb); | |
6526 | return -EINVAL; | |
6527 | } | |
6528 | ||
6529 | nla_nest_end(skb, data); | |
6530 | genlmsg_end(skb, hdr); | |
6531 | return genlmsg_reply(skb, rdev->testmode_info); | |
6532 | } | |
6533 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6534 | ||
6535 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6536 | int approxlen, gfp_t gfp) | |
6537 | { | |
6538 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6539 | ||
6540 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6541 | } | |
6542 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6543 | ||
6544 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6545 | { | |
6546 | void *hdr = ((void **)skb->cb)[1]; | |
6547 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6548 | ||
6549 | nla_nest_end(skb, data); | |
6550 | genlmsg_end(skb, hdr); | |
6551 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6552 | } | |
6553 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6554 | #endif | |
6555 | ||
b23aa676 SO |
6556 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6557 | { | |
4c476991 JB |
6558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6559 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6560 | struct cfg80211_connect_params connect; |
6561 | struct wiphy *wiphy; | |
fffd0934 | 6562 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6563 | int err; |
6564 | ||
6565 | memset(&connect, 0, sizeof(connect)); | |
6566 | ||
6567 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6568 | return -EINVAL; | |
6569 | ||
6570 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6571 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6572 | return -EINVAL; | |
6573 | ||
6574 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6575 | connect.auth_type = | |
6576 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6577 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6578 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6579 | return -EINVAL; |
6580 | } else | |
6581 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6582 | ||
6583 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6584 | ||
c0692b8f | 6585 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6586 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6587 | if (err) |
6588 | return err; | |
b23aa676 | 6589 | |
074ac8df | 6590 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6591 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6592 | return -EOPNOTSUPP; | |
b23aa676 | 6593 | |
79c97e97 | 6594 | wiphy = &rdev->wiphy; |
b23aa676 | 6595 | |
4486ea98 BS |
6596 | connect.bg_scan_period = -1; |
6597 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6598 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6599 | connect.bg_scan_period = | |
6600 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6601 | } | |
6602 | ||
b23aa676 SO |
6603 | if (info->attrs[NL80211_ATTR_MAC]) |
6604 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6605 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6606 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6607 | ||
6608 | if (info->attrs[NL80211_ATTR_IE]) { | |
6609 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6610 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6611 | } | |
6612 | ||
cee00a95 JM |
6613 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6614 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6615 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6616 | connect.mfp != NL80211_MFP_NO) | |
6617 | return -EINVAL; | |
6618 | } else { | |
6619 | connect.mfp = NL80211_MFP_NO; | |
6620 | } | |
6621 | ||
b23aa676 SO |
6622 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6623 | connect.channel = | |
6624 | ieee80211_get_channel(wiphy, | |
6625 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6626 | if (!connect.channel || | |
4c476991 JB |
6627 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6628 | return -EINVAL; | |
b23aa676 SO |
6629 | } |
6630 | ||
fffd0934 JB |
6631 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6632 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6633 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6634 | if (IS_ERR(connkeys)) |
6635 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6636 | } |
6637 | ||
7e7c8926 BG |
6638 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6639 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6640 | ||
6641 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6642 | memcpy(&connect.ht_capa_mask, | |
6643 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6644 | sizeof(connect.ht_capa_mask)); | |
6645 | ||
6646 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6647 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6648 | kfree(connkeys); | |
7e7c8926 | 6649 | return -EINVAL; |
b4e4f47e | 6650 | } |
7e7c8926 BG |
6651 | memcpy(&connect.ht_capa, |
6652 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6653 | sizeof(connect.ht_capa)); | |
6654 | } | |
6655 | ||
ee2aca34 JB |
6656 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6657 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6658 | ||
6659 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6660 | memcpy(&connect.vht_capa_mask, | |
6661 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6662 | sizeof(connect.vht_capa_mask)); | |
6663 | ||
6664 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6665 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6666 | kfree(connkeys); | |
6667 | return -EINVAL; | |
6668 | } | |
6669 | memcpy(&connect.vht_capa, | |
6670 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6671 | sizeof(connect.vht_capa)); | |
6672 | } | |
6673 | ||
fffd0934 | 6674 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
6675 | if (err) |
6676 | kfree(connkeys); | |
b23aa676 SO |
6677 | return err; |
6678 | } | |
6679 | ||
6680 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6681 | { | |
4c476991 JB |
6682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6683 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6684 | u16 reason; |
6685 | ||
6686 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6687 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6688 | else | |
6689 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6690 | ||
6691 | if (reason == 0) | |
6692 | return -EINVAL; | |
6693 | ||
074ac8df | 6694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6696 | return -EOPNOTSUPP; | |
b23aa676 | 6697 | |
4c476991 | 6698 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
6699 | } |
6700 | ||
463d0183 JB |
6701 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6702 | { | |
4c476991 | 6703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6704 | struct net *net; |
6705 | int err; | |
6706 | u32 pid; | |
6707 | ||
6708 | if (!info->attrs[NL80211_ATTR_PID]) | |
6709 | return -EINVAL; | |
6710 | ||
6711 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6712 | ||
463d0183 | 6713 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6714 | if (IS_ERR(net)) |
6715 | return PTR_ERR(net); | |
463d0183 JB |
6716 | |
6717 | err = 0; | |
6718 | ||
6719 | /* check if anything to do */ | |
4c476991 JB |
6720 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6721 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6722 | |
463d0183 | 6723 | put_net(net); |
463d0183 JB |
6724 | return err; |
6725 | } | |
6726 | ||
67fbb16b SO |
6727 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6728 | { | |
4c476991 | 6729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6730 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6731 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6732 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6733 | struct cfg80211_pmksa pmksa; |
6734 | ||
6735 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6736 | ||
6737 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6738 | return -EINVAL; | |
6739 | ||
6740 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6741 | return -EINVAL; | |
6742 | ||
67fbb16b SO |
6743 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6744 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6745 | ||
074ac8df | 6746 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6747 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6748 | return -EOPNOTSUPP; | |
67fbb16b SO |
6749 | |
6750 | switch (info->genlhdr->cmd) { | |
6751 | case NL80211_CMD_SET_PMKSA: | |
6752 | rdev_ops = rdev->ops->set_pmksa; | |
6753 | break; | |
6754 | case NL80211_CMD_DEL_PMKSA: | |
6755 | rdev_ops = rdev->ops->del_pmksa; | |
6756 | break; | |
6757 | default: | |
6758 | WARN_ON(1); | |
6759 | break; | |
6760 | } | |
6761 | ||
4c476991 JB |
6762 | if (!rdev_ops) |
6763 | return -EOPNOTSUPP; | |
67fbb16b | 6764 | |
4c476991 | 6765 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6766 | } |
6767 | ||
6768 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6769 | { | |
4c476991 JB |
6770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6771 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6772 | |
074ac8df | 6773 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6774 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6775 | return -EOPNOTSUPP; | |
67fbb16b | 6776 | |
4c476991 JB |
6777 | if (!rdev->ops->flush_pmksa) |
6778 | return -EOPNOTSUPP; | |
67fbb16b | 6779 | |
e35e4d28 | 6780 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6781 | } |
6782 | ||
109086ce AN |
6783 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6784 | { | |
6785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6786 | struct net_device *dev = info->user_ptr[1]; | |
6787 | u8 action_code, dialog_token; | |
6788 | u16 status_code; | |
6789 | u8 *peer; | |
6790 | ||
6791 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6792 | !rdev->ops->tdls_mgmt) | |
6793 | return -EOPNOTSUPP; | |
6794 | ||
6795 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6796 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6797 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6798 | !info->attrs[NL80211_ATTR_IE] || | |
6799 | !info->attrs[NL80211_ATTR_MAC]) | |
6800 | return -EINVAL; | |
6801 | ||
6802 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6803 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6804 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6805 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6806 | ||
e35e4d28 HG |
6807 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6808 | dialog_token, status_code, | |
6809 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6810 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6811 | } |
6812 | ||
6813 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6814 | { | |
6815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6816 | struct net_device *dev = info->user_ptr[1]; | |
6817 | enum nl80211_tdls_operation operation; | |
6818 | u8 *peer; | |
6819 | ||
6820 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6821 | !rdev->ops->tdls_oper) | |
6822 | return -EOPNOTSUPP; | |
6823 | ||
6824 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6825 | !info->attrs[NL80211_ATTR_MAC]) | |
6826 | return -EINVAL; | |
6827 | ||
6828 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6829 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6830 | ||
e35e4d28 | 6831 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6832 | } |
6833 | ||
9588bbd5 JM |
6834 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6835 | struct genl_info *info) | |
6836 | { | |
4c476991 | 6837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6838 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6839 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6840 | struct sk_buff *msg; |
6841 | void *hdr; | |
6842 | u64 cookie; | |
683b6d3b | 6843 | u32 duration; |
9588bbd5 JM |
6844 | int err; |
6845 | ||
6846 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6847 | !info->attrs[NL80211_ATTR_DURATION]) | |
6848 | return -EINVAL; | |
6849 | ||
6850 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6851 | ||
ebf348fc JB |
6852 | if (!rdev->ops->remain_on_channel || |
6853 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6854 | return -EOPNOTSUPP; | |
6855 | ||
9588bbd5 | 6856 | /* |
ebf348fc JB |
6857 | * We should be on that channel for at least a minimum amount of |
6858 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6859 | */ |
ebf348fc | 6860 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6861 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6862 | return -EINVAL; |
6863 | ||
683b6d3b JB |
6864 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6865 | if (err) | |
6866 | return err; | |
9588bbd5 JM |
6867 | |
6868 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6869 | if (!msg) |
6870 | return -ENOMEM; | |
9588bbd5 | 6871 | |
15e47304 | 6872 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6873 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6874 | ||
6875 | if (IS_ERR(hdr)) { | |
6876 | err = PTR_ERR(hdr); | |
6877 | goto free_msg; | |
6878 | } | |
6879 | ||
683b6d3b JB |
6880 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6881 | duration, &cookie); | |
9588bbd5 JM |
6882 | |
6883 | if (err) | |
6884 | goto free_msg; | |
6885 | ||
9360ffd1 DM |
6886 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6887 | goto nla_put_failure; | |
9588bbd5 JM |
6888 | |
6889 | genlmsg_end(msg, hdr); | |
4c476991 JB |
6890 | |
6891 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
6892 | |
6893 | nla_put_failure: | |
6894 | err = -ENOBUFS; | |
6895 | free_msg: | |
6896 | nlmsg_free(msg); | |
9588bbd5 JM |
6897 | return err; |
6898 | } | |
6899 | ||
6900 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
6901 | struct genl_info *info) | |
6902 | { | |
4c476991 | 6903 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6904 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 6905 | u64 cookie; |
9588bbd5 JM |
6906 | |
6907 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6908 | return -EINVAL; | |
6909 | ||
4c476991 JB |
6910 | if (!rdev->ops->cancel_remain_on_channel) |
6911 | return -EOPNOTSUPP; | |
9588bbd5 | 6912 | |
9588bbd5 JM |
6913 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
6914 | ||
e35e4d28 | 6915 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
6916 | } |
6917 | ||
13ae75b1 JM |
6918 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
6919 | u8 *rates, u8 rates_len) | |
6920 | { | |
6921 | u8 i; | |
6922 | u32 mask = 0; | |
6923 | ||
6924 | for (i = 0; i < rates_len; i++) { | |
6925 | int rate = (rates[i] & 0x7f) * 5; | |
6926 | int ridx; | |
6927 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
6928 | struct ieee80211_rate *srate = | |
6929 | &sband->bitrates[ridx]; | |
6930 | if (rate == srate->bitrate) { | |
6931 | mask |= 1 << ridx; | |
6932 | break; | |
6933 | } | |
6934 | } | |
6935 | if (ridx == sband->n_bitrates) | |
6936 | return 0; /* rate not found */ | |
6937 | } | |
6938 | ||
6939 | return mask; | |
6940 | } | |
6941 | ||
24db78c0 SW |
6942 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
6943 | u8 *rates, u8 rates_len, | |
6944 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
6945 | { | |
6946 | u8 i; | |
6947 | ||
6948 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
6949 | ||
6950 | for (i = 0; i < rates_len; i++) { | |
6951 | int ridx, rbit; | |
6952 | ||
6953 | ridx = rates[i] / 8; | |
6954 | rbit = BIT(rates[i] % 8); | |
6955 | ||
6956 | /* check validity */ | |
910570b5 | 6957 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
6958 | return false; |
6959 | ||
6960 | /* check availability */ | |
6961 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
6962 | mcs[ridx] |= rbit; | |
6963 | else | |
6964 | return false; | |
6965 | } | |
6966 | ||
6967 | return true; | |
6968 | } | |
6969 | ||
b54452b0 | 6970 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
6971 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
6972 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
6973 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
6974 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
6975 | }; |
6976 | ||
6977 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
6978 | struct genl_info *info) | |
6979 | { | |
6980 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 6981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 6982 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
6983 | int rem, i; |
6984 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
6985 | struct nlattr *tx_rates; |
6986 | struct ieee80211_supported_band *sband; | |
6987 | ||
6988 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
6989 | return -EINVAL; | |
6990 | ||
4c476991 JB |
6991 | if (!rdev->ops->set_bitrate_mask) |
6992 | return -EOPNOTSUPP; | |
13ae75b1 JM |
6993 | |
6994 | memset(&mask, 0, sizeof(mask)); | |
6995 | /* Default to all rates enabled */ | |
6996 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
6997 | sband = rdev->wiphy.bands[i]; | |
6998 | mask.control[i].legacy = | |
6999 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7000 | if (sband) |
7001 | memcpy(mask.control[i].mcs, | |
7002 | sband->ht_cap.mcs.rx_mask, | |
7003 | sizeof(mask.control[i].mcs)); | |
7004 | else | |
7005 | memset(mask.control[i].mcs, 0, | |
7006 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7007 | } |
7008 | ||
7009 | /* | |
7010 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7011 | * directly to the enum ieee80211_band values used in cfg80211. | |
7012 | */ | |
24db78c0 | 7013 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7014 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7015 | { | |
7016 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7017 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7018 | return -EINVAL; | |
13ae75b1 | 7019 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7020 | if (sband == NULL) |
7021 | return -EINVAL; | |
13ae75b1 JM |
7022 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7023 | nla_len(tx_rates), nl80211_txattr_policy); | |
7024 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7025 | mask.control[band].legacy = rateset_to_mask( | |
7026 | sband, | |
7027 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7028 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7029 | if ((mask.control[band].legacy == 0) && |
7030 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7031 | return -EINVAL; | |
24db78c0 SW |
7032 | } |
7033 | if (tb[NL80211_TXRATE_MCS]) { | |
7034 | if (!ht_rateset_to_mask( | |
7035 | sband, | |
7036 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7037 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7038 | mask.control[band].mcs)) | |
7039 | return -EINVAL; | |
7040 | } | |
7041 | ||
7042 | if (mask.control[band].legacy == 0) { | |
7043 | /* don't allow empty legacy rates if HT | |
7044 | * is not even supported. */ | |
7045 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7046 | return -EINVAL; | |
7047 | ||
7048 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7049 | if (mask.control[band].mcs[i]) | |
7050 | break; | |
7051 | ||
7052 | /* legacy and mcs rates may not be both empty */ | |
7053 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7054 | return -EINVAL; |
13ae75b1 JM |
7055 | } |
7056 | } | |
7057 | ||
e35e4d28 | 7058 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7059 | } |
7060 | ||
2e161f78 | 7061 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7062 | { |
4c476991 | 7063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7064 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7065 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7066 | |
7067 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7068 | return -EINVAL; | |
7069 | ||
2e161f78 JB |
7070 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7071 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7072 | |
71bbc994 JB |
7073 | switch (wdev->iftype) { |
7074 | case NL80211_IFTYPE_STATION: | |
7075 | case NL80211_IFTYPE_ADHOC: | |
7076 | case NL80211_IFTYPE_P2P_CLIENT: | |
7077 | case NL80211_IFTYPE_AP: | |
7078 | case NL80211_IFTYPE_AP_VLAN: | |
7079 | case NL80211_IFTYPE_MESH_POINT: | |
7080 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7081 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7082 | break; |
7083 | default: | |
4c476991 | 7084 | return -EOPNOTSUPP; |
71bbc994 | 7085 | } |
026331c4 JM |
7086 | |
7087 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7088 | if (!rdev->ops->mgmt_tx) |
7089 | return -EOPNOTSUPP; | |
026331c4 | 7090 | |
15e47304 | 7091 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7092 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7093 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7094 | } |
7095 | ||
2e161f78 | 7096 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7097 | { |
4c476991 | 7098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7099 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7100 | struct cfg80211_chan_def chandef; |
026331c4 | 7101 | int err; |
d64d373f | 7102 | void *hdr = NULL; |
026331c4 | 7103 | u64 cookie; |
e247bd90 | 7104 | struct sk_buff *msg = NULL; |
f7ca38df | 7105 | unsigned int wait = 0; |
e247bd90 JB |
7106 | bool offchan, no_cck, dont_wait_for_ack; |
7107 | ||
7108 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7109 | |
683b6d3b | 7110 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7111 | return -EINVAL; |
7112 | ||
4c476991 JB |
7113 | if (!rdev->ops->mgmt_tx) |
7114 | return -EOPNOTSUPP; | |
026331c4 | 7115 | |
71bbc994 JB |
7116 | switch (wdev->iftype) { |
7117 | case NL80211_IFTYPE_STATION: | |
7118 | case NL80211_IFTYPE_ADHOC: | |
7119 | case NL80211_IFTYPE_P2P_CLIENT: | |
7120 | case NL80211_IFTYPE_AP: | |
7121 | case NL80211_IFTYPE_AP_VLAN: | |
7122 | case NL80211_IFTYPE_MESH_POINT: | |
7123 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7124 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7125 | break; |
7126 | default: | |
4c476991 | 7127 | return -EOPNOTSUPP; |
71bbc994 | 7128 | } |
026331c4 | 7129 | |
f7ca38df | 7130 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7131 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7132 | return -EINVAL; |
7133 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7134 | |
7135 | /* | |
7136 | * We should wait on the channel for at least a minimum amount | |
7137 | * of time (10ms) but no longer than the driver supports. | |
7138 | */ | |
7139 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7140 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7141 | return -EINVAL; | |
7142 | ||
f7ca38df JB |
7143 | } |
7144 | ||
f7ca38df JB |
7145 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7146 | ||
7c4ef712 JB |
7147 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7148 | return -EINVAL; | |
7149 | ||
e9f935e3 RM |
7150 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7151 | ||
683b6d3b JB |
7152 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7153 | if (err) | |
7154 | return err; | |
026331c4 | 7155 | |
e247bd90 JB |
7156 | if (!dont_wait_for_ack) { |
7157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7158 | if (!msg) | |
7159 | return -ENOMEM; | |
026331c4 | 7160 | |
15e47304 | 7161 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7162 | NL80211_CMD_FRAME); |
026331c4 | 7163 | |
e247bd90 JB |
7164 | if (IS_ERR(hdr)) { |
7165 | err = PTR_ERR(hdr); | |
7166 | goto free_msg; | |
7167 | } | |
026331c4 | 7168 | } |
e247bd90 | 7169 | |
683b6d3b | 7170 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7171 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7172 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7173 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7174 | if (err) |
7175 | goto free_msg; | |
7176 | ||
e247bd90 | 7177 | if (msg) { |
9360ffd1 DM |
7178 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7179 | goto nla_put_failure; | |
026331c4 | 7180 | |
e247bd90 JB |
7181 | genlmsg_end(msg, hdr); |
7182 | return genlmsg_reply(msg, info); | |
7183 | } | |
7184 | ||
7185 | return 0; | |
026331c4 JM |
7186 | |
7187 | nla_put_failure: | |
7188 | err = -ENOBUFS; | |
7189 | free_msg: | |
7190 | nlmsg_free(msg); | |
026331c4 JM |
7191 | return err; |
7192 | } | |
7193 | ||
f7ca38df JB |
7194 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7195 | { | |
7196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7197 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7198 | u64 cookie; |
7199 | ||
7200 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7201 | return -EINVAL; | |
7202 | ||
7203 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7204 | return -EOPNOTSUPP; | |
7205 | ||
71bbc994 JB |
7206 | switch (wdev->iftype) { |
7207 | case NL80211_IFTYPE_STATION: | |
7208 | case NL80211_IFTYPE_ADHOC: | |
7209 | case NL80211_IFTYPE_P2P_CLIENT: | |
7210 | case NL80211_IFTYPE_AP: | |
7211 | case NL80211_IFTYPE_AP_VLAN: | |
7212 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7213 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7214 | break; |
7215 | default: | |
f7ca38df | 7216 | return -EOPNOTSUPP; |
71bbc994 | 7217 | } |
f7ca38df JB |
7218 | |
7219 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7220 | ||
e35e4d28 | 7221 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7222 | } |
7223 | ||
ffb9eb3d KV |
7224 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7225 | { | |
4c476991 | 7226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7227 | struct wireless_dev *wdev; |
4c476991 | 7228 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7229 | u8 ps_state; |
7230 | bool state; | |
7231 | int err; | |
7232 | ||
4c476991 JB |
7233 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7234 | return -EINVAL; | |
ffb9eb3d KV |
7235 | |
7236 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7237 | ||
4c476991 JB |
7238 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7239 | return -EINVAL; | |
ffb9eb3d KV |
7240 | |
7241 | wdev = dev->ieee80211_ptr; | |
7242 | ||
4c476991 JB |
7243 | if (!rdev->ops->set_power_mgmt) |
7244 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7245 | |
7246 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7247 | ||
7248 | if (state == wdev->ps) | |
4c476991 | 7249 | return 0; |
ffb9eb3d | 7250 | |
e35e4d28 | 7251 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7252 | if (!err) |
7253 | wdev->ps = state; | |
ffb9eb3d KV |
7254 | return err; |
7255 | } | |
7256 | ||
7257 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7258 | { | |
4c476991 | 7259 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7260 | enum nl80211_ps_state ps_state; |
7261 | struct wireless_dev *wdev; | |
4c476991 | 7262 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7263 | struct sk_buff *msg; |
7264 | void *hdr; | |
7265 | int err; | |
7266 | ||
ffb9eb3d KV |
7267 | wdev = dev->ieee80211_ptr; |
7268 | ||
4c476991 JB |
7269 | if (!rdev->ops->set_power_mgmt) |
7270 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7271 | |
7272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7273 | if (!msg) |
7274 | return -ENOMEM; | |
ffb9eb3d | 7275 | |
15e47304 | 7276 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7277 | NL80211_CMD_GET_POWER_SAVE); |
7278 | if (!hdr) { | |
4c476991 | 7279 | err = -ENOBUFS; |
ffb9eb3d KV |
7280 | goto free_msg; |
7281 | } | |
7282 | ||
7283 | if (wdev->ps) | |
7284 | ps_state = NL80211_PS_ENABLED; | |
7285 | else | |
7286 | ps_state = NL80211_PS_DISABLED; | |
7287 | ||
9360ffd1 DM |
7288 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7289 | goto nla_put_failure; | |
ffb9eb3d KV |
7290 | |
7291 | genlmsg_end(msg, hdr); | |
4c476991 | 7292 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7293 | |
4c476991 | 7294 | nla_put_failure: |
ffb9eb3d | 7295 | err = -ENOBUFS; |
4c476991 | 7296 | free_msg: |
ffb9eb3d | 7297 | nlmsg_free(msg); |
ffb9eb3d KV |
7298 | return err; |
7299 | } | |
7300 | ||
d6dc1a38 JO |
7301 | static struct nla_policy |
7302 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7303 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7304 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7305 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7306 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7307 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7308 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7309 | }; |
7310 | ||
84f10708 | 7311 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7312 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7313 | { |
7314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7315 | struct wireless_dev *wdev; | |
7316 | struct net_device *dev = info->user_ptr[1]; | |
7317 | ||
d9d8b019 | 7318 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7319 | return -EINVAL; |
7320 | ||
7321 | wdev = dev->ieee80211_ptr; | |
7322 | ||
7323 | if (!rdev->ops->set_cqm_txe_config) | |
7324 | return -EOPNOTSUPP; | |
7325 | ||
7326 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7327 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7328 | return -EOPNOTSUPP; | |
7329 | ||
e35e4d28 | 7330 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7331 | } |
7332 | ||
d6dc1a38 JO |
7333 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7334 | s32 threshold, u32 hysteresis) | |
7335 | { | |
4c476991 | 7336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7337 | struct wireless_dev *wdev; |
4c476991 | 7338 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7339 | |
7340 | if (threshold > 0) | |
7341 | return -EINVAL; | |
7342 | ||
d6dc1a38 JO |
7343 | wdev = dev->ieee80211_ptr; |
7344 | ||
4c476991 JB |
7345 | if (!rdev->ops->set_cqm_rssi_config) |
7346 | return -EOPNOTSUPP; | |
d6dc1a38 | 7347 | |
074ac8df | 7348 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7349 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7350 | return -EOPNOTSUPP; | |
d6dc1a38 | 7351 | |
e35e4d28 | 7352 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7353 | } |
7354 | ||
7355 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7356 | { | |
7357 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7358 | struct nlattr *cqm; | |
7359 | int err; | |
7360 | ||
7361 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7362 | if (!cqm) { | |
7363 | err = -EINVAL; | |
7364 | goto out; | |
7365 | } | |
7366 | ||
7367 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7368 | nl80211_attr_cqm_policy); | |
7369 | if (err) | |
7370 | goto out; | |
7371 | ||
7372 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7373 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7374 | s32 threshold; | |
7375 | u32 hysteresis; | |
7376 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7377 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7378 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7379 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7380 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7381 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7382 | u32 rate, pkts, intvl; | |
7383 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7384 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7385 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7386 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7387 | } else |
7388 | err = -EINVAL; | |
7389 | ||
7390 | out: | |
7391 | return err; | |
7392 | } | |
7393 | ||
29cbe68c JB |
7394 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7395 | { | |
7396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7397 | struct net_device *dev = info->user_ptr[1]; | |
7398 | struct mesh_config cfg; | |
c80d545d | 7399 | struct mesh_setup setup; |
29cbe68c JB |
7400 | int err; |
7401 | ||
7402 | /* start with default */ | |
7403 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7404 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7405 | |
24bdd9f4 | 7406 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7407 | /* and parse parameters if given */ |
24bdd9f4 | 7408 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7409 | if (err) |
7410 | return err; | |
7411 | } | |
7412 | ||
7413 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7414 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7415 | return -EINVAL; | |
7416 | ||
c80d545d JC |
7417 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7418 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7419 | ||
4bb62344 CYY |
7420 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7421 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7422 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7423 | return -EINVAL; | |
7424 | ||
9bdbf04d MP |
7425 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7426 | setup.beacon_interval = | |
7427 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7428 | if (setup.beacon_interval < 10 || | |
7429 | setup.beacon_interval > 10000) | |
7430 | return -EINVAL; | |
7431 | } | |
7432 | ||
7433 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7434 | setup.dtim_period = | |
7435 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7436 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7437 | return -EINVAL; | |
7438 | } | |
7439 | ||
c80d545d JC |
7440 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7441 | /* parse additional setup parameters if given */ | |
7442 | err = nl80211_parse_mesh_setup(info, &setup); | |
7443 | if (err) | |
7444 | return err; | |
7445 | } | |
7446 | ||
d37bb18a TP |
7447 | if (setup.user_mpm) |
7448 | cfg.auto_open_plinks = false; | |
7449 | ||
cc1d2806 | 7450 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7451 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7452 | if (err) | |
7453 | return err; | |
cc1d2806 JB |
7454 | } else { |
7455 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7456 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7457 | } |
7458 | ||
c80d545d | 7459 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7460 | } |
7461 | ||
7462 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7463 | { | |
7464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7465 | struct net_device *dev = info->user_ptr[1]; | |
7466 | ||
7467 | return cfg80211_leave_mesh(rdev, dev); | |
7468 | } | |
7469 | ||
dfb89c56 | 7470 | #ifdef CONFIG_PM |
bb92d199 AK |
7471 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7472 | struct cfg80211_registered_device *rdev) | |
7473 | { | |
7474 | struct nlattr *nl_pats, *nl_pat; | |
7475 | int i, pat_len; | |
7476 | ||
7477 | if (!rdev->wowlan->n_patterns) | |
7478 | return 0; | |
7479 | ||
7480 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7481 | if (!nl_pats) | |
7482 | return -ENOBUFS; | |
7483 | ||
7484 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
7485 | nl_pat = nla_nest_start(msg, i + 1); | |
7486 | if (!nl_pat) | |
7487 | return -ENOBUFS; | |
7488 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
7489 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, | |
7490 | DIV_ROUND_UP(pat_len, 8), | |
7491 | rdev->wowlan->patterns[i].mask) || | |
7492 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
7493 | pat_len, rdev->wowlan->patterns[i].pattern) || | |
7494 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, | |
7495 | rdev->wowlan->patterns[i].pkt_offset)) | |
7496 | return -ENOBUFS; | |
7497 | nla_nest_end(msg, nl_pat); | |
7498 | } | |
7499 | nla_nest_end(msg, nl_pats); | |
7500 | ||
7501 | return 0; | |
7502 | } | |
7503 | ||
2a0e047e JB |
7504 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7505 | struct cfg80211_wowlan_tcp *tcp) | |
7506 | { | |
7507 | struct nlattr *nl_tcp; | |
7508 | ||
7509 | if (!tcp) | |
7510 | return 0; | |
7511 | ||
7512 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7513 | if (!nl_tcp) | |
7514 | return -ENOBUFS; | |
7515 | ||
7516 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7517 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7518 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7519 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7520 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7521 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7522 | tcp->payload_len, tcp->payload) || | |
7523 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7524 | tcp->data_interval) || | |
7525 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7526 | tcp->wake_len, tcp->wake_data) || | |
7527 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7528 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7529 | return -ENOBUFS; | |
7530 | ||
7531 | if (tcp->payload_seq.len && | |
7532 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7533 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7534 | return -ENOBUFS; | |
7535 | ||
7536 | if (tcp->payload_tok.len && | |
7537 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7538 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7539 | &tcp->payload_tok)) | |
7540 | return -ENOBUFS; | |
7541 | ||
e248ad30 JB |
7542 | nla_nest_end(msg, nl_tcp); |
7543 | ||
2a0e047e JB |
7544 | return 0; |
7545 | } | |
7546 | ||
ff1b6e69 JB |
7547 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7548 | { | |
7549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7550 | struct sk_buff *msg; | |
7551 | void *hdr; | |
2a0e047e | 7552 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7553 | |
2a0e047e JB |
7554 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7555 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7556 | return -EOPNOTSUPP; |
7557 | ||
2a0e047e JB |
7558 | if (rdev->wowlan && rdev->wowlan->tcp) { |
7559 | /* adjust size to have room for all the data */ | |
7560 | size += rdev->wowlan->tcp->tokens_size + | |
7561 | rdev->wowlan->tcp->payload_len + | |
7562 | rdev->wowlan->tcp->wake_len + | |
7563 | rdev->wowlan->tcp->wake_len / 8; | |
7564 | } | |
7565 | ||
7566 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7567 | if (!msg) |
7568 | return -ENOMEM; | |
7569 | ||
15e47304 | 7570 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7571 | NL80211_CMD_GET_WOWLAN); |
7572 | if (!hdr) | |
7573 | goto nla_put_failure; | |
7574 | ||
7575 | if (rdev->wowlan) { | |
7576 | struct nlattr *nl_wowlan; | |
7577 | ||
7578 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7579 | if (!nl_wowlan) | |
7580 | goto nla_put_failure; | |
7581 | ||
9360ffd1 DM |
7582 | if ((rdev->wowlan->any && |
7583 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7584 | (rdev->wowlan->disconnect && | |
7585 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7586 | (rdev->wowlan->magic_pkt && | |
7587 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7588 | (rdev->wowlan->gtk_rekey_failure && | |
7589 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7590 | (rdev->wowlan->eap_identity_req && | |
7591 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7592 | (rdev->wowlan->four_way_handshake && | |
7593 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7594 | (rdev->wowlan->rfkill_release && | |
7595 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
7596 | goto nla_put_failure; | |
2a0e047e | 7597 | |
bb92d199 AK |
7598 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7599 | goto nla_put_failure; | |
2a0e047e JB |
7600 | |
7601 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) | |
7602 | goto nla_put_failure; | |
7603 | ||
ff1b6e69 JB |
7604 | nla_nest_end(msg, nl_wowlan); |
7605 | } | |
7606 | ||
7607 | genlmsg_end(msg, hdr); | |
7608 | return genlmsg_reply(msg, info); | |
7609 | ||
7610 | nla_put_failure: | |
7611 | nlmsg_free(msg); | |
7612 | return -ENOBUFS; | |
7613 | } | |
7614 | ||
2a0e047e JB |
7615 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7616 | struct nlattr *attr, | |
7617 | struct cfg80211_wowlan *trig) | |
7618 | { | |
7619 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7620 | struct cfg80211_wowlan_tcp *cfg; | |
7621 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7622 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7623 | u32 size; | |
7624 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7625 | int err, port; | |
7626 | ||
7627 | if (!rdev->wiphy.wowlan.tcp) | |
7628 | return -EINVAL; | |
7629 | ||
7630 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7631 | nla_data(attr), nla_len(attr), | |
7632 | nl80211_wowlan_tcp_policy); | |
7633 | if (err) | |
7634 | return err; | |
7635 | ||
7636 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7637 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7638 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7639 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7640 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7641 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7642 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7643 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7644 | return -EINVAL; | |
7645 | ||
7646 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
7647 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) | |
7648 | return -EINVAL; | |
7649 | ||
7650 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
723d568a JB |
7651 | rdev->wiphy.wowlan.tcp->data_interval_max || |
7652 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) | |
2a0e047e JB |
7653 | return -EINVAL; |
7654 | ||
7655 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
7656 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) | |
7657 | return -EINVAL; | |
7658 | ||
7659 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7660 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7661 | return -EINVAL; | |
7662 | ||
7663 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7664 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7665 | ||
7666 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7667 | tokens_size = tokln - sizeof(*tok); | |
7668 | ||
7669 | if (!tok->len || tokens_size % tok->len) | |
7670 | return -EINVAL; | |
7671 | if (!rdev->wiphy.wowlan.tcp->tok) | |
7672 | return -EINVAL; | |
7673 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) | |
7674 | return -EINVAL; | |
7675 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) | |
7676 | return -EINVAL; | |
7677 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) | |
7678 | return -EINVAL; | |
7679 | if (tok->offset + tok->len > data_size) | |
7680 | return -EINVAL; | |
7681 | } | |
7682 | ||
7683 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7684 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
7685 | if (!rdev->wiphy.wowlan.tcp->seq) | |
7686 | return -EINVAL; | |
7687 | if (seq->len == 0 || seq->len > 4) | |
7688 | return -EINVAL; | |
7689 | if (seq->len + seq->offset > data_size) | |
7690 | return -EINVAL; | |
7691 | } | |
7692 | ||
7693 | size = sizeof(*cfg); | |
7694 | size += data_size; | |
7695 | size += wake_size + wake_mask_size; | |
7696 | size += tokens_size; | |
7697 | ||
7698 | cfg = kzalloc(size, GFP_KERNEL); | |
7699 | if (!cfg) | |
7700 | return -ENOMEM; | |
7701 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7702 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7703 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7704 | ETH_ALEN); | |
7705 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7706 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7707 | else | |
7708 | port = 0; | |
7709 | #ifdef CONFIG_INET | |
7710 | /* allocate a socket and port for it and use it */ | |
7711 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7712 | IPPROTO_TCP, &cfg->sock, 1); | |
7713 | if (err) { | |
7714 | kfree(cfg); | |
7715 | return err; | |
7716 | } | |
7717 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7718 | sock_release(cfg->sock); | |
7719 | kfree(cfg); | |
7720 | return -EADDRINUSE; | |
7721 | } | |
7722 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7723 | #else | |
7724 | if (!port) { | |
7725 | kfree(cfg); | |
7726 | return -EINVAL; | |
7727 | } | |
7728 | cfg->src_port = port; | |
7729 | #endif | |
7730 | ||
7731 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7732 | cfg->payload_len = data_size; | |
7733 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7734 | memcpy((void *)cfg->payload, | |
7735 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7736 | data_size); | |
7737 | if (seq) | |
7738 | cfg->payload_seq = *seq; | |
7739 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7740 | cfg->wake_len = wake_size; | |
7741 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7742 | memcpy((void *)cfg->wake_data, | |
7743 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7744 | wake_size); | |
7745 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7746 | data_size + wake_size; | |
7747 | memcpy((void *)cfg->wake_mask, | |
7748 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7749 | wake_mask_size); | |
7750 | if (tok) { | |
7751 | cfg->tokens_size = tokens_size; | |
7752 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7753 | } | |
7754 | ||
7755 | trig->tcp = cfg; | |
7756 | ||
7757 | return 0; | |
7758 | } | |
7759 | ||
ff1b6e69 JB |
7760 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7761 | { | |
7762 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7763 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7764 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7765 | struct cfg80211_wowlan *ntrig; |
ff1b6e69 JB |
7766 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
7767 | int err, i; | |
6d52563f | 7768 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 | 7769 | |
2a0e047e JB |
7770 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
7771 | !rdev->wiphy.wowlan.tcp) | |
ff1b6e69 JB |
7772 | return -EOPNOTSUPP; |
7773 | ||
ae33bd81 JB |
7774 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7775 | cfg80211_rdev_free_wowlan(rdev); | |
7776 | rdev->wowlan = NULL; | |
7777 | goto set_wakeup; | |
7778 | } | |
ff1b6e69 JB |
7779 | |
7780 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7781 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7782 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7783 | nl80211_wowlan_policy); | |
7784 | if (err) | |
7785 | return err; | |
7786 | ||
7787 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7788 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7789 | return -EINVAL; | |
7790 | new_triggers.any = true; | |
7791 | } | |
7792 | ||
7793 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7794 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7795 | return -EINVAL; | |
7796 | new_triggers.disconnect = true; | |
7797 | } | |
7798 | ||
7799 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7800 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7801 | return -EINVAL; | |
7802 | new_triggers.magic_pkt = true; | |
7803 | } | |
7804 | ||
77dbbb13 JB |
7805 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7806 | return -EINVAL; | |
7807 | ||
7808 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7809 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7810 | return -EINVAL; | |
7811 | new_triggers.gtk_rekey_failure = true; | |
7812 | } | |
7813 | ||
7814 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7815 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7816 | return -EINVAL; | |
7817 | new_triggers.eap_identity_req = true; | |
7818 | } | |
7819 | ||
7820 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7821 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7822 | return -EINVAL; | |
7823 | new_triggers.four_way_handshake = true; | |
7824 | } | |
7825 | ||
7826 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7827 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7828 | return -EINVAL; | |
7829 | new_triggers.rfkill_release = true; | |
7830 | } | |
7831 | ||
ff1b6e69 JB |
7832 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7833 | struct nlattr *pat; | |
7834 | int n_patterns = 0; | |
bb92d199 | 7835 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7836 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7837 | ||
7838 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7839 | rem) | |
7840 | n_patterns++; | |
7841 | if (n_patterns > wowlan->n_patterns) | |
7842 | return -EINVAL; | |
7843 | ||
7844 | new_triggers.patterns = kcalloc(n_patterns, | |
7845 | sizeof(new_triggers.patterns[0]), | |
7846 | GFP_KERNEL); | |
7847 | if (!new_triggers.patterns) | |
7848 | return -ENOMEM; | |
7849 | ||
7850 | new_triggers.n_patterns = n_patterns; | |
7851 | i = 0; | |
7852 | ||
7853 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7854 | rem) { | |
7855 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7856 | nla_data(pat), nla_len(pat), NULL); | |
7857 | err = -EINVAL; | |
7858 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7859 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7860 | goto error; | |
7861 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7862 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7863 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7864 | mask_len) | |
7865 | goto error; | |
7866 | if (pat_len > wowlan->pattern_max_len || | |
7867 | pat_len < wowlan->pattern_min_len) | |
7868 | goto error; | |
7869 | ||
bb92d199 AK |
7870 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7871 | pkt_offset = 0; | |
7872 | else | |
7873 | pkt_offset = nla_get_u32( | |
7874 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7875 | if (pkt_offset > wowlan->max_pkt_offset) | |
7876 | goto error; | |
7877 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7878 | ||
ff1b6e69 JB |
7879 | new_triggers.patterns[i].mask = |
7880 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7881 | if (!new_triggers.patterns[i].mask) { | |
7882 | err = -ENOMEM; | |
7883 | goto error; | |
7884 | } | |
7885 | new_triggers.patterns[i].pattern = | |
7886 | new_triggers.patterns[i].mask + mask_len; | |
7887 | memcpy(new_triggers.patterns[i].mask, | |
7888 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
7889 | mask_len); | |
7890 | new_triggers.patterns[i].pattern_len = pat_len; | |
7891 | memcpy(new_triggers.patterns[i].pattern, | |
7892 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
7893 | pat_len); | |
7894 | i++; | |
7895 | } | |
7896 | } | |
7897 | ||
2a0e047e JB |
7898 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
7899 | err = nl80211_parse_wowlan_tcp( | |
7900 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
7901 | &new_triggers); | |
7902 | if (err) | |
7903 | goto error; | |
7904 | } | |
7905 | ||
ae33bd81 JB |
7906 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
7907 | if (!ntrig) { | |
7908 | err = -ENOMEM; | |
7909 | goto error; | |
ff1b6e69 | 7910 | } |
ae33bd81 JB |
7911 | cfg80211_rdev_free_wowlan(rdev); |
7912 | rdev->wowlan = ntrig; | |
ff1b6e69 | 7913 | |
ae33bd81 | 7914 | set_wakeup: |
6d52563f | 7915 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
e35e4d28 | 7916 | rdev_set_wakeup(rdev, rdev->wowlan); |
6d52563f | 7917 | |
ff1b6e69 JB |
7918 | return 0; |
7919 | error: | |
7920 | for (i = 0; i < new_triggers.n_patterns; i++) | |
7921 | kfree(new_triggers.patterns[i].mask); | |
7922 | kfree(new_triggers.patterns); | |
2a0e047e JB |
7923 | if (new_triggers.tcp && new_triggers.tcp->sock) |
7924 | sock_release(new_triggers.tcp->sock); | |
7925 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
7926 | return err; |
7927 | } | |
dfb89c56 | 7928 | #endif |
ff1b6e69 | 7929 | |
e5497d76 JB |
7930 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
7931 | { | |
7932 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7933 | struct net_device *dev = info->user_ptr[1]; | |
7934 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7935 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
7936 | struct cfg80211_gtk_rekey_data rekey_data; | |
7937 | int err; | |
7938 | ||
7939 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
7940 | return -EINVAL; | |
7941 | ||
7942 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
7943 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7944 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
7945 | nl80211_rekey_policy); | |
7946 | if (err) | |
7947 | return err; | |
7948 | ||
7949 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
7950 | return -ERANGE; | |
7951 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
7952 | return -ERANGE; | |
7953 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
7954 | return -ERANGE; | |
7955 | ||
7956 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
7957 | NL80211_KEK_LEN); | |
7958 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
7959 | NL80211_KCK_LEN); | |
7960 | memcpy(rekey_data.replay_ctr, | |
7961 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
7962 | NL80211_REPLAY_CTR_LEN); | |
7963 | ||
7964 | wdev_lock(wdev); | |
7965 | if (!wdev->current_bss) { | |
7966 | err = -ENOTCONN; | |
7967 | goto out; | |
7968 | } | |
7969 | ||
7970 | if (!rdev->ops->set_rekey_data) { | |
7971 | err = -EOPNOTSUPP; | |
7972 | goto out; | |
7973 | } | |
7974 | ||
e35e4d28 | 7975 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
7976 | out: |
7977 | wdev_unlock(wdev); | |
7978 | return err; | |
7979 | } | |
7980 | ||
28946da7 JB |
7981 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
7982 | struct genl_info *info) | |
7983 | { | |
7984 | struct net_device *dev = info->user_ptr[1]; | |
7985 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7986 | ||
7987 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
7988 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
7989 | return -EINVAL; | |
7990 | ||
15e47304 | 7991 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
7992 | return -EBUSY; |
7993 | ||
15e47304 | 7994 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
7995 | return 0; |
7996 | } | |
7997 | ||
7f6cf311 JB |
7998 | static int nl80211_probe_client(struct sk_buff *skb, |
7999 | struct genl_info *info) | |
8000 | { | |
8001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8002 | struct net_device *dev = info->user_ptr[1]; | |
8003 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8004 | struct sk_buff *msg; | |
8005 | void *hdr; | |
8006 | const u8 *addr; | |
8007 | u64 cookie; | |
8008 | int err; | |
8009 | ||
8010 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8011 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8012 | return -EOPNOTSUPP; | |
8013 | ||
8014 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8015 | return -EINVAL; | |
8016 | ||
8017 | if (!rdev->ops->probe_client) | |
8018 | return -EOPNOTSUPP; | |
8019 | ||
8020 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8021 | if (!msg) | |
8022 | return -ENOMEM; | |
8023 | ||
15e47304 | 8024 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8025 | NL80211_CMD_PROBE_CLIENT); |
8026 | ||
8027 | if (IS_ERR(hdr)) { | |
8028 | err = PTR_ERR(hdr); | |
8029 | goto free_msg; | |
8030 | } | |
8031 | ||
8032 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8033 | ||
e35e4d28 | 8034 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8035 | if (err) |
8036 | goto free_msg; | |
8037 | ||
9360ffd1 DM |
8038 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8039 | goto nla_put_failure; | |
7f6cf311 JB |
8040 | |
8041 | genlmsg_end(msg, hdr); | |
8042 | ||
8043 | return genlmsg_reply(msg, info); | |
8044 | ||
8045 | nla_put_failure: | |
8046 | err = -ENOBUFS; | |
8047 | free_msg: | |
8048 | nlmsg_free(msg); | |
8049 | return err; | |
8050 | } | |
8051 | ||
5e760230 JB |
8052 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8053 | { | |
8054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8055 | struct cfg80211_beacon_registration *reg, *nreg; |
8056 | int rv; | |
5e760230 JB |
8057 | |
8058 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8059 | return -EOPNOTSUPP; | |
8060 | ||
37c73b5f BG |
8061 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8062 | if (!nreg) | |
8063 | return -ENOMEM; | |
8064 | ||
8065 | /* First, check if already registered. */ | |
8066 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8067 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8068 | if (reg->nlportid == info->snd_portid) { | |
8069 | rv = -EALREADY; | |
8070 | goto out_err; | |
8071 | } | |
8072 | } | |
8073 | /* Add it to the list */ | |
8074 | nreg->nlportid = info->snd_portid; | |
8075 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8076 | |
37c73b5f | 8077 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8078 | |
8079 | return 0; | |
37c73b5f BG |
8080 | out_err: |
8081 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8082 | kfree(nreg); | |
8083 | return rv; | |
5e760230 JB |
8084 | } |
8085 | ||
98104fde JB |
8086 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8087 | { | |
8088 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8089 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8090 | int err; | |
8091 | ||
8092 | if (!rdev->ops->start_p2p_device) | |
8093 | return -EOPNOTSUPP; | |
8094 | ||
8095 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8096 | return -EOPNOTSUPP; | |
8097 | ||
8098 | if (wdev->p2p_started) | |
8099 | return 0; | |
8100 | ||
98104fde | 8101 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8102 | if (err) |
8103 | return err; | |
8104 | ||
eeb126e9 | 8105 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8106 | if (err) |
8107 | return err; | |
8108 | ||
8109 | wdev->p2p_started = true; | |
98104fde | 8110 | rdev->opencount++; |
98104fde JB |
8111 | |
8112 | return 0; | |
8113 | } | |
8114 | ||
8115 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8116 | { | |
8117 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8118 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8119 | ||
8120 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8121 | return -EOPNOTSUPP; | |
8122 | ||
8123 | if (!rdev->ops->stop_p2p_device) | |
8124 | return -EOPNOTSUPP; | |
8125 | ||
f9f47529 | 8126 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8127 | |
8128 | return 0; | |
8129 | } | |
8130 | ||
3713b4e3 JB |
8131 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8132 | struct genl_info *info) | |
8133 | { | |
8134 | void *hdr; | |
8135 | struct sk_buff *msg; | |
8136 | ||
8137 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8138 | if (!msg) | |
8139 | return -ENOMEM; | |
8140 | ||
8141 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8142 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8143 | if (!hdr) | |
8144 | goto nla_put_failure; | |
8145 | ||
8146 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8147 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8148 | goto nla_put_failure; | |
8149 | ||
8150 | genlmsg_end(msg, hdr); | |
8151 | return genlmsg_reply(msg, info); | |
8152 | ||
8153 | nla_put_failure: | |
8154 | kfree_skb(msg); | |
8155 | return -ENOBUFS; | |
8156 | } | |
8157 | ||
355199e0 JM |
8158 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8159 | { | |
8160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8161 | struct cfg80211_update_ft_ies_params ft_params; | |
8162 | struct net_device *dev = info->user_ptr[1]; | |
8163 | ||
8164 | if (!rdev->ops->update_ft_ies) | |
8165 | return -EOPNOTSUPP; | |
8166 | ||
8167 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8168 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8169 | return -EINVAL; | |
8170 | ||
8171 | memset(&ft_params, 0, sizeof(ft_params)); | |
8172 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8173 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8174 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8175 | ||
8176 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8177 | } | |
8178 | ||
5de17984 AS |
8179 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8180 | struct genl_info *info) | |
8181 | { | |
8182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8183 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8184 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8185 | u16 duration; | |
8186 | int ret; | |
8187 | ||
8188 | if (!rdev->ops->crit_proto_start) | |
8189 | return -EOPNOTSUPP; | |
8190 | ||
8191 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8192 | return -EINVAL; | |
8193 | ||
8194 | if (rdev->crit_proto_nlportid) | |
8195 | return -EBUSY; | |
8196 | ||
8197 | /* determine protocol if provided */ | |
8198 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8199 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8200 | ||
8201 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8202 | return -EINVAL; | |
8203 | ||
8204 | /* timeout must be provided */ | |
8205 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8206 | return -EINVAL; | |
8207 | ||
8208 | duration = | |
8209 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8210 | ||
8211 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8212 | return -ERANGE; | |
8213 | ||
8214 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8215 | if (!ret) | |
8216 | rdev->crit_proto_nlportid = info->snd_portid; | |
8217 | ||
8218 | return ret; | |
8219 | } | |
8220 | ||
8221 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8222 | struct genl_info *info) | |
8223 | { | |
8224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8225 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8226 | ||
8227 | if (!rdev->ops->crit_proto_stop) | |
8228 | return -EOPNOTSUPP; | |
8229 | ||
8230 | if (rdev->crit_proto_nlportid) { | |
8231 | rdev->crit_proto_nlportid = 0; | |
8232 | rdev_crit_proto_stop(rdev, wdev); | |
8233 | } | |
8234 | return 0; | |
8235 | } | |
8236 | ||
4c476991 JB |
8237 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8238 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8239 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8240 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8241 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8242 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8243 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8244 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8245 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8246 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8247 | |
8248 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8249 | struct genl_info *info) | |
8250 | { | |
8251 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8252 | struct wireless_dev *wdev; |
4c476991 | 8253 | struct net_device *dev; |
4c476991 JB |
8254 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8255 | ||
8256 | if (rtnl) | |
8257 | rtnl_lock(); | |
8258 | ||
8259 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8260 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8261 | if (IS_ERR(rdev)) { |
8262 | if (rtnl) | |
8263 | rtnl_unlock(); | |
8264 | return PTR_ERR(rdev); | |
8265 | } | |
8266 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8267 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8268 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
8269 | ASSERT_RTNL(); |
8270 | ||
89a54e48 JB |
8271 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
8272 | info->attrs); | |
8273 | if (IS_ERR(wdev)) { | |
4c476991 JB |
8274 | if (rtnl) |
8275 | rtnl_unlock(); | |
89a54e48 | 8276 | return PTR_ERR(wdev); |
4c476991 | 8277 | } |
89a54e48 | 8278 | |
89a54e48 JB |
8279 | dev = wdev->netdev; |
8280 | rdev = wiphy_to_dev(wdev->wiphy); | |
8281 | ||
1bf614ef JB |
8282 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8283 | if (!dev) { | |
1bf614ef JB |
8284 | if (rtnl) |
8285 | rtnl_unlock(); | |
8286 | return -EINVAL; | |
8287 | } | |
8288 | ||
8289 | info->user_ptr[1] = dev; | |
8290 | } else { | |
8291 | info->user_ptr[1] = wdev; | |
41265714 | 8292 | } |
1bf614ef JB |
8293 | |
8294 | if (dev) { | |
8295 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8296 | !netif_running(dev)) { | |
1bf614ef JB |
8297 | if (rtnl) |
8298 | rtnl_unlock(); | |
8299 | return -ENETDOWN; | |
8300 | } | |
8301 | ||
8302 | dev_hold(dev); | |
98104fde JB |
8303 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8304 | if (!wdev->p2p_started) { | |
98104fde JB |
8305 | if (rtnl) |
8306 | rtnl_unlock(); | |
8307 | return -ENETDOWN; | |
8308 | } | |
41265714 | 8309 | } |
89a54e48 | 8310 | |
4c476991 | 8311 | info->user_ptr[0] = rdev; |
4c476991 JB |
8312 | } |
8313 | ||
8314 | return 0; | |
8315 | } | |
8316 | ||
8317 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8318 | struct genl_info *info) | |
8319 | { | |
1bf614ef JB |
8320 | if (info->user_ptr[1]) { |
8321 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8322 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8323 | ||
8324 | if (wdev->netdev) | |
8325 | dev_put(wdev->netdev); | |
8326 | } else { | |
8327 | dev_put(info->user_ptr[1]); | |
8328 | } | |
8329 | } | |
4c476991 JB |
8330 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8331 | rtnl_unlock(); | |
8332 | } | |
8333 | ||
55682965 JB |
8334 | static struct genl_ops nl80211_ops[] = { |
8335 | { | |
8336 | .cmd = NL80211_CMD_GET_WIPHY, | |
8337 | .doit = nl80211_get_wiphy, | |
8338 | .dumpit = nl80211_dump_wiphy, | |
8339 | .policy = nl80211_policy, | |
8340 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8341 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8342 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8343 | }, |
8344 | { | |
8345 | .cmd = NL80211_CMD_SET_WIPHY, | |
8346 | .doit = nl80211_set_wiphy, | |
8347 | .policy = nl80211_policy, | |
8348 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8349 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8350 | }, |
8351 | { | |
8352 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8353 | .doit = nl80211_get_interface, | |
8354 | .dumpit = nl80211_dump_interface, | |
8355 | .policy = nl80211_policy, | |
8356 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8357 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
8358 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8359 | }, |
8360 | { | |
8361 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8362 | .doit = nl80211_set_interface, | |
8363 | .policy = nl80211_policy, | |
8364 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8365 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8366 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8367 | }, |
8368 | { | |
8369 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8370 | .doit = nl80211_new_interface, | |
8371 | .policy = nl80211_policy, | |
8372 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8373 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8374 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8375 | }, |
8376 | { | |
8377 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8378 | .doit = nl80211_del_interface, | |
8379 | .policy = nl80211_policy, | |
41ade00f | 8380 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8381 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8382 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8383 | }, |
8384 | { | |
8385 | .cmd = NL80211_CMD_GET_KEY, | |
8386 | .doit = nl80211_get_key, | |
8387 | .policy = nl80211_policy, | |
8388 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8390 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8391 | }, |
8392 | { | |
8393 | .cmd = NL80211_CMD_SET_KEY, | |
8394 | .doit = nl80211_set_key, | |
8395 | .policy = nl80211_policy, | |
8396 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8398 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8399 | }, |
8400 | { | |
8401 | .cmd = NL80211_CMD_NEW_KEY, | |
8402 | .doit = nl80211_new_key, | |
8403 | .policy = nl80211_policy, | |
8404 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8405 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8406 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8407 | }, |
8408 | { | |
8409 | .cmd = NL80211_CMD_DEL_KEY, | |
8410 | .doit = nl80211_del_key, | |
8411 | .policy = nl80211_policy, | |
55682965 | 8412 | .flags = GENL_ADMIN_PERM, |
41265714 | 8413 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8414 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8415 | }, |
ed1b6cc7 JB |
8416 | { |
8417 | .cmd = NL80211_CMD_SET_BEACON, | |
8418 | .policy = nl80211_policy, | |
8419 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8420 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8421 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8422 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8423 | }, |
8424 | { | |
8860020e | 8425 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8426 | .policy = nl80211_policy, |
8427 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8428 | .doit = nl80211_start_ap, |
2b5f8b0b | 8429 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8430 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8431 | }, |
8432 | { | |
8860020e | 8433 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8434 | .policy = nl80211_policy, |
8435 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8436 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8437 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8438 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8439 | }, |
5727ef1b JB |
8440 | { |
8441 | .cmd = NL80211_CMD_GET_STATION, | |
8442 | .doit = nl80211_get_station, | |
2ec600d6 | 8443 | .dumpit = nl80211_dump_station, |
5727ef1b | 8444 | .policy = nl80211_policy, |
4c476991 JB |
8445 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8446 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8447 | }, |
8448 | { | |
8449 | .cmd = NL80211_CMD_SET_STATION, | |
8450 | .doit = nl80211_set_station, | |
8451 | .policy = nl80211_policy, | |
8452 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8454 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8455 | }, |
8456 | { | |
8457 | .cmd = NL80211_CMD_NEW_STATION, | |
8458 | .doit = nl80211_new_station, | |
8459 | .policy = nl80211_policy, | |
8460 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8462 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8463 | }, |
8464 | { | |
8465 | .cmd = NL80211_CMD_DEL_STATION, | |
8466 | .doit = nl80211_del_station, | |
8467 | .policy = nl80211_policy, | |
2ec600d6 | 8468 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8470 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8471 | }, |
8472 | { | |
8473 | .cmd = NL80211_CMD_GET_MPATH, | |
8474 | .doit = nl80211_get_mpath, | |
8475 | .dumpit = nl80211_dump_mpath, | |
8476 | .policy = nl80211_policy, | |
8477 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8479 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8480 | }, |
8481 | { | |
8482 | .cmd = NL80211_CMD_SET_MPATH, | |
8483 | .doit = nl80211_set_mpath, | |
8484 | .policy = nl80211_policy, | |
8485 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8486 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8487 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8488 | }, |
8489 | { | |
8490 | .cmd = NL80211_CMD_NEW_MPATH, | |
8491 | .doit = nl80211_new_mpath, | |
8492 | .policy = nl80211_policy, | |
8493 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8494 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8495 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8496 | }, |
8497 | { | |
8498 | .cmd = NL80211_CMD_DEL_MPATH, | |
8499 | .doit = nl80211_del_mpath, | |
8500 | .policy = nl80211_policy, | |
9f1ba906 | 8501 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8502 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8503 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8504 | }, |
8505 | { | |
8506 | .cmd = NL80211_CMD_SET_BSS, | |
8507 | .doit = nl80211_set_bss, | |
8508 | .policy = nl80211_policy, | |
b2e1b302 | 8509 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8510 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8511 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8512 | }, |
f130347c LR |
8513 | { |
8514 | .cmd = NL80211_CMD_GET_REG, | |
8515 | .doit = nl80211_get_reg, | |
8516 | .policy = nl80211_policy, | |
5fe231e8 | 8517 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
8518 | /* can be retrieved by unprivileged users */ |
8519 | }, | |
b2e1b302 LR |
8520 | { |
8521 | .cmd = NL80211_CMD_SET_REG, | |
8522 | .doit = nl80211_set_reg, | |
8523 | .policy = nl80211_policy, | |
8524 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 8525 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
8526 | }, |
8527 | { | |
8528 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8529 | .doit = nl80211_req_set_reg, | |
8530 | .policy = nl80211_policy, | |
93da9cc1 | 8531 | .flags = GENL_ADMIN_PERM, |
8532 | }, | |
8533 | { | |
24bdd9f4 JC |
8534 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8535 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8536 | .policy = nl80211_policy, |
8537 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8539 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8540 | }, |
8541 | { | |
24bdd9f4 JC |
8542 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8543 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8544 | .policy = nl80211_policy, |
9aed3cc1 | 8545 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8546 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8547 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8548 | }, |
2a519311 JB |
8549 | { |
8550 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8551 | .doit = nl80211_trigger_scan, | |
8552 | .policy = nl80211_policy, | |
8553 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8554 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8555 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8556 | }, |
8557 | { | |
8558 | .cmd = NL80211_CMD_GET_SCAN, | |
8559 | .policy = nl80211_policy, | |
8560 | .dumpit = nl80211_dump_scan, | |
8561 | }, | |
807f8a8c LC |
8562 | { |
8563 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8564 | .doit = nl80211_start_sched_scan, | |
8565 | .policy = nl80211_policy, | |
8566 | .flags = GENL_ADMIN_PERM, | |
8567 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8568 | NL80211_FLAG_NEED_RTNL, | |
8569 | }, | |
8570 | { | |
8571 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8572 | .doit = nl80211_stop_sched_scan, | |
8573 | .policy = nl80211_policy, | |
8574 | .flags = GENL_ADMIN_PERM, | |
8575 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8576 | NL80211_FLAG_NEED_RTNL, | |
8577 | }, | |
636a5d36 JM |
8578 | { |
8579 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8580 | .doit = nl80211_authenticate, | |
8581 | .policy = nl80211_policy, | |
8582 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8583 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8584 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8585 | }, |
8586 | { | |
8587 | .cmd = NL80211_CMD_ASSOCIATE, | |
8588 | .doit = nl80211_associate, | |
8589 | .policy = nl80211_policy, | |
8590 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8592 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8593 | }, |
8594 | { | |
8595 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8596 | .doit = nl80211_deauthenticate, | |
8597 | .policy = nl80211_policy, | |
8598 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8600 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8601 | }, |
8602 | { | |
8603 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8604 | .doit = nl80211_disassociate, | |
8605 | .policy = nl80211_policy, | |
8606 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8607 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8608 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8609 | }, |
04a773ad JB |
8610 | { |
8611 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8612 | .doit = nl80211_join_ibss, | |
8613 | .policy = nl80211_policy, | |
8614 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8615 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8616 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8617 | }, |
8618 | { | |
8619 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8620 | .doit = nl80211_leave_ibss, | |
8621 | .policy = nl80211_policy, | |
8622 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8624 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8625 | }, |
aff89a9b JB |
8626 | #ifdef CONFIG_NL80211_TESTMODE |
8627 | { | |
8628 | .cmd = NL80211_CMD_TESTMODE, | |
8629 | .doit = nl80211_testmode_do, | |
71063f0e | 8630 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8631 | .policy = nl80211_policy, |
8632 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8633 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8634 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8635 | }, |
8636 | #endif | |
b23aa676 SO |
8637 | { |
8638 | .cmd = NL80211_CMD_CONNECT, | |
8639 | .doit = nl80211_connect, | |
8640 | .policy = nl80211_policy, | |
8641 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8643 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8644 | }, |
8645 | { | |
8646 | .cmd = NL80211_CMD_DISCONNECT, | |
8647 | .doit = nl80211_disconnect, | |
8648 | .policy = nl80211_policy, | |
8649 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8650 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8651 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8652 | }, |
463d0183 JB |
8653 | { |
8654 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8655 | .doit = nl80211_wiphy_netns, | |
8656 | .policy = nl80211_policy, | |
8657 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8658 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8659 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8660 | }, |
61fa713c HS |
8661 | { |
8662 | .cmd = NL80211_CMD_GET_SURVEY, | |
8663 | .policy = nl80211_policy, | |
8664 | .dumpit = nl80211_dump_survey, | |
8665 | }, | |
67fbb16b SO |
8666 | { |
8667 | .cmd = NL80211_CMD_SET_PMKSA, | |
8668 | .doit = nl80211_setdel_pmksa, | |
8669 | .policy = nl80211_policy, | |
8670 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8672 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8673 | }, |
8674 | { | |
8675 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8676 | .doit = nl80211_setdel_pmksa, | |
8677 | .policy = nl80211_policy, | |
8678 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8680 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8681 | }, |
8682 | { | |
8683 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8684 | .doit = nl80211_flush_pmksa, | |
8685 | .policy = nl80211_policy, | |
8686 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8687 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8688 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8689 | }, |
9588bbd5 JM |
8690 | { |
8691 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8692 | .doit = nl80211_remain_on_channel, | |
8693 | .policy = nl80211_policy, | |
8694 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8695 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8696 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8697 | }, |
8698 | { | |
8699 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8700 | .doit = nl80211_cancel_remain_on_channel, | |
8701 | .policy = nl80211_policy, | |
8702 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8703 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8704 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8705 | }, |
13ae75b1 JM |
8706 | { |
8707 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8708 | .doit = nl80211_set_tx_bitrate_mask, | |
8709 | .policy = nl80211_policy, | |
8710 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8711 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8712 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8713 | }, |
026331c4 | 8714 | { |
2e161f78 JB |
8715 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8716 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8717 | .policy = nl80211_policy, |
8718 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8719 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8720 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8721 | }, |
8722 | { | |
2e161f78 JB |
8723 | .cmd = NL80211_CMD_FRAME, |
8724 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8725 | .policy = nl80211_policy, |
f7ca38df | 8726 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8727 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8728 | NL80211_FLAG_NEED_RTNL, |
8729 | }, | |
8730 | { | |
8731 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8732 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8733 | .policy = nl80211_policy, | |
026331c4 | 8734 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8735 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8736 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8737 | }, |
ffb9eb3d KV |
8738 | { |
8739 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8740 | .doit = nl80211_set_power_save, | |
8741 | .policy = nl80211_policy, | |
8742 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8743 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8744 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8745 | }, |
8746 | { | |
8747 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8748 | .doit = nl80211_get_power_save, | |
8749 | .policy = nl80211_policy, | |
8750 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8751 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8752 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8753 | }, |
d6dc1a38 JO |
8754 | { |
8755 | .cmd = NL80211_CMD_SET_CQM, | |
8756 | .doit = nl80211_set_cqm, | |
8757 | .policy = nl80211_policy, | |
8758 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8759 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8760 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8761 | }, |
f444de05 JB |
8762 | { |
8763 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8764 | .doit = nl80211_set_channel, | |
8765 | .policy = nl80211_policy, | |
8766 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8767 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8768 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 8769 | }, |
e8347eba BJ |
8770 | { |
8771 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
8772 | .doit = nl80211_set_wds_peer, | |
8773 | .policy = nl80211_policy, | |
8774 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
8775 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8776 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 8777 | }, |
29cbe68c JB |
8778 | { |
8779 | .cmd = NL80211_CMD_JOIN_MESH, | |
8780 | .doit = nl80211_join_mesh, | |
8781 | .policy = nl80211_policy, | |
8782 | .flags = GENL_ADMIN_PERM, | |
8783 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8784 | NL80211_FLAG_NEED_RTNL, | |
8785 | }, | |
8786 | { | |
8787 | .cmd = NL80211_CMD_LEAVE_MESH, | |
8788 | .doit = nl80211_leave_mesh, | |
8789 | .policy = nl80211_policy, | |
8790 | .flags = GENL_ADMIN_PERM, | |
8791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8792 | NL80211_FLAG_NEED_RTNL, | |
8793 | }, | |
dfb89c56 | 8794 | #ifdef CONFIG_PM |
ff1b6e69 JB |
8795 | { |
8796 | .cmd = NL80211_CMD_GET_WOWLAN, | |
8797 | .doit = nl80211_get_wowlan, | |
8798 | .policy = nl80211_policy, | |
8799 | /* can be retrieved by unprivileged users */ | |
8800 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8801 | NL80211_FLAG_NEED_RTNL, | |
8802 | }, | |
8803 | { | |
8804 | .cmd = NL80211_CMD_SET_WOWLAN, | |
8805 | .doit = nl80211_set_wowlan, | |
8806 | .policy = nl80211_policy, | |
8807 | .flags = GENL_ADMIN_PERM, | |
8808 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8809 | NL80211_FLAG_NEED_RTNL, | |
8810 | }, | |
dfb89c56 | 8811 | #endif |
e5497d76 JB |
8812 | { |
8813 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
8814 | .doit = nl80211_set_rekey_data, | |
8815 | .policy = nl80211_policy, | |
8816 | .flags = GENL_ADMIN_PERM, | |
8817 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8818 | NL80211_FLAG_NEED_RTNL, | |
8819 | }, | |
109086ce AN |
8820 | { |
8821 | .cmd = NL80211_CMD_TDLS_MGMT, | |
8822 | .doit = nl80211_tdls_mgmt, | |
8823 | .policy = nl80211_policy, | |
8824 | .flags = GENL_ADMIN_PERM, | |
8825 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8826 | NL80211_FLAG_NEED_RTNL, | |
8827 | }, | |
8828 | { | |
8829 | .cmd = NL80211_CMD_TDLS_OPER, | |
8830 | .doit = nl80211_tdls_oper, | |
8831 | .policy = nl80211_policy, | |
8832 | .flags = GENL_ADMIN_PERM, | |
8833 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8834 | NL80211_FLAG_NEED_RTNL, | |
8835 | }, | |
28946da7 JB |
8836 | { |
8837 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
8838 | .doit = nl80211_register_unexpected_frame, | |
8839 | .policy = nl80211_policy, | |
8840 | .flags = GENL_ADMIN_PERM, | |
8841 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8842 | NL80211_FLAG_NEED_RTNL, | |
8843 | }, | |
7f6cf311 JB |
8844 | { |
8845 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
8846 | .doit = nl80211_probe_client, | |
8847 | .policy = nl80211_policy, | |
8848 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8849 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
8850 | NL80211_FLAG_NEED_RTNL, |
8851 | }, | |
5e760230 JB |
8852 | { |
8853 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
8854 | .doit = nl80211_register_beacons, | |
8855 | .policy = nl80211_policy, | |
8856 | .flags = GENL_ADMIN_PERM, | |
8857 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8858 | NL80211_FLAG_NEED_RTNL, | |
8859 | }, | |
1d9d9213 SW |
8860 | { |
8861 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
8862 | .doit = nl80211_set_noack_map, | |
8863 | .policy = nl80211_policy, | |
8864 | .flags = GENL_ADMIN_PERM, | |
8865 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8866 | NL80211_FLAG_NEED_RTNL, | |
8867 | }, | |
98104fde JB |
8868 | { |
8869 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
8870 | .doit = nl80211_start_p2p_device, | |
8871 | .policy = nl80211_policy, | |
8872 | .flags = GENL_ADMIN_PERM, | |
8873 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
8874 | NL80211_FLAG_NEED_RTNL, | |
8875 | }, | |
8876 | { | |
8877 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
8878 | .doit = nl80211_stop_p2p_device, | |
8879 | .policy = nl80211_policy, | |
8880 | .flags = GENL_ADMIN_PERM, | |
8881 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8882 | NL80211_FLAG_NEED_RTNL, | |
8883 | }, | |
f4e583c8 AQ |
8884 | { |
8885 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
8886 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
8887 | .policy = nl80211_policy, |
8888 | .flags = GENL_ADMIN_PERM, | |
8889 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8890 | NL80211_FLAG_NEED_RTNL, | |
8891 | }, | |
8892 | { | |
8893 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
8894 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
8895 | .policy = nl80211_policy, |
8896 | .flags = GENL_ADMIN_PERM, | |
8897 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8898 | NL80211_FLAG_NEED_RTNL, | |
8899 | }, | |
04f39047 SW |
8900 | { |
8901 | .cmd = NL80211_CMD_RADAR_DETECT, | |
8902 | .doit = nl80211_start_radar_detection, | |
8903 | .policy = nl80211_policy, | |
8904 | .flags = GENL_ADMIN_PERM, | |
8905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8906 | NL80211_FLAG_NEED_RTNL, | |
8907 | }, | |
3713b4e3 JB |
8908 | { |
8909 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
8910 | .doit = nl80211_get_protocol_features, | |
8911 | .policy = nl80211_policy, | |
8912 | }, | |
355199e0 JM |
8913 | { |
8914 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
8915 | .doit = nl80211_update_ft_ies, | |
8916 | .policy = nl80211_policy, | |
8917 | .flags = GENL_ADMIN_PERM, | |
8918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8919 | NL80211_FLAG_NEED_RTNL, | |
8920 | }, | |
5de17984 AS |
8921 | { |
8922 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
8923 | .doit = nl80211_crit_protocol_start, | |
8924 | .policy = nl80211_policy, | |
8925 | .flags = GENL_ADMIN_PERM, | |
8926 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8927 | NL80211_FLAG_NEED_RTNL, | |
8928 | }, | |
8929 | { | |
8930 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
8931 | .doit = nl80211_crit_protocol_stop, | |
8932 | .policy = nl80211_policy, | |
8933 | .flags = GENL_ADMIN_PERM, | |
8934 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8935 | NL80211_FLAG_NEED_RTNL, | |
8936 | } | |
55682965 | 8937 | }; |
9588bbd5 | 8938 | |
6039f6d2 JM |
8939 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
8940 | .name = "mlme", | |
8941 | }; | |
55682965 JB |
8942 | |
8943 | /* multicast groups */ | |
8944 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
8945 | .name = "config", | |
8946 | }; | |
2a519311 JB |
8947 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
8948 | .name = "scan", | |
8949 | }; | |
73d54c9e LR |
8950 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
8951 | .name = "regulatory", | |
8952 | }; | |
55682965 JB |
8953 | |
8954 | /* notification functions */ | |
8955 | ||
8956 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
8957 | { | |
8958 | struct sk_buff *msg; | |
8959 | ||
fd2120ca | 8960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
8961 | if (!msg) |
8962 | return; | |
8963 | ||
3713b4e3 JB |
8964 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
8965 | false, NULL, NULL, NULL) < 0) { | |
55682965 JB |
8966 | nlmsg_free(msg); |
8967 | return; | |
8968 | } | |
8969 | ||
463d0183 JB |
8970 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
8971 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
8972 | } |
8973 | ||
362a415d JB |
8974 | static int nl80211_add_scan_req(struct sk_buff *msg, |
8975 | struct cfg80211_registered_device *rdev) | |
8976 | { | |
8977 | struct cfg80211_scan_request *req = rdev->scan_req; | |
8978 | struct nlattr *nest; | |
8979 | int i; | |
8980 | ||
8981 | if (WARN_ON(!req)) | |
8982 | return 0; | |
8983 | ||
8984 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
8985 | if (!nest) | |
8986 | goto nla_put_failure; | |
9360ffd1 DM |
8987 | for (i = 0; i < req->n_ssids; i++) { |
8988 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
8989 | goto nla_put_failure; | |
8990 | } | |
362a415d JB |
8991 | nla_nest_end(msg, nest); |
8992 | ||
8993 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8994 | if (!nest) | |
8995 | goto nla_put_failure; | |
9360ffd1 DM |
8996 | for (i = 0; i < req->n_channels; i++) { |
8997 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
8998 | goto nla_put_failure; | |
8999 | } | |
362a415d JB |
9000 | nla_nest_end(msg, nest); |
9001 | ||
9360ffd1 DM |
9002 | if (req->ie && |
9003 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9004 | goto nla_put_failure; | |
362a415d | 9005 | |
ed473771 SL |
9006 | if (req->flags) |
9007 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9008 | ||
362a415d JB |
9009 | return 0; |
9010 | nla_put_failure: | |
9011 | return -ENOBUFS; | |
9012 | } | |
9013 | ||
a538e2d5 JB |
9014 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9015 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9016 | struct wireless_dev *wdev, |
15e47304 | 9017 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9018 | u32 cmd) |
2a519311 JB |
9019 | { |
9020 | void *hdr; | |
9021 | ||
15e47304 | 9022 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9023 | if (!hdr) |
9024 | return -1; | |
9025 | ||
9360ffd1 | 9026 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9027 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9028 | wdev->netdev->ifindex)) || | |
9029 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9030 | goto nla_put_failure; |
2a519311 | 9031 | |
362a415d JB |
9032 | /* ignore errors and send incomplete event anyway */ |
9033 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9034 | |
9035 | return genlmsg_end(msg, hdr); | |
9036 | ||
9037 | nla_put_failure: | |
9038 | genlmsg_cancel(msg, hdr); | |
9039 | return -EMSGSIZE; | |
9040 | } | |
9041 | ||
807f8a8c LC |
9042 | static int |
9043 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9044 | struct cfg80211_registered_device *rdev, | |
9045 | struct net_device *netdev, | |
15e47304 | 9046 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9047 | { |
9048 | void *hdr; | |
9049 | ||
15e47304 | 9050 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9051 | if (!hdr) |
9052 | return -1; | |
9053 | ||
9360ffd1 DM |
9054 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9055 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9056 | goto nla_put_failure; | |
807f8a8c LC |
9057 | |
9058 | return genlmsg_end(msg, hdr); | |
9059 | ||
9060 | nla_put_failure: | |
9061 | genlmsg_cancel(msg, hdr); | |
9062 | return -EMSGSIZE; | |
9063 | } | |
9064 | ||
a538e2d5 | 9065 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9066 | struct wireless_dev *wdev) |
a538e2d5 JB |
9067 | { |
9068 | struct sk_buff *msg; | |
9069 | ||
58050fce | 9070 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9071 | if (!msg) |
9072 | return; | |
9073 | ||
fd014284 | 9074 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9075 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9076 | nlmsg_free(msg); | |
9077 | return; | |
9078 | } | |
9079 | ||
463d0183 JB |
9080 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9081 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9082 | } |
9083 | ||
2a519311 | 9084 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9085 | struct wireless_dev *wdev) |
2a519311 JB |
9086 | { |
9087 | struct sk_buff *msg; | |
9088 | ||
fd2120ca | 9089 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9090 | if (!msg) |
9091 | return; | |
9092 | ||
fd014284 | 9093 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9094 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9095 | nlmsg_free(msg); |
9096 | return; | |
9097 | } | |
9098 | ||
463d0183 JB |
9099 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9100 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9101 | } |
9102 | ||
9103 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9104 | struct wireless_dev *wdev) |
2a519311 JB |
9105 | { |
9106 | struct sk_buff *msg; | |
9107 | ||
fd2120ca | 9108 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9109 | if (!msg) |
9110 | return; | |
9111 | ||
fd014284 | 9112 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9113 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9114 | nlmsg_free(msg); |
9115 | return; | |
9116 | } | |
9117 | ||
463d0183 JB |
9118 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9119 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9120 | } |
9121 | ||
807f8a8c LC |
9122 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9123 | struct net_device *netdev) | |
9124 | { | |
9125 | struct sk_buff *msg; | |
9126 | ||
9127 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9128 | if (!msg) | |
9129 | return; | |
9130 | ||
9131 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9132 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9133 | nlmsg_free(msg); | |
9134 | return; | |
9135 | } | |
9136 | ||
9137 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9138 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9139 | } | |
9140 | ||
9141 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9142 | struct net_device *netdev, u32 cmd) | |
9143 | { | |
9144 | struct sk_buff *msg; | |
9145 | ||
58050fce | 9146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9147 | if (!msg) |
9148 | return; | |
9149 | ||
9150 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9151 | nlmsg_free(msg); | |
9152 | return; | |
9153 | } | |
9154 | ||
9155 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9156 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9157 | } | |
9158 | ||
73d54c9e LR |
9159 | /* |
9160 | * This can happen on global regulatory changes or device specific settings | |
9161 | * based on custom world regulatory domains. | |
9162 | */ | |
9163 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9164 | { | |
9165 | struct sk_buff *msg; | |
9166 | void *hdr; | |
9167 | ||
fd2120ca | 9168 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9169 | if (!msg) |
9170 | return; | |
9171 | ||
9172 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9173 | if (!hdr) { | |
9174 | nlmsg_free(msg); | |
9175 | return; | |
9176 | } | |
9177 | ||
9178 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9179 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9180 | goto nla_put_failure; | |
9181 | ||
9182 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9183 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9184 | NL80211_REGDOM_TYPE_WORLD)) | |
9185 | goto nla_put_failure; | |
9186 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9187 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9188 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9189 | goto nla_put_failure; | |
9190 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9191 | request->intersect) { | |
9192 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9193 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9194 | goto nla_put_failure; | |
9195 | } else { | |
9196 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9197 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9198 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9199 | request->alpha2)) | |
9200 | goto nla_put_failure; | |
9201 | } | |
9202 | ||
f4173766 | 9203 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9204 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9205 | goto nla_put_failure; | |
73d54c9e | 9206 | |
3b7b72ee | 9207 | genlmsg_end(msg, hdr); |
73d54c9e | 9208 | |
bc43b28c | 9209 | rcu_read_lock(); |
463d0183 | 9210 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9211 | GFP_ATOMIC); |
9212 | rcu_read_unlock(); | |
73d54c9e LR |
9213 | |
9214 | return; | |
9215 | ||
9216 | nla_put_failure: | |
9217 | genlmsg_cancel(msg, hdr); | |
9218 | nlmsg_free(msg); | |
9219 | } | |
9220 | ||
6039f6d2 JM |
9221 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9222 | struct net_device *netdev, | |
9223 | const u8 *buf, size_t len, | |
e6d6e342 | 9224 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9225 | { |
9226 | struct sk_buff *msg; | |
9227 | void *hdr; | |
9228 | ||
e6d6e342 | 9229 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9230 | if (!msg) |
9231 | return; | |
9232 | ||
9233 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9234 | if (!hdr) { | |
9235 | nlmsg_free(msg); | |
9236 | return; | |
9237 | } | |
9238 | ||
9360ffd1 DM |
9239 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9240 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9241 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9242 | goto nla_put_failure; | |
6039f6d2 | 9243 | |
3b7b72ee | 9244 | genlmsg_end(msg, hdr); |
6039f6d2 | 9245 | |
463d0183 JB |
9246 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9247 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9248 | return; |
9249 | ||
9250 | nla_put_failure: | |
9251 | genlmsg_cancel(msg, hdr); | |
9252 | nlmsg_free(msg); | |
9253 | } | |
9254 | ||
9255 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9256 | struct net_device *netdev, const u8 *buf, |
9257 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9258 | { |
9259 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9260 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9261 | } |
9262 | ||
9263 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9264 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9265 | size_t len, gfp_t gfp) |
6039f6d2 | 9266 | { |
e6d6e342 JB |
9267 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9268 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9269 | } |
9270 | ||
53b46b84 | 9271 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9272 | struct net_device *netdev, const u8 *buf, |
9273 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9274 | { |
9275 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9276 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9277 | } |
9278 | ||
53b46b84 JM |
9279 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9280 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9281 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9282 | { |
9283 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9284 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9285 | } |
9286 | ||
947add36 JB |
9287 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
9288 | size_t len) | |
cf4e594e | 9289 | { |
947add36 JB |
9290 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9291 | struct wiphy *wiphy = wdev->wiphy; | |
9292 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9293 | ||
9294 | trace_cfg80211_send_unprot_deauth(dev); | |
9295 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9296 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); | |
cf4e594e | 9297 | } |
947add36 | 9298 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
cf4e594e | 9299 | |
947add36 JB |
9300 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
9301 | size_t len) | |
cf4e594e | 9302 | { |
947add36 JB |
9303 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9304 | struct wiphy *wiphy = wdev->wiphy; | |
9305 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9306 | ||
9307 | trace_cfg80211_send_unprot_disassoc(dev); | |
9308 | nl80211_send_mlme_event(rdev, dev, buf, len, | |
9309 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); | |
cf4e594e | 9310 | } |
947add36 | 9311 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
cf4e594e | 9312 | |
1b06bb40 LR |
9313 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9314 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9315 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9316 | { |
9317 | struct sk_buff *msg; | |
9318 | void *hdr; | |
9319 | ||
e6d6e342 | 9320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9321 | if (!msg) |
9322 | return; | |
9323 | ||
9324 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9325 | if (!hdr) { | |
9326 | nlmsg_free(msg); | |
9327 | return; | |
9328 | } | |
9329 | ||
9360ffd1 DM |
9330 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9331 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9332 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9333 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9334 | goto nla_put_failure; | |
1965c853 | 9335 | |
3b7b72ee | 9336 | genlmsg_end(msg, hdr); |
1965c853 | 9337 | |
463d0183 JB |
9338 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9339 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9340 | return; |
9341 | ||
9342 | nla_put_failure: | |
9343 | genlmsg_cancel(msg, hdr); | |
9344 | nlmsg_free(msg); | |
9345 | } | |
9346 | ||
9347 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9348 | struct net_device *netdev, const u8 *addr, |
9349 | gfp_t gfp) | |
1965c853 JM |
9350 | { |
9351 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9352 | addr, gfp); |
1965c853 JM |
9353 | } |
9354 | ||
9355 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9356 | struct net_device *netdev, const u8 *addr, |
9357 | gfp_t gfp) | |
1965c853 | 9358 | { |
e6d6e342 JB |
9359 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9360 | addr, gfp); | |
1965c853 JM |
9361 | } |
9362 | ||
b23aa676 SO |
9363 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9364 | struct net_device *netdev, const u8 *bssid, | |
9365 | const u8 *req_ie, size_t req_ie_len, | |
9366 | const u8 *resp_ie, size_t resp_ie_len, | |
9367 | u16 status, gfp_t gfp) | |
9368 | { | |
9369 | struct sk_buff *msg; | |
9370 | void *hdr; | |
9371 | ||
58050fce | 9372 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9373 | if (!msg) |
9374 | return; | |
9375 | ||
9376 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9377 | if (!hdr) { | |
9378 | nlmsg_free(msg); | |
9379 | return; | |
9380 | } | |
9381 | ||
9360ffd1 DM |
9382 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9383 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9384 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9385 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9386 | (req_ie && | |
9387 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9388 | (resp_ie && | |
9389 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9390 | goto nla_put_failure; | |
b23aa676 | 9391 | |
3b7b72ee | 9392 | genlmsg_end(msg, hdr); |
b23aa676 | 9393 | |
463d0183 JB |
9394 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9395 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9396 | return; |
9397 | ||
9398 | nla_put_failure: | |
9399 | genlmsg_cancel(msg, hdr); | |
9400 | nlmsg_free(msg); | |
9401 | ||
9402 | } | |
9403 | ||
9404 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9405 | struct net_device *netdev, const u8 *bssid, | |
9406 | const u8 *req_ie, size_t req_ie_len, | |
9407 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9408 | { | |
9409 | struct sk_buff *msg; | |
9410 | void *hdr; | |
9411 | ||
58050fce | 9412 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9413 | if (!msg) |
9414 | return; | |
9415 | ||
9416 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9417 | if (!hdr) { | |
9418 | nlmsg_free(msg); | |
9419 | return; | |
9420 | } | |
9421 | ||
9360ffd1 DM |
9422 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9423 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9424 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9425 | (req_ie && | |
9426 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9427 | (resp_ie && | |
9428 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9429 | goto nla_put_failure; | |
b23aa676 | 9430 | |
3b7b72ee | 9431 | genlmsg_end(msg, hdr); |
b23aa676 | 9432 | |
463d0183 JB |
9433 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9434 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9435 | return; |
9436 | ||
9437 | nla_put_failure: | |
9438 | genlmsg_cancel(msg, hdr); | |
9439 | nlmsg_free(msg); | |
9440 | ||
9441 | } | |
9442 | ||
9443 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9444 | struct net_device *netdev, u16 reason, | |
667503dd | 9445 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9446 | { |
9447 | struct sk_buff *msg; | |
9448 | void *hdr; | |
9449 | ||
58050fce | 9450 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9451 | if (!msg) |
9452 | return; | |
9453 | ||
9454 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9455 | if (!hdr) { | |
9456 | nlmsg_free(msg); | |
9457 | return; | |
9458 | } | |
9459 | ||
9360ffd1 DM |
9460 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9461 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9462 | (from_ap && reason && | |
9463 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9464 | (from_ap && | |
9465 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9466 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9467 | goto nla_put_failure; | |
b23aa676 | 9468 | |
3b7b72ee | 9469 | genlmsg_end(msg, hdr); |
b23aa676 | 9470 | |
463d0183 JB |
9471 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9472 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9473 | return; |
9474 | ||
9475 | nla_put_failure: | |
9476 | genlmsg_cancel(msg, hdr); | |
9477 | nlmsg_free(msg); | |
9478 | ||
9479 | } | |
9480 | ||
04a773ad JB |
9481 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9482 | struct net_device *netdev, const u8 *bssid, | |
9483 | gfp_t gfp) | |
9484 | { | |
9485 | struct sk_buff *msg; | |
9486 | void *hdr; | |
9487 | ||
fd2120ca | 9488 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9489 | if (!msg) |
9490 | return; | |
9491 | ||
9492 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9493 | if (!hdr) { | |
9494 | nlmsg_free(msg); | |
9495 | return; | |
9496 | } | |
9497 | ||
9360ffd1 DM |
9498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9499 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9500 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9501 | goto nla_put_failure; | |
04a773ad | 9502 | |
3b7b72ee | 9503 | genlmsg_end(msg, hdr); |
04a773ad | 9504 | |
463d0183 JB |
9505 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9506 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9507 | return; |
9508 | ||
9509 | nla_put_failure: | |
9510 | genlmsg_cancel(msg, hdr); | |
9511 | nlmsg_free(msg); | |
9512 | } | |
9513 | ||
947add36 JB |
9514 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9515 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9516 | { |
947add36 JB |
9517 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9518 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9519 | struct sk_buff *msg; |
9520 | void *hdr; | |
9521 | ||
947add36 JB |
9522 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9523 | return; | |
9524 | ||
9525 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9526 | ||
c93b5e71 JC |
9527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9528 | if (!msg) | |
9529 | return; | |
9530 | ||
9531 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9532 | if (!hdr) { | |
9533 | nlmsg_free(msg); | |
9534 | return; | |
9535 | } | |
9536 | ||
9360ffd1 | 9537 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9538 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9539 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9540 | (ie_len && ie && |
9541 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9542 | goto nla_put_failure; | |
c93b5e71 | 9543 | |
3b7b72ee | 9544 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9545 | |
9546 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9547 | nl80211_mlme_mcgrp.id, gfp); | |
9548 | return; | |
9549 | ||
9550 | nla_put_failure: | |
9551 | genlmsg_cancel(msg, hdr); | |
9552 | nlmsg_free(msg); | |
9553 | } | |
947add36 | 9554 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9555 | |
a3b8b056 JM |
9556 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9557 | struct net_device *netdev, const u8 *addr, | |
9558 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9559 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9560 | { |
9561 | struct sk_buff *msg; | |
9562 | void *hdr; | |
9563 | ||
e6d6e342 | 9564 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9565 | if (!msg) |
9566 | return; | |
9567 | ||
9568 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9569 | if (!hdr) { | |
9570 | nlmsg_free(msg); | |
9571 | return; | |
9572 | } | |
9573 | ||
9360ffd1 DM |
9574 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9575 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9576 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9577 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9578 | (key_id != -1 && | |
9579 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9580 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9581 | goto nla_put_failure; | |
a3b8b056 | 9582 | |
3b7b72ee | 9583 | genlmsg_end(msg, hdr); |
a3b8b056 | 9584 | |
463d0183 JB |
9585 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9586 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9587 | return; |
9588 | ||
9589 | nla_put_failure: | |
9590 | genlmsg_cancel(msg, hdr); | |
9591 | nlmsg_free(msg); | |
9592 | } | |
9593 | ||
6bad8766 LR |
9594 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9595 | struct ieee80211_channel *channel_before, | |
9596 | struct ieee80211_channel *channel_after) | |
9597 | { | |
9598 | struct sk_buff *msg; | |
9599 | void *hdr; | |
9600 | struct nlattr *nl_freq; | |
9601 | ||
fd2120ca | 9602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9603 | if (!msg) |
9604 | return; | |
9605 | ||
9606 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9607 | if (!hdr) { | |
9608 | nlmsg_free(msg); | |
9609 | return; | |
9610 | } | |
9611 | ||
9612 | /* | |
9613 | * Since we are applying the beacon hint to a wiphy we know its | |
9614 | * wiphy_idx is valid | |
9615 | */ | |
9360ffd1 DM |
9616 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9617 | goto nla_put_failure; | |
6bad8766 LR |
9618 | |
9619 | /* Before */ | |
9620 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9621 | if (!nl_freq) | |
9622 | goto nla_put_failure; | |
cdc89b97 | 9623 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
9624 | goto nla_put_failure; |
9625 | nla_nest_end(msg, nl_freq); | |
9626 | ||
9627 | /* After */ | |
9628 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9629 | if (!nl_freq) | |
9630 | goto nla_put_failure; | |
cdc89b97 | 9631 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
9632 | goto nla_put_failure; |
9633 | nla_nest_end(msg, nl_freq); | |
9634 | ||
3b7b72ee | 9635 | genlmsg_end(msg, hdr); |
6bad8766 | 9636 | |
463d0183 JB |
9637 | rcu_read_lock(); |
9638 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9639 | GFP_ATOMIC); | |
9640 | rcu_read_unlock(); | |
6bad8766 LR |
9641 | |
9642 | return; | |
9643 | ||
9644 | nla_put_failure: | |
9645 | genlmsg_cancel(msg, hdr); | |
9646 | nlmsg_free(msg); | |
9647 | } | |
9648 | ||
9588bbd5 JM |
9649 | static void nl80211_send_remain_on_chan_event( |
9650 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9651 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9652 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9653 | unsigned int duration, gfp_t gfp) |
9654 | { | |
9655 | struct sk_buff *msg; | |
9656 | void *hdr; | |
9657 | ||
9658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9659 | if (!msg) | |
9660 | return; | |
9661 | ||
9662 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9663 | if (!hdr) { | |
9664 | nlmsg_free(msg); | |
9665 | return; | |
9666 | } | |
9667 | ||
9360ffd1 | 9668 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9669 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9670 | wdev->netdev->ifindex)) || | |
00f53350 | 9671 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9672 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9673 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9674 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9675 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9676 | goto nla_put_failure; | |
9588bbd5 | 9677 | |
9360ffd1 DM |
9678 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9679 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9680 | goto nla_put_failure; | |
9588bbd5 | 9681 | |
3b7b72ee | 9682 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9683 | |
9684 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9685 | nl80211_mlme_mcgrp.id, gfp); | |
9686 | return; | |
9687 | ||
9688 | nla_put_failure: | |
9689 | genlmsg_cancel(msg, hdr); | |
9690 | nlmsg_free(msg); | |
9691 | } | |
9692 | ||
947add36 JB |
9693 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
9694 | struct ieee80211_channel *chan, | |
9695 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 9696 | { |
947add36 JB |
9697 | struct wiphy *wiphy = wdev->wiphy; |
9698 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9699 | ||
9700 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 9701 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 9702 | rdev, wdev, cookie, chan, |
42d97a59 | 9703 | duration, gfp); |
9588bbd5 | 9704 | } |
947add36 | 9705 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 9706 | |
947add36 JB |
9707 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
9708 | struct ieee80211_channel *chan, | |
9709 | gfp_t gfp) | |
9588bbd5 | 9710 | { |
947add36 JB |
9711 | struct wiphy *wiphy = wdev->wiphy; |
9712 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9713 | ||
9714 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 9715 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 9716 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 9717 | } |
947add36 | 9718 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 9719 | |
947add36 JB |
9720 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
9721 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 9722 | { |
947add36 JB |
9723 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9724 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
9725 | struct sk_buff *msg; |
9726 | ||
947add36 JB |
9727 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
9728 | ||
58050fce | 9729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9730 | if (!msg) |
9731 | return; | |
9732 | ||
66266b3a JL |
9733 | if (nl80211_send_station(msg, 0, 0, 0, |
9734 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9735 | nlmsg_free(msg); |
9736 | return; | |
9737 | } | |
9738 | ||
9739 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9740 | nl80211_mlme_mcgrp.id, gfp); | |
9741 | } | |
947add36 | 9742 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 9743 | |
947add36 | 9744 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 9745 | { |
947add36 JB |
9746 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9747 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
9748 | struct sk_buff *msg; |
9749 | void *hdr; | |
9750 | ||
947add36 JB |
9751 | trace_cfg80211_del_sta(dev, mac_addr); |
9752 | ||
58050fce | 9753 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9754 | if (!msg) |
9755 | return; | |
9756 | ||
9757 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
9758 | if (!hdr) { | |
9759 | nlmsg_free(msg); | |
9760 | return; | |
9761 | } | |
9762 | ||
9360ffd1 DM |
9763 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9764 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
9765 | goto nla_put_failure; | |
ec15e68b | 9766 | |
3b7b72ee | 9767 | genlmsg_end(msg, hdr); |
ec15e68b JM |
9768 | |
9769 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9770 | nl80211_mlme_mcgrp.id, gfp); | |
9771 | return; | |
9772 | ||
9773 | nla_put_failure: | |
9774 | genlmsg_cancel(msg, hdr); | |
9775 | nlmsg_free(msg); | |
9776 | } | |
947add36 | 9777 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 9778 | |
947add36 JB |
9779 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
9780 | enum nl80211_connect_failed_reason reason, | |
9781 | gfp_t gfp) | |
ed44a951 | 9782 | { |
947add36 JB |
9783 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9784 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
9785 | struct sk_buff *msg; |
9786 | void *hdr; | |
9787 | ||
9788 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9789 | if (!msg) | |
9790 | return; | |
9791 | ||
9792 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
9793 | if (!hdr) { | |
9794 | nlmsg_free(msg); | |
9795 | return; | |
9796 | } | |
9797 | ||
9798 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9799 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
9800 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
9801 | goto nla_put_failure; | |
9802 | ||
9803 | genlmsg_end(msg, hdr); | |
9804 | ||
9805 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9806 | nl80211_mlme_mcgrp.id, gfp); | |
9807 | return; | |
9808 | ||
9809 | nla_put_failure: | |
9810 | genlmsg_cancel(msg, hdr); | |
9811 | nlmsg_free(msg); | |
9812 | } | |
947add36 | 9813 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 9814 | |
b92ab5d8 JB |
9815 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
9816 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
9817 | { |
9818 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9819 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9820 | struct sk_buff *msg; | |
9821 | void *hdr; | |
9822 | int err; | |
15e47304 | 9823 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 9824 | |
15e47304 | 9825 | if (!nlportid) |
28946da7 JB |
9826 | return false; |
9827 | ||
9828 | msg = nlmsg_new(100, gfp); | |
9829 | if (!msg) | |
9830 | return true; | |
9831 | ||
b92ab5d8 | 9832 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
9833 | if (!hdr) { |
9834 | nlmsg_free(msg); | |
9835 | return true; | |
9836 | } | |
9837 | ||
9360ffd1 DM |
9838 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9839 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9840 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9841 | goto nla_put_failure; | |
28946da7 JB |
9842 | |
9843 | err = genlmsg_end(msg, hdr); | |
9844 | if (err < 0) { | |
9845 | nlmsg_free(msg); | |
9846 | return true; | |
9847 | } | |
9848 | ||
15e47304 | 9849 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
9850 | return true; |
9851 | ||
9852 | nla_put_failure: | |
9853 | genlmsg_cancel(msg, hdr); | |
9854 | nlmsg_free(msg); | |
9855 | return true; | |
9856 | } | |
9857 | ||
947add36 JB |
9858 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
9859 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9860 | { |
947add36 JB |
9861 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9862 | bool ret; | |
9863 | ||
9864 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
9865 | ||
9866 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9867 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
9868 | trace_cfg80211_return_bool(false); | |
9869 | return false; | |
9870 | } | |
9871 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
9872 | addr, gfp); | |
9873 | trace_cfg80211_return_bool(ret); | |
9874 | return ret; | |
b92ab5d8 | 9875 | } |
947add36 | 9876 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 9877 | |
947add36 JB |
9878 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
9879 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9880 | { |
947add36 JB |
9881 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9882 | bool ret; | |
9883 | ||
9884 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
9885 | ||
9886 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9887 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
9888 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
9889 | trace_cfg80211_return_bool(false); | |
9890 | return false; | |
9891 | } | |
9892 | ret = __nl80211_unexpected_frame(dev, | |
9893 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
9894 | addr, gfp); | |
9895 | trace_cfg80211_return_bool(ret); | |
9896 | return ret; | |
b92ab5d8 | 9897 | } |
947add36 | 9898 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 9899 | |
2e161f78 | 9900 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 9901 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
9902 | int freq, int sig_dbm, |
9903 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 9904 | { |
71bbc994 | 9905 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9906 | struct sk_buff *msg; |
9907 | void *hdr; | |
026331c4 JM |
9908 | |
9909 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9910 | if (!msg) | |
9911 | return -ENOMEM; | |
9912 | ||
2e161f78 | 9913 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
9914 | if (!hdr) { |
9915 | nlmsg_free(msg); | |
9916 | return -ENOMEM; | |
9917 | } | |
9918 | ||
9360ffd1 | 9919 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9920 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9921 | netdev->ifindex)) || | |
a838490b | 9922 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
9923 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
9924 | (sig_dbm && | |
9925 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9926 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9927 | goto nla_put_failure; | |
026331c4 | 9928 | |
3b7b72ee | 9929 | genlmsg_end(msg, hdr); |
026331c4 | 9930 | |
15e47304 | 9931 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
9932 | |
9933 | nla_put_failure: | |
9934 | genlmsg_cancel(msg, hdr); | |
9935 | nlmsg_free(msg); | |
9936 | return -ENOBUFS; | |
9937 | } | |
9938 | ||
947add36 JB |
9939 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
9940 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 9941 | { |
947add36 JB |
9942 | struct wiphy *wiphy = wdev->wiphy; |
9943 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 9944 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9945 | struct sk_buff *msg; |
9946 | void *hdr; | |
9947 | ||
947add36 JB |
9948 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
9949 | ||
026331c4 JM |
9950 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9951 | if (!msg) | |
9952 | return; | |
9953 | ||
2e161f78 | 9954 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
9955 | if (!hdr) { |
9956 | nlmsg_free(msg); | |
9957 | return; | |
9958 | } | |
9959 | ||
9360ffd1 | 9960 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9961 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9962 | netdev->ifindex)) || | |
a838490b | 9963 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
9964 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
9965 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
9966 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
9967 | goto nla_put_failure; | |
026331c4 | 9968 | |
3b7b72ee | 9969 | genlmsg_end(msg, hdr); |
026331c4 JM |
9970 | |
9971 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
9972 | return; | |
9973 | ||
9974 | nla_put_failure: | |
9975 | genlmsg_cancel(msg, hdr); | |
9976 | nlmsg_free(msg); | |
9977 | } | |
947add36 | 9978 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 9979 | |
947add36 JB |
9980 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
9981 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
9982 | gfp_t gfp) | |
d6dc1a38 | 9983 | { |
947add36 JB |
9984 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9985 | struct wiphy *wiphy = wdev->wiphy; | |
9986 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
9987 | struct sk_buff *msg; |
9988 | struct nlattr *pinfoattr; | |
9989 | void *hdr; | |
9990 | ||
947add36 JB |
9991 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
9992 | ||
58050fce | 9993 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
9994 | if (!msg) |
9995 | return; | |
9996 | ||
9997 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
9998 | if (!hdr) { | |
9999 | nlmsg_free(msg); | |
10000 | return; | |
10001 | } | |
10002 | ||
9360ffd1 | 10003 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10004 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10005 | goto nla_put_failure; |
d6dc1a38 JO |
10006 | |
10007 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10008 | if (!pinfoattr) | |
10009 | goto nla_put_failure; | |
10010 | ||
9360ffd1 DM |
10011 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10012 | rssi_event)) | |
10013 | goto nla_put_failure; | |
d6dc1a38 JO |
10014 | |
10015 | nla_nest_end(msg, pinfoattr); | |
10016 | ||
3b7b72ee | 10017 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10018 | |
10019 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10020 | nl80211_mlme_mcgrp.id, gfp); | |
10021 | return; | |
10022 | ||
10023 | nla_put_failure: | |
10024 | genlmsg_cancel(msg, hdr); | |
10025 | nlmsg_free(msg); | |
10026 | } | |
947add36 | 10027 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10028 | |
947add36 JB |
10029 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10030 | struct net_device *netdev, const u8 *bssid, | |
10031 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10032 | { |
10033 | struct sk_buff *msg; | |
10034 | struct nlattr *rekey_attr; | |
10035 | void *hdr; | |
10036 | ||
58050fce | 10037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10038 | if (!msg) |
10039 | return; | |
10040 | ||
10041 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10042 | if (!hdr) { | |
10043 | nlmsg_free(msg); | |
10044 | return; | |
10045 | } | |
10046 | ||
9360ffd1 DM |
10047 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10048 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10049 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10050 | goto nla_put_failure; | |
e5497d76 JB |
10051 | |
10052 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10053 | if (!rekey_attr) | |
10054 | goto nla_put_failure; | |
10055 | ||
9360ffd1 DM |
10056 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10057 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10058 | goto nla_put_failure; | |
e5497d76 JB |
10059 | |
10060 | nla_nest_end(msg, rekey_attr); | |
10061 | ||
3b7b72ee | 10062 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10063 | |
10064 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10065 | nl80211_mlme_mcgrp.id, gfp); | |
10066 | return; | |
10067 | ||
10068 | nla_put_failure: | |
10069 | genlmsg_cancel(msg, hdr); | |
10070 | nlmsg_free(msg); | |
10071 | } | |
10072 | ||
947add36 JB |
10073 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10074 | const u8 *replay_ctr, gfp_t gfp) | |
10075 | { | |
10076 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10077 | struct wiphy *wiphy = wdev->wiphy; | |
10078 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10079 | ||
10080 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10081 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10082 | } | |
10083 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10084 | ||
10085 | static void | |
10086 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10087 | struct net_device *netdev, int index, | |
10088 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10089 | { |
10090 | struct sk_buff *msg; | |
10091 | struct nlattr *attr; | |
10092 | void *hdr; | |
10093 | ||
58050fce | 10094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10095 | if (!msg) |
10096 | return; | |
10097 | ||
10098 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10099 | if (!hdr) { | |
10100 | nlmsg_free(msg); | |
10101 | return; | |
10102 | } | |
10103 | ||
9360ffd1 DM |
10104 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10105 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10106 | goto nla_put_failure; | |
c9df56b4 JM |
10107 | |
10108 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10109 | if (!attr) | |
10110 | goto nla_put_failure; | |
10111 | ||
9360ffd1 DM |
10112 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10113 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10114 | (preauth && | |
10115 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10116 | goto nla_put_failure; | |
c9df56b4 JM |
10117 | |
10118 | nla_nest_end(msg, attr); | |
10119 | ||
3b7b72ee | 10120 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10121 | |
10122 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10123 | nl80211_mlme_mcgrp.id, gfp); | |
10124 | return; | |
10125 | ||
10126 | nla_put_failure: | |
10127 | genlmsg_cancel(msg, hdr); | |
10128 | nlmsg_free(msg); | |
10129 | } | |
10130 | ||
947add36 JB |
10131 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10132 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10133 | { | |
10134 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10135 | struct wiphy *wiphy = wdev->wiphy; | |
10136 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10137 | ||
10138 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10139 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10140 | } | |
10141 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10142 | ||
10143 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10144 | struct net_device *netdev, | |
10145 | struct cfg80211_chan_def *chandef, | |
10146 | gfp_t gfp) | |
5314526b TP |
10147 | { |
10148 | struct sk_buff *msg; | |
10149 | void *hdr; | |
10150 | ||
58050fce | 10151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10152 | if (!msg) |
10153 | return; | |
10154 | ||
10155 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10156 | if (!hdr) { | |
10157 | nlmsg_free(msg); | |
10158 | return; | |
10159 | } | |
10160 | ||
683b6d3b JB |
10161 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10162 | goto nla_put_failure; | |
10163 | ||
10164 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10165 | goto nla_put_failure; |
5314526b TP |
10166 | |
10167 | genlmsg_end(msg, hdr); | |
10168 | ||
10169 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10170 | nl80211_mlme_mcgrp.id, gfp); | |
10171 | return; | |
10172 | ||
10173 | nla_put_failure: | |
10174 | genlmsg_cancel(msg, hdr); | |
10175 | nlmsg_free(msg); | |
10176 | } | |
10177 | ||
947add36 JB |
10178 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10179 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10180 | { |
947add36 JB |
10181 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10182 | struct wiphy *wiphy = wdev->wiphy; | |
10183 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10184 | ||
10185 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10186 | ||
10187 | wdev_lock(wdev); | |
10188 | ||
10189 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10190 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10191 | goto out; | |
10192 | ||
10193 | wdev->channel = chandef->chan; | |
10194 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10195 | out: | |
10196 | wdev_unlock(wdev); | |
10197 | return; | |
10198 | } | |
10199 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10200 | ||
10201 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10202 | const u8 *peer, u32 num_packets, | |
10203 | u32 rate, u32 intvl, gfp_t gfp) | |
10204 | { | |
10205 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10206 | struct wiphy *wiphy = wdev->wiphy; | |
10207 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10208 | struct sk_buff *msg; |
10209 | struct nlattr *pinfoattr; | |
10210 | void *hdr; | |
10211 | ||
10212 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10213 | if (!msg) | |
10214 | return; | |
10215 | ||
10216 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10217 | if (!hdr) { | |
10218 | nlmsg_free(msg); | |
10219 | return; | |
10220 | } | |
10221 | ||
10222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10223 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10224 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10225 | goto nla_put_failure; | |
10226 | ||
10227 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10228 | if (!pinfoattr) | |
10229 | goto nla_put_failure; | |
10230 | ||
10231 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10232 | goto nla_put_failure; | |
10233 | ||
10234 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10235 | goto nla_put_failure; | |
10236 | ||
10237 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10238 | goto nla_put_failure; | |
10239 | ||
10240 | nla_nest_end(msg, pinfoattr); | |
10241 | ||
10242 | genlmsg_end(msg, hdr); | |
10243 | ||
10244 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10245 | nl80211_mlme_mcgrp.id, gfp); | |
10246 | return; | |
10247 | ||
10248 | nla_put_failure: | |
10249 | genlmsg_cancel(msg, hdr); | |
10250 | nlmsg_free(msg); | |
10251 | } | |
947add36 | 10252 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10253 | |
04f39047 SW |
10254 | void |
10255 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10256 | struct cfg80211_chan_def *chandef, | |
10257 | enum nl80211_radar_event event, | |
10258 | struct net_device *netdev, gfp_t gfp) | |
10259 | { | |
10260 | struct sk_buff *msg; | |
10261 | void *hdr; | |
10262 | ||
10263 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10264 | if (!msg) | |
10265 | return; | |
10266 | ||
10267 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10268 | if (!hdr) { | |
10269 | nlmsg_free(msg); | |
10270 | return; | |
10271 | } | |
10272 | ||
10273 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10274 | goto nla_put_failure; | |
10275 | ||
10276 | /* NOP and radar events don't need a netdev parameter */ | |
10277 | if (netdev) { | |
10278 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10279 | ||
10280 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10281 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10282 | goto nla_put_failure; | |
10283 | } | |
10284 | ||
10285 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10286 | goto nla_put_failure; | |
10287 | ||
10288 | if (nl80211_send_chandef(msg, chandef)) | |
10289 | goto nla_put_failure; | |
10290 | ||
10291 | if (genlmsg_end(msg, hdr) < 0) { | |
10292 | nlmsg_free(msg); | |
10293 | return; | |
10294 | } | |
10295 | ||
10296 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10297 | nl80211_mlme_mcgrp.id, gfp); | |
10298 | return; | |
10299 | ||
10300 | nla_put_failure: | |
10301 | genlmsg_cancel(msg, hdr); | |
10302 | nlmsg_free(msg); | |
10303 | } | |
10304 | ||
947add36 JB |
10305 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10306 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10307 | { |
947add36 JB |
10308 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10309 | struct wiphy *wiphy = wdev->wiphy; | |
10310 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10311 | struct sk_buff *msg; |
10312 | struct nlattr *pinfoattr; | |
10313 | void *hdr; | |
10314 | ||
947add36 JB |
10315 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10316 | ||
58050fce | 10317 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10318 | if (!msg) |
10319 | return; | |
10320 | ||
10321 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10322 | if (!hdr) { | |
10323 | nlmsg_free(msg); | |
10324 | return; | |
10325 | } | |
10326 | ||
9360ffd1 | 10327 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10328 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10329 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10330 | goto nla_put_failure; | |
c063dbf5 JB |
10331 | |
10332 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10333 | if (!pinfoattr) | |
10334 | goto nla_put_failure; | |
10335 | ||
9360ffd1 DM |
10336 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10337 | goto nla_put_failure; | |
c063dbf5 JB |
10338 | |
10339 | nla_nest_end(msg, pinfoattr); | |
10340 | ||
3b7b72ee | 10341 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10342 | |
10343 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10344 | nl80211_mlme_mcgrp.id, gfp); | |
10345 | return; | |
10346 | ||
10347 | nla_put_failure: | |
10348 | genlmsg_cancel(msg, hdr); | |
10349 | nlmsg_free(msg); | |
10350 | } | |
947add36 | 10351 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10352 | |
7f6cf311 JB |
10353 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10354 | u64 cookie, bool acked, gfp_t gfp) | |
10355 | { | |
10356 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10357 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10358 | struct sk_buff *msg; | |
10359 | void *hdr; | |
10360 | int err; | |
10361 | ||
4ee3e063 BL |
10362 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10363 | ||
58050fce | 10364 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10365 | |
7f6cf311 JB |
10366 | if (!msg) |
10367 | return; | |
10368 | ||
10369 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10370 | if (!hdr) { | |
10371 | nlmsg_free(msg); | |
10372 | return; | |
10373 | } | |
10374 | ||
9360ffd1 DM |
10375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10376 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10377 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10378 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10379 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10380 | goto nla_put_failure; | |
7f6cf311 JB |
10381 | |
10382 | err = genlmsg_end(msg, hdr); | |
10383 | if (err < 0) { | |
10384 | nlmsg_free(msg); | |
10385 | return; | |
10386 | } | |
10387 | ||
10388 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10389 | nl80211_mlme_mcgrp.id, gfp); | |
10390 | return; | |
10391 | ||
10392 | nla_put_failure: | |
10393 | genlmsg_cancel(msg, hdr); | |
10394 | nlmsg_free(msg); | |
10395 | } | |
10396 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10397 | ||
5e760230 JB |
10398 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10399 | const u8 *frame, size_t len, | |
37c73b5f | 10400 | int freq, int sig_dbm) |
5e760230 JB |
10401 | { |
10402 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10403 | struct sk_buff *msg; | |
10404 | void *hdr; | |
37c73b5f | 10405 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10406 | |
4ee3e063 BL |
10407 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10408 | ||
37c73b5f BG |
10409 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10410 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10411 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10412 | if (!msg) { | |
10413 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10414 | return; | |
10415 | } | |
5e760230 | 10416 | |
37c73b5f BG |
10417 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10418 | if (!hdr) | |
10419 | goto nla_put_failure; | |
5e760230 | 10420 | |
37c73b5f BG |
10421 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10422 | (freq && | |
10423 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10424 | (sig_dbm && | |
10425 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10426 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10427 | goto nla_put_failure; | |
5e760230 | 10428 | |
37c73b5f | 10429 | genlmsg_end(msg, hdr); |
5e760230 | 10430 | |
37c73b5f BG |
10431 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10432 | } | |
10433 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10434 | return; |
10435 | ||
10436 | nla_put_failure: | |
37c73b5f BG |
10437 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10438 | if (hdr) | |
10439 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10440 | nlmsg_free(msg); |
10441 | } | |
10442 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10443 | ||
cd8f7cb4 JB |
10444 | #ifdef CONFIG_PM |
10445 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10446 | struct cfg80211_wowlan_wakeup *wakeup, | |
10447 | gfp_t gfp) | |
10448 | { | |
10449 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10450 | struct sk_buff *msg; | |
10451 | void *hdr; | |
10452 | int err, size = 200; | |
10453 | ||
10454 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10455 | ||
10456 | if (wakeup) | |
10457 | size += wakeup->packet_present_len; | |
10458 | ||
10459 | msg = nlmsg_new(size, gfp); | |
10460 | if (!msg) | |
10461 | return; | |
10462 | ||
10463 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10464 | if (!hdr) | |
10465 | goto free_msg; | |
10466 | ||
10467 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10468 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10469 | goto free_msg; | |
10470 | ||
10471 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10472 | wdev->netdev->ifindex)) | |
10473 | goto free_msg; | |
10474 | ||
10475 | if (wakeup) { | |
10476 | struct nlattr *reasons; | |
10477 | ||
10478 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10479 | ||
10480 | if (wakeup->disconnect && | |
10481 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10482 | goto free_msg; | |
10483 | if (wakeup->magic_pkt && | |
10484 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10485 | goto free_msg; | |
10486 | if (wakeup->gtk_rekey_failure && | |
10487 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10488 | goto free_msg; | |
10489 | if (wakeup->eap_identity_req && | |
10490 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10491 | goto free_msg; | |
10492 | if (wakeup->four_way_handshake && | |
10493 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10494 | goto free_msg; | |
10495 | if (wakeup->rfkill_release && | |
10496 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10497 | goto free_msg; | |
10498 | ||
10499 | if (wakeup->pattern_idx >= 0 && | |
10500 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10501 | wakeup->pattern_idx)) | |
10502 | goto free_msg; | |
10503 | ||
2a0e047e JB |
10504 | if (wakeup->tcp_match) |
10505 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10506 | ||
10507 | if (wakeup->tcp_connlost) | |
10508 | nla_put_flag(msg, | |
10509 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10510 | ||
10511 | if (wakeup->tcp_nomoretokens) | |
10512 | nla_put_flag(msg, | |
10513 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10514 | ||
cd8f7cb4 JB |
10515 | if (wakeup->packet) { |
10516 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10517 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10518 | ||
10519 | if (!wakeup->packet_80211) { | |
10520 | pkt_attr = | |
10521 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10522 | len_attr = | |
10523 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10524 | } | |
10525 | ||
10526 | if (wakeup->packet_len && | |
10527 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10528 | goto free_msg; | |
10529 | ||
10530 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10531 | wakeup->packet)) | |
10532 | goto free_msg; | |
10533 | } | |
10534 | ||
10535 | nla_nest_end(msg, reasons); | |
10536 | } | |
10537 | ||
10538 | err = genlmsg_end(msg, hdr); | |
10539 | if (err < 0) | |
10540 | goto free_msg; | |
10541 | ||
10542 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10543 | nl80211_mlme_mcgrp.id, gfp); | |
10544 | return; | |
10545 | ||
10546 | free_msg: | |
10547 | nlmsg_free(msg); | |
10548 | } | |
10549 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10550 | #endif | |
10551 | ||
3475b094 JM |
10552 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10553 | enum nl80211_tdls_operation oper, | |
10554 | u16 reason_code, gfp_t gfp) | |
10555 | { | |
10556 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10557 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10558 | struct sk_buff *msg; | |
10559 | void *hdr; | |
10560 | int err; | |
10561 | ||
10562 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10563 | reason_code); | |
10564 | ||
10565 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10566 | if (!msg) | |
10567 | return; | |
10568 | ||
10569 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10570 | if (!hdr) { | |
10571 | nlmsg_free(msg); | |
10572 | return; | |
10573 | } | |
10574 | ||
10575 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10576 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10577 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10578 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10579 | (reason_code > 0 && | |
10580 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10581 | goto nla_put_failure; | |
10582 | ||
10583 | err = genlmsg_end(msg, hdr); | |
10584 | if (err < 0) { | |
10585 | nlmsg_free(msg); | |
10586 | return; | |
10587 | } | |
10588 | ||
10589 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10590 | nl80211_mlme_mcgrp.id, gfp); | |
10591 | return; | |
10592 | ||
10593 | nla_put_failure: | |
10594 | genlmsg_cancel(msg, hdr); | |
10595 | nlmsg_free(msg); | |
10596 | } | |
10597 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10598 | ||
026331c4 JM |
10599 | static int nl80211_netlink_notify(struct notifier_block * nb, |
10600 | unsigned long state, | |
10601 | void *_notify) | |
10602 | { | |
10603 | struct netlink_notify *notify = _notify; | |
10604 | struct cfg80211_registered_device *rdev; | |
10605 | struct wireless_dev *wdev; | |
37c73b5f | 10606 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
10607 | |
10608 | if (state != NETLINK_URELEASE) | |
10609 | return NOTIFY_DONE; | |
10610 | ||
10611 | rcu_read_lock(); | |
10612 | ||
5e760230 | 10613 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 10614 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 10615 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
10616 | |
10617 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10618 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
10619 | list) { | |
10620 | if (reg->nlportid == notify->portid) { | |
10621 | list_del(®->list); | |
10622 | kfree(reg); | |
10623 | break; | |
10624 | } | |
10625 | } | |
10626 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 10627 | } |
026331c4 JM |
10628 | |
10629 | rcu_read_unlock(); | |
10630 | ||
10631 | return NOTIFY_DONE; | |
10632 | } | |
10633 | ||
10634 | static struct notifier_block nl80211_netlink_notifier = { | |
10635 | .notifier_call = nl80211_netlink_notify, | |
10636 | }; | |
10637 | ||
355199e0 JM |
10638 | void cfg80211_ft_event(struct net_device *netdev, |
10639 | struct cfg80211_ft_event_params *ft_event) | |
10640 | { | |
10641 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
10642 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10643 | struct sk_buff *msg; | |
10644 | void *hdr; | |
10645 | int err; | |
10646 | ||
10647 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
10648 | ||
10649 | if (!ft_event->target_ap) | |
10650 | return; | |
10651 | ||
10652 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10653 | if (!msg) | |
10654 | return; | |
10655 | ||
10656 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
10657 | if (!hdr) { | |
10658 | nlmsg_free(msg); | |
10659 | return; | |
10660 | } | |
10661 | ||
10662 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
10663 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
10664 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
10665 | if (ft_event->ies) | |
10666 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
10667 | if (ft_event->ric_ies) | |
10668 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
10669 | ft_event->ric_ies); | |
10670 | ||
10671 | err = genlmsg_end(msg, hdr); | |
10672 | if (err < 0) { | |
10673 | nlmsg_free(msg); | |
10674 | return; | |
10675 | } | |
10676 | ||
10677 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10678 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
10679 | } | |
10680 | EXPORT_SYMBOL(cfg80211_ft_event); | |
10681 | ||
5de17984 AS |
10682 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
10683 | { | |
10684 | struct cfg80211_registered_device *rdev; | |
10685 | struct sk_buff *msg; | |
10686 | void *hdr; | |
10687 | u32 nlportid; | |
10688 | ||
10689 | rdev = wiphy_to_dev(wdev->wiphy); | |
10690 | if (!rdev->crit_proto_nlportid) | |
10691 | return; | |
10692 | ||
10693 | nlportid = rdev->crit_proto_nlportid; | |
10694 | rdev->crit_proto_nlportid = 0; | |
10695 | ||
10696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10697 | if (!msg) | |
10698 | return; | |
10699 | ||
10700 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
10701 | if (!hdr) | |
10702 | goto nla_put_failure; | |
10703 | ||
10704 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10705 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10706 | goto nla_put_failure; | |
10707 | ||
10708 | genlmsg_end(msg, hdr); | |
10709 | ||
10710 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
10711 | return; | |
10712 | ||
10713 | nla_put_failure: | |
10714 | if (hdr) | |
10715 | genlmsg_cancel(msg, hdr); | |
10716 | nlmsg_free(msg); | |
10717 | ||
10718 | } | |
10719 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
10720 | ||
55682965 JB |
10721 | /* initialisation/exit functions */ |
10722 | ||
10723 | int nl80211_init(void) | |
10724 | { | |
0d63cbb5 | 10725 | int err; |
55682965 | 10726 | |
0d63cbb5 MM |
10727 | err = genl_register_family_with_ops(&nl80211_fam, |
10728 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10729 | if (err) |
10730 | return err; | |
10731 | ||
55682965 JB |
10732 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10733 | if (err) | |
10734 | goto err_out; | |
10735 | ||
2a519311 JB |
10736 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10737 | if (err) | |
10738 | goto err_out; | |
10739 | ||
73d54c9e LR |
10740 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10741 | if (err) | |
10742 | goto err_out; | |
10743 | ||
6039f6d2 JM |
10744 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10745 | if (err) | |
10746 | goto err_out; | |
10747 | ||
aff89a9b JB |
10748 | #ifdef CONFIG_NL80211_TESTMODE |
10749 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10750 | if (err) | |
10751 | goto err_out; | |
10752 | #endif | |
10753 | ||
026331c4 JM |
10754 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
10755 | if (err) | |
10756 | goto err_out; | |
10757 | ||
55682965 JB |
10758 | return 0; |
10759 | err_out: | |
10760 | genl_unregister_family(&nl80211_fam); | |
10761 | return err; | |
10762 | } | |
10763 | ||
10764 | void nl80211_exit(void) | |
10765 | { | |
026331c4 | 10766 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
10767 | genl_unregister_family(&nl80211_fam); |
10768 | } |