]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
11 | #include <linux/list.h> |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/ieee80211.h> | |
14 | #include <linux/nl80211.h> | |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/netlink.h> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
2a0e047e | 22 | #include <net/inet_connection_sock.h> |
55682965 JB |
23 | #include "core.h" |
24 | #include "nl80211.h" | |
b2e1b302 | 25 | #include "reg.h" |
e35e4d28 | 26 | #include "rdev-ops.h" |
55682965 | 27 | |
5fb628e9 JM |
28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
29 | struct genl_info *info, | |
30 | struct cfg80211_crypto_settings *settings, | |
31 | int cipher_limit); | |
32 | ||
4c476991 JB |
33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
34 | struct genl_info *info); | |
35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
36 | struct genl_info *info); | |
37 | ||
55682965 JB |
38 | /* the netlink family */ |
39 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
42 | .hdrsize = 0, /* no private header */ | |
43 | .version = 1, /* no particular meaning now */ | |
55682965 | 44 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 45 | .netnsok = true, |
4c476991 JB |
46 | .pre_doit = nl80211_pre_doit, |
47 | .post_doit = nl80211_post_doit, | |
55682965 JB |
48 | }; |
49 | ||
89a54e48 JB |
50 | /* returns ERR_PTR values */ |
51 | static struct wireless_dev * | |
52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 53 | { |
89a54e48 JB |
54 | struct cfg80211_registered_device *rdev; |
55 | struct wireless_dev *result = NULL; | |
56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
58 | u64 wdev_id; | |
59 | int wiphy_idx = -1; | |
60 | int ifidx = -1; | |
55682965 | 61 | |
5fe231e8 | 62 | ASSERT_RTNL(); |
55682965 | 63 | |
89a54e48 JB |
64 | if (!have_ifidx && !have_wdev_id) |
65 | return ERR_PTR(-EINVAL); | |
55682965 | 66 | |
89a54e48 JB |
67 | if (have_ifidx) |
68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
69 | if (have_wdev_id) { | |
70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
71 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
72 | } |
73 | ||
89a54e48 JB |
74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
75 | struct wireless_dev *wdev; | |
76 | ||
77 | if (wiphy_net(&rdev->wiphy) != netns) | |
78 | continue; | |
79 | ||
80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
81 | continue; | |
82 | ||
89a54e48 JB |
83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
84 | if (have_ifidx && wdev->netdev && | |
85 | wdev->netdev->ifindex == ifidx) { | |
86 | result = wdev; | |
87 | break; | |
88 | } | |
89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
90 | result = wdev; | |
91 | break; | |
92 | } | |
93 | } | |
89a54e48 JB |
94 | |
95 | if (result) | |
96 | break; | |
97 | } | |
98 | ||
99 | if (result) | |
100 | return result; | |
101 | return ERR_PTR(-ENODEV); | |
55682965 JB |
102 | } |
103 | ||
a9455408 | 104 | static struct cfg80211_registered_device * |
878d9ec7 | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 106 | { |
7fee4778 JB |
107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
108 | struct net_device *netdev; | |
a9455408 | 109 | |
5fe231e8 | 110 | ASSERT_RTNL(); |
a9455408 | 111 | |
878d9ec7 | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
113 | !attrs[NL80211_ATTR_IFINDEX] && |
114 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
115 | return ERR_PTR(-EINVAL); |
116 | ||
878d9ec7 | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 120 | |
89a54e48 JB |
121 | if (attrs[NL80211_ATTR_WDEV]) { |
122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
123 | struct wireless_dev *wdev; | |
124 | bool found = false; | |
125 | ||
126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
127 | if (tmp) { | |
128 | /* make sure wdev exists */ | |
89a54e48 JB |
129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
130 | if (wdev->identifier != (u32)wdev_id) | |
131 | continue; | |
132 | found = true; | |
133 | break; | |
134 | } | |
89a54e48 JB |
135 | |
136 | if (!found) | |
137 | tmp = NULL; | |
138 | ||
139 | if (rdev && tmp != rdev) | |
140 | return ERR_PTR(-EINVAL); | |
141 | rdev = tmp; | |
142 | } | |
143 | } | |
144 | ||
878d9ec7 JB |
145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
4f7eff10 | 147 | netdev = dev_get_by_index(netns, ifindex); |
7fee4778 JB |
148 | if (netdev) { |
149 | if (netdev->ieee80211_ptr) | |
150 | tmp = wiphy_to_dev( | |
151 | netdev->ieee80211_ptr->wiphy); | |
152 | else | |
153 | tmp = NULL; | |
154 | ||
155 | dev_put(netdev); | |
156 | ||
157 | /* not wireless device -- return error */ | |
158 | if (!tmp) | |
159 | return ERR_PTR(-EINVAL); | |
160 | ||
161 | /* mismatch -- return error */ | |
162 | if (rdev && tmp != rdev) | |
163 | return ERR_PTR(-EINVAL); | |
164 | ||
165 | rdev = tmp; | |
a9455408 | 166 | } |
a9455408 | 167 | } |
a9455408 | 168 | |
4f7eff10 JB |
169 | if (!rdev) |
170 | return ERR_PTR(-ENODEV); | |
a9455408 | 171 | |
4f7eff10 JB |
172 | if (netns != wiphy_net(&rdev->wiphy)) |
173 | return ERR_PTR(-ENODEV); | |
174 | ||
175 | return rdev; | |
a9455408 JB |
176 | } |
177 | ||
178 | /* | |
179 | * This function returns a pointer to the driver | |
180 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
181 | * |
182 | * The result of this can be a PTR_ERR and hence must | |
183 | * be checked with IS_ERR() for errors. | |
184 | */ | |
185 | static struct cfg80211_registered_device * | |
4f7eff10 | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 187 | { |
5fe231e8 | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
189 | } |
190 | ||
55682965 | 191 | /* policy for the attributes */ |
b54452b0 | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 195 | .len = 20-1 }, |
31888487 | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 197 | |
72bdcf34 | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
203 | ||
b9a5f8ca JM |
204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
209 | |
210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 213 | |
e007b857 EP |
214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 216 | |
b9454e83 | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
219 | .len = WLAN_MAX_KEY_LEN }, | |
220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
225 | |
226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
229 | .len = IEEE80211_MAX_DATA_LEN }, | |
230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
231 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
236 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 243 | |
b2e1b302 LR |
244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
246 | ||
9f1ba906 JM |
247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
251 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 253 | |
24bdd9f4 | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 256 | |
6c739419 | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
258 | |
259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
261 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
264 | |
265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
266 | .len = IEEE80211_MAX_SSID_LEN }, | |
267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
272 | [NL80211_ATTR_STA_FLAGS2] = { |
273 | .len = sizeof(struct nl80211_sta_flag_update), | |
274 | }, | |
3f77316c | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
284 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
289 | .len = IEEE80211_MAX_DATA_LEN }, | |
290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
312 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
323 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
327 | .len = NL80211_HT_CAPABILITY_LEN | |
328 | }, | |
1d9d9213 | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
346 | .len = NL80211_VHT_CAPABILITY_LEN, | |
347 | }, | |
355199e0 JM |
348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
350 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
352 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
353 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
354 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
355 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, | |
356 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, | |
55682965 JB |
357 | }; |
358 | ||
e31b8213 | 359 | /* policy for the key attributes */ |
b54452b0 | 360 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 361 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
362 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
363 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 364 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
365 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
366 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 367 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
368 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
369 | }; | |
370 | ||
371 | /* policy for the key default flags */ | |
372 | static const struct nla_policy | |
373 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
374 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
375 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
376 | }; |
377 | ||
ff1b6e69 JB |
378 | /* policy for WoWLAN attributes */ |
379 | static const struct nla_policy | |
380 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
381 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
382 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
383 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
384 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
385 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
386 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
387 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
388 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
389 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
390 | }; | |
391 | ||
392 | static const struct nla_policy | |
393 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
394 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
395 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
396 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
397 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
398 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
399 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
400 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
401 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
402 | }, | |
403 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
404 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
405 | }, | |
406 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
407 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
408 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
409 | }; |
410 | ||
be29b99a AK |
411 | /* policy for coalesce rule attributes */ |
412 | static const struct nla_policy | |
413 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
414 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
415 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
416 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
417 | }; | |
418 | ||
e5497d76 JB |
419 | /* policy for GTK rekey offload attributes */ |
420 | static const struct nla_policy | |
421 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
422 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
423 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
424 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
425 | }; | |
426 | ||
a1f1c21c LC |
427 | static const struct nla_policy |
428 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 429 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 430 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 431 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
432 | }; |
433 | ||
97990a06 JB |
434 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
435 | struct netlink_callback *cb, | |
436 | struct cfg80211_registered_device **rdev, | |
437 | struct wireless_dev **wdev) | |
a043897a | 438 | { |
97990a06 | 439 | int err; |
a043897a | 440 | |
97990a06 | 441 | rtnl_lock(); |
a043897a | 442 | |
97990a06 JB |
443 | if (!cb->args[0]) { |
444 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
445 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
446 | nl80211_policy); | |
447 | if (err) | |
448 | goto out_unlock; | |
67748893 | 449 | |
97990a06 JB |
450 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
451 | nl80211_fam.attrbuf); | |
452 | if (IS_ERR(*wdev)) { | |
453 | err = PTR_ERR(*wdev); | |
454 | goto out_unlock; | |
455 | } | |
456 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
457 | cb->args[0] = (*rdev)->wiphy_idx; | |
458 | cb->args[1] = (*wdev)->identifier; | |
459 | } else { | |
460 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); | |
461 | struct wireless_dev *tmp; | |
67748893 | 462 | |
97990a06 JB |
463 | if (!wiphy) { |
464 | err = -ENODEV; | |
465 | goto out_unlock; | |
466 | } | |
467 | *rdev = wiphy_to_dev(wiphy); | |
468 | *wdev = NULL; | |
67748893 | 469 | |
97990a06 JB |
470 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
471 | if (tmp->identifier == cb->args[1]) { | |
472 | *wdev = tmp; | |
473 | break; | |
474 | } | |
475 | } | |
67748893 | 476 | |
97990a06 JB |
477 | if (!*wdev) { |
478 | err = -ENODEV; | |
479 | goto out_unlock; | |
480 | } | |
67748893 JB |
481 | } |
482 | ||
67748893 | 483 | return 0; |
97990a06 | 484 | out_unlock: |
67748893 JB |
485 | rtnl_unlock(); |
486 | return err; | |
487 | } | |
488 | ||
97990a06 | 489 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 490 | { |
67748893 JB |
491 | rtnl_unlock(); |
492 | } | |
493 | ||
f4a11bb0 JB |
494 | /* IE validation */ |
495 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
496 | { | |
497 | const u8 *pos; | |
498 | int len; | |
499 | ||
500 | if (!attr) | |
501 | return true; | |
502 | ||
503 | pos = nla_data(attr); | |
504 | len = nla_len(attr); | |
505 | ||
506 | while (len) { | |
507 | u8 elemlen; | |
508 | ||
509 | if (len < 2) | |
510 | return false; | |
511 | len -= 2; | |
512 | ||
513 | elemlen = pos[1]; | |
514 | if (elemlen > len) | |
515 | return false; | |
516 | ||
517 | len -= elemlen; | |
518 | pos += 2 + elemlen; | |
519 | } | |
520 | ||
521 | return true; | |
522 | } | |
523 | ||
55682965 | 524 | /* message building helper */ |
15e47304 | 525 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
526 | int flags, u8 cmd) |
527 | { | |
528 | /* since there is no private header just add the generic one */ | |
15e47304 | 529 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
530 | } |
531 | ||
5dab3b8a | 532 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
533 | struct ieee80211_channel *chan, |
534 | bool large) | |
5dab3b8a | 535 | { |
9360ffd1 DM |
536 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
537 | chan->center_freq)) | |
538 | goto nla_put_failure; | |
5dab3b8a | 539 | |
9360ffd1 DM |
540 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
541 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
542 | goto nla_put_failure; | |
543 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
544 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
545 | goto nla_put_failure; | |
546 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
547 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
548 | goto nla_put_failure; | |
cdc89b97 JB |
549 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
550 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
551 | goto nla_put_failure; | |
552 | if (large) { | |
553 | u32 time; | |
554 | ||
555 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
556 | ||
557 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
558 | chan->dfs_state)) | |
559 | goto nla_put_failure; | |
560 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
561 | time)) | |
562 | goto nla_put_failure; | |
563 | } | |
564 | } | |
5dab3b8a | 565 | |
fe1abafd JB |
566 | if (large) { |
567 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
569 | goto nla_put_failure; | |
570 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
572 | goto nla_put_failure; | |
573 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
574 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
575 | goto nla_put_failure; | |
576 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
578 | goto nla_put_failure; | |
579 | } | |
580 | ||
9360ffd1 DM |
581 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
582 | DBM_TO_MBM(chan->max_power))) | |
583 | goto nla_put_failure; | |
5dab3b8a LR |
584 | |
585 | return 0; | |
586 | ||
587 | nla_put_failure: | |
588 | return -ENOBUFS; | |
589 | } | |
590 | ||
55682965 JB |
591 | /* netlink command implementations */ |
592 | ||
b9454e83 JB |
593 | struct key_parse { |
594 | struct key_params p; | |
595 | int idx; | |
e31b8213 | 596 | int type; |
b9454e83 | 597 | bool def, defmgmt; |
dbd2fd65 | 598 | bool def_uni, def_multi; |
b9454e83 JB |
599 | }; |
600 | ||
601 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
602 | { | |
603 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
604 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
605 | nl80211_key_policy); | |
606 | if (err) | |
607 | return err; | |
608 | ||
609 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
610 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
611 | ||
dbd2fd65 JB |
612 | if (k->def) { |
613 | k->def_uni = true; | |
614 | k->def_multi = true; | |
615 | } | |
616 | if (k->defmgmt) | |
617 | k->def_multi = true; | |
618 | ||
b9454e83 JB |
619 | if (tb[NL80211_KEY_IDX]) |
620 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
621 | ||
622 | if (tb[NL80211_KEY_DATA]) { | |
623 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
624 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
625 | } | |
626 | ||
627 | if (tb[NL80211_KEY_SEQ]) { | |
628 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
629 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
630 | } | |
631 | ||
632 | if (tb[NL80211_KEY_CIPHER]) | |
633 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
634 | ||
e31b8213 JB |
635 | if (tb[NL80211_KEY_TYPE]) { |
636 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
637 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
638 | return -EINVAL; | |
639 | } | |
640 | ||
dbd2fd65 JB |
641 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
642 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
643 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
644 | tb[NL80211_KEY_DEFAULT_TYPES], | |
645 | nl80211_key_default_policy); | |
dbd2fd65 JB |
646 | if (err) |
647 | return err; | |
648 | ||
649 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
650 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
651 | } | |
652 | ||
b9454e83 JB |
653 | return 0; |
654 | } | |
655 | ||
656 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
657 | { | |
658 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
659 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
660 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
661 | } | |
662 | ||
663 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
664 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
665 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
666 | } | |
667 | ||
668 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
669 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
670 | ||
671 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
672 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
673 | ||
674 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
675 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
676 | ||
dbd2fd65 JB |
677 | if (k->def) { |
678 | k->def_uni = true; | |
679 | k->def_multi = true; | |
680 | } | |
681 | if (k->defmgmt) | |
682 | k->def_multi = true; | |
683 | ||
e31b8213 JB |
684 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
685 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
686 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
687 | return -EINVAL; | |
688 | } | |
689 | ||
dbd2fd65 JB |
690 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
691 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
692 | int err = nla_parse_nested( | |
693 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
694 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
695 | nl80211_key_default_policy); | |
696 | if (err) | |
697 | return err; | |
698 | ||
699 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
700 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
701 | } | |
702 | ||
b9454e83 JB |
703 | return 0; |
704 | } | |
705 | ||
706 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
707 | { | |
708 | int err; | |
709 | ||
710 | memset(k, 0, sizeof(*k)); | |
711 | k->idx = -1; | |
e31b8213 | 712 | k->type = -1; |
b9454e83 JB |
713 | |
714 | if (info->attrs[NL80211_ATTR_KEY]) | |
715 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
716 | else | |
717 | err = nl80211_parse_key_old(info, k); | |
718 | ||
719 | if (err) | |
720 | return err; | |
721 | ||
722 | if (k->def && k->defmgmt) | |
723 | return -EINVAL; | |
724 | ||
dbd2fd65 JB |
725 | if (k->defmgmt) { |
726 | if (k->def_uni || !k->def_multi) | |
727 | return -EINVAL; | |
728 | } | |
729 | ||
b9454e83 JB |
730 | if (k->idx != -1) { |
731 | if (k->defmgmt) { | |
732 | if (k->idx < 4 || k->idx > 5) | |
733 | return -EINVAL; | |
734 | } else if (k->def) { | |
735 | if (k->idx < 0 || k->idx > 3) | |
736 | return -EINVAL; | |
737 | } else { | |
738 | if (k->idx < 0 || k->idx > 5) | |
739 | return -EINVAL; | |
740 | } | |
741 | } | |
742 | ||
743 | return 0; | |
744 | } | |
745 | ||
fffd0934 JB |
746 | static struct cfg80211_cached_keys * |
747 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 748 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
749 | { |
750 | struct key_parse parse; | |
751 | struct nlattr *key; | |
752 | struct cfg80211_cached_keys *result; | |
753 | int rem, err, def = 0; | |
754 | ||
755 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
756 | if (!result) | |
757 | return ERR_PTR(-ENOMEM); | |
758 | ||
759 | result->def = -1; | |
760 | result->defmgmt = -1; | |
761 | ||
762 | nla_for_each_nested(key, keys, rem) { | |
763 | memset(&parse, 0, sizeof(parse)); | |
764 | parse.idx = -1; | |
765 | ||
766 | err = nl80211_parse_key_new(key, &parse); | |
767 | if (err) | |
768 | goto error; | |
769 | err = -EINVAL; | |
770 | if (!parse.p.key) | |
771 | goto error; | |
772 | if (parse.idx < 0 || parse.idx > 4) | |
773 | goto error; | |
774 | if (parse.def) { | |
775 | if (def) | |
776 | goto error; | |
777 | def = 1; | |
778 | result->def = parse.idx; | |
dbd2fd65 JB |
779 | if (!parse.def_uni || !parse.def_multi) |
780 | goto error; | |
fffd0934 JB |
781 | } else if (parse.defmgmt) |
782 | goto error; | |
783 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 784 | parse.idx, false, NULL); |
fffd0934 JB |
785 | if (err) |
786 | goto error; | |
787 | result->params[parse.idx].cipher = parse.p.cipher; | |
788 | result->params[parse.idx].key_len = parse.p.key_len; | |
789 | result->params[parse.idx].key = result->data[parse.idx]; | |
790 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
791 | |
792 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
793 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
794 | if (no_ht) | |
795 | *no_ht = true; | |
796 | } | |
fffd0934 JB |
797 | } |
798 | ||
799 | return result; | |
800 | error: | |
801 | kfree(result); | |
802 | return ERR_PTR(err); | |
803 | } | |
804 | ||
805 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
806 | { | |
807 | ASSERT_WDEV_LOCK(wdev); | |
808 | ||
fffd0934 JB |
809 | switch (wdev->iftype) { |
810 | case NL80211_IFTYPE_AP: | |
811 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 812 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 813 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
814 | break; |
815 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 816 | case NL80211_IFTYPE_STATION: |
074ac8df | 817 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 818 | if (!wdev->current_bss) |
fffd0934 JB |
819 | return -ENOLINK; |
820 | break; | |
821 | default: | |
822 | return -EINVAL; | |
823 | } | |
824 | ||
825 | return 0; | |
826 | } | |
827 | ||
7527a782 JB |
828 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
829 | { | |
830 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
831 | int i; | |
832 | ||
833 | if (!nl_modes) | |
834 | goto nla_put_failure; | |
835 | ||
836 | i = 0; | |
837 | while (ifmodes) { | |
9360ffd1 DM |
838 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
839 | goto nla_put_failure; | |
7527a782 JB |
840 | ifmodes >>= 1; |
841 | i++; | |
842 | } | |
843 | ||
844 | nla_nest_end(msg, nl_modes); | |
845 | return 0; | |
846 | ||
847 | nla_put_failure: | |
848 | return -ENOBUFS; | |
849 | } | |
850 | ||
851 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
852 | struct sk_buff *msg, |
853 | bool large) | |
7527a782 JB |
854 | { |
855 | struct nlattr *nl_combis; | |
856 | int i, j; | |
857 | ||
858 | nl_combis = nla_nest_start(msg, | |
859 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
860 | if (!nl_combis) | |
861 | goto nla_put_failure; | |
862 | ||
863 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
864 | const struct ieee80211_iface_combination *c; | |
865 | struct nlattr *nl_combi, *nl_limits; | |
866 | ||
867 | c = &wiphy->iface_combinations[i]; | |
868 | ||
869 | nl_combi = nla_nest_start(msg, i + 1); | |
870 | if (!nl_combi) | |
871 | goto nla_put_failure; | |
872 | ||
873 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
874 | if (!nl_limits) | |
875 | goto nla_put_failure; | |
876 | ||
877 | for (j = 0; j < c->n_limits; j++) { | |
878 | struct nlattr *nl_limit; | |
879 | ||
880 | nl_limit = nla_nest_start(msg, j + 1); | |
881 | if (!nl_limit) | |
882 | goto nla_put_failure; | |
9360ffd1 DM |
883 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
884 | c->limits[j].max)) | |
885 | goto nla_put_failure; | |
7527a782 JB |
886 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
887 | c->limits[j].types)) | |
888 | goto nla_put_failure; | |
889 | nla_nest_end(msg, nl_limit); | |
890 | } | |
891 | ||
892 | nla_nest_end(msg, nl_limits); | |
893 | ||
9360ffd1 DM |
894 | if (c->beacon_int_infra_match && |
895 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
896 | goto nla_put_failure; | |
897 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
898 | c->num_different_channels) || | |
899 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
900 | c->max_interfaces)) | |
901 | goto nla_put_failure; | |
cdc89b97 JB |
902 | if (large && |
903 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
904 | c->radar_detect_widths)) | |
905 | goto nla_put_failure; | |
7527a782 JB |
906 | |
907 | nla_nest_end(msg, nl_combi); | |
908 | } | |
909 | ||
910 | nla_nest_end(msg, nl_combis); | |
911 | ||
912 | return 0; | |
913 | nla_put_failure: | |
914 | return -ENOBUFS; | |
915 | } | |
916 | ||
3713b4e3 | 917 | #ifdef CONFIG_PM |
b56cf720 JB |
918 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
919 | struct sk_buff *msg) | |
920 | { | |
964dc9e2 | 921 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
922 | struct nlattr *nl_tcp; |
923 | ||
924 | if (!tcp) | |
925 | return 0; | |
926 | ||
927 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
928 | if (!nl_tcp) | |
929 | return -ENOBUFS; | |
930 | ||
931 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
932 | tcp->data_payload_max)) | |
933 | return -ENOBUFS; | |
934 | ||
935 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
936 | tcp->data_payload_max)) | |
937 | return -ENOBUFS; | |
938 | ||
939 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
940 | return -ENOBUFS; | |
941 | ||
942 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
943 | sizeof(*tcp->tok), tcp->tok)) | |
944 | return -ENOBUFS; | |
945 | ||
946 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
947 | tcp->data_interval_max)) | |
948 | return -ENOBUFS; | |
949 | ||
950 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
951 | tcp->wake_payload_max)) | |
952 | return -ENOBUFS; | |
953 | ||
954 | nla_nest_end(msg, nl_tcp); | |
955 | return 0; | |
956 | } | |
957 | ||
3713b4e3 | 958 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
959 | struct cfg80211_registered_device *dev, |
960 | bool large) | |
55682965 | 961 | { |
3713b4e3 | 962 | struct nlattr *nl_wowlan; |
55682965 | 963 | |
964dc9e2 | 964 | if (!dev->wiphy.wowlan) |
3713b4e3 | 965 | return 0; |
55682965 | 966 | |
3713b4e3 JB |
967 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
968 | if (!nl_wowlan) | |
969 | return -ENOBUFS; | |
9360ffd1 | 970 | |
964dc9e2 | 971 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 972 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
964dc9e2 | 973 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 974 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
964dc9e2 | 975 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
964dc9e2 | 977 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
964dc9e2 | 979 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
964dc9e2 | 981 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
964dc9e2 | 983 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
964dc9e2 | 985 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
987 | return -ENOBUFS; | |
9360ffd1 | 988 | |
964dc9e2 | 989 | if (dev->wiphy.wowlan->n_patterns) { |
50ac6607 | 990 | struct nl80211_pattern_support pat = { |
964dc9e2 JB |
991 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
992 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, | |
993 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, | |
994 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 995 | }; |
9360ffd1 | 996 | |
3713b4e3 JB |
997 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
998 | sizeof(pat), &pat)) | |
999 | return -ENOBUFS; | |
1000 | } | |
9360ffd1 | 1001 | |
b56cf720 JB |
1002 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1003 | return -ENOBUFS; | |
1004 | ||
3713b4e3 | 1005 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1006 | |
3713b4e3 JB |
1007 | return 0; |
1008 | } | |
1009 | #endif | |
9360ffd1 | 1010 | |
be29b99a AK |
1011 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1012 | struct cfg80211_registered_device *dev) | |
1013 | { | |
1014 | struct nl80211_coalesce_rule_support rule; | |
1015 | ||
1016 | if (!dev->wiphy.coalesce) | |
1017 | return 0; | |
1018 | ||
1019 | rule.max_rules = dev->wiphy.coalesce->n_rules; | |
1020 | rule.max_delay = dev->wiphy.coalesce->max_delay; | |
1021 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; | |
1022 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; | |
1023 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; | |
1024 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; | |
1025 | ||
1026 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1027 | return -ENOBUFS; | |
1028 | ||
1029 | return 0; | |
1030 | } | |
1031 | ||
3713b4e3 JB |
1032 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1033 | struct ieee80211_supported_band *sband) | |
1034 | { | |
1035 | struct nlattr *nl_rates, *nl_rate; | |
1036 | struct ieee80211_rate *rate; | |
1037 | int i; | |
87bbbe22 | 1038 | |
3713b4e3 JB |
1039 | /* add HT info */ |
1040 | if (sband->ht_cap.ht_supported && | |
1041 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1042 | sizeof(sband->ht_cap.mcs), | |
1043 | &sband->ht_cap.mcs) || | |
1044 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1045 | sband->ht_cap.cap) || | |
1046 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1047 | sband->ht_cap.ampdu_factor) || | |
1048 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1049 | sband->ht_cap.ampdu_density))) | |
1050 | return -ENOBUFS; | |
afe0cbf8 | 1051 | |
3713b4e3 JB |
1052 | /* add VHT info */ |
1053 | if (sband->vht_cap.vht_supported && | |
1054 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1055 | sizeof(sband->vht_cap.vht_mcs), | |
1056 | &sband->vht_cap.vht_mcs) || | |
1057 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1058 | sband->vht_cap.cap))) | |
1059 | return -ENOBUFS; | |
f59ac048 | 1060 | |
3713b4e3 JB |
1061 | /* add bitrates */ |
1062 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1063 | if (!nl_rates) | |
1064 | return -ENOBUFS; | |
ee688b00 | 1065 | |
3713b4e3 JB |
1066 | for (i = 0; i < sband->n_bitrates; i++) { |
1067 | nl_rate = nla_nest_start(msg, i); | |
1068 | if (!nl_rate) | |
1069 | return -ENOBUFS; | |
ee688b00 | 1070 | |
3713b4e3 JB |
1071 | rate = &sband->bitrates[i]; |
1072 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1073 | rate->bitrate)) | |
1074 | return -ENOBUFS; | |
1075 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1076 | nla_put_flag(msg, | |
1077 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1078 | return -ENOBUFS; | |
ee688b00 | 1079 | |
3713b4e3 JB |
1080 | nla_nest_end(msg, nl_rate); |
1081 | } | |
d51626df | 1082 | |
3713b4e3 | 1083 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1084 | |
3713b4e3 JB |
1085 | return 0; |
1086 | } | |
ee688b00 | 1087 | |
3713b4e3 JB |
1088 | static int |
1089 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1090 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1091 | { | |
1092 | u16 stypes; | |
1093 | struct nlattr *nl_ftypes, *nl_ifs; | |
1094 | enum nl80211_iftype ift; | |
1095 | int i; | |
ee688b00 | 1096 | |
3713b4e3 JB |
1097 | if (!mgmt_stypes) |
1098 | return 0; | |
5dab3b8a | 1099 | |
3713b4e3 JB |
1100 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1101 | if (!nl_ifs) | |
1102 | return -ENOBUFS; | |
e2f367f2 | 1103 | |
3713b4e3 JB |
1104 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1105 | nl_ftypes = nla_nest_start(msg, ift); | |
1106 | if (!nl_ftypes) | |
1107 | return -ENOBUFS; | |
1108 | i = 0; | |
1109 | stypes = mgmt_stypes[ift].tx; | |
1110 | while (stypes) { | |
1111 | if ((stypes & 1) && | |
1112 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1113 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1114 | return -ENOBUFS; | |
1115 | stypes >>= 1; | |
1116 | i++; | |
ee688b00 | 1117 | } |
3713b4e3 JB |
1118 | nla_nest_end(msg, nl_ftypes); |
1119 | } | |
ee688b00 | 1120 | |
3713b4e3 | 1121 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1122 | |
3713b4e3 JB |
1123 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1124 | if (!nl_ifs) | |
1125 | return -ENOBUFS; | |
ee688b00 | 1126 | |
3713b4e3 JB |
1127 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1128 | nl_ftypes = nla_nest_start(msg, ift); | |
1129 | if (!nl_ftypes) | |
1130 | return -ENOBUFS; | |
1131 | i = 0; | |
1132 | stypes = mgmt_stypes[ift].rx; | |
1133 | while (stypes) { | |
1134 | if ((stypes & 1) && | |
1135 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1136 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1137 | return -ENOBUFS; | |
1138 | stypes >>= 1; | |
1139 | i++; | |
1140 | } | |
1141 | nla_nest_end(msg, nl_ftypes); | |
1142 | } | |
1143 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1144 | |
3713b4e3 JB |
1145 | return 0; |
1146 | } | |
ee688b00 | 1147 | |
86e8cf98 JB |
1148 | struct nl80211_dump_wiphy_state { |
1149 | s64 filter_wiphy; | |
1150 | long start; | |
1151 | long split_start, band_start, chan_start; | |
1152 | bool split; | |
1153 | }; | |
1154 | ||
3713b4e3 JB |
1155 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1156 | struct sk_buff *msg, u32 portid, u32 seq, | |
86e8cf98 | 1157 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1158 | { |
1159 | void *hdr; | |
1160 | struct nlattr *nl_bands, *nl_band; | |
1161 | struct nlattr *nl_freqs, *nl_freq; | |
1162 | struct nlattr *nl_cmds; | |
1163 | enum ieee80211_band band; | |
1164 | struct ieee80211_channel *chan; | |
1165 | int i; | |
1166 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1167 | dev->wiphy.mgmt_stypes; | |
fe1abafd | 1168 | u32 features; |
ee688b00 | 1169 | |
3713b4e3 JB |
1170 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1171 | if (!hdr) | |
1172 | return -ENOBUFS; | |
ee688b00 | 1173 | |
86e8cf98 JB |
1174 | if (WARN_ON(!state)) |
1175 | return -EINVAL; | |
ee688b00 | 1176 | |
3713b4e3 JB |
1177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1178 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1179 | wiphy_name(&dev->wiphy)) || | |
1180 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1181 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1182 | goto nla_put_failure; |
1183 | ||
86e8cf98 | 1184 | switch (state->split_start) { |
3713b4e3 JB |
1185 | case 0: |
1186 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1187 | dev->wiphy.retry_short) || | |
1188 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1189 | dev->wiphy.retry_long) || | |
1190 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1191 | dev->wiphy.frag_threshold) || | |
1192 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1193 | dev->wiphy.rts_threshold) || | |
1194 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1195 | dev->wiphy.coverage_class) || | |
1196 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1197 | dev->wiphy.max_scan_ssids) || | |
1198 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1199 | dev->wiphy.max_sched_scan_ssids) || | |
1200 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1201 | dev->wiphy.max_scan_ie_len) || | |
1202 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1203 | dev->wiphy.max_sched_scan_ie_len) || | |
1204 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1205 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1206 | goto nla_put_failure; |
3713b4e3 JB |
1207 | |
1208 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1209 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1210 | goto nla_put_failure; |
3713b4e3 JB |
1211 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1212 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1213 | goto nla_put_failure; | |
1214 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1215 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1216 | goto nla_put_failure; | |
1217 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1218 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1219 | goto nla_put_failure; | |
1220 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1221 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1222 | goto nla_put_failure; | |
1223 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1224 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1225 | goto nla_put_failure; |
2f301ab2 SW |
1226 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
1227 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1228 | goto nla_put_failure; | |
8fdc621d | 1229 | |
86e8cf98 JB |
1230 | state->split_start++; |
1231 | if (state->split) | |
3713b4e3 JB |
1232 | break; |
1233 | case 1: | |
1234 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1235 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1236 | dev->wiphy.cipher_suites)) | |
1237 | goto nla_put_failure; | |
4745fc09 | 1238 | |
3713b4e3 JB |
1239 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1240 | dev->wiphy.max_num_pmkids)) | |
1241 | goto nla_put_failure; | |
b23aa676 | 1242 | |
3713b4e3 JB |
1243 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1244 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1245 | goto nla_put_failure; |
b23aa676 | 1246 | |
3713b4e3 JB |
1247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1248 | dev->wiphy.available_antennas_tx) || | |
1249 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1250 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1251 | goto nla_put_failure; |
b23aa676 | 1252 | |
3713b4e3 JB |
1253 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1254 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1255 | dev->wiphy.probe_resp_offload)) | |
1256 | goto nla_put_failure; | |
8fdc621d | 1257 | |
3713b4e3 JB |
1258 | if ((dev->wiphy.available_antennas_tx || |
1259 | dev->wiphy.available_antennas_rx) && | |
1260 | dev->ops->get_antenna) { | |
1261 | u32 tx_ant = 0, rx_ant = 0; | |
1262 | int res; | |
1263 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1264 | if (!res) { | |
1265 | if (nla_put_u32(msg, | |
1266 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1267 | tx_ant) || | |
1268 | nla_put_u32(msg, | |
1269 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1270 | rx_ant)) | |
1271 | goto nla_put_failure; | |
1272 | } | |
1273 | } | |
a293911d | 1274 | |
86e8cf98 JB |
1275 | state->split_start++; |
1276 | if (state->split) | |
3713b4e3 JB |
1277 | break; |
1278 | case 2: | |
1279 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1280 | dev->wiphy.interface_modes)) | |
1281 | goto nla_put_failure; | |
86e8cf98 JB |
1282 | state->split_start++; |
1283 | if (state->split) | |
3713b4e3 JB |
1284 | break; |
1285 | case 3: | |
1286 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1287 | if (!nl_bands) | |
1288 | goto nla_put_failure; | |
f7ca38df | 1289 | |
86e8cf98 JB |
1290 | for (band = state->band_start; |
1291 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1292 | struct ieee80211_supported_band *sband; |
2e161f78 | 1293 | |
3713b4e3 | 1294 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1295 | |
3713b4e3 JB |
1296 | if (!sband) |
1297 | continue; | |
1298 | ||
1299 | nl_band = nla_nest_start(msg, band); | |
1300 | if (!nl_band) | |
2e161f78 | 1301 | goto nla_put_failure; |
3713b4e3 | 1302 | |
86e8cf98 | 1303 | switch (state->chan_start) { |
3713b4e3 JB |
1304 | case 0: |
1305 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1306 | goto nla_put_failure; |
86e8cf98 JB |
1307 | state->chan_start++; |
1308 | if (state->split) | |
3713b4e3 JB |
1309 | break; |
1310 | default: | |
1311 | /* add frequencies */ | |
1312 | nl_freqs = nla_nest_start( | |
1313 | msg, NL80211_BAND_ATTR_FREQS); | |
1314 | if (!nl_freqs) | |
1315 | goto nla_put_failure; | |
1316 | ||
86e8cf98 | 1317 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1318 | i < sband->n_channels; |
1319 | i++) { | |
1320 | nl_freq = nla_nest_start(msg, i); | |
1321 | if (!nl_freq) | |
1322 | goto nla_put_failure; | |
1323 | ||
1324 | chan = &sband->channels[i]; | |
1325 | ||
86e8cf98 JB |
1326 | if (nl80211_msg_put_channel( |
1327 | msg, chan, | |
1328 | state->split)) | |
3713b4e3 JB |
1329 | goto nla_put_failure; |
1330 | ||
1331 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1332 | if (state->split) |
3713b4e3 JB |
1333 | break; |
1334 | } | |
1335 | if (i < sband->n_channels) | |
86e8cf98 | 1336 | state->chan_start = i + 2; |
3713b4e3 | 1337 | else |
86e8cf98 | 1338 | state->chan_start = 0; |
3713b4e3 JB |
1339 | nla_nest_end(msg, nl_freqs); |
1340 | } | |
1341 | ||
1342 | nla_nest_end(msg, nl_band); | |
1343 | ||
86e8cf98 | 1344 | if (state->split) { |
3713b4e3 | 1345 | /* start again here */ |
86e8cf98 | 1346 | if (state->chan_start) |
3713b4e3 JB |
1347 | band--; |
1348 | break; | |
2e161f78 | 1349 | } |
2e161f78 | 1350 | } |
3713b4e3 | 1351 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1352 | |
3713b4e3 | 1353 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1354 | state->band_start = band + 1; |
3713b4e3 | 1355 | else |
86e8cf98 | 1356 | state->band_start = 0; |
74b70a4e | 1357 | |
3713b4e3 | 1358 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1359 | if (state->band_start == 0 && state->chan_start == 0) |
1360 | state->split_start++; | |
1361 | if (state->split) | |
3713b4e3 JB |
1362 | break; |
1363 | case 4: | |
1364 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1365 | if (!nl_cmds) | |
2e161f78 JB |
1366 | goto nla_put_failure; |
1367 | ||
3713b4e3 JB |
1368 | i = 0; |
1369 | #define CMD(op, n) \ | |
1370 | do { \ | |
1371 | if (dev->ops->op) { \ | |
1372 | i++; \ | |
1373 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1374 | goto nla_put_failure; \ | |
1375 | } \ | |
1376 | } while (0) | |
1377 | ||
1378 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1379 | CMD(change_virtual_intf, SET_INTERFACE); | |
1380 | CMD(add_key, NEW_KEY); | |
1381 | CMD(start_ap, START_AP); | |
1382 | CMD(add_station, NEW_STATION); | |
1383 | CMD(add_mpath, NEW_MPATH); | |
1384 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1385 | CMD(change_bss, SET_BSS); | |
1386 | CMD(auth, AUTHENTICATE); | |
1387 | CMD(assoc, ASSOCIATE); | |
1388 | CMD(deauth, DEAUTHENTICATE); | |
1389 | CMD(disassoc, DISASSOCIATE); | |
1390 | CMD(join_ibss, JOIN_IBSS); | |
1391 | CMD(join_mesh, JOIN_MESH); | |
1392 | CMD(set_pmksa, SET_PMKSA); | |
1393 | CMD(del_pmksa, DEL_PMKSA); | |
1394 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1395 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1396 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1397 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1398 | CMD(mgmt_tx, FRAME); | |
1399 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1400 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1401 | i++; | |
1402 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1403 | goto nla_put_failure; |
2e161f78 | 1404 | } |
3713b4e3 JB |
1405 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1406 | dev->ops->join_mesh) { | |
1407 | i++; | |
1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1409 | goto nla_put_failure; | |
1410 | } | |
1411 | CMD(set_wds_peer, SET_WDS_PEER); | |
1412 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1413 | CMD(tdls_mgmt, TDLS_MGMT); | |
1414 | CMD(tdls_oper, TDLS_OPER); | |
1415 | } | |
1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1417 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1418 | CMD(probe_client, PROBE_CLIENT); | |
1419 | CMD(set_noack_map, SET_NOACK_MAP); | |
1420 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1421 | i++; | |
1422 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1423 | goto nla_put_failure; | |
1424 | } | |
1425 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1426 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
86e8cf98 | 1427 | if (state->split) { |
5de17984 AS |
1428 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1429 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
16ef1fe2 SW |
1430 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
1431 | CMD(channel_switch, CHANNEL_SWITCH); | |
5de17984 | 1432 | } |
2e161f78 | 1433 | |
3713b4e3 JB |
1434 | #ifdef CONFIG_NL80211_TESTMODE |
1435 | CMD(testmode_cmd, TESTMODE); | |
1436 | #endif | |
ff1b6e69 | 1437 | |
3713b4e3 | 1438 | #undef CMD |
ff1b6e69 | 1439 | |
3713b4e3 JB |
1440 | if (dev->ops->connect || dev->ops->auth) { |
1441 | i++; | |
1442 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1443 | goto nla_put_failure; |
ff1b6e69 JB |
1444 | } |
1445 | ||
3713b4e3 JB |
1446 | if (dev->ops->disconnect || dev->ops->deauth) { |
1447 | i++; | |
1448 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1449 | goto nla_put_failure; | |
1450 | } | |
1451 | ||
1452 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1453 | state->split_start++; |
1454 | if (state->split) | |
3713b4e3 JB |
1455 | break; |
1456 | case 5: | |
1457 | if (dev->ops->remain_on_channel && | |
1458 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1459 | nla_put_u32(msg, | |
1460 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1461 | dev->wiphy.max_remain_on_channel_duration)) | |
1462 | goto nla_put_failure; | |
1463 | ||
1464 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1465 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1466 | goto nla_put_failure; | |
1467 | ||
1468 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1469 | goto nla_put_failure; | |
86e8cf98 JB |
1470 | state->split_start++; |
1471 | if (state->split) | |
3713b4e3 JB |
1472 | break; |
1473 | case 6: | |
1474 | #ifdef CONFIG_PM | |
86e8cf98 | 1475 | if (nl80211_send_wowlan(msg, dev, state->split)) |
3713b4e3 | 1476 | goto nla_put_failure; |
86e8cf98 JB |
1477 | state->split_start++; |
1478 | if (state->split) | |
3713b4e3 JB |
1479 | break; |
1480 | #else | |
86e8cf98 | 1481 | state->split_start++; |
dfb89c56 | 1482 | #endif |
3713b4e3 JB |
1483 | case 7: |
1484 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1485 | dev->wiphy.software_iftypes)) | |
1486 | goto nla_put_failure; | |
ff1b6e69 | 1487 | |
86e8cf98 JB |
1488 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
1489 | state->split)) | |
3713b4e3 | 1490 | goto nla_put_failure; |
7527a782 | 1491 | |
86e8cf98 JB |
1492 | state->split_start++; |
1493 | if (state->split) | |
3713b4e3 JB |
1494 | break; |
1495 | case 8: | |
1496 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1497 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1498 | dev->wiphy.ap_sme_capa)) | |
1499 | goto nla_put_failure; | |
7527a782 | 1500 | |
fe1abafd JB |
1501 | features = dev->wiphy.features; |
1502 | /* | |
1503 | * We can only add the per-channel limit information if the | |
1504 | * dump is split, otherwise it makes it too big. Therefore | |
1505 | * only advertise it in that case. | |
1506 | */ | |
86e8cf98 | 1507 | if (state->split) |
fe1abafd JB |
1508 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1509 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1510 | goto nla_put_failure; |
562a7480 | 1511 | |
3713b4e3 JB |
1512 | if (dev->wiphy.ht_capa_mod_mask && |
1513 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1514 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1515 | dev->wiphy.ht_capa_mod_mask)) | |
1516 | goto nla_put_failure; | |
1f074bd8 | 1517 | |
3713b4e3 JB |
1518 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1519 | dev->wiphy.max_acl_mac_addrs && | |
1520 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1521 | dev->wiphy.max_acl_mac_addrs)) | |
1522 | goto nla_put_failure; | |
7e7c8926 | 1523 | |
3713b4e3 JB |
1524 | /* |
1525 | * Any information below this point is only available to | |
1526 | * applications that can deal with it being split. This | |
1527 | * helps ensure that newly added capabilities don't break | |
1528 | * older tools by overrunning their buffers. | |
1529 | * | |
1530 | * We still increment split_start so that in the split | |
1531 | * case we'll continue with more data in the next round, | |
1532 | * but break unconditionally so unsplit data stops here. | |
1533 | */ | |
86e8cf98 | 1534 | state->split_start++; |
3713b4e3 JB |
1535 | break; |
1536 | case 9: | |
fe1abafd JB |
1537 | if (dev->wiphy.extended_capabilities && |
1538 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1539 | dev->wiphy.extended_capabilities_len, | |
1540 | dev->wiphy.extended_capabilities) || | |
1541 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1542 | dev->wiphy.extended_capabilities_len, | |
1543 | dev->wiphy.extended_capabilities_mask))) | |
1544 | goto nla_put_failure; | |
a50df0c4 | 1545 | |
ee2aca34 JB |
1546 | if (dev->wiphy.vht_capa_mod_mask && |
1547 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1548 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1549 | dev->wiphy.vht_capa_mod_mask)) | |
1550 | goto nla_put_failure; | |
1551 | ||
be29b99a AK |
1552 | state->split_start++; |
1553 | break; | |
1554 | case 10: | |
1555 | if (nl80211_send_coalesce(msg, dev)) | |
1556 | goto nla_put_failure; | |
1557 | ||
3713b4e3 | 1558 | /* done */ |
86e8cf98 | 1559 | state->split_start = 0; |
3713b4e3 JB |
1560 | break; |
1561 | } | |
55682965 JB |
1562 | return genlmsg_end(msg, hdr); |
1563 | ||
1564 | nla_put_failure: | |
bc3ed28c TG |
1565 | genlmsg_cancel(msg, hdr); |
1566 | return -EMSGSIZE; | |
55682965 JB |
1567 | } |
1568 | ||
86e8cf98 JB |
1569 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1570 | struct netlink_callback *cb, | |
1571 | struct nl80211_dump_wiphy_state *state) | |
1572 | { | |
1573 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1574 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1575 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1576 | /* ignore parse errors for backward compatibility */ | |
1577 | if (ret) | |
1578 | return 0; | |
1579 | ||
1580 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1581 | if (tb[NL80211_ATTR_WIPHY]) | |
1582 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1583 | if (tb[NL80211_ATTR_WDEV]) | |
1584 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1585 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1586 | struct net_device *netdev; | |
1587 | struct cfg80211_registered_device *rdev; | |
1588 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1589 | ||
1590 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
1591 | if (!netdev) | |
1592 | return -ENODEV; | |
1593 | if (netdev->ieee80211_ptr) { | |
1594 | rdev = wiphy_to_dev( | |
1595 | netdev->ieee80211_ptr->wiphy); | |
1596 | state->filter_wiphy = rdev->wiphy_idx; | |
1597 | } | |
1598 | dev_put(netdev); | |
1599 | } | |
1600 | ||
1601 | return 0; | |
1602 | } | |
1603 | ||
55682965 JB |
1604 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1605 | { | |
645e77de | 1606 | int idx = 0, ret; |
86e8cf98 | 1607 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
55682965 | 1608 | struct cfg80211_registered_device *dev; |
3a5a423b | 1609 | |
5fe231e8 | 1610 | rtnl_lock(); |
86e8cf98 JB |
1611 | if (!state) { |
1612 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1613 | if (!state) { |
1614 | rtnl_unlock(); | |
86e8cf98 | 1615 | return -ENOMEM; |
3713b4e3 | 1616 | } |
86e8cf98 JB |
1617 | state->filter_wiphy = -1; |
1618 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1619 | if (ret) { | |
1620 | kfree(state); | |
1621 | rtnl_unlock(); | |
1622 | return ret; | |
3713b4e3 | 1623 | } |
86e8cf98 | 1624 | cb->args[0] = (long)state; |
3713b4e3 JB |
1625 | } |
1626 | ||
79c97e97 | 1627 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1628 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1629 | continue; | |
86e8cf98 | 1630 | if (++idx <= state->start) |
55682965 | 1631 | continue; |
86e8cf98 JB |
1632 | if (state->filter_wiphy != -1 && |
1633 | state->filter_wiphy != dev->wiphy_idx) | |
3713b4e3 JB |
1634 | continue; |
1635 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1636 | do { | |
1637 | ret = nl80211_send_wiphy(dev, skb, | |
1638 | NETLINK_CB(cb->skb).portid, | |
1639 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1640 | NLM_F_MULTI, state); |
3713b4e3 JB |
1641 | if (ret < 0) { |
1642 | /* | |
1643 | * If sending the wiphy data didn't fit (ENOBUFS | |
1644 | * or EMSGSIZE returned), this SKB is still | |
1645 | * empty (so it's not too big because another | |
1646 | * wiphy dataset is already in the skb) and | |
1647 | * we've not tried to adjust the dump allocation | |
1648 | * yet ... then adjust the alloc size to be | |
1649 | * bigger, and return 1 but with the empty skb. | |
1650 | * This results in an empty message being RX'ed | |
1651 | * in userspace, but that is ignored. | |
1652 | * | |
1653 | * We can then retry with the larger buffer. | |
1654 | */ | |
1655 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1656 | !skb->len && | |
1657 | cb->min_dump_alloc < 4096) { | |
1658 | cb->min_dump_alloc = 4096; | |
d98cae64 | 1659 | rtnl_unlock(); |
3713b4e3 JB |
1660 | return 1; |
1661 | } | |
1662 | idx--; | |
1663 | break; | |
645e77de | 1664 | } |
86e8cf98 | 1665 | } while (state->split_start > 0); |
3713b4e3 | 1666 | break; |
55682965 | 1667 | } |
5fe231e8 | 1668 | rtnl_unlock(); |
55682965 | 1669 | |
86e8cf98 | 1670 | state->start = idx; |
55682965 JB |
1671 | |
1672 | return skb->len; | |
1673 | } | |
1674 | ||
86e8cf98 JB |
1675 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1676 | { | |
1677 | kfree((void *)cb->args[0]); | |
1678 | return 0; | |
1679 | } | |
1680 | ||
55682965 JB |
1681 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1682 | { | |
1683 | struct sk_buff *msg; | |
4c476991 | 1684 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
86e8cf98 | 1685 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1686 | |
645e77de | 1687 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1688 | if (!msg) |
4c476991 | 1689 | return -ENOMEM; |
55682965 | 1690 | |
3713b4e3 | 1691 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
86e8cf98 | 1692 | &state) < 0) { |
4c476991 JB |
1693 | nlmsg_free(msg); |
1694 | return -ENOBUFS; | |
1695 | } | |
55682965 | 1696 | |
134e6375 | 1697 | return genlmsg_reply(msg, info); |
55682965 JB |
1698 | } |
1699 | ||
31888487 JM |
1700 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1701 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1702 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1703 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1704 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1705 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1706 | }; | |
1707 | ||
1708 | static int parse_txq_params(struct nlattr *tb[], | |
1709 | struct ieee80211_txq_params *txq_params) | |
1710 | { | |
a3304b0a | 1711 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1712 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1713 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1714 | return -EINVAL; | |
1715 | ||
a3304b0a | 1716 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1717 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1718 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1719 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1720 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1721 | ||
a3304b0a JB |
1722 | if (txq_params->ac >= NL80211_NUM_ACS) |
1723 | return -EINVAL; | |
1724 | ||
31888487 JM |
1725 | return 0; |
1726 | } | |
1727 | ||
f444de05 JB |
1728 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1729 | { | |
1730 | /* | |
cc1d2806 JB |
1731 | * You can only set the channel explicitly for WDS interfaces, |
1732 | * all others have their channel managed via their respective | |
1733 | * "establish a connection" command (connect, join, ...) | |
1734 | * | |
1735 | * For AP/GO and mesh mode, the channel can be set with the | |
1736 | * channel userspace API, but is only stored and passed to the | |
1737 | * low-level driver when the AP starts or the mesh is joined. | |
1738 | * This is for backward compatibility, userspace can also give | |
1739 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1740 | * |
1741 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1742 | * whatever else is going on, so they have their own special |
1743 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1744 | */ |
1745 | return !wdev || | |
1746 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1747 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1748 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1749 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1750 | } |
1751 | ||
683b6d3b JB |
1752 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1753 | struct genl_info *info, | |
1754 | struct cfg80211_chan_def *chandef) | |
1755 | { | |
dbeca2ea | 1756 | u32 control_freq; |
683b6d3b JB |
1757 | |
1758 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1759 | return -EINVAL; | |
1760 | ||
1761 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1762 | ||
1763 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1764 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1765 | chandef->center_freq1 = control_freq; | |
1766 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1767 | |
1768 | /* Primary channel not allowed */ | |
1769 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1770 | return -EINVAL; | |
1771 | ||
3d9d1d66 JB |
1772 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1773 | enum nl80211_channel_type chantype; | |
1774 | ||
1775 | chantype = nla_get_u32( | |
1776 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1777 | ||
1778 | switch (chantype) { | |
1779 | case NL80211_CHAN_NO_HT: | |
1780 | case NL80211_CHAN_HT20: | |
1781 | case NL80211_CHAN_HT40PLUS: | |
1782 | case NL80211_CHAN_HT40MINUS: | |
1783 | cfg80211_chandef_create(chandef, chandef->chan, | |
1784 | chantype); | |
1785 | break; | |
1786 | default: | |
1787 | return -EINVAL; | |
1788 | } | |
1789 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1790 | chandef->width = | |
1791 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1792 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1793 | chandef->center_freq1 = | |
1794 | nla_get_u32( | |
1795 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1796 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1797 | chandef->center_freq2 = | |
1798 | nla_get_u32( | |
1799 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1800 | } | |
1801 | ||
9f5e8f6e | 1802 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1803 | return -EINVAL; |
1804 | ||
9f5e8f6e JB |
1805 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1806 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1807 | return -EINVAL; |
1808 | ||
2f301ab2 SW |
1809 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1810 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1811 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1812 | return -EINVAL; | |
1813 | ||
683b6d3b JB |
1814 | return 0; |
1815 | } | |
1816 | ||
f444de05 JB |
1817 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1818 | struct wireless_dev *wdev, | |
1819 | struct genl_info *info) | |
1820 | { | |
683b6d3b | 1821 | struct cfg80211_chan_def chandef; |
f444de05 | 1822 | int result; |
e8c9bd5b JB |
1823 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1824 | ||
1825 | if (wdev) | |
1826 | iftype = wdev->iftype; | |
f444de05 | 1827 | |
f444de05 JB |
1828 | if (!nl80211_can_set_dev_channel(wdev)) |
1829 | return -EOPNOTSUPP; | |
1830 | ||
683b6d3b JB |
1831 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1832 | if (result) | |
1833 | return result; | |
f444de05 | 1834 | |
e8c9bd5b | 1835 | switch (iftype) { |
aa430da4 JB |
1836 | case NL80211_IFTYPE_AP: |
1837 | case NL80211_IFTYPE_P2P_GO: | |
1838 | if (wdev->beacon_interval) { | |
1839 | result = -EBUSY; | |
1840 | break; | |
1841 | } | |
683b6d3b | 1842 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1843 | result = -EINVAL; |
1844 | break; | |
1845 | } | |
683b6d3b | 1846 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1847 | result = 0; |
1848 | break; | |
cc1d2806 | 1849 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1850 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1851 | break; |
e8c9bd5b | 1852 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1853 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1854 | break; |
aa430da4 | 1855 | default: |
e8c9bd5b | 1856 | result = -EINVAL; |
f444de05 | 1857 | } |
f444de05 JB |
1858 | |
1859 | return result; | |
1860 | } | |
1861 | ||
1862 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1863 | { | |
4c476991 JB |
1864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1865 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1866 | |
4c476991 | 1867 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1868 | } |
1869 | ||
e8347eba BJ |
1870 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1871 | { | |
43b19952 JB |
1872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1873 | struct net_device *dev = info->user_ptr[1]; | |
1874 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1875 | const u8 *bssid; |
e8347eba BJ |
1876 | |
1877 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1878 | return -EINVAL; | |
1879 | ||
43b19952 JB |
1880 | if (netif_running(dev)) |
1881 | return -EBUSY; | |
e8347eba | 1882 | |
43b19952 JB |
1883 | if (!rdev->ops->set_wds_peer) |
1884 | return -EOPNOTSUPP; | |
e8347eba | 1885 | |
43b19952 JB |
1886 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1887 | return -EOPNOTSUPP; | |
e8347eba BJ |
1888 | |
1889 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1890 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1891 | } |
1892 | ||
1893 | ||
55682965 JB |
1894 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1895 | { | |
1896 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1897 | struct net_device *netdev = NULL; |
1898 | struct wireless_dev *wdev; | |
a1e567c8 | 1899 | int result = 0, rem_txq_params = 0; |
31888487 | 1900 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1901 | u32 changed; |
1902 | u8 retry_short = 0, retry_long = 0; | |
1903 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1904 | u8 coverage_class = 0; |
55682965 | 1905 | |
5fe231e8 JB |
1906 | ASSERT_RTNL(); |
1907 | ||
f444de05 JB |
1908 | /* |
1909 | * Try to find the wiphy and netdev. Normally this | |
1910 | * function shouldn't need the netdev, but this is | |
1911 | * done for backward compatibility -- previously | |
1912 | * setting the channel was done per wiphy, but now | |
1913 | * it is per netdev. Previous userland like hostapd | |
1914 | * also passed a netdev to set_wiphy, so that it is | |
1915 | * possible to let that go to the right netdev! | |
1916 | */ | |
4bbf4d56 | 1917 | |
f444de05 JB |
1918 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1919 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1920 | ||
1921 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
5fe231e8 | 1922 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 1923 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 1924 | else |
f444de05 | 1925 | netdev = NULL; |
4bbf4d56 JB |
1926 | } |
1927 | ||
f444de05 | 1928 | if (!netdev) { |
878d9ec7 JB |
1929 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1930 | info->attrs); | |
5fe231e8 | 1931 | if (IS_ERR(rdev)) |
4c476991 | 1932 | return PTR_ERR(rdev); |
f444de05 JB |
1933 | wdev = NULL; |
1934 | netdev = NULL; | |
1935 | result = 0; | |
71fe96bf | 1936 | } else |
f444de05 | 1937 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1938 | |
1939 | /* | |
1940 | * end workaround code, by now the rdev is available | |
1941 | * and locked, and wdev may or may not be NULL. | |
1942 | */ | |
4bbf4d56 JB |
1943 | |
1944 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1945 | result = cfg80211_dev_rename( |
1946 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 1947 | |
4bbf4d56 JB |
1948 | if (result) |
1949 | goto bad_res; | |
31888487 JM |
1950 | |
1951 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1952 | struct ieee80211_txq_params txq_params; | |
1953 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1954 | ||
1955 | if (!rdev->ops->set_txq_params) { | |
1956 | result = -EOPNOTSUPP; | |
1957 | goto bad_res; | |
1958 | } | |
1959 | ||
f70f01c2 EP |
1960 | if (!netdev) { |
1961 | result = -EINVAL; | |
1962 | goto bad_res; | |
1963 | } | |
1964 | ||
133a3ff2 JB |
1965 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1966 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1967 | result = -EINVAL; | |
1968 | goto bad_res; | |
1969 | } | |
1970 | ||
2b5f8b0b JB |
1971 | if (!netif_running(netdev)) { |
1972 | result = -ENETDOWN; | |
1973 | goto bad_res; | |
1974 | } | |
1975 | ||
31888487 JM |
1976 | nla_for_each_nested(nl_txq_params, |
1977 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1978 | rem_txq_params) { | |
1979 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1980 | nla_data(nl_txq_params), | |
1981 | nla_len(nl_txq_params), | |
1982 | txq_params_policy); | |
1983 | result = parse_txq_params(tb, &txq_params); | |
1984 | if (result) | |
1985 | goto bad_res; | |
1986 | ||
e35e4d28 HG |
1987 | result = rdev_set_txq_params(rdev, netdev, |
1988 | &txq_params); | |
31888487 JM |
1989 | if (result) |
1990 | goto bad_res; | |
1991 | } | |
1992 | } | |
55682965 | 1993 | |
72bdcf34 | 1994 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1995 | result = __nl80211_set_channel(rdev, |
1996 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1997 | info); | |
72bdcf34 JM |
1998 | if (result) |
1999 | goto bad_res; | |
2000 | } | |
2001 | ||
98d2ff8b | 2002 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2003 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2004 | enum nl80211_tx_power_setting type; |
2005 | int idx, mbm = 0; | |
2006 | ||
c8442118 JB |
2007 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2008 | txp_wdev = NULL; | |
2009 | ||
98d2ff8b | 2010 | if (!rdev->ops->set_tx_power) { |
60ea385f | 2011 | result = -EOPNOTSUPP; |
98d2ff8b JO |
2012 | goto bad_res; |
2013 | } | |
2014 | ||
2015 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2016 | type = nla_get_u32(info->attrs[idx]); | |
2017 | ||
2018 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
2019 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
2020 | result = -EINVAL; | |
2021 | goto bad_res; | |
2022 | } | |
2023 | ||
2024 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2025 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2026 | mbm = nla_get_u32(info->attrs[idx]); | |
2027 | } | |
2028 | ||
c8442118 | 2029 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
2030 | if (result) |
2031 | goto bad_res; | |
2032 | } | |
2033 | ||
afe0cbf8 BR |
2034 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2035 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2036 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2037 | if ((!rdev->wiphy.available_antennas_tx && |
2038 | !rdev->wiphy.available_antennas_rx) || | |
2039 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
2040 | result = -EOPNOTSUPP; |
2041 | goto bad_res; | |
2042 | } | |
2043 | ||
2044 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2045 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2046 | ||
a7ffac95 | 2047 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2048 | * available antenna masks, except for the "all" mask */ |
2049 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
2050 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
2051 | result = -EINVAL; |
2052 | goto bad_res; | |
2053 | } | |
2054 | ||
7f531e03 BR |
2055 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2056 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2057 | |
e35e4d28 | 2058 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
2059 | if (result) |
2060 | goto bad_res; | |
2061 | } | |
2062 | ||
b9a5f8ca JM |
2063 | changed = 0; |
2064 | ||
2065 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2066 | retry_short = nla_get_u8( | |
2067 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2068 | if (retry_short == 0) { | |
2069 | result = -EINVAL; | |
2070 | goto bad_res; | |
2071 | } | |
2072 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2073 | } | |
2074 | ||
2075 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2076 | retry_long = nla_get_u8( | |
2077 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2078 | if (retry_long == 0) { | |
2079 | result = -EINVAL; | |
2080 | goto bad_res; | |
2081 | } | |
2082 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2083 | } | |
2084 | ||
2085 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2086 | frag_threshold = nla_get_u32( | |
2087 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2088 | if (frag_threshold < 256) { | |
2089 | result = -EINVAL; | |
2090 | goto bad_res; | |
2091 | } | |
2092 | if (frag_threshold != (u32) -1) { | |
2093 | /* | |
2094 | * Fragments (apart from the last one) are required to | |
2095 | * have even length. Make the fragmentation code | |
2096 | * simpler by stripping LSB should someone try to use | |
2097 | * odd threshold value. | |
2098 | */ | |
2099 | frag_threshold &= ~0x1; | |
2100 | } | |
2101 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2102 | } | |
2103 | ||
2104 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2105 | rts_threshold = nla_get_u32( | |
2106 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2107 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2108 | } | |
2109 | ||
81077e82 LT |
2110 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2111 | coverage_class = nla_get_u8( | |
2112 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2113 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2114 | } | |
2115 | ||
b9a5f8ca JM |
2116 | if (changed) { |
2117 | u8 old_retry_short, old_retry_long; | |
2118 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2119 | u8 old_coverage_class; |
b9a5f8ca JM |
2120 | |
2121 | if (!rdev->ops->set_wiphy_params) { | |
2122 | result = -EOPNOTSUPP; | |
2123 | goto bad_res; | |
2124 | } | |
2125 | ||
2126 | old_retry_short = rdev->wiphy.retry_short; | |
2127 | old_retry_long = rdev->wiphy.retry_long; | |
2128 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2129 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2130 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2131 | |
2132 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2133 | rdev->wiphy.retry_short = retry_short; | |
2134 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2135 | rdev->wiphy.retry_long = retry_long; | |
2136 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2137 | rdev->wiphy.frag_threshold = frag_threshold; | |
2138 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2139 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2140 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2141 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2142 | |
e35e4d28 | 2143 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2144 | if (result) { |
2145 | rdev->wiphy.retry_short = old_retry_short; | |
2146 | rdev->wiphy.retry_long = old_retry_long; | |
2147 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2148 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2149 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2150 | } |
2151 | } | |
72bdcf34 | 2152 | |
306d6112 | 2153 | bad_res: |
f444de05 JB |
2154 | if (netdev) |
2155 | dev_put(netdev); | |
55682965 JB |
2156 | return result; |
2157 | } | |
2158 | ||
71bbc994 JB |
2159 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2160 | { | |
2161 | return (u64)wdev->identifier | | |
2162 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2163 | } | |
55682965 | 2164 | |
683b6d3b JB |
2165 | static int nl80211_send_chandef(struct sk_buff *msg, |
2166 | struct cfg80211_chan_def *chandef) | |
2167 | { | |
9f5e8f6e | 2168 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2169 | |
683b6d3b JB |
2170 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2171 | chandef->chan->center_freq)) | |
2172 | return -ENOBUFS; | |
3d9d1d66 JB |
2173 | switch (chandef->width) { |
2174 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2175 | case NL80211_CHAN_WIDTH_20: | |
2176 | case NL80211_CHAN_WIDTH_40: | |
2177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2178 | cfg80211_get_chandef_type(chandef))) | |
2179 | return -ENOBUFS; | |
2180 | break; | |
2181 | default: | |
2182 | break; | |
2183 | } | |
2184 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2185 | return -ENOBUFS; | |
2186 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2187 | return -ENOBUFS; | |
2188 | if (chandef->center_freq2 && | |
2189 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2190 | return -ENOBUFS; |
2191 | return 0; | |
2192 | } | |
2193 | ||
15e47304 | 2194 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2195 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2196 | struct wireless_dev *wdev) |
55682965 | 2197 | { |
72fb2abc | 2198 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2199 | void *hdr; |
2200 | ||
15e47304 | 2201 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2202 | if (!hdr) |
2203 | return -1; | |
2204 | ||
72fb2abc JB |
2205 | if (dev && |
2206 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2207 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2208 | goto nla_put_failure; |
2209 | ||
2210 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2211 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2212 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2213 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2214 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2215 | rdev->devlist_generation ^ | |
2216 | (cfg80211_rdev_list_generation << 2))) | |
2217 | goto nla_put_failure; | |
f5ea9120 | 2218 | |
5b7ccaf3 | 2219 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2220 | int ret; |
2221 | struct cfg80211_chan_def chandef; | |
2222 | ||
2223 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2224 | if (ret == 0) { | |
2225 | if (nl80211_send_chandef(msg, &chandef)) | |
2226 | goto nla_put_failure; | |
2227 | } | |
d91df0e3 PF |
2228 | } |
2229 | ||
b84e7a05 AQ |
2230 | if (wdev->ssid_len) { |
2231 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2232 | goto nla_put_failure; | |
2233 | } | |
2234 | ||
55682965 JB |
2235 | return genlmsg_end(msg, hdr); |
2236 | ||
2237 | nla_put_failure: | |
bc3ed28c TG |
2238 | genlmsg_cancel(msg, hdr); |
2239 | return -EMSGSIZE; | |
55682965 JB |
2240 | } |
2241 | ||
2242 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2243 | { | |
2244 | int wp_idx = 0; | |
2245 | int if_idx = 0; | |
2246 | int wp_start = cb->args[0]; | |
2247 | int if_start = cb->args[1]; | |
f5ea9120 | 2248 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2249 | struct wireless_dev *wdev; |
2250 | ||
5fe231e8 | 2251 | rtnl_lock(); |
f5ea9120 JB |
2252 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2253 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2254 | continue; |
bba95fef JB |
2255 | if (wp_idx < wp_start) { |
2256 | wp_idx++; | |
55682965 | 2257 | continue; |
bba95fef | 2258 | } |
55682965 JB |
2259 | if_idx = 0; |
2260 | ||
89a54e48 | 2261 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2262 | if (if_idx < if_start) { |
2263 | if_idx++; | |
55682965 | 2264 | continue; |
bba95fef | 2265 | } |
15e47304 | 2266 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2267 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2268 | rdev, wdev) < 0) { |
bba95fef JB |
2269 | goto out; |
2270 | } | |
2271 | if_idx++; | |
55682965 | 2272 | } |
bba95fef JB |
2273 | |
2274 | wp_idx++; | |
55682965 | 2275 | } |
bba95fef | 2276 | out: |
5fe231e8 | 2277 | rtnl_unlock(); |
55682965 JB |
2278 | |
2279 | cb->args[0] = wp_idx; | |
2280 | cb->args[1] = if_idx; | |
2281 | ||
2282 | return skb->len; | |
2283 | } | |
2284 | ||
2285 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2286 | { | |
2287 | struct sk_buff *msg; | |
4c476991 | 2288 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2289 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2290 | |
fd2120ca | 2291 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2292 | if (!msg) |
4c476991 | 2293 | return -ENOMEM; |
55682965 | 2294 | |
15e47304 | 2295 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2296 | dev, wdev) < 0) { |
4c476991 JB |
2297 | nlmsg_free(msg); |
2298 | return -ENOBUFS; | |
2299 | } | |
55682965 | 2300 | |
134e6375 | 2301 | return genlmsg_reply(msg, info); |
55682965 JB |
2302 | } |
2303 | ||
66f7ac50 MW |
2304 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2305 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2306 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2307 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2308 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2309 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2310 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2311 | }; |
2312 | ||
2313 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2314 | { | |
2315 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2316 | int flag; | |
2317 | ||
2318 | *mntrflags = 0; | |
2319 | ||
2320 | if (!nla) | |
2321 | return -EINVAL; | |
2322 | ||
2323 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2324 | nla, mntr_flags_policy)) | |
2325 | return -EINVAL; | |
2326 | ||
2327 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2328 | if (flags[flag]) | |
2329 | *mntrflags |= (1<<flag); | |
2330 | ||
2331 | return 0; | |
2332 | } | |
2333 | ||
9bc383de | 2334 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2335 | struct net_device *netdev, u8 use_4addr, |
2336 | enum nl80211_iftype iftype) | |
9bc383de | 2337 | { |
ad4bb6f8 | 2338 | if (!use_4addr) { |
f350a0a8 | 2339 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2340 | return -EBUSY; |
9bc383de | 2341 | return 0; |
ad4bb6f8 | 2342 | } |
9bc383de JB |
2343 | |
2344 | switch (iftype) { | |
2345 | case NL80211_IFTYPE_AP_VLAN: | |
2346 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2347 | return 0; | |
2348 | break; | |
2349 | case NL80211_IFTYPE_STATION: | |
2350 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2351 | return 0; | |
2352 | break; | |
2353 | default: | |
2354 | break; | |
2355 | } | |
2356 | ||
2357 | return -EOPNOTSUPP; | |
2358 | } | |
2359 | ||
55682965 JB |
2360 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2361 | { | |
4c476991 | 2362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2363 | struct vif_params params; |
e36d56b6 | 2364 | int err; |
04a773ad | 2365 | enum nl80211_iftype otype, ntype; |
4c476991 | 2366 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2367 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2368 | bool change = false; |
55682965 | 2369 | |
2ec600d6 LCC |
2370 | memset(¶ms, 0, sizeof(params)); |
2371 | ||
04a773ad | 2372 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2373 | |
723b038d | 2374 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2375 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2376 | if (otype != ntype) |
ac7f9cfa | 2377 | change = true; |
4c476991 JB |
2378 | if (ntype > NL80211_IFTYPE_MAX) |
2379 | return -EINVAL; | |
723b038d JB |
2380 | } |
2381 | ||
92ffe055 | 2382 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2383 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2384 | ||
4c476991 JB |
2385 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2386 | return -EINVAL; | |
29cbe68c JB |
2387 | if (netif_running(dev)) |
2388 | return -EBUSY; | |
2389 | ||
2390 | wdev_lock(wdev); | |
2391 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2392 | IEEE80211_MAX_MESH_ID_LEN); | |
2393 | wdev->mesh_id_up_len = | |
2394 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2395 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2396 | wdev->mesh_id_up_len); | |
2397 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2398 | } |
2399 | ||
8b787643 FF |
2400 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2401 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2402 | change = true; | |
ad4bb6f8 | 2403 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2404 | if (err) |
4c476991 | 2405 | return err; |
8b787643 FF |
2406 | } else { |
2407 | params.use_4addr = -1; | |
2408 | } | |
2409 | ||
92ffe055 | 2410 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2411 | if (ntype != NL80211_IFTYPE_MONITOR) |
2412 | return -EINVAL; | |
92ffe055 JB |
2413 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2414 | &_flags); | |
ac7f9cfa | 2415 | if (err) |
4c476991 | 2416 | return err; |
ac7f9cfa JB |
2417 | |
2418 | flags = &_flags; | |
2419 | change = true; | |
92ffe055 | 2420 | } |
3b85875a | 2421 | |
e057d3c3 FF |
2422 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
2423 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2424 | return -EOPNOTSUPP; | |
2425 | ||
ac7f9cfa | 2426 | if (change) |
3d54d255 | 2427 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2428 | else |
2429 | err = 0; | |
60719ffd | 2430 | |
9bc383de JB |
2431 | if (!err && params.use_4addr != -1) |
2432 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2433 | ||
55682965 JB |
2434 | return err; |
2435 | } | |
2436 | ||
2437 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2438 | { | |
4c476991 | 2439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2440 | struct vif_params params; |
84efbb84 | 2441 | struct wireless_dev *wdev; |
1c90f9d4 | 2442 | struct sk_buff *msg; |
55682965 JB |
2443 | int err; |
2444 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2445 | u32 flags; |
55682965 | 2446 | |
2ec600d6 LCC |
2447 | memset(¶ms, 0, sizeof(params)); |
2448 | ||
55682965 JB |
2449 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2450 | return -EINVAL; | |
2451 | ||
2452 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2453 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2454 | if (type > NL80211_IFTYPE_MAX) | |
2455 | return -EINVAL; | |
2456 | } | |
2457 | ||
79c97e97 | 2458 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2459 | !(rdev->wiphy.interface_modes & (1 << type))) |
2460 | return -EOPNOTSUPP; | |
55682965 | 2461 | |
1c18f145 AS |
2462 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2463 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2464 | ETH_ALEN); | |
2465 | if (!is_valid_ether_addr(params.macaddr)) | |
2466 | return -EADDRNOTAVAIL; | |
2467 | } | |
2468 | ||
9bc383de | 2469 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2470 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2471 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2472 | if (err) |
4c476991 | 2473 | return err; |
9bc383de | 2474 | } |
8b787643 | 2475 | |
1c90f9d4 JB |
2476 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2477 | if (!msg) | |
2478 | return -ENOMEM; | |
2479 | ||
66f7ac50 MW |
2480 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2481 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2482 | &flags); | |
e057d3c3 FF |
2483 | |
2484 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && | |
2485 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2486 | return -EOPNOTSUPP; | |
2487 | ||
e35e4d28 HG |
2488 | wdev = rdev_add_virtual_intf(rdev, |
2489 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2490 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2491 | if (IS_ERR(wdev)) { |
2492 | nlmsg_free(msg); | |
84efbb84 | 2493 | return PTR_ERR(wdev); |
1c90f9d4 | 2494 | } |
2ec600d6 | 2495 | |
98104fde JB |
2496 | switch (type) { |
2497 | case NL80211_IFTYPE_MESH_POINT: | |
2498 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2499 | break; | |
29cbe68c JB |
2500 | wdev_lock(wdev); |
2501 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2502 | IEEE80211_MAX_MESH_ID_LEN); | |
2503 | wdev->mesh_id_up_len = | |
2504 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2505 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2506 | wdev->mesh_id_up_len); | |
2507 | wdev_unlock(wdev); | |
98104fde JB |
2508 | break; |
2509 | case NL80211_IFTYPE_P2P_DEVICE: | |
2510 | /* | |
2511 | * P2P Device doesn't have a netdev, so doesn't go | |
2512 | * through the netdev notifier and must be added here | |
2513 | */ | |
2514 | mutex_init(&wdev->mtx); | |
2515 | INIT_LIST_HEAD(&wdev->event_list); | |
2516 | spin_lock_init(&wdev->event_lock); | |
2517 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2518 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2519 | ||
98104fde JB |
2520 | wdev->identifier = ++rdev->wdev_id; |
2521 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2522 | rdev->devlist_generation++; | |
98104fde JB |
2523 | break; |
2524 | default: | |
2525 | break; | |
29cbe68c JB |
2526 | } |
2527 | ||
15e47304 | 2528 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2529 | rdev, wdev) < 0) { |
2530 | nlmsg_free(msg); | |
2531 | return -ENOBUFS; | |
2532 | } | |
2533 | ||
2534 | return genlmsg_reply(msg, info); | |
55682965 JB |
2535 | } |
2536 | ||
2537 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2538 | { | |
4c476991 | 2539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2540 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2541 | |
4c476991 JB |
2542 | if (!rdev->ops->del_virtual_intf) |
2543 | return -EOPNOTSUPP; | |
55682965 | 2544 | |
84efbb84 JB |
2545 | /* |
2546 | * If we remove a wireless device without a netdev then clear | |
2547 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2548 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2549 | * since the wdev has been freed, unlike with a netdev where | |
2550 | * we need the dev_put() for the netdev to really be freed. | |
2551 | */ | |
2552 | if (!wdev->netdev) | |
2553 | info->user_ptr[1] = NULL; | |
2554 | ||
e35e4d28 | 2555 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2556 | } |
2557 | ||
1d9d9213 SW |
2558 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2559 | { | |
2560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2561 | struct net_device *dev = info->user_ptr[1]; | |
2562 | u16 noack_map; | |
2563 | ||
2564 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2565 | return -EINVAL; | |
2566 | ||
2567 | if (!rdev->ops->set_noack_map) | |
2568 | return -EOPNOTSUPP; | |
2569 | ||
2570 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2571 | ||
e35e4d28 | 2572 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2573 | } |
2574 | ||
41ade00f JB |
2575 | struct get_key_cookie { |
2576 | struct sk_buff *msg; | |
2577 | int error; | |
b9454e83 | 2578 | int idx; |
41ade00f JB |
2579 | }; |
2580 | ||
2581 | static void get_key_callback(void *c, struct key_params *params) | |
2582 | { | |
b9454e83 | 2583 | struct nlattr *key; |
41ade00f JB |
2584 | struct get_key_cookie *cookie = c; |
2585 | ||
9360ffd1 DM |
2586 | if ((params->key && |
2587 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2588 | params->key_len, params->key)) || | |
2589 | (params->seq && | |
2590 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2591 | params->seq_len, params->seq)) || | |
2592 | (params->cipher && | |
2593 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2594 | params->cipher))) | |
2595 | goto nla_put_failure; | |
41ade00f | 2596 | |
b9454e83 JB |
2597 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2598 | if (!key) | |
2599 | goto nla_put_failure; | |
2600 | ||
9360ffd1 DM |
2601 | if ((params->key && |
2602 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2603 | params->key_len, params->key)) || | |
2604 | (params->seq && | |
2605 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2606 | params->seq_len, params->seq)) || | |
2607 | (params->cipher && | |
2608 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2609 | params->cipher))) | |
2610 | goto nla_put_failure; | |
b9454e83 | 2611 | |
9360ffd1 DM |
2612 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2613 | goto nla_put_failure; | |
b9454e83 JB |
2614 | |
2615 | nla_nest_end(cookie->msg, key); | |
2616 | ||
41ade00f JB |
2617 | return; |
2618 | nla_put_failure: | |
2619 | cookie->error = 1; | |
2620 | } | |
2621 | ||
2622 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2623 | { | |
4c476991 | 2624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2625 | int err; |
4c476991 | 2626 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2627 | u8 key_idx = 0; |
e31b8213 JB |
2628 | const u8 *mac_addr = NULL; |
2629 | bool pairwise; | |
41ade00f JB |
2630 | struct get_key_cookie cookie = { |
2631 | .error = 0, | |
2632 | }; | |
2633 | void *hdr; | |
2634 | struct sk_buff *msg; | |
2635 | ||
2636 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2637 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2638 | ||
3cfcf6ac | 2639 | if (key_idx > 5) |
41ade00f JB |
2640 | return -EINVAL; |
2641 | ||
2642 | if (info->attrs[NL80211_ATTR_MAC]) | |
2643 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2644 | ||
e31b8213 JB |
2645 | pairwise = !!mac_addr; |
2646 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2647 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2648 | if (kt >= NUM_NL80211_KEYTYPES) | |
2649 | return -EINVAL; | |
2650 | if (kt != NL80211_KEYTYPE_GROUP && | |
2651 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2652 | return -EINVAL; | |
2653 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2654 | } | |
2655 | ||
4c476991 JB |
2656 | if (!rdev->ops->get_key) |
2657 | return -EOPNOTSUPP; | |
41ade00f | 2658 | |
fd2120ca | 2659 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2660 | if (!msg) |
2661 | return -ENOMEM; | |
41ade00f | 2662 | |
15e47304 | 2663 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2664 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2665 | if (IS_ERR(hdr)) |
2666 | return PTR_ERR(hdr); | |
41ade00f JB |
2667 | |
2668 | cookie.msg = msg; | |
b9454e83 | 2669 | cookie.idx = key_idx; |
41ade00f | 2670 | |
9360ffd1 DM |
2671 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2672 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2673 | goto nla_put_failure; | |
2674 | if (mac_addr && | |
2675 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2676 | goto nla_put_failure; | |
41ade00f | 2677 | |
e31b8213 JB |
2678 | if (pairwise && mac_addr && |
2679 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2680 | return -ENOENT; | |
2681 | ||
e35e4d28 HG |
2682 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2683 | get_key_callback); | |
41ade00f JB |
2684 | |
2685 | if (err) | |
6c95e2a2 | 2686 | goto free_msg; |
41ade00f JB |
2687 | |
2688 | if (cookie.error) | |
2689 | goto nla_put_failure; | |
2690 | ||
2691 | genlmsg_end(msg, hdr); | |
4c476991 | 2692 | return genlmsg_reply(msg, info); |
41ade00f JB |
2693 | |
2694 | nla_put_failure: | |
2695 | err = -ENOBUFS; | |
6c95e2a2 | 2696 | free_msg: |
41ade00f | 2697 | nlmsg_free(msg); |
41ade00f JB |
2698 | return err; |
2699 | } | |
2700 | ||
2701 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2702 | { | |
4c476991 | 2703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2704 | struct key_parse key; |
41ade00f | 2705 | int err; |
4c476991 | 2706 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2707 | |
b9454e83 JB |
2708 | err = nl80211_parse_key(info, &key); |
2709 | if (err) | |
2710 | return err; | |
41ade00f | 2711 | |
b9454e83 | 2712 | if (key.idx < 0) |
41ade00f JB |
2713 | return -EINVAL; |
2714 | ||
b9454e83 JB |
2715 | /* only support setting default key */ |
2716 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2717 | return -EINVAL; |
2718 | ||
dbd2fd65 | 2719 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2720 | |
dbd2fd65 JB |
2721 | if (key.def) { |
2722 | if (!rdev->ops->set_default_key) { | |
2723 | err = -EOPNOTSUPP; | |
2724 | goto out; | |
2725 | } | |
41ade00f | 2726 | |
dbd2fd65 JB |
2727 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2728 | if (err) | |
2729 | goto out; | |
2730 | ||
e35e4d28 | 2731 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2732 | key.def_uni, key.def_multi); |
2733 | ||
2734 | if (err) | |
2735 | goto out; | |
fffd0934 | 2736 | |
3d23e349 | 2737 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2738 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2739 | #endif | |
2740 | } else { | |
2741 | if (key.def_uni || !key.def_multi) { | |
2742 | err = -EINVAL; | |
2743 | goto out; | |
2744 | } | |
2745 | ||
2746 | if (!rdev->ops->set_default_mgmt_key) { | |
2747 | err = -EOPNOTSUPP; | |
2748 | goto out; | |
2749 | } | |
2750 | ||
2751 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2752 | if (err) | |
2753 | goto out; | |
2754 | ||
e35e4d28 | 2755 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2756 | if (err) |
2757 | goto out; | |
2758 | ||
2759 | #ifdef CONFIG_CFG80211_WEXT | |
2760 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2761 | #endif |
dbd2fd65 JB |
2762 | } |
2763 | ||
2764 | out: | |
fffd0934 | 2765 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2766 | |
41ade00f JB |
2767 | return err; |
2768 | } | |
2769 | ||
2770 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2771 | { | |
4c476991 | 2772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2773 | int err; |
4c476991 | 2774 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2775 | struct key_parse key; |
e31b8213 | 2776 | const u8 *mac_addr = NULL; |
41ade00f | 2777 | |
b9454e83 JB |
2778 | err = nl80211_parse_key(info, &key); |
2779 | if (err) | |
2780 | return err; | |
41ade00f | 2781 | |
b9454e83 | 2782 | if (!key.p.key) |
41ade00f JB |
2783 | return -EINVAL; |
2784 | ||
41ade00f JB |
2785 | if (info->attrs[NL80211_ATTR_MAC]) |
2786 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2787 | ||
e31b8213 JB |
2788 | if (key.type == -1) { |
2789 | if (mac_addr) | |
2790 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2791 | else | |
2792 | key.type = NL80211_KEYTYPE_GROUP; | |
2793 | } | |
2794 | ||
2795 | /* for now */ | |
2796 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2797 | key.type != NL80211_KEYTYPE_GROUP) | |
2798 | return -EINVAL; | |
2799 | ||
4c476991 JB |
2800 | if (!rdev->ops->add_key) |
2801 | return -EOPNOTSUPP; | |
25e47c18 | 2802 | |
e31b8213 JB |
2803 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2804 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2805 | mac_addr)) | |
4c476991 | 2806 | return -EINVAL; |
41ade00f | 2807 | |
fffd0934 JB |
2808 | wdev_lock(dev->ieee80211_ptr); |
2809 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2810 | if (!err) | |
e35e4d28 HG |
2811 | err = rdev_add_key(rdev, dev, key.idx, |
2812 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2813 | mac_addr, &key.p); | |
fffd0934 | 2814 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2815 | |
41ade00f JB |
2816 | return err; |
2817 | } | |
2818 | ||
2819 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2820 | { | |
4c476991 | 2821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2822 | int err; |
4c476991 | 2823 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2824 | u8 *mac_addr = NULL; |
b9454e83 | 2825 | struct key_parse key; |
41ade00f | 2826 | |
b9454e83 JB |
2827 | err = nl80211_parse_key(info, &key); |
2828 | if (err) | |
2829 | return err; | |
41ade00f JB |
2830 | |
2831 | if (info->attrs[NL80211_ATTR_MAC]) | |
2832 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2833 | ||
e31b8213 JB |
2834 | if (key.type == -1) { |
2835 | if (mac_addr) | |
2836 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2837 | else | |
2838 | key.type = NL80211_KEYTYPE_GROUP; | |
2839 | } | |
2840 | ||
2841 | /* for now */ | |
2842 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2843 | key.type != NL80211_KEYTYPE_GROUP) | |
2844 | return -EINVAL; | |
2845 | ||
4c476991 JB |
2846 | if (!rdev->ops->del_key) |
2847 | return -EOPNOTSUPP; | |
41ade00f | 2848 | |
fffd0934 JB |
2849 | wdev_lock(dev->ieee80211_ptr); |
2850 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2851 | |
2852 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2853 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2854 | err = -ENOENT; | |
2855 | ||
fffd0934 | 2856 | if (!err) |
e35e4d28 HG |
2857 | err = rdev_del_key(rdev, dev, key.idx, |
2858 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2859 | mac_addr); | |
41ade00f | 2860 | |
3d23e349 | 2861 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2862 | if (!err) { |
b9454e83 | 2863 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2864 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2865 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2866 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2867 | } | |
2868 | #endif | |
fffd0934 | 2869 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2870 | |
41ade00f JB |
2871 | return err; |
2872 | } | |
2873 | ||
77765eaf VT |
2874 | /* This function returns an error or the number of nested attributes */ |
2875 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2876 | { | |
2877 | struct nlattr *attr; | |
2878 | int n_entries = 0, tmp; | |
2879 | ||
2880 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2881 | if (nla_len(attr) != ETH_ALEN) | |
2882 | return -EINVAL; | |
2883 | ||
2884 | n_entries++; | |
2885 | } | |
2886 | ||
2887 | return n_entries; | |
2888 | } | |
2889 | ||
2890 | /* | |
2891 | * This function parses ACL information and allocates memory for ACL data. | |
2892 | * On successful return, the calling function is responsible to free the | |
2893 | * ACL buffer returned by this function. | |
2894 | */ | |
2895 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2896 | struct genl_info *info) | |
2897 | { | |
2898 | enum nl80211_acl_policy acl_policy; | |
2899 | struct nlattr *attr; | |
2900 | struct cfg80211_acl_data *acl; | |
2901 | int i = 0, n_entries, tmp; | |
2902 | ||
2903 | if (!wiphy->max_acl_mac_addrs) | |
2904 | return ERR_PTR(-EOPNOTSUPP); | |
2905 | ||
2906 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2907 | return ERR_PTR(-EINVAL); | |
2908 | ||
2909 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2910 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2911 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2912 | return ERR_PTR(-EINVAL); | |
2913 | ||
2914 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2915 | return ERR_PTR(-EINVAL); | |
2916 | ||
2917 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2918 | if (n_entries < 0) | |
2919 | return ERR_PTR(n_entries); | |
2920 | ||
2921 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2922 | return ERR_PTR(-ENOTSUPP); | |
2923 | ||
2924 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2925 | GFP_KERNEL); | |
2926 | if (!acl) | |
2927 | return ERR_PTR(-ENOMEM); | |
2928 | ||
2929 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2930 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2931 | i++; | |
2932 | } | |
2933 | ||
2934 | acl->n_acl_entries = n_entries; | |
2935 | acl->acl_policy = acl_policy; | |
2936 | ||
2937 | return acl; | |
2938 | } | |
2939 | ||
2940 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2941 | { | |
2942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2943 | struct net_device *dev = info->user_ptr[1]; | |
2944 | struct cfg80211_acl_data *acl; | |
2945 | int err; | |
2946 | ||
2947 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2948 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2949 | return -EOPNOTSUPP; | |
2950 | ||
2951 | if (!dev->ieee80211_ptr->beacon_interval) | |
2952 | return -EINVAL; | |
2953 | ||
2954 | acl = parse_acl_data(&rdev->wiphy, info); | |
2955 | if (IS_ERR(acl)) | |
2956 | return PTR_ERR(acl); | |
2957 | ||
2958 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2959 | ||
2960 | kfree(acl); | |
2961 | ||
2962 | return err; | |
2963 | } | |
2964 | ||
a1193be8 | 2965 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 2966 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 2967 | { |
8860020e | 2968 | bool haveinfo = false; |
ed1b6cc7 | 2969 | |
a1193be8 SW |
2970 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
2971 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
2972 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2973 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2974 | return -EINVAL; |
2975 | ||
8860020e | 2976 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2977 | |
a1193be8 SW |
2978 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
2979 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
2980 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
2981 | if (!bcn->head_len) |
2982 | return -EINVAL; | |
2983 | haveinfo = true; | |
ed1b6cc7 JB |
2984 | } |
2985 | ||
a1193be8 SW |
2986 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
2987 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
2988 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 2989 | haveinfo = true; |
ed1b6cc7 JB |
2990 | } |
2991 | ||
4c476991 JB |
2992 | if (!haveinfo) |
2993 | return -EINVAL; | |
3b85875a | 2994 | |
a1193be8 SW |
2995 | if (attrs[NL80211_ATTR_IE]) { |
2996 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
2997 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2998 | } |
2999 | ||
a1193be8 | 3000 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3001 | bcn->proberesp_ies = |
a1193be8 | 3002 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3003 | bcn->proberesp_ies_len = |
a1193be8 | 3004 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3005 | } |
3006 | ||
a1193be8 | 3007 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3008 | bcn->assocresp_ies = |
a1193be8 | 3009 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3010 | bcn->assocresp_ies_len = |
a1193be8 | 3011 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3012 | } |
3013 | ||
a1193be8 SW |
3014 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3015 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3016 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3017 | } |
3018 | ||
8860020e JB |
3019 | return 0; |
3020 | } | |
3021 | ||
46c1dd0c FF |
3022 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3023 | struct cfg80211_ap_settings *params) | |
3024 | { | |
3025 | struct wireless_dev *wdev; | |
3026 | bool ret = false; | |
3027 | ||
89a54e48 | 3028 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3029 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3030 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3031 | continue; | |
3032 | ||
683b6d3b | 3033 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3034 | continue; |
3035 | ||
683b6d3b | 3036 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3037 | ret = true; |
3038 | break; | |
3039 | } | |
3040 | ||
46c1dd0c FF |
3041 | return ret; |
3042 | } | |
3043 | ||
e39e5b5e JM |
3044 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3045 | enum nl80211_auth_type auth_type, | |
3046 | enum nl80211_commands cmd) | |
3047 | { | |
3048 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3049 | return false; | |
3050 | ||
3051 | switch (cmd) { | |
3052 | case NL80211_CMD_AUTHENTICATE: | |
3053 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3054 | auth_type == NL80211_AUTHTYPE_SAE) | |
3055 | return false; | |
3056 | return true; | |
3057 | case NL80211_CMD_CONNECT: | |
3058 | case NL80211_CMD_START_AP: | |
3059 | /* SAE not supported yet */ | |
3060 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3061 | return false; | |
3062 | return true; | |
3063 | default: | |
3064 | return false; | |
3065 | } | |
3066 | } | |
3067 | ||
8860020e JB |
3068 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3069 | { | |
3070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3071 | struct net_device *dev = info->user_ptr[1]; | |
3072 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3073 | struct cfg80211_ap_settings params; | |
3074 | int err; | |
04f39047 | 3075 | u8 radar_detect_width = 0; |
8860020e JB |
3076 | |
3077 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3078 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3079 | return -EOPNOTSUPP; | |
3080 | ||
3081 | if (!rdev->ops->start_ap) | |
3082 | return -EOPNOTSUPP; | |
3083 | ||
3084 | if (wdev->beacon_interval) | |
3085 | return -EALREADY; | |
3086 | ||
3087 | memset(¶ms, 0, sizeof(params)); | |
3088 | ||
3089 | /* these are required for START_AP */ | |
3090 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3091 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3092 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3093 | return -EINVAL; | |
3094 | ||
a1193be8 | 3095 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3096 | if (err) |
3097 | return err; | |
3098 | ||
3099 | params.beacon_interval = | |
3100 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3101 | params.dtim_period = | |
3102 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3103 | ||
3104 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3105 | if (err) | |
3106 | return err; | |
3107 | ||
3108 | /* | |
3109 | * In theory, some of these attributes should be required here | |
3110 | * but since they were not used when the command was originally | |
3111 | * added, keep them optional for old user space programs to let | |
3112 | * them continue to work with drivers that do not need the | |
3113 | * additional information -- drivers must check! | |
3114 | */ | |
3115 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3116 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3117 | params.ssid_len = | |
3118 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3119 | if (params.ssid_len == 0 || | |
3120 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3121 | return -EINVAL; | |
3122 | } | |
3123 | ||
3124 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3125 | params.hidden_ssid = nla_get_u32( | |
3126 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3127 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3128 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3129 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3130 | return -EINVAL; | |
3131 | } | |
3132 | ||
3133 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3134 | ||
3135 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3136 | params.auth_type = nla_get_u32( | |
3137 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3138 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3139 | NL80211_CMD_START_AP)) | |
8860020e JB |
3140 | return -EINVAL; |
3141 | } else | |
3142 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3143 | ||
3144 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3145 | NL80211_MAX_NR_CIPHER_SUITES); | |
3146 | if (err) | |
3147 | return err; | |
3148 | ||
1b658f11 VT |
3149 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3150 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3151 | return -EOPNOTSUPP; | |
3152 | params.inactivity_timeout = nla_get_u16( | |
3153 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3154 | } | |
3155 | ||
53cabad7 JB |
3156 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3157 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3158 | return -EINVAL; | |
3159 | params.p2p_ctwindow = | |
3160 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3161 | if (params.p2p_ctwindow > 127) | |
3162 | return -EINVAL; | |
3163 | if (params.p2p_ctwindow != 0 && | |
3164 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3165 | return -EINVAL; | |
3166 | } | |
3167 | ||
3168 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3169 | u8 tmp; | |
3170 | ||
3171 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3172 | return -EINVAL; | |
3173 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3174 | if (tmp > 1) | |
3175 | return -EINVAL; | |
3176 | params.p2p_opp_ps = tmp; | |
3177 | if (params.p2p_opp_ps != 0 && | |
3178 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3179 | return -EINVAL; | |
3180 | } | |
3181 | ||
aa430da4 | 3182 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3183 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3184 | if (err) | |
3185 | return err; | |
3186 | } else if (wdev->preset_chandef.chan) { | |
3187 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3188 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3189 | return -EINVAL; |
3190 | ||
683b6d3b | 3191 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3192 | return -EINVAL; |
3193 | ||
04f39047 SW |
3194 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3195 | if (err < 0) | |
3196 | return err; | |
3197 | if (err) { | |
3198 | radar_detect_width = BIT(params.chandef.width); | |
3199 | params.radar_required = true; | |
3200 | } | |
3201 | ||
04f39047 SW |
3202 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3203 | params.chandef.chan, | |
3204 | CHAN_MODE_SHARED, | |
3205 | radar_detect_width); | |
e4e32459 MK |
3206 | if (err) |
3207 | return err; | |
3208 | ||
77765eaf VT |
3209 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3210 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3211 | if (IS_ERR(params.acl)) | |
3212 | return PTR_ERR(params.acl); | |
3213 | } | |
3214 | ||
e35e4d28 | 3215 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3216 | if (!err) { |
683b6d3b | 3217 | wdev->preset_chandef = params.chandef; |
8860020e | 3218 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3219 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3220 | wdev->ssid_len = params.ssid_len; |
3221 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3222 | } |
77765eaf VT |
3223 | |
3224 | kfree(params.acl); | |
3225 | ||
56d1893d | 3226 | return err; |
ed1b6cc7 JB |
3227 | } |
3228 | ||
8860020e JB |
3229 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3230 | { | |
3231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3232 | struct net_device *dev = info->user_ptr[1]; | |
3233 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3234 | struct cfg80211_beacon_data params; | |
3235 | int err; | |
3236 | ||
3237 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3238 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3239 | return -EOPNOTSUPP; | |
3240 | ||
3241 | if (!rdev->ops->change_beacon) | |
3242 | return -EOPNOTSUPP; | |
3243 | ||
3244 | if (!wdev->beacon_interval) | |
3245 | return -EINVAL; | |
3246 | ||
a1193be8 | 3247 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3248 | if (err) |
3249 | return err; | |
3250 | ||
e35e4d28 | 3251 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3252 | } |
3253 | ||
3254 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3255 | { |
4c476991 JB |
3256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3257 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3258 | |
60771780 | 3259 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3260 | } |
3261 | ||
5727ef1b JB |
3262 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3263 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3264 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3265 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3266 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3267 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3268 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3269 | }; |
3270 | ||
eccb8e8f | 3271 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3272 | enum nl80211_iftype iftype, |
eccb8e8f | 3273 | struct station_parameters *params) |
5727ef1b JB |
3274 | { |
3275 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3276 | struct nlattr *nla; |
5727ef1b JB |
3277 | int flag; |
3278 | ||
eccb8e8f JB |
3279 | /* |
3280 | * Try parsing the new attribute first so userspace | |
3281 | * can specify both for older kernels. | |
3282 | */ | |
3283 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3284 | if (nla) { | |
3285 | struct nl80211_sta_flag_update *sta_flags; | |
3286 | ||
3287 | sta_flags = nla_data(nla); | |
3288 | params->sta_flags_mask = sta_flags->mask; | |
3289 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3290 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3291 | if ((params->sta_flags_mask | |
3292 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3293 | return -EINVAL; | |
3294 | return 0; | |
3295 | } | |
3296 | ||
3297 | /* if present, parse the old attribute */ | |
5727ef1b | 3298 | |
eccb8e8f | 3299 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3300 | if (!nla) |
3301 | return 0; | |
3302 | ||
3303 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3304 | nla, sta_flags_policy)) | |
3305 | return -EINVAL; | |
3306 | ||
bdd3ae3d JB |
3307 | /* |
3308 | * Only allow certain flags for interface types so that | |
3309 | * other attributes are silently ignored. Remember that | |
3310 | * this is backward compatibility code with old userspace | |
3311 | * and shouldn't be hit in other cases anyway. | |
3312 | */ | |
3313 | switch (iftype) { | |
3314 | case NL80211_IFTYPE_AP: | |
3315 | case NL80211_IFTYPE_AP_VLAN: | |
3316 | case NL80211_IFTYPE_P2P_GO: | |
3317 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3318 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3319 | BIT(NL80211_STA_FLAG_WME) | | |
3320 | BIT(NL80211_STA_FLAG_MFP); | |
3321 | break; | |
3322 | case NL80211_IFTYPE_P2P_CLIENT: | |
3323 | case NL80211_IFTYPE_STATION: | |
3324 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3325 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3326 | break; | |
3327 | case NL80211_IFTYPE_MESH_POINT: | |
3328 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3329 | BIT(NL80211_STA_FLAG_MFP) | | |
3330 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3331 | default: | |
3332 | return -EINVAL; | |
3333 | } | |
5727ef1b | 3334 | |
3383b5a6 JB |
3335 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3336 | if (flags[flag]) { | |
eccb8e8f | 3337 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3338 | |
3383b5a6 JB |
3339 | /* no longer support new API additions in old API */ |
3340 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3341 | return -EINVAL; | |
3342 | } | |
3343 | } | |
3344 | ||
5727ef1b JB |
3345 | return 0; |
3346 | } | |
3347 | ||
c8dcfd8a FF |
3348 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3349 | int attr) | |
3350 | { | |
3351 | struct nlattr *rate; | |
8eb41c8d VK |
3352 | u32 bitrate; |
3353 | u16 bitrate_compat; | |
c8dcfd8a FF |
3354 | |
3355 | rate = nla_nest_start(msg, attr); | |
3356 | if (!rate) | |
db9c64cf | 3357 | return false; |
c8dcfd8a FF |
3358 | |
3359 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3360 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3361 | /* report 16-bit bitrate only if we can */ |
3362 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3363 | if (bitrate > 0 && |
3364 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3365 | return false; | |
3366 | if (bitrate_compat > 0 && | |
3367 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3368 | return false; | |
3369 | ||
3370 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3371 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3372 | return false; | |
3373 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3374 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3375 | return false; | |
3376 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3377 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3378 | return false; | |
3379 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3380 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3381 | return false; | |
3382 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3383 | return false; | |
3384 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3385 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3386 | return false; | |
3387 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3388 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3389 | return false; | |
3390 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3391 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3392 | return false; | |
3393 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3394 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3395 | return false; | |
3396 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3397 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3398 | return false; | |
3399 | } | |
c8dcfd8a FF |
3400 | |
3401 | nla_nest_end(msg, rate); | |
3402 | return true; | |
c8dcfd8a FF |
3403 | } |
3404 | ||
119363c7 FF |
3405 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3406 | int id) | |
3407 | { | |
3408 | void *attr; | |
3409 | int i = 0; | |
3410 | ||
3411 | if (!mask) | |
3412 | return true; | |
3413 | ||
3414 | attr = nla_nest_start(msg, id); | |
3415 | if (!attr) | |
3416 | return false; | |
3417 | ||
3418 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3419 | if (!(mask & BIT(i))) | |
3420 | continue; | |
3421 | ||
3422 | if (nla_put_u8(msg, i, signal[i])) | |
3423 | return false; | |
3424 | } | |
3425 | ||
3426 | nla_nest_end(msg, attr); | |
3427 | ||
3428 | return true; | |
3429 | } | |
3430 | ||
15e47304 | 3431 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3432 | int flags, |
3433 | struct cfg80211_registered_device *rdev, | |
3434 | struct net_device *dev, | |
98b62183 | 3435 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3436 | { |
3437 | void *hdr; | |
f4263c98 | 3438 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3439 | |
15e47304 | 3440 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3441 | if (!hdr) |
3442 | return -1; | |
3443 | ||
9360ffd1 DM |
3444 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3445 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3446 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3447 | goto nla_put_failure; | |
f5ea9120 | 3448 | |
2ec600d6 LCC |
3449 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3450 | if (!sinfoattr) | |
fd5b74dc | 3451 | goto nla_put_failure; |
9360ffd1 DM |
3452 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3453 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3454 | sinfo->connected_time)) | |
3455 | goto nla_put_failure; | |
3456 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3457 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3458 | sinfo->inactive_time)) | |
3459 | goto nla_put_failure; | |
42745e03 VK |
3460 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3461 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3462 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3463 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3464 | goto nla_put_failure; |
42745e03 | 3465 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3466 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3467 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3468 | (u32)sinfo->tx_bytes)) |
3469 | goto nla_put_failure; | |
3470 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3471 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3472 | sinfo->rx_bytes)) | |
3473 | goto nla_put_failure; | |
3474 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3475 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3476 | sinfo->tx_bytes)) |
3477 | goto nla_put_failure; | |
3478 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3479 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3480 | goto nla_put_failure; | |
3481 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3482 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3483 | goto nla_put_failure; | |
3484 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3485 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3486 | sinfo->plink_state)) | |
3487 | goto nla_put_failure; | |
66266b3a JL |
3488 | switch (rdev->wiphy.signal_type) { |
3489 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3490 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3491 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3492 | sinfo->signal)) | |
3493 | goto nla_put_failure; | |
3494 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3495 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3496 | sinfo->signal_avg)) | |
3497 | goto nla_put_failure; | |
66266b3a JL |
3498 | break; |
3499 | default: | |
3500 | break; | |
3501 | } | |
119363c7 FF |
3502 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3503 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3504 | sinfo->chain_signal, | |
3505 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3506 | goto nla_put_failure; | |
3507 | } | |
3508 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3509 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3510 | sinfo->chain_signal_avg, | |
3511 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3512 | goto nla_put_failure; | |
3513 | } | |
420e7fab | 3514 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3515 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3516 | NL80211_STA_INFO_TX_BITRATE)) | |
3517 | goto nla_put_failure; | |
3518 | } | |
3519 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3520 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3521 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3522 | goto nla_put_failure; |
420e7fab | 3523 | } |
9360ffd1 DM |
3524 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3525 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3526 | sinfo->rx_packets)) | |
3527 | goto nla_put_failure; | |
3528 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3529 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3530 | sinfo->tx_packets)) | |
3531 | goto nla_put_failure; | |
3532 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3533 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3534 | sinfo->tx_retries)) | |
3535 | goto nla_put_failure; | |
3536 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3537 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3538 | sinfo->tx_failed)) | |
3539 | goto nla_put_failure; | |
3540 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3541 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3542 | sinfo->beacon_loss_count)) | |
3543 | goto nla_put_failure; | |
3b1c5a53 MP |
3544 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3545 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3546 | sinfo->local_pm)) | |
3547 | goto nla_put_failure; | |
3548 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3549 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3550 | sinfo->peer_pm)) | |
3551 | goto nla_put_failure; | |
3552 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3553 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3554 | sinfo->nonpeer_pm)) | |
3555 | goto nla_put_failure; | |
f4263c98 PS |
3556 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3557 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3558 | if (!bss_param) | |
3559 | goto nla_put_failure; | |
3560 | ||
9360ffd1 DM |
3561 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3562 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3563 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3564 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3565 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3566 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3567 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3568 | sinfo->bss_param.dtim_period) || | |
3569 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3570 | sinfo->bss_param.beacon_interval)) | |
3571 | goto nla_put_failure; | |
f4263c98 PS |
3572 | |
3573 | nla_nest_end(msg, bss_param); | |
3574 | } | |
9360ffd1 DM |
3575 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3576 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3577 | sizeof(struct nl80211_sta_flag_update), | |
3578 | &sinfo->sta_flags)) | |
3579 | goto nla_put_failure; | |
7eab0f64 JL |
3580 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3581 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3582 | sinfo->t_offset)) | |
3583 | goto nla_put_failure; | |
2ec600d6 | 3584 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3585 | |
9360ffd1 DM |
3586 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3587 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3588 | sinfo->assoc_req_ies)) | |
3589 | goto nla_put_failure; | |
50d3dfb7 | 3590 | |
fd5b74dc JB |
3591 | return genlmsg_end(msg, hdr); |
3592 | ||
3593 | nla_put_failure: | |
bc3ed28c TG |
3594 | genlmsg_cancel(msg, hdr); |
3595 | return -EMSGSIZE; | |
fd5b74dc JB |
3596 | } |
3597 | ||
2ec600d6 | 3598 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3599 | struct netlink_callback *cb) |
2ec600d6 | 3600 | { |
2ec600d6 LCC |
3601 | struct station_info sinfo; |
3602 | struct cfg80211_registered_device *dev; | |
97990a06 | 3603 | struct wireless_dev *wdev; |
2ec600d6 | 3604 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3605 | int sta_idx = cb->args[2]; |
2ec600d6 | 3606 | int err; |
2ec600d6 | 3607 | |
97990a06 | 3608 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3609 | if (err) |
3610 | return err; | |
bba95fef | 3611 | |
97990a06 JB |
3612 | if (!wdev->netdev) { |
3613 | err = -EINVAL; | |
3614 | goto out_err; | |
3615 | } | |
3616 | ||
bba95fef | 3617 | if (!dev->ops->dump_station) { |
eec60b03 | 3618 | err = -EOPNOTSUPP; |
bba95fef JB |
3619 | goto out_err; |
3620 | } | |
3621 | ||
bba95fef | 3622 | while (1) { |
f612cedf | 3623 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3624 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3625 | mac_addr, &sinfo); |
bba95fef JB |
3626 | if (err == -ENOENT) |
3627 | break; | |
3628 | if (err) | |
3b85875a | 3629 | goto out_err; |
bba95fef JB |
3630 | |
3631 | if (nl80211_send_station(skb, | |
15e47304 | 3632 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3633 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3634 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3635 | &sinfo) < 0) |
3636 | goto out; | |
3637 | ||
3638 | sta_idx++; | |
3639 | } | |
3640 | ||
3641 | ||
3642 | out: | |
97990a06 | 3643 | cb->args[2] = sta_idx; |
bba95fef | 3644 | err = skb->len; |
bba95fef | 3645 | out_err: |
97990a06 | 3646 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3647 | |
3648 | return err; | |
2ec600d6 | 3649 | } |
fd5b74dc | 3650 | |
5727ef1b JB |
3651 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3652 | { | |
4c476991 JB |
3653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3654 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3655 | struct station_info sinfo; |
fd5b74dc JB |
3656 | struct sk_buff *msg; |
3657 | u8 *mac_addr = NULL; | |
4c476991 | 3658 | int err; |
fd5b74dc | 3659 | |
2ec600d6 | 3660 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3661 | |
3662 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3663 | return -EINVAL; | |
3664 | ||
3665 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3666 | ||
4c476991 JB |
3667 | if (!rdev->ops->get_station) |
3668 | return -EOPNOTSUPP; | |
3b85875a | 3669 | |
e35e4d28 | 3670 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3671 | if (err) |
4c476991 | 3672 | return err; |
2ec600d6 | 3673 | |
fd2120ca | 3674 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3675 | if (!msg) |
4c476991 | 3676 | return -ENOMEM; |
fd5b74dc | 3677 | |
15e47304 | 3678 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3679 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3680 | nlmsg_free(msg); |
3681 | return -ENOBUFS; | |
3682 | } | |
3b85875a | 3683 | |
4c476991 | 3684 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3685 | } |
3686 | ||
77ee7c89 JB |
3687 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3688 | struct station_parameters *params, | |
3689 | enum cfg80211_station_type statype) | |
3690 | { | |
3691 | if (params->listen_interval != -1) | |
3692 | return -EINVAL; | |
3693 | if (params->aid) | |
3694 | return -EINVAL; | |
3695 | ||
3696 | /* When you run into this, adjust the code below for the new flag */ | |
3697 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3698 | ||
3699 | switch (statype) { | |
eef941e6 TP |
3700 | case CFG80211_STA_MESH_PEER_KERNEL: |
3701 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3702 | /* |
3703 | * No ignoring the TDLS flag here -- the userspace mesh | |
3704 | * code doesn't have the bug of including TDLS in the | |
3705 | * mask everywhere. | |
3706 | */ | |
3707 | if (params->sta_flags_mask & | |
3708 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3709 | BIT(NL80211_STA_FLAG_MFP) | | |
3710 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3711 | return -EINVAL; | |
3712 | break; | |
3713 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3714 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3715 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3716 | return -EINVAL; | |
3717 | /* ignore since it can't change */ | |
3718 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3719 | break; | |
3720 | default: | |
3721 | /* disallow mesh-specific things */ | |
3722 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3723 | return -EINVAL; | |
3724 | if (params->local_pm) | |
3725 | return -EINVAL; | |
3726 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3727 | return -EINVAL; | |
3728 | } | |
3729 | ||
3730 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3731 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3732 | /* TDLS can't be set, ... */ | |
3733 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3734 | return -EINVAL; | |
3735 | /* | |
3736 | * ... but don't bother the driver with it. This works around | |
3737 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3738 | * TLDS_PEER flag in the mask even for AP mode. | |
3739 | */ | |
3740 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3741 | } | |
3742 | ||
3743 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3744 | /* reject other things that can't change */ | |
3745 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3746 | return -EINVAL; | |
3747 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3748 | return -EINVAL; | |
3749 | if (params->supported_rates) | |
3750 | return -EINVAL; | |
3751 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3752 | return -EINVAL; | |
3753 | } | |
3754 | ||
3755 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3756 | if (params->vlan) | |
3757 | return -EINVAL; | |
3758 | } | |
3759 | ||
3760 | switch (statype) { | |
3761 | case CFG80211_STA_AP_MLME_CLIENT: | |
3762 | /* Use this only for authorizing/unauthorizing a station */ | |
3763 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3764 | return -EOPNOTSUPP; | |
3765 | break; | |
3766 | case CFG80211_STA_AP_CLIENT: | |
3767 | /* accept only the listed bits */ | |
3768 | if (params->sta_flags_mask & | |
3769 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3770 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3771 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3772 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3773 | BIT(NL80211_STA_FLAG_WME) | | |
3774 | BIT(NL80211_STA_FLAG_MFP))) | |
3775 | return -EINVAL; | |
3776 | ||
3777 | /* but authenticated/associated only if driver handles it */ | |
3778 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3779 | params->sta_flags_mask & | |
3780 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3781 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3782 | return -EINVAL; | |
3783 | break; | |
3784 | case CFG80211_STA_IBSS: | |
3785 | case CFG80211_STA_AP_STA: | |
3786 | /* reject any changes other than AUTHORIZED */ | |
3787 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3788 | return -EINVAL; | |
3789 | break; | |
3790 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3791 | /* reject any changes other than AUTHORIZED or WME */ | |
3792 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3793 | BIT(NL80211_STA_FLAG_WME))) | |
3794 | return -EINVAL; | |
3795 | /* force (at least) rates when authorizing */ | |
3796 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3797 | !params->supported_rates) | |
3798 | return -EINVAL; | |
3799 | break; | |
3800 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3801 | /* reject any changes */ | |
3802 | return -EINVAL; | |
eef941e6 | 3803 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3804 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3805 | return -EINVAL; | |
3806 | break; | |
eef941e6 | 3807 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3808 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3809 | return -EINVAL; | |
3810 | break; | |
3811 | } | |
3812 | ||
3813 | return 0; | |
3814 | } | |
3815 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3816 | ||
5727ef1b | 3817 | /* |
c258d2de | 3818 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3819 | */ |
80b99899 JB |
3820 | static struct net_device *get_vlan(struct genl_info *info, |
3821 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3822 | { |
463d0183 | 3823 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3824 | struct net_device *v; |
3825 | int ret; | |
3826 | ||
3827 | if (!vlanattr) | |
3828 | return NULL; | |
3829 | ||
3830 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3831 | if (!v) | |
3832 | return ERR_PTR(-ENODEV); | |
3833 | ||
3834 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3835 | ret = -EINVAL; | |
3836 | goto error; | |
5727ef1b | 3837 | } |
80b99899 | 3838 | |
77ee7c89 JB |
3839 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3840 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3841 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3842 | ret = -EINVAL; | |
3843 | goto error; | |
3844 | } | |
3845 | ||
80b99899 JB |
3846 | if (!netif_running(v)) { |
3847 | ret = -ENETDOWN; | |
3848 | goto error; | |
3849 | } | |
3850 | ||
3851 | return v; | |
3852 | error: | |
3853 | dev_put(v); | |
3854 | return ERR_PTR(ret); | |
5727ef1b JB |
3855 | } |
3856 | ||
df881293 JM |
3857 | static struct nla_policy |
3858 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3859 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3860 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3861 | }; | |
3862 | ||
ff276691 JB |
3863 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3864 | struct station_parameters *params) | |
df881293 | 3865 | { |
df881293 JM |
3866 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3867 | struct nlattr *nla; | |
3868 | int err; | |
3869 | ||
df881293 JM |
3870 | /* parse WME attributes if present */ |
3871 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3872 | return 0; | |
3873 | ||
3874 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3875 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3876 | nl80211_sta_wme_policy); | |
3877 | if (err) | |
3878 | return err; | |
3879 | ||
3880 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3881 | params->uapsd_queues = nla_get_u8( | |
3882 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3883 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3884 | return -EINVAL; | |
3885 | ||
3886 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3887 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3888 | ||
3889 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3890 | return -EINVAL; | |
3891 | ||
3892 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3893 | ||
3894 | return 0; | |
3895 | } | |
3896 | ||
ff276691 JB |
3897 | static int nl80211_set_station_tdls(struct genl_info *info, |
3898 | struct station_parameters *params) | |
3899 | { | |
3900 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
5e4b6f56 JM |
3901 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
3902 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
3903 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3904 | params->ht_capa = | |
3905 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3906 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3907 | params->vht_capa = | |
3908 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3909 | ||
3910 | return nl80211_parse_sta_wme(info, params); | |
3911 | } | |
3912 | ||
5727ef1b JB |
3913 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3914 | { | |
4c476991 | 3915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3916 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3917 | struct station_parameters params; |
77ee7c89 JB |
3918 | u8 *mac_addr; |
3919 | int err; | |
5727ef1b JB |
3920 | |
3921 | memset(¶ms, 0, sizeof(params)); | |
3922 | ||
3923 | params.listen_interval = -1; | |
3924 | ||
77ee7c89 JB |
3925 | if (!rdev->ops->change_station) |
3926 | return -EOPNOTSUPP; | |
3927 | ||
5727ef1b JB |
3928 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3929 | return -EINVAL; | |
3930 | ||
3931 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3932 | return -EINVAL; | |
3933 | ||
3934 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3935 | ||
3936 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3937 | params.supported_rates = | |
3938 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3939 | params.supported_rates_len = | |
3940 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3941 | } | |
3942 | ||
9d62a986 JM |
3943 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3944 | params.capability = | |
3945 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3946 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3947 | } | |
3948 | ||
3949 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3950 | params.ext_capab = | |
3951 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3952 | params.ext_capab_len = | |
3953 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3954 | } | |
3955 | ||
df881293 | 3956 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3957 | return -EINVAL; |
36aedc90 | 3958 | |
bdd3ae3d | 3959 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3960 | return -EINVAL; |
3961 | ||
f8bacc21 | 3962 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3963 | params.plink_action = |
f8bacc21 JB |
3964 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3965 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3966 | return -EINVAL; | |
3967 | } | |
2ec600d6 | 3968 | |
f8bacc21 | 3969 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3970 | params.plink_state = |
f8bacc21 JB |
3971 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3972 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3973 | return -EINVAL; | |
3974 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3975 | } | |
9c3990aa | 3976 | |
3b1c5a53 MP |
3977 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3978 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3979 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3980 | ||
3981 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3982 | pm > NL80211_MESH_POWER_MAX) | |
3983 | return -EINVAL; | |
3984 | ||
3985 | params.local_pm = pm; | |
3986 | } | |
3987 | ||
77ee7c89 JB |
3988 | /* Include parameters for TDLS peer (will check later) */ |
3989 | err = nl80211_set_station_tdls(info, ¶ms); | |
3990 | if (err) | |
3991 | return err; | |
3992 | ||
3993 | params.vlan = get_vlan(info, rdev); | |
3994 | if (IS_ERR(params.vlan)) | |
3995 | return PTR_ERR(params.vlan); | |
3996 | ||
a97f4424 JB |
3997 | switch (dev->ieee80211_ptr->iftype) { |
3998 | case NL80211_IFTYPE_AP: | |
3999 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4000 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4001 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4002 | case NL80211_IFTYPE_STATION: |
267335d6 | 4003 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4004 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4005 | break; |
4006 | default: | |
77ee7c89 JB |
4007 | err = -EOPNOTSUPP; |
4008 | goto out_put_vlan; | |
034d655e JB |
4009 | } |
4010 | ||
77ee7c89 | 4011 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4012 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4013 | |
77ee7c89 | 4014 | out_put_vlan: |
5727ef1b JB |
4015 | if (params.vlan) |
4016 | dev_put(params.vlan); | |
3b85875a | 4017 | |
5727ef1b JB |
4018 | return err; |
4019 | } | |
4020 | ||
4021 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4022 | { | |
4c476991 | 4023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4024 | int err; |
4c476991 | 4025 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4026 | struct station_parameters params; |
4027 | u8 *mac_addr = NULL; | |
4028 | ||
4029 | memset(¶ms, 0, sizeof(params)); | |
4030 | ||
984c311b JB |
4031 | if (!rdev->ops->add_station) |
4032 | return -EOPNOTSUPP; | |
4033 | ||
5727ef1b JB |
4034 | if (!info->attrs[NL80211_ATTR_MAC]) |
4035 | return -EINVAL; | |
4036 | ||
5727ef1b JB |
4037 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4038 | return -EINVAL; | |
4039 | ||
4040 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4041 | return -EINVAL; | |
4042 | ||
5e4b6f56 JM |
4043 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4044 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4045 | return -EINVAL; |
4046 | ||
5727ef1b JB |
4047 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4048 | params.supported_rates = | |
4049 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4050 | params.supported_rates_len = | |
4051 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4052 | params.listen_interval = | |
4053 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4054 | |
3d124ea2 | 4055 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4056 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4057 | else |
4058 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4059 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4060 | return -EINVAL; | |
51b50fbe | 4061 | |
9d62a986 JM |
4062 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4063 | params.capability = | |
4064 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4065 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4066 | } | |
4067 | ||
4068 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4069 | params.ext_capab = | |
4070 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4071 | params.ext_capab_len = | |
4072 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4073 | } | |
4074 | ||
36aedc90 JM |
4075 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4076 | params.ht_capa = | |
4077 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4078 | |
f461be3e MP |
4079 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4080 | params.vht_capa = | |
4081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4082 | ||
f8bacc21 | 4083 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4084 | params.plink_action = |
f8bacc21 JB |
4085 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4086 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4087 | return -EINVAL; | |
4088 | } | |
96b78dff | 4089 | |
ff276691 JB |
4090 | err = nl80211_parse_sta_wme(info, ¶ms); |
4091 | if (err) | |
4092 | return err; | |
bdd90d5e | 4093 | |
bdd3ae3d | 4094 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4095 | return -EINVAL; |
4096 | ||
77ee7c89 JB |
4097 | /* When you run into this, adjust the code below for the new flag */ |
4098 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4099 | ||
bdd90d5e JB |
4100 | switch (dev->ieee80211_ptr->iftype) { |
4101 | case NL80211_IFTYPE_AP: | |
4102 | case NL80211_IFTYPE_AP_VLAN: | |
4103 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4104 | /* ignore WME attributes if iface/sta is not capable */ |
4105 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4106 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4107 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4108 | |
bdd90d5e | 4109 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4110 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4111 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4112 | return -EINVAL; |
bdd90d5e JB |
4113 | /* but don't bother the driver with it */ |
4114 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4115 | |
d582cffb JB |
4116 | /* allow authenticated/associated only if driver handles it */ |
4117 | if (!(rdev->wiphy.features & | |
4118 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4119 | params.sta_flags_mask & | |
4120 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4121 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4122 | return -EINVAL; | |
4123 | ||
bdd90d5e JB |
4124 | /* must be last in here for error handling */ |
4125 | params.vlan = get_vlan(info, rdev); | |
4126 | if (IS_ERR(params.vlan)) | |
4127 | return PTR_ERR(params.vlan); | |
4128 | break; | |
4129 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4130 | /* ignore uAPSD data */ |
4131 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4132 | ||
d582cffb JB |
4133 | /* associated is disallowed */ |
4134 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4135 | return -EINVAL; | |
bdd90d5e | 4136 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4137 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4138 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4139 | return -EINVAL; |
4140 | break; | |
4141 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4142 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4143 | /* ignore uAPSD data */ |
4144 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4145 | ||
77ee7c89 JB |
4146 | /* these are disallowed */ |
4147 | if (params.sta_flags_mask & | |
4148 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4149 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4150 | return -EINVAL; |
bdd90d5e JB |
4151 | /* Only TDLS peers can be added */ |
4152 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4153 | return -EINVAL; | |
4154 | /* Can only add if TDLS ... */ | |
4155 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4156 | return -EOPNOTSUPP; | |
4157 | /* ... with external setup is supported */ | |
4158 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4159 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4160 | /* |
4161 | * Older wpa_supplicant versions always mark the TDLS peer | |
4162 | * as authorized, but it shouldn't yet be. | |
4163 | */ | |
4164 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4165 | break; |
4166 | default: | |
4167 | return -EOPNOTSUPP; | |
c75786c9 EP |
4168 | } |
4169 | ||
bdd90d5e | 4170 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4171 | |
e35e4d28 | 4172 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4173 | |
5727ef1b JB |
4174 | if (params.vlan) |
4175 | dev_put(params.vlan); | |
5727ef1b JB |
4176 | return err; |
4177 | } | |
4178 | ||
4179 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4180 | { | |
4c476991 JB |
4181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4182 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4183 | u8 *mac_addr = NULL; |
4184 | ||
4185 | if (info->attrs[NL80211_ATTR_MAC]) | |
4186 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4187 | ||
e80cf853 | 4188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4189 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4190 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4192 | return -EINVAL; | |
5727ef1b | 4193 | |
4c476991 JB |
4194 | if (!rdev->ops->del_station) |
4195 | return -EOPNOTSUPP; | |
3b85875a | 4196 | |
e35e4d28 | 4197 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4198 | } |
4199 | ||
15e47304 | 4200 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4201 | int flags, struct net_device *dev, |
4202 | u8 *dst, u8 *next_hop, | |
4203 | struct mpath_info *pinfo) | |
4204 | { | |
4205 | void *hdr; | |
4206 | struct nlattr *pinfoattr; | |
4207 | ||
15e47304 | 4208 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4209 | if (!hdr) |
4210 | return -1; | |
4211 | ||
9360ffd1 DM |
4212 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4213 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4214 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4215 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4216 | goto nla_put_failure; | |
f5ea9120 | 4217 | |
2ec600d6 LCC |
4218 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4219 | if (!pinfoattr) | |
4220 | goto nla_put_failure; | |
9360ffd1 DM |
4221 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4222 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4223 | pinfo->frame_qlen)) | |
4224 | goto nla_put_failure; | |
4225 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4226 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4227 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4228 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4229 | pinfo->metric)) || | |
4230 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4231 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4232 | pinfo->exptime)) || | |
4233 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4234 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4235 | pinfo->flags)) || | |
4236 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4237 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4238 | pinfo->discovery_timeout)) || | |
4239 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4240 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4241 | pinfo->discovery_retries))) | |
4242 | goto nla_put_failure; | |
2ec600d6 LCC |
4243 | |
4244 | nla_nest_end(msg, pinfoattr); | |
4245 | ||
4246 | return genlmsg_end(msg, hdr); | |
4247 | ||
4248 | nla_put_failure: | |
bc3ed28c TG |
4249 | genlmsg_cancel(msg, hdr); |
4250 | return -EMSGSIZE; | |
2ec600d6 LCC |
4251 | } |
4252 | ||
4253 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4254 | struct netlink_callback *cb) |
2ec600d6 | 4255 | { |
2ec600d6 LCC |
4256 | struct mpath_info pinfo; |
4257 | struct cfg80211_registered_device *dev; | |
97990a06 | 4258 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4259 | u8 dst[ETH_ALEN]; |
4260 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4261 | int path_idx = cb->args[2]; |
2ec600d6 | 4262 | int err; |
2ec600d6 | 4263 | |
97990a06 | 4264 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4265 | if (err) |
4266 | return err; | |
bba95fef JB |
4267 | |
4268 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4269 | err = -EOPNOTSUPP; |
bba95fef JB |
4270 | goto out_err; |
4271 | } | |
4272 | ||
97990a06 | 4273 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4274 | err = -EOPNOTSUPP; |
0448b5fc | 4275 | goto out_err; |
eec60b03 JM |
4276 | } |
4277 | ||
bba95fef | 4278 | while (1) { |
97990a06 JB |
4279 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4280 | next_hop, &pinfo); | |
bba95fef | 4281 | if (err == -ENOENT) |
2ec600d6 | 4282 | break; |
bba95fef | 4283 | if (err) |
3b85875a | 4284 | goto out_err; |
2ec600d6 | 4285 | |
15e47304 | 4286 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4287 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4288 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4289 | &pinfo) < 0) |
4290 | goto out; | |
2ec600d6 | 4291 | |
bba95fef | 4292 | path_idx++; |
2ec600d6 | 4293 | } |
2ec600d6 | 4294 | |
2ec600d6 | 4295 | |
bba95fef | 4296 | out: |
97990a06 | 4297 | cb->args[2] = path_idx; |
bba95fef | 4298 | err = skb->len; |
bba95fef | 4299 | out_err: |
97990a06 | 4300 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4301 | return err; |
2ec600d6 LCC |
4302 | } |
4303 | ||
4304 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4305 | { | |
4c476991 | 4306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4307 | int err; |
4c476991 | 4308 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4309 | struct mpath_info pinfo; |
4310 | struct sk_buff *msg; | |
4311 | u8 *dst = NULL; | |
4312 | u8 next_hop[ETH_ALEN]; | |
4313 | ||
4314 | memset(&pinfo, 0, sizeof(pinfo)); | |
4315 | ||
4316 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4317 | return -EINVAL; | |
4318 | ||
4319 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4320 | ||
4c476991 JB |
4321 | if (!rdev->ops->get_mpath) |
4322 | return -EOPNOTSUPP; | |
2ec600d6 | 4323 | |
4c476991 JB |
4324 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4325 | return -EOPNOTSUPP; | |
eec60b03 | 4326 | |
e35e4d28 | 4327 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4328 | if (err) |
4c476991 | 4329 | return err; |
2ec600d6 | 4330 | |
fd2120ca | 4331 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4332 | if (!msg) |
4c476991 | 4333 | return -ENOMEM; |
2ec600d6 | 4334 | |
15e47304 | 4335 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4336 | dev, dst, next_hop, &pinfo) < 0) { |
4337 | nlmsg_free(msg); | |
4338 | return -ENOBUFS; | |
4339 | } | |
3b85875a | 4340 | |
4c476991 | 4341 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4342 | } |
4343 | ||
4344 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4345 | { | |
4c476991 JB |
4346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4347 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4348 | u8 *dst = NULL; |
4349 | u8 *next_hop = NULL; | |
4350 | ||
4351 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4352 | return -EINVAL; | |
4353 | ||
4354 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4355 | return -EINVAL; | |
4356 | ||
4357 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4358 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4359 | ||
4c476991 JB |
4360 | if (!rdev->ops->change_mpath) |
4361 | return -EOPNOTSUPP; | |
35a8efe1 | 4362 | |
4c476991 JB |
4363 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4364 | return -EOPNOTSUPP; | |
2ec600d6 | 4365 | |
e35e4d28 | 4366 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4367 | } |
4c476991 | 4368 | |
2ec600d6 LCC |
4369 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4370 | { | |
4c476991 JB |
4371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4372 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4373 | u8 *dst = NULL; |
4374 | u8 *next_hop = NULL; | |
4375 | ||
4376 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4377 | return -EINVAL; | |
4378 | ||
4379 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4380 | return -EINVAL; | |
4381 | ||
4382 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4383 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4384 | ||
4c476991 JB |
4385 | if (!rdev->ops->add_mpath) |
4386 | return -EOPNOTSUPP; | |
35a8efe1 | 4387 | |
4c476991 JB |
4388 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4389 | return -EOPNOTSUPP; | |
2ec600d6 | 4390 | |
e35e4d28 | 4391 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4392 | } |
4393 | ||
4394 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4395 | { | |
4c476991 JB |
4396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4397 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4398 | u8 *dst = NULL; |
4399 | ||
4400 | if (info->attrs[NL80211_ATTR_MAC]) | |
4401 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4402 | ||
4c476991 JB |
4403 | if (!rdev->ops->del_mpath) |
4404 | return -EOPNOTSUPP; | |
3b85875a | 4405 | |
e35e4d28 | 4406 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4407 | } |
4408 | ||
9f1ba906 JM |
4409 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4410 | { | |
4c476991 JB |
4411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4412 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
4413 | struct bss_parameters params; |
4414 | ||
4415 | memset(¶ms, 0, sizeof(params)); | |
4416 | /* default to not changing parameters */ | |
4417 | params.use_cts_prot = -1; | |
4418 | params.use_short_preamble = -1; | |
4419 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4420 | params.ap_isolate = -1; |
50b12f59 | 4421 | params.ht_opmode = -1; |
53cabad7 JB |
4422 | params.p2p_ctwindow = -1; |
4423 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4424 | |
4425 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4426 | params.use_cts_prot = | |
4427 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4428 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4429 | params.use_short_preamble = | |
4430 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4431 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4432 | params.use_short_slot_time = | |
4433 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4434 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4435 | params.basic_rates = | |
4436 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4437 | params.basic_rates_len = | |
4438 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4439 | } | |
fd8aaaf3 FF |
4440 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4441 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4442 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4443 | params.ht_opmode = | |
4444 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4445 | |
53cabad7 JB |
4446 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4447 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4448 | return -EINVAL; | |
4449 | params.p2p_ctwindow = | |
4450 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4451 | if (params.p2p_ctwindow < 0) | |
4452 | return -EINVAL; | |
4453 | if (params.p2p_ctwindow != 0 && | |
4454 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4455 | return -EINVAL; | |
4456 | } | |
4457 | ||
4458 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4459 | u8 tmp; | |
4460 | ||
4461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4462 | return -EINVAL; | |
4463 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4464 | if (tmp > 1) | |
4465 | return -EINVAL; | |
4466 | params.p2p_opp_ps = tmp; | |
4467 | if (params.p2p_opp_ps && | |
4468 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4469 | return -EINVAL; | |
4470 | } | |
4471 | ||
4c476991 JB |
4472 | if (!rdev->ops->change_bss) |
4473 | return -EOPNOTSUPP; | |
9f1ba906 | 4474 | |
074ac8df | 4475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4476 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4477 | return -EOPNOTSUPP; | |
3b85875a | 4478 | |
e35e4d28 | 4479 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4480 | } |
4481 | ||
b54452b0 | 4482 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4483 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4484 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4485 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4486 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4487 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4488 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4489 | }; | |
4490 | ||
4491 | static int parse_reg_rule(struct nlattr *tb[], | |
4492 | struct ieee80211_reg_rule *reg_rule) | |
4493 | { | |
4494 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4495 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4496 | ||
4497 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4498 | return -EINVAL; | |
4499 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4500 | return -EINVAL; | |
4501 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4502 | return -EINVAL; | |
4503 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4504 | return -EINVAL; | |
4505 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4506 | return -EINVAL; | |
4507 | ||
4508 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4509 | ||
4510 | freq_range->start_freq_khz = | |
4511 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4512 | freq_range->end_freq_khz = | |
4513 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4514 | freq_range->max_bandwidth_khz = | |
4515 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4516 | ||
4517 | power_rule->max_eirp = | |
4518 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4519 | ||
4520 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4521 | power_rule->max_antenna_gain = | |
4522 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4523 | ||
4524 | return 0; | |
4525 | } | |
4526 | ||
4527 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4528 | { | |
4529 | int r; | |
4530 | char *data = NULL; | |
57b5ce07 | 4531 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4532 | |
80778f18 LR |
4533 | /* |
4534 | * You should only get this when cfg80211 hasn't yet initialized | |
4535 | * completely when built-in to the kernel right between the time | |
4536 | * window between nl80211_init() and regulatory_init(), if that is | |
4537 | * even possible. | |
4538 | */ | |
458f4f9e | 4539 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4540 | return -EINPROGRESS; |
80778f18 | 4541 | |
fe33eb39 LR |
4542 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4543 | return -EINVAL; | |
b2e1b302 LR |
4544 | |
4545 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4546 | ||
57b5ce07 LR |
4547 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4548 | user_reg_hint_type = | |
4549 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4550 | else | |
4551 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4552 | ||
4553 | switch (user_reg_hint_type) { | |
4554 | case NL80211_USER_REG_HINT_USER: | |
4555 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4556 | break; | |
4557 | default: | |
4558 | return -EINVAL; | |
4559 | } | |
4560 | ||
4561 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4562 | |
b2e1b302 LR |
4563 | return r; |
4564 | } | |
4565 | ||
24bdd9f4 | 4566 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4567 | struct genl_info *info) |
93da9cc1 | 4568 | { |
4c476991 | 4569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4570 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4571 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4572 | struct mesh_config cur_params; | |
4573 | int err = 0; | |
93da9cc1 | 4574 | void *hdr; |
4575 | struct nlattr *pinfoattr; | |
4576 | struct sk_buff *msg; | |
4577 | ||
29cbe68c JB |
4578 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4579 | return -EOPNOTSUPP; | |
4580 | ||
24bdd9f4 | 4581 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4582 | return -EOPNOTSUPP; |
f3f92586 | 4583 | |
29cbe68c JB |
4584 | wdev_lock(wdev); |
4585 | /* If not connected, get default parameters */ | |
4586 | if (!wdev->mesh_id_len) | |
4587 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4588 | else | |
e35e4d28 | 4589 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4590 | wdev_unlock(wdev); |
4591 | ||
93da9cc1 | 4592 | if (err) |
4c476991 | 4593 | return err; |
93da9cc1 | 4594 | |
4595 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4596 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4597 | if (!msg) |
4598 | return -ENOMEM; | |
15e47304 | 4599 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4600 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4601 | if (!hdr) |
efe1cf0c | 4602 | goto out; |
24bdd9f4 | 4603 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4604 | if (!pinfoattr) |
4605 | goto nla_put_failure; | |
9360ffd1 DM |
4606 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4607 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4608 | cur_params.dot11MeshRetryTimeout) || | |
4609 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4610 | cur_params.dot11MeshConfirmTimeout) || | |
4611 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4612 | cur_params.dot11MeshHoldingTimeout) || | |
4613 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4614 | cur_params.dot11MeshMaxPeerLinks) || | |
4615 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4616 | cur_params.dot11MeshMaxRetries) || | |
4617 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4618 | cur_params.dot11MeshTTL) || | |
4619 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4620 | cur_params.element_ttl) || | |
4621 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4622 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4623 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4624 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4625 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4626 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4627 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4628 | cur_params.path_refresh_time) || | |
4629 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4630 | cur_params.min_discovery_timeout) || | |
4631 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4632 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4633 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4634 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4635 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4636 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4637 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4638 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4639 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4640 | cur_params.dot11MeshHWMPRootMode) || | |
4641 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4642 | cur_params.dot11MeshHWMPRannInterval) || | |
4643 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4644 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4645 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4646 | cur_params.dot11MeshForwarding) || | |
4647 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4648 | cur_params.rssi_threshold) || |
4649 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4650 | cur_params.ht_opmode) || |
4651 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4652 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4653 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4654 | cur_params.dot11MeshHWMProotInterval) || |
4655 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4656 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4657 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4658 | cur_params.power_mode) || | |
4659 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4660 | cur_params.dot11MeshAwakeWindowDuration) || |
4661 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4662 | cur_params.plink_timeout)) | |
9360ffd1 | 4663 | goto nla_put_failure; |
93da9cc1 | 4664 | nla_nest_end(msg, pinfoattr); |
4665 | genlmsg_end(msg, hdr); | |
4c476991 | 4666 | return genlmsg_reply(msg, info); |
93da9cc1 | 4667 | |
3b85875a | 4668 | nla_put_failure: |
93da9cc1 | 4669 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4670 | out: |
d080e275 | 4671 | nlmsg_free(msg); |
4c476991 | 4672 | return -ENOBUFS; |
93da9cc1 | 4673 | } |
4674 | ||
b54452b0 | 4675 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4676 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4677 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4678 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4679 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4680 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4681 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4682 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4683 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4684 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4685 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4686 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4687 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4688 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4689 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4690 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4691 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4692 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4693 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4694 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4695 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4696 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4697 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4698 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4699 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4700 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4701 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4702 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4703 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4704 | }; |
4705 | ||
c80d545d JC |
4706 | static const struct nla_policy |
4707 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4708 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4709 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4710 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4711 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4712 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4713 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4714 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4715 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4716 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4717 | }; |
4718 | ||
24bdd9f4 | 4719 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4720 | struct mesh_config *cfg, |
4721 | u32 *mask_out) | |
93da9cc1 | 4722 | { |
93da9cc1 | 4723 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4724 | u32 mask = 0; |
93da9cc1 | 4725 | |
ea54fba2 MP |
4726 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4727 | do { \ | |
4728 | if (tb[attr]) { \ | |
4729 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4730 | return -EINVAL; \ | |
4731 | cfg->param = fn(tb[attr]); \ | |
4732 | mask |= (1 << (attr - 1)); \ | |
4733 | } \ | |
4734 | } while (0) | |
bd90fdcc JB |
4735 | |
4736 | ||
24bdd9f4 | 4737 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4738 | return -EINVAL; |
4739 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4740 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4741 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4742 | return -EINVAL; |
4743 | ||
93da9cc1 | 4744 | /* This makes sure that there aren't more than 32 mesh config |
4745 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4746 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4747 | ||
4748 | /* Fill in the params struct */ | |
ea54fba2 | 4749 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4750 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4751 | nla_get_u16); | |
ea54fba2 | 4752 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4753 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4754 | nla_get_u16); | |
ea54fba2 | 4755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4756 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4757 | nla_get_u16); | |
ea54fba2 | 4758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4759 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4760 | nla_get_u16); | |
ea54fba2 | 4761 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4762 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4763 | nla_get_u8); | |
ea54fba2 | 4764 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4765 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4766 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4767 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4768 | nla_get_u8); | |
ea54fba2 | 4769 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4770 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4771 | nla_get_u8); | |
ea54fba2 MP |
4772 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4773 | 1, 255, mask, | |
a4f606ea CYY |
4774 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4775 | nla_get_u32); | |
ea54fba2 | 4776 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4777 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4778 | nla_get_u8); | |
ea54fba2 | 4779 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4780 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4781 | nla_get_u32); | |
ea54fba2 | 4782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4783 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4784 | nla_get_u16); | |
ea54fba2 MP |
4785 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4786 | 1, 65535, mask, | |
a4f606ea CYY |
4787 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4788 | nla_get_u32); | |
93da9cc1 | 4789 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4790 | 1, 65535, mask, |
4791 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4792 | nla_get_u16); |
dca7e943 | 4793 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4794 | 1, 65535, mask, |
4795 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4796 | nla_get_u16); |
93da9cc1 | 4797 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4798 | dot11MeshHWMPnetDiameterTraversalTime, |
4799 | 1, 65535, mask, | |
a4f606ea CYY |
4800 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4801 | nla_get_u16); | |
ea54fba2 MP |
4802 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4803 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4804 | nla_get_u8); | |
4805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4806 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4807 | nla_get_u16); |
63c5723b | 4808 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4809 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4810 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4811 | nla_get_u8); |
ea54fba2 | 4812 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4813 | mask, NL80211_MESHCONF_FORWARDING, |
4814 | nla_get_u8); | |
ea54fba2 | 4815 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4816 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4817 | nla_get_u32); | |
ea54fba2 | 4818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4819 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4820 | nla_get_u16); |
4821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4822 | 1, 65535, mask, |
ac1073a6 CYY |
4823 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4824 | nla_get_u32); | |
ea54fba2 | 4825 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4826 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4827 | nla_get_u16); |
4828 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4829 | dot11MeshHWMPconfirmationInterval, |
4830 | 1, 65535, mask, | |
728b19e5 | 4831 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4832 | nla_get_u16); |
3b1c5a53 MP |
4833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4834 | NL80211_MESH_POWER_ACTIVE, | |
4835 | NL80211_MESH_POWER_MAX, | |
4836 | mask, NL80211_MESHCONF_POWER_MODE, | |
4837 | nla_get_u32); | |
4838 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4839 | 0, 65535, mask, | |
4840 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
4841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
4842 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4843 | nla_get_u32); | |
bd90fdcc JB |
4844 | if (mask_out) |
4845 | *mask_out = mask; | |
c80d545d | 4846 | |
bd90fdcc JB |
4847 | return 0; |
4848 | ||
4849 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4850 | } | |
4851 | ||
c80d545d JC |
4852 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4853 | struct mesh_setup *setup) | |
4854 | { | |
bb2798d4 | 4855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4856 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4857 | ||
4858 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4859 | return -EINVAL; | |
4860 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4861 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4862 | nl80211_mesh_setup_params_policy)) | |
4863 | return -EINVAL; | |
4864 | ||
d299a1f2 JC |
4865 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4866 | setup->sync_method = | |
4867 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4868 | IEEE80211_SYNC_METHOD_VENDOR : | |
4869 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4870 | ||
c80d545d JC |
4871 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4872 | setup->path_sel_proto = | |
4873 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4874 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4875 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4876 | ||
4877 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4878 | setup->path_metric = | |
4879 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4880 | IEEE80211_PATH_METRIC_VENDOR : | |
4881 | IEEE80211_PATH_METRIC_AIRTIME; | |
4882 | ||
581a8b0f JC |
4883 | |
4884 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4885 | struct nlattr *ieattr = |
581a8b0f | 4886 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4887 | if (!is_valid_ie_attr(ieattr)) |
4888 | return -EINVAL; | |
581a8b0f JC |
4889 | setup->ie = nla_data(ieattr); |
4890 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4891 | } |
bb2798d4 TP |
4892 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4893 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4894 | return -EINVAL; | |
4895 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4896 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4897 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4898 | if (setup->is_secure) |
4899 | setup->user_mpm = true; | |
c80d545d | 4900 | |
6e16d90b CT |
4901 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
4902 | if (!setup->user_mpm) | |
4903 | return -EINVAL; | |
4904 | setup->auth_id = | |
4905 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
4906 | } | |
4907 | ||
c80d545d JC |
4908 | return 0; |
4909 | } | |
4910 | ||
24bdd9f4 | 4911 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4912 | struct genl_info *info) |
bd90fdcc JB |
4913 | { |
4914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4915 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4916 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4917 | struct mesh_config cfg; |
4918 | u32 mask; | |
4919 | int err; | |
4920 | ||
29cbe68c JB |
4921 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4922 | return -EOPNOTSUPP; | |
4923 | ||
24bdd9f4 | 4924 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4925 | return -EOPNOTSUPP; |
4926 | ||
24bdd9f4 | 4927 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4928 | if (err) |
4929 | return err; | |
4930 | ||
29cbe68c JB |
4931 | wdev_lock(wdev); |
4932 | if (!wdev->mesh_id_len) | |
4933 | err = -ENOLINK; | |
4934 | ||
4935 | if (!err) | |
e35e4d28 | 4936 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4937 | |
4938 | wdev_unlock(wdev); | |
4939 | ||
4940 | return err; | |
93da9cc1 | 4941 | } |
4942 | ||
f130347c LR |
4943 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4944 | { | |
458f4f9e | 4945 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4946 | struct sk_buff *msg; |
4947 | void *hdr = NULL; | |
4948 | struct nlattr *nl_reg_rules; | |
4949 | unsigned int i; | |
f130347c LR |
4950 | |
4951 | if (!cfg80211_regdomain) | |
5fe231e8 | 4952 | return -EINVAL; |
f130347c | 4953 | |
fd2120ca | 4954 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
4955 | if (!msg) |
4956 | return -ENOBUFS; | |
f130347c | 4957 | |
15e47304 | 4958 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4959 | NL80211_CMD_GET_REG); |
4960 | if (!hdr) | |
efe1cf0c | 4961 | goto put_failure; |
f130347c | 4962 | |
57b5ce07 LR |
4963 | if (reg_last_request_cell_base() && |
4964 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4965 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4966 | goto nla_put_failure; | |
4967 | ||
458f4f9e JB |
4968 | rcu_read_lock(); |
4969 | regdom = rcu_dereference(cfg80211_regdomain); | |
4970 | ||
4971 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4972 | (regdom->dfs_region && | |
4973 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4974 | goto nla_put_failure_rcu; | |
4975 | ||
f130347c LR |
4976 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4977 | if (!nl_reg_rules) | |
458f4f9e | 4978 | goto nla_put_failure_rcu; |
f130347c | 4979 | |
458f4f9e | 4980 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4981 | struct nlattr *nl_reg_rule; |
4982 | const struct ieee80211_reg_rule *reg_rule; | |
4983 | const struct ieee80211_freq_range *freq_range; | |
4984 | const struct ieee80211_power_rule *power_rule; | |
4985 | ||
458f4f9e | 4986 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4987 | freq_range = ®_rule->freq_range; |
4988 | power_rule = ®_rule->power_rule; | |
4989 | ||
4990 | nl_reg_rule = nla_nest_start(msg, i); | |
4991 | if (!nl_reg_rule) | |
458f4f9e | 4992 | goto nla_put_failure_rcu; |
f130347c | 4993 | |
9360ffd1 DM |
4994 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4995 | reg_rule->flags) || | |
4996 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4997 | freq_range->start_freq_khz) || | |
4998 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4999 | freq_range->end_freq_khz) || | |
5000 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
5001 | freq_range->max_bandwidth_khz) || | |
5002 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
5003 | power_rule->max_antenna_gain) || | |
5004 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
5005 | power_rule->max_eirp)) | |
458f4f9e | 5006 | goto nla_put_failure_rcu; |
f130347c LR |
5007 | |
5008 | nla_nest_end(msg, nl_reg_rule); | |
5009 | } | |
458f4f9e | 5010 | rcu_read_unlock(); |
f130347c LR |
5011 | |
5012 | nla_nest_end(msg, nl_reg_rules); | |
5013 | ||
5014 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5015 | return genlmsg_reply(msg, info); |
f130347c | 5016 | |
458f4f9e JB |
5017 | nla_put_failure_rcu: |
5018 | rcu_read_unlock(); | |
f130347c LR |
5019 | nla_put_failure: |
5020 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5021 | put_failure: |
d080e275 | 5022 | nlmsg_free(msg); |
5fe231e8 | 5023 | return -EMSGSIZE; |
f130347c LR |
5024 | } |
5025 | ||
b2e1b302 LR |
5026 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5027 | { | |
5028 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5029 | struct nlattr *nl_reg_rule; | |
5030 | char *alpha2 = NULL; | |
5031 | int rem_reg_rules = 0, r = 0; | |
5032 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 5033 | u8 dfs_region = 0; |
b2e1b302 LR |
5034 | struct ieee80211_regdomain *rd = NULL; |
5035 | ||
5036 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5037 | return -EINVAL; | |
5038 | ||
5039 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5040 | return -EINVAL; | |
5041 | ||
5042 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5043 | ||
8b60b078 LR |
5044 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5045 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5046 | ||
b2e1b302 | 5047 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5048 | rem_reg_rules) { |
b2e1b302 LR |
5049 | num_rules++; |
5050 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5051 | return -EINVAL; |
b2e1b302 LR |
5052 | } |
5053 | ||
b2e1b302 | 5054 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5055 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5056 | |
5057 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5058 | if (!rd) |
5059 | return -ENOMEM; | |
b2e1b302 LR |
5060 | |
5061 | rd->n_reg_rules = num_rules; | |
5062 | rd->alpha2[0] = alpha2[0]; | |
5063 | rd->alpha2[1] = alpha2[1]; | |
5064 | ||
8b60b078 LR |
5065 | /* |
5066 | * Disable DFS master mode if the DFS region was | |
5067 | * not supported or known on this kernel. | |
5068 | */ | |
5069 | if (reg_supported_dfs_region(dfs_region)) | |
5070 | rd->dfs_region = dfs_region; | |
5071 | ||
b2e1b302 | 5072 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5073 | rem_reg_rules) { |
b2e1b302 | 5074 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
5075 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
5076 | reg_rule_policy); | |
b2e1b302 LR |
5077 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5078 | if (r) | |
5079 | goto bad_reg; | |
5080 | ||
5081 | rule_idx++; | |
5082 | ||
d0e18f83 LR |
5083 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5084 | r = -EINVAL; | |
b2e1b302 | 5085 | goto bad_reg; |
d0e18f83 | 5086 | } |
b2e1b302 LR |
5087 | } |
5088 | ||
b2e1b302 | 5089 | r = set_regdom(rd); |
6913b49a | 5090 | /* set_regdom took ownership */ |
1a919318 | 5091 | rd = NULL; |
b2e1b302 | 5092 | |
d2372b31 | 5093 | bad_reg: |
b2e1b302 | 5094 | kfree(rd); |
d0e18f83 | 5095 | return r; |
b2e1b302 LR |
5096 | } |
5097 | ||
83f5e2cf JB |
5098 | static int validate_scan_freqs(struct nlattr *freqs) |
5099 | { | |
5100 | struct nlattr *attr1, *attr2; | |
5101 | int n_channels = 0, tmp1, tmp2; | |
5102 | ||
5103 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5104 | n_channels++; | |
5105 | /* | |
5106 | * Some hardware has a limited channel list for | |
5107 | * scanning, and it is pretty much nonsensical | |
5108 | * to scan for a channel twice, so disallow that | |
5109 | * and don't require drivers to check that the | |
5110 | * channel list they get isn't longer than what | |
5111 | * they can scan, as long as they can scan all | |
5112 | * the channels they registered at once. | |
5113 | */ | |
5114 | nla_for_each_nested(attr2, freqs, tmp2) | |
5115 | if (attr1 != attr2 && | |
5116 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5117 | return 0; | |
5118 | } | |
5119 | ||
5120 | return n_channels; | |
5121 | } | |
5122 | ||
2a519311 JB |
5123 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5124 | { | |
4c476991 | 5125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5126 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5127 | struct cfg80211_scan_request *request; |
2a519311 JB |
5128 | struct nlattr *attr; |
5129 | struct wiphy *wiphy; | |
83f5e2cf | 5130 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5131 | size_t ie_len; |
2a519311 | 5132 | |
f4a11bb0 JB |
5133 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5134 | return -EINVAL; | |
5135 | ||
79c97e97 | 5136 | wiphy = &rdev->wiphy; |
2a519311 | 5137 | |
4c476991 JB |
5138 | if (!rdev->ops->scan) |
5139 | return -EOPNOTSUPP; | |
2a519311 | 5140 | |
f9f47529 JB |
5141 | if (rdev->scan_req) { |
5142 | err = -EBUSY; | |
5143 | goto unlock; | |
5144 | } | |
2a519311 JB |
5145 | |
5146 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5147 | n_channels = validate_scan_freqs( |
5148 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5149 | if (!n_channels) { |
5150 | err = -EINVAL; | |
5151 | goto unlock; | |
5152 | } | |
2a519311 | 5153 | } else { |
34850ab2 | 5154 | enum ieee80211_band band; |
83f5e2cf JB |
5155 | n_channels = 0; |
5156 | ||
2a519311 JB |
5157 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5158 | if (wiphy->bands[band]) | |
5159 | n_channels += wiphy->bands[band]->n_channels; | |
5160 | } | |
5161 | ||
5162 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5163 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5164 | n_ssids++; | |
5165 | ||
f9f47529 JB |
5166 | if (n_ssids > wiphy->max_scan_ssids) { |
5167 | err = -EINVAL; | |
5168 | goto unlock; | |
5169 | } | |
2a519311 | 5170 | |
70692ad2 JM |
5171 | if (info->attrs[NL80211_ATTR_IE]) |
5172 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5173 | else | |
5174 | ie_len = 0; | |
5175 | ||
f9f47529 JB |
5176 | if (ie_len > wiphy->max_scan_ie_len) { |
5177 | err = -EINVAL; | |
5178 | goto unlock; | |
5179 | } | |
18a83659 | 5180 | |
2a519311 | 5181 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5182 | + sizeof(*request->ssids) * n_ssids |
5183 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5184 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5185 | if (!request) { |
5186 | err = -ENOMEM; | |
5187 | goto unlock; | |
5188 | } | |
2a519311 | 5189 | |
2a519311 | 5190 | if (n_ssids) |
5ba63533 | 5191 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5192 | request->n_ssids = n_ssids; |
70692ad2 JM |
5193 | if (ie_len) { |
5194 | if (request->ssids) | |
5195 | request->ie = (void *)(request->ssids + n_ssids); | |
5196 | else | |
5197 | request->ie = (void *)(request->channels + n_channels); | |
5198 | } | |
2a519311 | 5199 | |
584991dc | 5200 | i = 0; |
2a519311 JB |
5201 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5202 | /* user specified, bail out if channel not found */ | |
2a519311 | 5203 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5204 | struct ieee80211_channel *chan; |
5205 | ||
5206 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5207 | ||
5208 | if (!chan) { | |
2a519311 JB |
5209 | err = -EINVAL; |
5210 | goto out_free; | |
5211 | } | |
584991dc JB |
5212 | |
5213 | /* ignore disabled channels */ | |
5214 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5215 | continue; | |
5216 | ||
5217 | request->channels[i] = chan; | |
2a519311 JB |
5218 | i++; |
5219 | } | |
5220 | } else { | |
34850ab2 JB |
5221 | enum ieee80211_band band; |
5222 | ||
2a519311 | 5223 | /* all channels */ |
2a519311 JB |
5224 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5225 | int j; | |
5226 | if (!wiphy->bands[band]) | |
5227 | continue; | |
5228 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5229 | struct ieee80211_channel *chan; |
5230 | ||
5231 | chan = &wiphy->bands[band]->channels[j]; | |
5232 | ||
5233 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5234 | continue; | |
5235 | ||
5236 | request->channels[i] = chan; | |
2a519311 JB |
5237 | i++; |
5238 | } | |
5239 | } | |
5240 | } | |
5241 | ||
584991dc JB |
5242 | if (!i) { |
5243 | err = -EINVAL; | |
5244 | goto out_free; | |
5245 | } | |
5246 | ||
5247 | request->n_channels = i; | |
5248 | ||
2a519311 JB |
5249 | i = 0; |
5250 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5251 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5252 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5253 | err = -EINVAL; |
5254 | goto out_free; | |
5255 | } | |
57a27e1d | 5256 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5257 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5258 | i++; |
5259 | } | |
5260 | } | |
5261 | ||
70692ad2 JM |
5262 | if (info->attrs[NL80211_ATTR_IE]) { |
5263 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5264 | memcpy((void *)request->ie, |
5265 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5266 | request->ie_len); |
5267 | } | |
5268 | ||
34850ab2 | 5269 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5270 | if (wiphy->bands[i]) |
5271 | request->rates[i] = | |
5272 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5273 | |
5274 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5275 | nla_for_each_nested(attr, | |
5276 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5277 | tmp) { | |
5278 | enum ieee80211_band band = nla_type(attr); | |
5279 | ||
84404623 | 5280 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5281 | err = -EINVAL; |
5282 | goto out_free; | |
5283 | } | |
5284 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5285 | nla_data(attr), | |
5286 | nla_len(attr), | |
5287 | &request->rates[band]); | |
5288 | if (err) | |
5289 | goto out_free; | |
5290 | } | |
5291 | } | |
5292 | ||
46856bbf | 5293 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5294 | request->flags = nla_get_u32( |
5295 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5296 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5297 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5298 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5299 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5300 | err = -EOPNOTSUPP; |
5301 | goto out_free; | |
5302 | } | |
5303 | } | |
ed473771 | 5304 | |
e9f935e3 RM |
5305 | request->no_cck = |
5306 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5307 | ||
fd014284 | 5308 | request->wdev = wdev; |
79c97e97 | 5309 | request->wiphy = &rdev->wiphy; |
15d6030b | 5310 | request->scan_start = jiffies; |
2a519311 | 5311 | |
79c97e97 | 5312 | rdev->scan_req = request; |
e35e4d28 | 5313 | err = rdev_scan(rdev, request); |
2a519311 | 5314 | |
463d0183 | 5315 | if (!err) { |
fd014284 JB |
5316 | nl80211_send_scan_start(rdev, wdev); |
5317 | if (wdev->netdev) | |
5318 | dev_hold(wdev->netdev); | |
4c476991 | 5319 | } else { |
2a519311 | 5320 | out_free: |
79c97e97 | 5321 | rdev->scan_req = NULL; |
2a519311 JB |
5322 | kfree(request); |
5323 | } | |
3b85875a | 5324 | |
f9f47529 | 5325 | unlock: |
2a519311 JB |
5326 | return err; |
5327 | } | |
5328 | ||
807f8a8c LC |
5329 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5330 | struct genl_info *info) | |
5331 | { | |
5332 | struct cfg80211_sched_scan_request *request; | |
5333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5334 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5335 | struct nlattr *attr; |
5336 | struct wiphy *wiphy; | |
a1f1c21c | 5337 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5338 | u32 interval; |
807f8a8c LC |
5339 | enum ieee80211_band band; |
5340 | size_t ie_len; | |
a1f1c21c | 5341 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5342 | |
5343 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5344 | !rdev->ops->sched_scan_start) | |
5345 | return -EOPNOTSUPP; | |
5346 | ||
5347 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5348 | return -EINVAL; | |
5349 | ||
bbe6ad6d LC |
5350 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5351 | return -EINVAL; | |
5352 | ||
5353 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5354 | if (interval == 0) | |
5355 | return -EINVAL; | |
5356 | ||
807f8a8c LC |
5357 | wiphy = &rdev->wiphy; |
5358 | ||
5359 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5360 | n_channels = validate_scan_freqs( | |
5361 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5362 | if (!n_channels) | |
5363 | return -EINVAL; | |
5364 | } else { | |
5365 | n_channels = 0; | |
5366 | ||
5367 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5368 | if (wiphy->bands[band]) | |
5369 | n_channels += wiphy->bands[band]->n_channels; | |
5370 | } | |
5371 | ||
5372 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5373 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5374 | tmp) | |
5375 | n_ssids++; | |
5376 | ||
93b6aa69 | 5377 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5378 | return -EINVAL; |
5379 | ||
a1f1c21c LC |
5380 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5381 | nla_for_each_nested(attr, | |
5382 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5383 | tmp) | |
5384 | n_match_sets++; | |
5385 | ||
5386 | if (n_match_sets > wiphy->max_match_sets) | |
5387 | return -EINVAL; | |
5388 | ||
807f8a8c LC |
5389 | if (info->attrs[NL80211_ATTR_IE]) |
5390 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5391 | else | |
5392 | ie_len = 0; | |
5393 | ||
5a865bad | 5394 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5395 | return -EINVAL; |
5396 | ||
c10841ca LC |
5397 | if (rdev->sched_scan_req) { |
5398 | err = -EINPROGRESS; | |
5399 | goto out; | |
5400 | } | |
5401 | ||
807f8a8c | 5402 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5403 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5404 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5405 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5406 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5407 | if (!request) { |
5408 | err = -ENOMEM; | |
5409 | goto out; | |
5410 | } | |
807f8a8c LC |
5411 | |
5412 | if (n_ssids) | |
5413 | request->ssids = (void *)&request->channels[n_channels]; | |
5414 | request->n_ssids = n_ssids; | |
5415 | if (ie_len) { | |
5416 | if (request->ssids) | |
5417 | request->ie = (void *)(request->ssids + n_ssids); | |
5418 | else | |
5419 | request->ie = (void *)(request->channels + n_channels); | |
5420 | } | |
5421 | ||
a1f1c21c LC |
5422 | if (n_match_sets) { |
5423 | if (request->ie) | |
5424 | request->match_sets = (void *)(request->ie + ie_len); | |
5425 | else if (request->ssids) | |
5426 | request->match_sets = | |
5427 | (void *)(request->ssids + n_ssids); | |
5428 | else | |
5429 | request->match_sets = | |
5430 | (void *)(request->channels + n_channels); | |
5431 | } | |
5432 | request->n_match_sets = n_match_sets; | |
5433 | ||
807f8a8c LC |
5434 | i = 0; |
5435 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5436 | /* user specified, bail out if channel not found */ | |
5437 | nla_for_each_nested(attr, | |
5438 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5439 | tmp) { | |
5440 | struct ieee80211_channel *chan; | |
5441 | ||
5442 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5443 | ||
5444 | if (!chan) { | |
5445 | err = -EINVAL; | |
5446 | goto out_free; | |
5447 | } | |
5448 | ||
5449 | /* ignore disabled channels */ | |
5450 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5451 | continue; | |
5452 | ||
5453 | request->channels[i] = chan; | |
5454 | i++; | |
5455 | } | |
5456 | } else { | |
5457 | /* all channels */ | |
5458 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5459 | int j; | |
5460 | if (!wiphy->bands[band]) | |
5461 | continue; | |
5462 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5463 | struct ieee80211_channel *chan; | |
5464 | ||
5465 | chan = &wiphy->bands[band]->channels[j]; | |
5466 | ||
5467 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5468 | continue; | |
5469 | ||
5470 | request->channels[i] = chan; | |
5471 | i++; | |
5472 | } | |
5473 | } | |
5474 | } | |
5475 | ||
5476 | if (!i) { | |
5477 | err = -EINVAL; | |
5478 | goto out_free; | |
5479 | } | |
5480 | ||
5481 | request->n_channels = i; | |
5482 | ||
5483 | i = 0; | |
5484 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5485 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5486 | tmp) { | |
57a27e1d | 5487 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5488 | err = -EINVAL; |
5489 | goto out_free; | |
5490 | } | |
57a27e1d | 5491 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5492 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5493 | nla_len(attr)); | |
807f8a8c LC |
5494 | i++; |
5495 | } | |
5496 | } | |
5497 | ||
a1f1c21c LC |
5498 | i = 0; |
5499 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5500 | nla_for_each_nested(attr, | |
5501 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5502 | tmp) { | |
88e920b4 | 5503 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5504 | |
5505 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5506 | nla_data(attr), nla_len(attr), | |
5507 | nl80211_match_policy); | |
4a4ab0d7 | 5508 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5509 | if (ssid) { |
5510 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5511 | err = -EINVAL; | |
5512 | goto out_free; | |
5513 | } | |
5514 | memcpy(request->match_sets[i].ssid.ssid, | |
5515 | nla_data(ssid), nla_len(ssid)); | |
5516 | request->match_sets[i].ssid.ssid_len = | |
5517 | nla_len(ssid); | |
5518 | } | |
88e920b4 TP |
5519 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5520 | if (rssi) | |
5521 | request->rssi_thold = nla_get_u32(rssi); | |
5522 | else | |
5523 | request->rssi_thold = | |
5524 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5525 | i++; |
5526 | } | |
5527 | } | |
5528 | ||
807f8a8c LC |
5529 | if (info->attrs[NL80211_ATTR_IE]) { |
5530 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5531 | memcpy((void *)request->ie, | |
5532 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5533 | request->ie_len); | |
5534 | } | |
5535 | ||
46856bbf | 5536 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5537 | request->flags = nla_get_u32( |
5538 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5539 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5540 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5541 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5542 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5543 | err = -EOPNOTSUPP; |
5544 | goto out_free; | |
5545 | } | |
5546 | } | |
ed473771 | 5547 | |
807f8a8c LC |
5548 | request->dev = dev; |
5549 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5550 | request->interval = interval; |
15d6030b | 5551 | request->scan_start = jiffies; |
807f8a8c | 5552 | |
e35e4d28 | 5553 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5554 | if (!err) { |
5555 | rdev->sched_scan_req = request; | |
5556 | nl80211_send_sched_scan(rdev, dev, | |
5557 | NL80211_CMD_START_SCHED_SCAN); | |
5558 | goto out; | |
5559 | } | |
5560 | ||
5561 | out_free: | |
5562 | kfree(request); | |
5563 | out: | |
5564 | return err; | |
5565 | } | |
5566 | ||
5567 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5568 | struct genl_info *info) | |
5569 | { | |
5570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5571 | ||
5572 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5573 | !rdev->ops->sched_scan_stop) | |
5574 | return -EOPNOTSUPP; | |
5575 | ||
5fe231e8 | 5576 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5577 | } |
5578 | ||
04f39047 SW |
5579 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5580 | struct genl_info *info) | |
5581 | { | |
5582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5583 | struct net_device *dev = info->user_ptr[1]; | |
5584 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5585 | struct cfg80211_chan_def chandef; | |
5586 | int err; | |
5587 | ||
5588 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5589 | if (err) | |
5590 | return err; | |
5591 | ||
5592 | if (wdev->cac_started) | |
5593 | return -EBUSY; | |
5594 | ||
5595 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5596 | if (err < 0) | |
5597 | return err; | |
5598 | ||
5599 | if (err == 0) | |
5600 | return -EINVAL; | |
5601 | ||
5602 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5603 | return -EINVAL; | |
5604 | ||
5605 | if (!rdev->ops->start_radar_detection) | |
5606 | return -EOPNOTSUPP; | |
5607 | ||
04f39047 SW |
5608 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5609 | chandef.chan, CHAN_MODE_SHARED, | |
5610 | BIT(chandef.width)); | |
5611 | if (err) | |
5fe231e8 | 5612 | return err; |
04f39047 SW |
5613 | |
5614 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5615 | if (!err) { | |
5616 | wdev->channel = chandef.chan; | |
5617 | wdev->cac_started = true; | |
5618 | wdev->cac_start_time = jiffies; | |
5619 | } | |
04f39047 SW |
5620 | return err; |
5621 | } | |
5622 | ||
16ef1fe2 SW |
5623 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5624 | { | |
5625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5626 | struct net_device *dev = info->user_ptr[1]; | |
5627 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5628 | struct cfg80211_csa_settings params; | |
5629 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5630 | * function is called under RTNL lock, so this should not be a problem. | |
5631 | */ | |
5632 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5633 | u8 radar_detect_width = 0; | |
5634 | int err; | |
5635 | ||
5636 | if (!rdev->ops->channel_switch || | |
5637 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5638 | return -EOPNOTSUPP; | |
5639 | ||
5640 | /* may add IBSS support later */ | |
5641 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5642 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5643 | return -EOPNOTSUPP; | |
5644 | ||
5645 | memset(¶ms, 0, sizeof(params)); | |
5646 | ||
5647 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5648 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5649 | return -EINVAL; | |
5650 | ||
5651 | /* only important for AP, IBSS and mesh create IEs internally */ | |
5652 | if (!info->attrs[NL80211_ATTR_CSA_IES]) | |
5653 | return -EINVAL; | |
5654 | ||
5655 | /* useless if AP is not running */ | |
5656 | if (!wdev->beacon_interval) | |
5657 | return -EINVAL; | |
5658 | ||
5659 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5660 | ||
5661 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); | |
5662 | if (err) | |
5663 | return err; | |
5664 | ||
5665 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5666 | info->attrs[NL80211_ATTR_CSA_IES], | |
5667 | nl80211_policy); | |
5668 | if (err) | |
5669 | return err; | |
5670 | ||
5671 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5672 | if (err) | |
5673 | return err; | |
5674 | ||
5675 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5676 | return -EINVAL; | |
5677 | ||
5678 | params.counter_offset_beacon = | |
5679 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5680 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) | |
5681 | return -EINVAL; | |
5682 | ||
5683 | /* sanity check - counters should be the same */ | |
5684 | if (params.beacon_csa.tail[params.counter_offset_beacon] != | |
5685 | params.count) | |
5686 | return -EINVAL; | |
5687 | ||
5688 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | |
5689 | params.counter_offset_presp = | |
5690 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5691 | if (params.counter_offset_presp >= | |
5692 | params.beacon_csa.probe_resp_len) | |
5693 | return -EINVAL; | |
5694 | ||
5695 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != | |
5696 | params.count) | |
5697 | return -EINVAL; | |
5698 | } | |
5699 | ||
5700 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); | |
5701 | if (err) | |
5702 | return err; | |
5703 | ||
5704 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) | |
5705 | return -EINVAL; | |
5706 | ||
5707 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); | |
5708 | if (err < 0) { | |
5709 | return err; | |
5710 | } else if (err) { | |
5711 | radar_detect_width = BIT(params.chandef.width); | |
5712 | params.radar_required = true; | |
5713 | } | |
5714 | ||
5715 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5716 | params.chandef.chan, | |
5717 | CHAN_MODE_SHARED, | |
5718 | radar_detect_width); | |
5719 | if (err) | |
5720 | return err; | |
5721 | ||
5722 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | |
5723 | params.block_tx = true; | |
5724 | ||
5725 | return rdev_channel_switch(rdev, dev, ¶ms); | |
5726 | } | |
5727 | ||
9720bb3a JB |
5728 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5729 | u32 seq, int flags, | |
2a519311 | 5730 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5731 | struct wireless_dev *wdev, |
5732 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5733 | { |
48ab905d | 5734 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5735 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5736 | void *hdr; |
5737 | struct nlattr *bss; | |
8cef2c9d | 5738 | bool tsf = false; |
48ab905d JB |
5739 | |
5740 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5741 | |
15e47304 | 5742 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5743 | NL80211_CMD_NEW_SCAN_RESULTS); |
5744 | if (!hdr) | |
5745 | return -1; | |
5746 | ||
9720bb3a JB |
5747 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5748 | ||
97990a06 JB |
5749 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5750 | goto nla_put_failure; | |
5751 | if (wdev->netdev && | |
9360ffd1 DM |
5752 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5753 | goto nla_put_failure; | |
97990a06 JB |
5754 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5755 | goto nla_put_failure; | |
2a519311 JB |
5756 | |
5757 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5758 | if (!bss) | |
5759 | goto nla_put_failure; | |
9360ffd1 | 5760 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5761 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5762 | goto nla_put_failure; |
9caf0364 JB |
5763 | |
5764 | rcu_read_lock(); | |
5765 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5766 | if (ies) { |
5767 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5768 | goto fail_unlock_rcu; | |
5769 | tsf = true; | |
5770 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5771 | ies->len, ies->data)) | |
5772 | goto fail_unlock_rcu; | |
9caf0364 JB |
5773 | } |
5774 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5775 | if (ies) { |
5776 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5777 | goto fail_unlock_rcu; | |
5778 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5779 | ies->len, ies->data)) | |
5780 | goto fail_unlock_rcu; | |
9caf0364 JB |
5781 | } |
5782 | rcu_read_unlock(); | |
5783 | ||
9360ffd1 DM |
5784 | if (res->beacon_interval && |
5785 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5786 | goto nla_put_failure; | |
5787 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5788 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 5789 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
5790 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
5791 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5792 | goto nla_put_failure; | |
2a519311 | 5793 | |
77965c97 | 5794 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5795 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5796 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5797 | goto nla_put_failure; | |
2a519311 JB |
5798 | break; |
5799 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5800 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5801 | goto nla_put_failure; | |
2a519311 JB |
5802 | break; |
5803 | default: | |
5804 | break; | |
5805 | } | |
5806 | ||
48ab905d | 5807 | switch (wdev->iftype) { |
074ac8df | 5808 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5809 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5810 | if (intbss == wdev->current_bss && |
5811 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5812 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5813 | goto nla_put_failure; | |
48ab905d JB |
5814 | break; |
5815 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5816 | if (intbss == wdev->current_bss && |
5817 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5818 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5819 | goto nla_put_failure; | |
48ab905d JB |
5820 | break; |
5821 | default: | |
5822 | break; | |
5823 | } | |
5824 | ||
2a519311 JB |
5825 | nla_nest_end(msg, bss); |
5826 | ||
5827 | return genlmsg_end(msg, hdr); | |
5828 | ||
8cef2c9d JB |
5829 | fail_unlock_rcu: |
5830 | rcu_read_unlock(); | |
2a519311 JB |
5831 | nla_put_failure: |
5832 | genlmsg_cancel(msg, hdr); | |
5833 | return -EMSGSIZE; | |
5834 | } | |
5835 | ||
97990a06 | 5836 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5837 | { |
48ab905d | 5838 | struct cfg80211_registered_device *rdev; |
2a519311 | 5839 | struct cfg80211_internal_bss *scan; |
48ab905d | 5840 | struct wireless_dev *wdev; |
97990a06 | 5841 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5842 | int err; |
5843 | ||
97990a06 | 5844 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5845 | if (err) |
5846 | return err; | |
2a519311 | 5847 | |
48ab905d JB |
5848 | wdev_lock(wdev); |
5849 | spin_lock_bh(&rdev->bss_lock); | |
5850 | cfg80211_bss_expire(rdev); | |
5851 | ||
9720bb3a JB |
5852 | cb->seq = rdev->bss_generation; |
5853 | ||
48ab905d | 5854 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5855 | if (++idx <= start) |
5856 | continue; | |
9720bb3a | 5857 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5858 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5859 | rdev, wdev, scan) < 0) { |
2a519311 | 5860 | idx--; |
67748893 | 5861 | break; |
2a519311 JB |
5862 | } |
5863 | } | |
5864 | ||
48ab905d JB |
5865 | spin_unlock_bh(&rdev->bss_lock); |
5866 | wdev_unlock(wdev); | |
2a519311 | 5867 | |
97990a06 JB |
5868 | cb->args[2] = idx; |
5869 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5870 | |
67748893 | 5871 | return skb->len; |
2a519311 JB |
5872 | } |
5873 | ||
15e47304 | 5874 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5875 | int flags, struct net_device *dev, |
5876 | struct survey_info *survey) | |
5877 | { | |
5878 | void *hdr; | |
5879 | struct nlattr *infoattr; | |
5880 | ||
15e47304 | 5881 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5882 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5883 | if (!hdr) | |
5884 | return -ENOMEM; | |
5885 | ||
9360ffd1 DM |
5886 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5887 | goto nla_put_failure; | |
61fa713c HS |
5888 | |
5889 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5890 | if (!infoattr) | |
5891 | goto nla_put_failure; | |
5892 | ||
9360ffd1 DM |
5893 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5894 | survey->channel->center_freq)) | |
5895 | goto nla_put_failure; | |
5896 | ||
5897 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5898 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5899 | goto nla_put_failure; | |
5900 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5901 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5902 | goto nla_put_failure; | |
5903 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5904 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5905 | survey->channel_time)) | |
5906 | goto nla_put_failure; | |
5907 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5908 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5909 | survey->channel_time_busy)) | |
5910 | goto nla_put_failure; | |
5911 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5912 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5913 | survey->channel_time_ext_busy)) | |
5914 | goto nla_put_failure; | |
5915 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5916 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5917 | survey->channel_time_rx)) | |
5918 | goto nla_put_failure; | |
5919 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5920 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5921 | survey->channel_time_tx)) | |
5922 | goto nla_put_failure; | |
61fa713c HS |
5923 | |
5924 | nla_nest_end(msg, infoattr); | |
5925 | ||
5926 | return genlmsg_end(msg, hdr); | |
5927 | ||
5928 | nla_put_failure: | |
5929 | genlmsg_cancel(msg, hdr); | |
5930 | return -EMSGSIZE; | |
5931 | } | |
5932 | ||
5933 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5934 | struct netlink_callback *cb) | |
5935 | { | |
5936 | struct survey_info survey; | |
5937 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5938 | struct wireless_dev *wdev; |
5939 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5940 | int res; |
5941 | ||
97990a06 | 5942 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5943 | if (res) |
5944 | return res; | |
61fa713c | 5945 | |
97990a06 JB |
5946 | if (!wdev->netdev) { |
5947 | res = -EINVAL; | |
5948 | goto out_err; | |
5949 | } | |
5950 | ||
61fa713c HS |
5951 | if (!dev->ops->dump_survey) { |
5952 | res = -EOPNOTSUPP; | |
5953 | goto out_err; | |
5954 | } | |
5955 | ||
5956 | while (1) { | |
180cdc79 LR |
5957 | struct ieee80211_channel *chan; |
5958 | ||
97990a06 | 5959 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5960 | if (res == -ENOENT) |
5961 | break; | |
5962 | if (res) | |
5963 | goto out_err; | |
5964 | ||
180cdc79 LR |
5965 | /* Survey without a channel doesn't make sense */ |
5966 | if (!survey.channel) { | |
5967 | res = -EINVAL; | |
5968 | goto out; | |
5969 | } | |
5970 | ||
5971 | chan = ieee80211_get_channel(&dev->wiphy, | |
5972 | survey.channel->center_freq); | |
5973 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5974 | survey_idx++; | |
5975 | continue; | |
5976 | } | |
5977 | ||
61fa713c | 5978 | if (nl80211_send_survey(skb, |
15e47304 | 5979 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5980 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5981 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5982 | goto out; |
5983 | survey_idx++; | |
5984 | } | |
5985 | ||
5986 | out: | |
97990a06 | 5987 | cb->args[2] = survey_idx; |
61fa713c HS |
5988 | res = skb->len; |
5989 | out_err: | |
97990a06 | 5990 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5991 | return res; |
5992 | } | |
5993 | ||
b23aa676 SO |
5994 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5995 | { | |
5996 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5997 | NL80211_WPA_VERSION_2)); | |
5998 | } | |
5999 | ||
636a5d36 JM |
6000 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6001 | { | |
4c476991 JB |
6002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6003 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6004 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6005 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6006 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6007 | enum nl80211_auth_type auth_type; |
fffd0934 | 6008 | struct key_parse key; |
d5cdfacb | 6009 | bool local_state_change; |
636a5d36 | 6010 | |
f4a11bb0 JB |
6011 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6012 | return -EINVAL; | |
6013 | ||
6014 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6015 | return -EINVAL; | |
6016 | ||
1778092e JM |
6017 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6018 | return -EINVAL; | |
6019 | ||
19957bb3 JB |
6020 | if (!info->attrs[NL80211_ATTR_SSID]) |
6021 | return -EINVAL; | |
6022 | ||
6023 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6024 | return -EINVAL; | |
6025 | ||
fffd0934 JB |
6026 | err = nl80211_parse_key(info, &key); |
6027 | if (err) | |
6028 | return err; | |
6029 | ||
6030 | if (key.idx >= 0) { | |
e31b8213 JB |
6031 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6032 | return -EINVAL; | |
fffd0934 JB |
6033 | if (!key.p.key || !key.p.key_len) |
6034 | return -EINVAL; | |
6035 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6036 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6037 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6038 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6039 | return -EINVAL; | |
6040 | if (key.idx > 4) | |
6041 | return -EINVAL; | |
6042 | } else { | |
6043 | key.p.key_len = 0; | |
6044 | key.p.key = NULL; | |
6045 | } | |
6046 | ||
afea0b7a JB |
6047 | if (key.idx >= 0) { |
6048 | int i; | |
6049 | bool ok = false; | |
6050 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6051 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6052 | ok = true; | |
6053 | break; | |
6054 | } | |
6055 | } | |
4c476991 JB |
6056 | if (!ok) |
6057 | return -EINVAL; | |
afea0b7a JB |
6058 | } |
6059 | ||
4c476991 JB |
6060 | if (!rdev->ops->auth) |
6061 | return -EOPNOTSUPP; | |
636a5d36 | 6062 | |
074ac8df | 6063 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6064 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6065 | return -EOPNOTSUPP; | |
eec60b03 | 6066 | |
19957bb3 | 6067 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 6068 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 6069 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
6070 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6071 | return -EINVAL; | |
636a5d36 | 6072 | |
19957bb3 JB |
6073 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6074 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6075 | |
6076 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6077 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6078 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6079 | } |
6080 | ||
19957bb3 | 6081 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6082 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6083 | return -EINVAL; |
636a5d36 | 6084 | |
e39e5b5e JM |
6085 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6086 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6087 | return -EINVAL; | |
6088 | ||
6089 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6090 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6091 | return -EINVAL; | |
6092 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6093 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6094 | /* need to include at least Auth Transaction and Status Code */ | |
6095 | if (sae_data_len < 4) | |
6096 | return -EINVAL; | |
6097 | } | |
6098 | ||
d5cdfacb JM |
6099 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6100 | ||
95de817b JB |
6101 | /* |
6102 | * Since we no longer track auth state, ignore | |
6103 | * requests to only change local state. | |
6104 | */ | |
6105 | if (local_state_change) | |
6106 | return 0; | |
6107 | ||
91bf9b26 JB |
6108 | wdev_lock(dev->ieee80211_ptr); |
6109 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6110 | ssid, ssid_len, ie, ie_len, | |
6111 | key.p.key, key.p.key_len, key.idx, | |
6112 | sae_data, sae_data_len); | |
6113 | wdev_unlock(dev->ieee80211_ptr); | |
6114 | return err; | |
636a5d36 JM |
6115 | } |
6116 | ||
c0692b8f JB |
6117 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6118 | struct genl_info *info, | |
3dc27d25 JB |
6119 | struct cfg80211_crypto_settings *settings, |
6120 | int cipher_limit) | |
b23aa676 | 6121 | { |
c0b2bbd8 JB |
6122 | memset(settings, 0, sizeof(*settings)); |
6123 | ||
b23aa676 SO |
6124 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6125 | ||
c0692b8f JB |
6126 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6127 | u16 proto; | |
6128 | proto = nla_get_u16( | |
6129 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6130 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6131 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6132 | proto != ETH_P_PAE) | |
6133 | return -EINVAL; | |
6134 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6135 | settings->control_port_no_encrypt = true; | |
6136 | } else | |
6137 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6138 | ||
b23aa676 SO |
6139 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6140 | void *data; | |
6141 | int len, i; | |
6142 | ||
6143 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6144 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6145 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6146 | ||
6147 | if (len % sizeof(u32)) | |
6148 | return -EINVAL; | |
6149 | ||
3dc27d25 | 6150 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6151 | return -EINVAL; |
6152 | ||
6153 | memcpy(settings->ciphers_pairwise, data, len); | |
6154 | ||
6155 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6156 | if (!cfg80211_supported_cipher_suite( |
6157 | &rdev->wiphy, | |
b23aa676 SO |
6158 | settings->ciphers_pairwise[i])) |
6159 | return -EINVAL; | |
6160 | } | |
6161 | ||
6162 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6163 | settings->cipher_group = | |
6164 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6165 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6166 | settings->cipher_group)) | |
b23aa676 SO |
6167 | return -EINVAL; |
6168 | } | |
6169 | ||
6170 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6171 | settings->wpa_versions = | |
6172 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6173 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6174 | return -EINVAL; | |
6175 | } | |
6176 | ||
6177 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6178 | void *data; | |
6d30240e | 6179 | int len; |
b23aa676 SO |
6180 | |
6181 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6182 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6183 | settings->n_akm_suites = len / sizeof(u32); | |
6184 | ||
6185 | if (len % sizeof(u32)) | |
6186 | return -EINVAL; | |
6187 | ||
1b9ca027 JM |
6188 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6189 | return -EINVAL; | |
6190 | ||
b23aa676 | 6191 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6192 | } |
6193 | ||
6194 | return 0; | |
6195 | } | |
6196 | ||
636a5d36 JM |
6197 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6198 | { | |
4c476991 JB |
6199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6200 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6201 | struct ieee80211_channel *chan; |
f62fab73 JB |
6202 | struct cfg80211_assoc_request req = {}; |
6203 | const u8 *bssid, *ssid; | |
6204 | int err, ssid_len = 0; | |
636a5d36 | 6205 | |
f4a11bb0 JB |
6206 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6207 | return -EINVAL; | |
6208 | ||
6209 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6210 | !info->attrs[NL80211_ATTR_SSID] || |
6211 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6212 | return -EINVAL; |
6213 | ||
4c476991 JB |
6214 | if (!rdev->ops->assoc) |
6215 | return -EOPNOTSUPP; | |
636a5d36 | 6216 | |
074ac8df | 6217 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6218 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6219 | return -EOPNOTSUPP; | |
eec60b03 | 6220 | |
19957bb3 | 6221 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6222 | |
19957bb3 JB |
6223 | chan = ieee80211_get_channel(&rdev->wiphy, |
6224 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6225 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6226 | return -EINVAL; | |
636a5d36 | 6227 | |
19957bb3 JB |
6228 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6229 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6230 | |
6231 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6232 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6233 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6234 | } |
6235 | ||
dc6382ce | 6236 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6237 | enum nl80211_mfp mfp = |
dc6382ce | 6238 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6239 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6240 | req.use_mfp = true; |
4c476991 JB |
6241 | else if (mfp != NL80211_MFP_NO) |
6242 | return -EINVAL; | |
dc6382ce JM |
6243 | } |
6244 | ||
3e5d7649 | 6245 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6246 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6247 | |
7e7c8926 | 6248 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6249 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6250 | |
6251 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6252 | memcpy(&req.ht_capa_mask, |
6253 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6254 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6255 | |
6256 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6257 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6258 | return -EINVAL; |
f62fab73 JB |
6259 | memcpy(&req.ht_capa, |
6260 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6261 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6262 | } |
6263 | ||
ee2aca34 | 6264 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6265 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6266 | |
6267 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6268 | memcpy(&req.vht_capa_mask, |
6269 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6270 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6271 | |
6272 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6273 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6274 | return -EINVAL; |
f62fab73 JB |
6275 | memcpy(&req.vht_capa, |
6276 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6277 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6278 | } |
6279 | ||
f62fab73 | 6280 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6281 | if (!err) { |
6282 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6283 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6284 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6285 | wdev_unlock(dev->ieee80211_ptr); |
6286 | } | |
636a5d36 | 6287 | |
636a5d36 JM |
6288 | return err; |
6289 | } | |
6290 | ||
6291 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6292 | { | |
4c476991 JB |
6293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6294 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6295 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6296 | int ie_len = 0, err; |
19957bb3 | 6297 | u16 reason_code; |
d5cdfacb | 6298 | bool local_state_change; |
636a5d36 | 6299 | |
f4a11bb0 JB |
6300 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6301 | return -EINVAL; | |
6302 | ||
6303 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6304 | return -EINVAL; | |
6305 | ||
6306 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6307 | return -EINVAL; | |
6308 | ||
4c476991 JB |
6309 | if (!rdev->ops->deauth) |
6310 | return -EOPNOTSUPP; | |
636a5d36 | 6311 | |
074ac8df | 6312 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6313 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6314 | return -EOPNOTSUPP; | |
eec60b03 | 6315 | |
19957bb3 | 6316 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6317 | |
19957bb3 JB |
6318 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6319 | if (reason_code == 0) { | |
f4a11bb0 | 6320 | /* Reason Code 0 is reserved */ |
4c476991 | 6321 | return -EINVAL; |
255e737e | 6322 | } |
636a5d36 JM |
6323 | |
6324 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6325 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6326 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6327 | } |
6328 | ||
d5cdfacb JM |
6329 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6330 | ||
91bf9b26 JB |
6331 | wdev_lock(dev->ieee80211_ptr); |
6332 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6333 | local_state_change); | |
6334 | wdev_unlock(dev->ieee80211_ptr); | |
6335 | return err; | |
636a5d36 JM |
6336 | } |
6337 | ||
6338 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6339 | { | |
4c476991 JB |
6340 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6341 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6342 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6343 | int ie_len = 0, err; |
19957bb3 | 6344 | u16 reason_code; |
d5cdfacb | 6345 | bool local_state_change; |
636a5d36 | 6346 | |
f4a11bb0 JB |
6347 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6348 | return -EINVAL; | |
6349 | ||
6350 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6351 | return -EINVAL; | |
6352 | ||
6353 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6354 | return -EINVAL; | |
6355 | ||
4c476991 JB |
6356 | if (!rdev->ops->disassoc) |
6357 | return -EOPNOTSUPP; | |
636a5d36 | 6358 | |
074ac8df | 6359 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6360 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6361 | return -EOPNOTSUPP; | |
eec60b03 | 6362 | |
19957bb3 | 6363 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6364 | |
19957bb3 JB |
6365 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6366 | if (reason_code == 0) { | |
f4a11bb0 | 6367 | /* Reason Code 0 is reserved */ |
4c476991 | 6368 | return -EINVAL; |
255e737e | 6369 | } |
636a5d36 JM |
6370 | |
6371 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6372 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6373 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6374 | } |
6375 | ||
d5cdfacb JM |
6376 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6377 | ||
91bf9b26 JB |
6378 | wdev_lock(dev->ieee80211_ptr); |
6379 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6380 | local_state_change); | |
6381 | wdev_unlock(dev->ieee80211_ptr); | |
6382 | return err; | |
636a5d36 JM |
6383 | } |
6384 | ||
dd5b4cc7 FF |
6385 | static bool |
6386 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6387 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6388 | int rateval) | |
6389 | { | |
6390 | struct wiphy *wiphy = &rdev->wiphy; | |
6391 | bool found = false; | |
6392 | int band, i; | |
6393 | ||
6394 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6395 | struct ieee80211_supported_band *sband; | |
6396 | ||
6397 | sband = wiphy->bands[band]; | |
6398 | if (!sband) | |
6399 | continue; | |
6400 | ||
6401 | for (i = 0; i < sband->n_bitrates; i++) { | |
6402 | if (sband->bitrates[i].bitrate == rateval) { | |
6403 | mcast_rate[band] = i + 1; | |
6404 | found = true; | |
6405 | break; | |
6406 | } | |
6407 | } | |
6408 | } | |
6409 | ||
6410 | return found; | |
6411 | } | |
6412 | ||
04a773ad JB |
6413 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6414 | { | |
4c476991 JB |
6415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6416 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6417 | struct cfg80211_ibss_params ibss; |
6418 | struct wiphy *wiphy; | |
fffd0934 | 6419 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6420 | int err; |
6421 | ||
8e30bc55 JB |
6422 | memset(&ibss, 0, sizeof(ibss)); |
6423 | ||
04a773ad JB |
6424 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6425 | return -EINVAL; | |
6426 | ||
683b6d3b | 6427 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6428 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6429 | return -EINVAL; | |
6430 | ||
8e30bc55 JB |
6431 | ibss.beacon_interval = 100; |
6432 | ||
6433 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6434 | ibss.beacon_interval = | |
6435 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6436 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6437 | return -EINVAL; | |
6438 | } | |
6439 | ||
4c476991 JB |
6440 | if (!rdev->ops->join_ibss) |
6441 | return -EOPNOTSUPP; | |
04a773ad | 6442 | |
4c476991 JB |
6443 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6444 | return -EOPNOTSUPP; | |
04a773ad | 6445 | |
79c97e97 | 6446 | wiphy = &rdev->wiphy; |
04a773ad | 6447 | |
39193498 | 6448 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6449 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6450 | |
6451 | if (!is_valid_ether_addr(ibss.bssid)) | |
6452 | return -EINVAL; | |
6453 | } | |
04a773ad JB |
6454 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6455 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6456 | ||
6457 | if (info->attrs[NL80211_ATTR_IE]) { | |
6458 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6459 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6460 | } | |
6461 | ||
683b6d3b JB |
6462 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6463 | if (err) | |
6464 | return err; | |
04a773ad | 6465 | |
683b6d3b | 6466 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6467 | return -EINVAL; |
6468 | ||
2f301ab2 | 6469 | switch (ibss.chandef.width) { |
bf372645 SW |
6470 | case NL80211_CHAN_WIDTH_5: |
6471 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6472 | case NL80211_CHAN_WIDTH_20_NOHT: |
6473 | break; | |
6474 | case NL80211_CHAN_WIDTH_20: | |
6475 | case NL80211_CHAN_WIDTH_40: | |
6476 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6477 | break; | |
6478 | default: | |
c04d6150 | 6479 | return -EINVAL; |
2f301ab2 | 6480 | } |
db9c64cf | 6481 | |
04a773ad | 6482 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6483 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6484 | ||
fbd2c8dc TP |
6485 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6486 | u8 *rates = | |
6487 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6488 | int n_rates = | |
6489 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6490 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6491 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6492 | |
34850ab2 JB |
6493 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6494 | &ibss.basic_rates); | |
6495 | if (err) | |
6496 | return err; | |
fbd2c8dc | 6497 | } |
dd5b4cc7 | 6498 | |
803768f5 SW |
6499 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6500 | memcpy(&ibss.ht_capa_mask, | |
6501 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6502 | sizeof(ibss.ht_capa_mask)); | |
6503 | ||
6504 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6505 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6506 | return -EINVAL; | |
6507 | memcpy(&ibss.ht_capa, | |
6508 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6509 | sizeof(ibss.ht_capa)); | |
6510 | } | |
6511 | ||
dd5b4cc7 FF |
6512 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6513 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6514 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6515 | return -EINVAL; | |
fbd2c8dc | 6516 | |
4c476991 | 6517 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6518 | bool no_ht = false; |
6519 | ||
4c476991 | 6520 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6521 | info->attrs[NL80211_ATTR_KEYS], |
6522 | &no_ht); | |
4c476991 JB |
6523 | if (IS_ERR(connkeys)) |
6524 | return PTR_ERR(connkeys); | |
de7044ee | 6525 | |
3d9d1d66 JB |
6526 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6527 | no_ht) { | |
de7044ee SM |
6528 | kfree(connkeys); |
6529 | return -EINVAL; | |
6530 | } | |
4c476991 | 6531 | } |
04a773ad | 6532 | |
267335d6 AQ |
6533 | ibss.control_port = |
6534 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6535 | ||
4c476991 | 6536 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6537 | if (err) |
6538 | kfree(connkeys); | |
04a773ad JB |
6539 | return err; |
6540 | } | |
6541 | ||
6542 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6543 | { | |
4c476991 JB |
6544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6545 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6546 | |
4c476991 JB |
6547 | if (!rdev->ops->leave_ibss) |
6548 | return -EOPNOTSUPP; | |
04a773ad | 6549 | |
4c476991 JB |
6550 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6551 | return -EOPNOTSUPP; | |
04a773ad | 6552 | |
4c476991 | 6553 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6554 | } |
6555 | ||
f4e583c8 AQ |
6556 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6557 | { | |
6558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6559 | struct net_device *dev = info->user_ptr[1]; | |
6560 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6561 | u32 nla_rate; | |
6562 | int err; | |
6563 | ||
6564 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6565 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6566 | return -EOPNOTSUPP; | |
6567 | ||
6568 | if (!rdev->ops->set_mcast_rate) | |
6569 | return -EOPNOTSUPP; | |
6570 | ||
6571 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6572 | ||
6573 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6574 | return -EINVAL; | |
6575 | ||
6576 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6577 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6578 | return -EINVAL; | |
6579 | ||
6580 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6581 | ||
6582 | return err; | |
6583 | } | |
6584 | ||
6585 | ||
aff89a9b JB |
6586 | #ifdef CONFIG_NL80211_TESTMODE |
6587 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6588 | .name = "testmode", | |
6589 | }; | |
6590 | ||
6591 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6592 | { | |
4c476991 | 6593 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6594 | int err; |
6595 | ||
6596 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6597 | return -EINVAL; | |
6598 | ||
aff89a9b JB |
6599 | err = -EOPNOTSUPP; |
6600 | if (rdev->ops->testmode_cmd) { | |
6601 | rdev->testmode_info = info; | |
e35e4d28 | 6602 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6603 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6604 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6605 | rdev->testmode_info = NULL; | |
6606 | } | |
6607 | ||
aff89a9b JB |
6608 | return err; |
6609 | } | |
6610 | ||
71063f0e WYG |
6611 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6612 | struct netlink_callback *cb) | |
6613 | { | |
00918d33 | 6614 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6615 | int err; |
6616 | long phy_idx; | |
6617 | void *data = NULL; | |
6618 | int data_len = 0; | |
6619 | ||
5fe231e8 JB |
6620 | rtnl_lock(); |
6621 | ||
71063f0e WYG |
6622 | if (cb->args[0]) { |
6623 | /* | |
6624 | * 0 is a valid index, but not valid for args[0], | |
6625 | * so we need to offset by 1. | |
6626 | */ | |
6627 | phy_idx = cb->args[0] - 1; | |
6628 | } else { | |
6629 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6630 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6631 | nl80211_policy); | |
6632 | if (err) | |
5fe231e8 | 6633 | goto out_err; |
00918d33 | 6634 | |
2bd7e35d JB |
6635 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6636 | nl80211_fam.attrbuf); | |
6637 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6638 | err = PTR_ERR(rdev); |
6639 | goto out_err; | |
00918d33 | 6640 | } |
2bd7e35d JB |
6641 | phy_idx = rdev->wiphy_idx; |
6642 | rdev = NULL; | |
2bd7e35d | 6643 | |
71063f0e WYG |
6644 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6645 | cb->args[1] = | |
6646 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6647 | } | |
6648 | ||
6649 | if (cb->args[1]) { | |
6650 | data = nla_data((void *)cb->args[1]); | |
6651 | data_len = nla_len((void *)cb->args[1]); | |
6652 | } | |
6653 | ||
00918d33 JB |
6654 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6655 | if (!rdev) { | |
5fe231e8 JB |
6656 | err = -ENOENT; |
6657 | goto out_err; | |
71063f0e | 6658 | } |
71063f0e | 6659 | |
00918d33 | 6660 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6661 | err = -EOPNOTSUPP; |
6662 | goto out_err; | |
6663 | } | |
6664 | ||
6665 | while (1) { | |
15e47304 | 6666 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6667 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6668 | NL80211_CMD_TESTMODE); | |
6669 | struct nlattr *tmdata; | |
6670 | ||
9360ffd1 | 6671 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6672 | genlmsg_cancel(skb, hdr); |
6673 | break; | |
6674 | } | |
6675 | ||
6676 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6677 | if (!tmdata) { | |
6678 | genlmsg_cancel(skb, hdr); | |
6679 | break; | |
6680 | } | |
e35e4d28 | 6681 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6682 | nla_nest_end(skb, tmdata); |
6683 | ||
6684 | if (err == -ENOBUFS || err == -ENOENT) { | |
6685 | genlmsg_cancel(skb, hdr); | |
6686 | break; | |
6687 | } else if (err) { | |
6688 | genlmsg_cancel(skb, hdr); | |
6689 | goto out_err; | |
6690 | } | |
6691 | ||
6692 | genlmsg_end(skb, hdr); | |
6693 | } | |
6694 | ||
6695 | err = skb->len; | |
6696 | /* see above */ | |
6697 | cb->args[0] = phy_idx + 1; | |
6698 | out_err: | |
5fe231e8 | 6699 | rtnl_unlock(); |
71063f0e WYG |
6700 | return err; |
6701 | } | |
6702 | ||
aff89a9b JB |
6703 | static struct sk_buff * |
6704 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6705 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6706 | { |
6707 | struct sk_buff *skb; | |
6708 | void *hdr; | |
6709 | struct nlattr *data; | |
6710 | ||
6711 | skb = nlmsg_new(approxlen + 100, gfp); | |
6712 | if (!skb) | |
6713 | return NULL; | |
6714 | ||
15e47304 | 6715 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6716 | if (!hdr) { |
6717 | kfree_skb(skb); | |
6718 | return NULL; | |
6719 | } | |
6720 | ||
9360ffd1 DM |
6721 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6722 | goto nla_put_failure; | |
aff89a9b JB |
6723 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6724 | ||
6725 | ((void **)skb->cb)[0] = rdev; | |
6726 | ((void **)skb->cb)[1] = hdr; | |
6727 | ((void **)skb->cb)[2] = data; | |
6728 | ||
6729 | return skb; | |
6730 | ||
6731 | nla_put_failure: | |
6732 | kfree_skb(skb); | |
6733 | return NULL; | |
6734 | } | |
6735 | ||
6736 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6737 | int approxlen) | |
6738 | { | |
6739 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6740 | ||
6741 | if (WARN_ON(!rdev->testmode_info)) | |
6742 | return NULL; | |
6743 | ||
6744 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6745 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6746 | rdev->testmode_info->snd_seq, |
6747 | GFP_KERNEL); | |
6748 | } | |
6749 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6750 | ||
6751 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6752 | { | |
6753 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6754 | void *hdr = ((void **)skb->cb)[1]; | |
6755 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6756 | ||
6757 | if (WARN_ON(!rdev->testmode_info)) { | |
6758 | kfree_skb(skb); | |
6759 | return -EINVAL; | |
6760 | } | |
6761 | ||
6762 | nla_nest_end(skb, data); | |
6763 | genlmsg_end(skb, hdr); | |
6764 | return genlmsg_reply(skb, rdev->testmode_info); | |
6765 | } | |
6766 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6767 | ||
6768 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6769 | int approxlen, gfp_t gfp) | |
6770 | { | |
6771 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6772 | ||
6773 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6774 | } | |
6775 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6776 | ||
6777 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6778 | { | |
6779 | void *hdr = ((void **)skb->cb)[1]; | |
6780 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6781 | ||
6782 | nla_nest_end(skb, data); | |
6783 | genlmsg_end(skb, hdr); | |
6784 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6785 | } | |
6786 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6787 | #endif | |
6788 | ||
b23aa676 SO |
6789 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6790 | { | |
4c476991 JB |
6791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6792 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6793 | struct cfg80211_connect_params connect; |
6794 | struct wiphy *wiphy; | |
fffd0934 | 6795 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6796 | int err; |
6797 | ||
6798 | memset(&connect, 0, sizeof(connect)); | |
6799 | ||
6800 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6801 | return -EINVAL; | |
6802 | ||
6803 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6804 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6805 | return -EINVAL; | |
6806 | ||
6807 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6808 | connect.auth_type = | |
6809 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6810 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6811 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6812 | return -EINVAL; |
6813 | } else | |
6814 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6815 | ||
6816 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6817 | ||
c0692b8f | 6818 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6819 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6820 | if (err) |
6821 | return err; | |
b23aa676 | 6822 | |
074ac8df | 6823 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6824 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6825 | return -EOPNOTSUPP; | |
b23aa676 | 6826 | |
79c97e97 | 6827 | wiphy = &rdev->wiphy; |
b23aa676 | 6828 | |
4486ea98 BS |
6829 | connect.bg_scan_period = -1; |
6830 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6831 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6832 | connect.bg_scan_period = | |
6833 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6834 | } | |
6835 | ||
b23aa676 SO |
6836 | if (info->attrs[NL80211_ATTR_MAC]) |
6837 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6838 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6839 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6840 | ||
6841 | if (info->attrs[NL80211_ATTR_IE]) { | |
6842 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6843 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6844 | } | |
6845 | ||
cee00a95 JM |
6846 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6847 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6848 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6849 | connect.mfp != NL80211_MFP_NO) | |
6850 | return -EINVAL; | |
6851 | } else { | |
6852 | connect.mfp = NL80211_MFP_NO; | |
6853 | } | |
6854 | ||
b23aa676 SO |
6855 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6856 | connect.channel = | |
6857 | ieee80211_get_channel(wiphy, | |
6858 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6859 | if (!connect.channel || | |
4c476991 JB |
6860 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6861 | return -EINVAL; | |
b23aa676 SO |
6862 | } |
6863 | ||
fffd0934 JB |
6864 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6865 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6866 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6867 | if (IS_ERR(connkeys)) |
6868 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6869 | } |
6870 | ||
7e7c8926 BG |
6871 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6872 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6873 | ||
6874 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6875 | memcpy(&connect.ht_capa_mask, | |
6876 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6877 | sizeof(connect.ht_capa_mask)); | |
6878 | ||
6879 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6880 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6881 | kfree(connkeys); | |
7e7c8926 | 6882 | return -EINVAL; |
b4e4f47e | 6883 | } |
7e7c8926 BG |
6884 | memcpy(&connect.ht_capa, |
6885 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6886 | sizeof(connect.ht_capa)); | |
6887 | } | |
6888 | ||
ee2aca34 JB |
6889 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6890 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6891 | ||
6892 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6893 | memcpy(&connect.vht_capa_mask, | |
6894 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6895 | sizeof(connect.vht_capa_mask)); | |
6896 | ||
6897 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6898 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6899 | kfree(connkeys); | |
6900 | return -EINVAL; | |
6901 | } | |
6902 | memcpy(&connect.vht_capa, | |
6903 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6904 | sizeof(connect.vht_capa)); | |
6905 | } | |
6906 | ||
83739b03 JB |
6907 | wdev_lock(dev->ieee80211_ptr); |
6908 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
6909 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
6910 | if (err) |
6911 | kfree(connkeys); | |
b23aa676 SO |
6912 | return err; |
6913 | } | |
6914 | ||
6915 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6916 | { | |
4c476991 JB |
6917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6918 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 6919 | u16 reason; |
83739b03 | 6920 | int ret; |
b23aa676 SO |
6921 | |
6922 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6923 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6924 | else | |
6925 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6926 | ||
6927 | if (reason == 0) | |
6928 | return -EINVAL; | |
6929 | ||
074ac8df | 6930 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6931 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6932 | return -EOPNOTSUPP; | |
b23aa676 | 6933 | |
83739b03 JB |
6934 | wdev_lock(dev->ieee80211_ptr); |
6935 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
6936 | wdev_unlock(dev->ieee80211_ptr); | |
6937 | return ret; | |
b23aa676 SO |
6938 | } |
6939 | ||
463d0183 JB |
6940 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6941 | { | |
4c476991 | 6942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6943 | struct net *net; |
6944 | int err; | |
6945 | u32 pid; | |
6946 | ||
6947 | if (!info->attrs[NL80211_ATTR_PID]) | |
6948 | return -EINVAL; | |
6949 | ||
6950 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6951 | ||
463d0183 | 6952 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6953 | if (IS_ERR(net)) |
6954 | return PTR_ERR(net); | |
463d0183 JB |
6955 | |
6956 | err = 0; | |
6957 | ||
6958 | /* check if anything to do */ | |
4c476991 JB |
6959 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6960 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6961 | |
463d0183 | 6962 | put_net(net); |
463d0183 JB |
6963 | return err; |
6964 | } | |
6965 | ||
67fbb16b SO |
6966 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6967 | { | |
4c476991 | 6968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6969 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6970 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6971 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6972 | struct cfg80211_pmksa pmksa; |
6973 | ||
6974 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6975 | ||
6976 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6977 | return -EINVAL; | |
6978 | ||
6979 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6980 | return -EINVAL; | |
6981 | ||
67fbb16b SO |
6982 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6983 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6984 | ||
074ac8df | 6985 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6986 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6987 | return -EOPNOTSUPP; | |
67fbb16b SO |
6988 | |
6989 | switch (info->genlhdr->cmd) { | |
6990 | case NL80211_CMD_SET_PMKSA: | |
6991 | rdev_ops = rdev->ops->set_pmksa; | |
6992 | break; | |
6993 | case NL80211_CMD_DEL_PMKSA: | |
6994 | rdev_ops = rdev->ops->del_pmksa; | |
6995 | break; | |
6996 | default: | |
6997 | WARN_ON(1); | |
6998 | break; | |
6999 | } | |
7000 | ||
4c476991 JB |
7001 | if (!rdev_ops) |
7002 | return -EOPNOTSUPP; | |
67fbb16b | 7003 | |
4c476991 | 7004 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7005 | } |
7006 | ||
7007 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7008 | { | |
4c476991 JB |
7009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7010 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7011 | |
074ac8df | 7012 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7013 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7014 | return -EOPNOTSUPP; | |
67fbb16b | 7015 | |
4c476991 JB |
7016 | if (!rdev->ops->flush_pmksa) |
7017 | return -EOPNOTSUPP; | |
67fbb16b | 7018 | |
e35e4d28 | 7019 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7020 | } |
7021 | ||
109086ce AN |
7022 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7023 | { | |
7024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7025 | struct net_device *dev = info->user_ptr[1]; | |
7026 | u8 action_code, dialog_token; | |
7027 | u16 status_code; | |
7028 | u8 *peer; | |
7029 | ||
7030 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7031 | !rdev->ops->tdls_mgmt) | |
7032 | return -EOPNOTSUPP; | |
7033 | ||
7034 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7035 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7036 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7037 | !info->attrs[NL80211_ATTR_IE] || | |
7038 | !info->attrs[NL80211_ATTR_MAC]) | |
7039 | return -EINVAL; | |
7040 | ||
7041 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7042 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7043 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7044 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
7045 | ||
e35e4d28 HG |
7046 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
7047 | dialog_token, status_code, | |
7048 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
7049 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7050 | } |
7051 | ||
7052 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7053 | { | |
7054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7055 | struct net_device *dev = info->user_ptr[1]; | |
7056 | enum nl80211_tdls_operation operation; | |
7057 | u8 *peer; | |
7058 | ||
7059 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7060 | !rdev->ops->tdls_oper) | |
7061 | return -EOPNOTSUPP; | |
7062 | ||
7063 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7064 | !info->attrs[NL80211_ATTR_MAC]) | |
7065 | return -EINVAL; | |
7066 | ||
7067 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7068 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7069 | ||
e35e4d28 | 7070 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7071 | } |
7072 | ||
9588bbd5 JM |
7073 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7074 | struct genl_info *info) | |
7075 | { | |
4c476991 | 7076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7077 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7078 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7079 | struct sk_buff *msg; |
7080 | void *hdr; | |
7081 | u64 cookie; | |
683b6d3b | 7082 | u32 duration; |
9588bbd5 JM |
7083 | int err; |
7084 | ||
7085 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7086 | !info->attrs[NL80211_ATTR_DURATION]) | |
7087 | return -EINVAL; | |
7088 | ||
7089 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7090 | ||
ebf348fc JB |
7091 | if (!rdev->ops->remain_on_channel || |
7092 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7093 | return -EOPNOTSUPP; | |
7094 | ||
9588bbd5 | 7095 | /* |
ebf348fc JB |
7096 | * We should be on that channel for at least a minimum amount of |
7097 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7098 | */ |
ebf348fc | 7099 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7100 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7101 | return -EINVAL; |
7102 | ||
683b6d3b JB |
7103 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7104 | if (err) | |
7105 | return err; | |
9588bbd5 JM |
7106 | |
7107 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7108 | if (!msg) |
7109 | return -ENOMEM; | |
9588bbd5 | 7110 | |
15e47304 | 7111 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
7112 | NL80211_CMD_REMAIN_ON_CHANNEL); |
7113 | ||
7114 | if (IS_ERR(hdr)) { | |
7115 | err = PTR_ERR(hdr); | |
7116 | goto free_msg; | |
7117 | } | |
7118 | ||
683b6d3b JB |
7119 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7120 | duration, &cookie); | |
9588bbd5 JM |
7121 | |
7122 | if (err) | |
7123 | goto free_msg; | |
7124 | ||
9360ffd1 DM |
7125 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7126 | goto nla_put_failure; | |
9588bbd5 JM |
7127 | |
7128 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7129 | |
7130 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7131 | |
7132 | nla_put_failure: | |
7133 | err = -ENOBUFS; | |
7134 | free_msg: | |
7135 | nlmsg_free(msg); | |
9588bbd5 JM |
7136 | return err; |
7137 | } | |
7138 | ||
7139 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7140 | struct genl_info *info) | |
7141 | { | |
4c476991 | 7142 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7143 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7144 | u64 cookie; |
9588bbd5 JM |
7145 | |
7146 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7147 | return -EINVAL; | |
7148 | ||
4c476991 JB |
7149 | if (!rdev->ops->cancel_remain_on_channel) |
7150 | return -EOPNOTSUPP; | |
9588bbd5 | 7151 | |
9588bbd5 JM |
7152 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7153 | ||
e35e4d28 | 7154 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7155 | } |
7156 | ||
13ae75b1 JM |
7157 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7158 | u8 *rates, u8 rates_len) | |
7159 | { | |
7160 | u8 i; | |
7161 | u32 mask = 0; | |
7162 | ||
7163 | for (i = 0; i < rates_len; i++) { | |
7164 | int rate = (rates[i] & 0x7f) * 5; | |
7165 | int ridx; | |
7166 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7167 | struct ieee80211_rate *srate = | |
7168 | &sband->bitrates[ridx]; | |
7169 | if (rate == srate->bitrate) { | |
7170 | mask |= 1 << ridx; | |
7171 | break; | |
7172 | } | |
7173 | } | |
7174 | if (ridx == sband->n_bitrates) | |
7175 | return 0; /* rate not found */ | |
7176 | } | |
7177 | ||
7178 | return mask; | |
7179 | } | |
7180 | ||
24db78c0 SW |
7181 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7182 | u8 *rates, u8 rates_len, | |
7183 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7184 | { | |
7185 | u8 i; | |
7186 | ||
7187 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7188 | ||
7189 | for (i = 0; i < rates_len; i++) { | |
7190 | int ridx, rbit; | |
7191 | ||
7192 | ridx = rates[i] / 8; | |
7193 | rbit = BIT(rates[i] % 8); | |
7194 | ||
7195 | /* check validity */ | |
910570b5 | 7196 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7197 | return false; |
7198 | ||
7199 | /* check availability */ | |
7200 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7201 | mcs[ridx] |= rbit; | |
7202 | else | |
7203 | return false; | |
7204 | } | |
7205 | ||
7206 | return true; | |
7207 | } | |
7208 | ||
b54452b0 | 7209 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7210 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7211 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7212 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7213 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7214 | }; |
7215 | ||
7216 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7217 | struct genl_info *info) | |
7218 | { | |
7219 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7221 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7222 | int rem, i; |
7223 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7224 | struct nlattr *tx_rates; |
7225 | struct ieee80211_supported_band *sband; | |
7226 | ||
7227 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7228 | return -EINVAL; | |
7229 | ||
4c476991 JB |
7230 | if (!rdev->ops->set_bitrate_mask) |
7231 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7232 | |
7233 | memset(&mask, 0, sizeof(mask)); | |
7234 | /* Default to all rates enabled */ | |
7235 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7236 | sband = rdev->wiphy.bands[i]; | |
7237 | mask.control[i].legacy = | |
7238 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7239 | if (sband) |
7240 | memcpy(mask.control[i].mcs, | |
7241 | sband->ht_cap.mcs.rx_mask, | |
7242 | sizeof(mask.control[i].mcs)); | |
7243 | else | |
7244 | memset(mask.control[i].mcs, 0, | |
7245 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7246 | } |
7247 | ||
7248 | /* | |
7249 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7250 | * directly to the enum ieee80211_band values used in cfg80211. | |
7251 | */ | |
24db78c0 | 7252 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7253 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7254 | { | |
7255 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7256 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7257 | return -EINVAL; | |
13ae75b1 | 7258 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7259 | if (sband == NULL) |
7260 | return -EINVAL; | |
13ae75b1 JM |
7261 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7262 | nla_len(tx_rates), nl80211_txattr_policy); | |
7263 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7264 | mask.control[band].legacy = rateset_to_mask( | |
7265 | sband, | |
7266 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7267 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7268 | if ((mask.control[band].legacy == 0) && |
7269 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7270 | return -EINVAL; | |
24db78c0 SW |
7271 | } |
7272 | if (tb[NL80211_TXRATE_MCS]) { | |
7273 | if (!ht_rateset_to_mask( | |
7274 | sband, | |
7275 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7276 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7277 | mask.control[band].mcs)) | |
7278 | return -EINVAL; | |
7279 | } | |
7280 | ||
7281 | if (mask.control[band].legacy == 0) { | |
7282 | /* don't allow empty legacy rates if HT | |
7283 | * is not even supported. */ | |
7284 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7285 | return -EINVAL; | |
7286 | ||
7287 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7288 | if (mask.control[band].mcs[i]) | |
7289 | break; | |
7290 | ||
7291 | /* legacy and mcs rates may not be both empty */ | |
7292 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7293 | return -EINVAL; |
13ae75b1 JM |
7294 | } |
7295 | } | |
7296 | ||
e35e4d28 | 7297 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7298 | } |
7299 | ||
2e161f78 | 7300 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7301 | { |
4c476991 | 7302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7303 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7304 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7305 | |
7306 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7307 | return -EINVAL; | |
7308 | ||
2e161f78 JB |
7309 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7310 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7311 | |
71bbc994 JB |
7312 | switch (wdev->iftype) { |
7313 | case NL80211_IFTYPE_STATION: | |
7314 | case NL80211_IFTYPE_ADHOC: | |
7315 | case NL80211_IFTYPE_P2P_CLIENT: | |
7316 | case NL80211_IFTYPE_AP: | |
7317 | case NL80211_IFTYPE_AP_VLAN: | |
7318 | case NL80211_IFTYPE_MESH_POINT: | |
7319 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7320 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7321 | break; |
7322 | default: | |
4c476991 | 7323 | return -EOPNOTSUPP; |
71bbc994 | 7324 | } |
026331c4 JM |
7325 | |
7326 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7327 | if (!rdev->ops->mgmt_tx) |
7328 | return -EOPNOTSUPP; | |
026331c4 | 7329 | |
15e47304 | 7330 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7331 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7332 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7333 | } |
7334 | ||
2e161f78 | 7335 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7336 | { |
4c476991 | 7337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7338 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7339 | struct cfg80211_chan_def chandef; |
026331c4 | 7340 | int err; |
d64d373f | 7341 | void *hdr = NULL; |
026331c4 | 7342 | u64 cookie; |
e247bd90 | 7343 | struct sk_buff *msg = NULL; |
f7ca38df | 7344 | unsigned int wait = 0; |
e247bd90 JB |
7345 | bool offchan, no_cck, dont_wait_for_ack; |
7346 | ||
7347 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7348 | |
683b6d3b | 7349 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7350 | return -EINVAL; |
7351 | ||
4c476991 JB |
7352 | if (!rdev->ops->mgmt_tx) |
7353 | return -EOPNOTSUPP; | |
026331c4 | 7354 | |
71bbc994 | 7355 | switch (wdev->iftype) { |
ea141b75 AQ |
7356 | case NL80211_IFTYPE_P2P_DEVICE: |
7357 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7358 | return -EINVAL; | |
71bbc994 JB |
7359 | case NL80211_IFTYPE_STATION: |
7360 | case NL80211_IFTYPE_ADHOC: | |
7361 | case NL80211_IFTYPE_P2P_CLIENT: | |
7362 | case NL80211_IFTYPE_AP: | |
7363 | case NL80211_IFTYPE_AP_VLAN: | |
7364 | case NL80211_IFTYPE_MESH_POINT: | |
7365 | case NL80211_IFTYPE_P2P_GO: | |
7366 | break; | |
7367 | default: | |
4c476991 | 7368 | return -EOPNOTSUPP; |
71bbc994 | 7369 | } |
026331c4 | 7370 | |
f7ca38df | 7371 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7372 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7373 | return -EINVAL; |
7374 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7375 | |
7376 | /* | |
7377 | * We should wait on the channel for at least a minimum amount | |
7378 | * of time (10ms) but no longer than the driver supports. | |
7379 | */ | |
7380 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7381 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7382 | return -EINVAL; | |
7383 | ||
f7ca38df JB |
7384 | } |
7385 | ||
f7ca38df JB |
7386 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7387 | ||
7c4ef712 JB |
7388 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7389 | return -EINVAL; | |
7390 | ||
e9f935e3 RM |
7391 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7392 | ||
ea141b75 AQ |
7393 | /* get the channel if any has been specified, otherwise pass NULL to |
7394 | * the driver. The latter will use the current one | |
7395 | */ | |
7396 | chandef.chan = NULL; | |
7397 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7398 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7399 | if (err) | |
7400 | return err; | |
7401 | } | |
7402 | ||
7403 | if (!chandef.chan && offchan) | |
7404 | return -EINVAL; | |
026331c4 | 7405 | |
e247bd90 JB |
7406 | if (!dont_wait_for_ack) { |
7407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7408 | if (!msg) | |
7409 | return -ENOMEM; | |
026331c4 | 7410 | |
15e47304 | 7411 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7412 | NL80211_CMD_FRAME); |
026331c4 | 7413 | |
e247bd90 JB |
7414 | if (IS_ERR(hdr)) { |
7415 | err = PTR_ERR(hdr); | |
7416 | goto free_msg; | |
7417 | } | |
026331c4 | 7418 | } |
e247bd90 | 7419 | |
683b6d3b | 7420 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7421 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7422 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7423 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7424 | if (err) |
7425 | goto free_msg; | |
7426 | ||
e247bd90 | 7427 | if (msg) { |
9360ffd1 DM |
7428 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7429 | goto nla_put_failure; | |
026331c4 | 7430 | |
e247bd90 JB |
7431 | genlmsg_end(msg, hdr); |
7432 | return genlmsg_reply(msg, info); | |
7433 | } | |
7434 | ||
7435 | return 0; | |
026331c4 JM |
7436 | |
7437 | nla_put_failure: | |
7438 | err = -ENOBUFS; | |
7439 | free_msg: | |
7440 | nlmsg_free(msg); | |
026331c4 JM |
7441 | return err; |
7442 | } | |
7443 | ||
f7ca38df JB |
7444 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7445 | { | |
7446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7447 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7448 | u64 cookie; |
7449 | ||
7450 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7451 | return -EINVAL; | |
7452 | ||
7453 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7454 | return -EOPNOTSUPP; | |
7455 | ||
71bbc994 JB |
7456 | switch (wdev->iftype) { |
7457 | case NL80211_IFTYPE_STATION: | |
7458 | case NL80211_IFTYPE_ADHOC: | |
7459 | case NL80211_IFTYPE_P2P_CLIENT: | |
7460 | case NL80211_IFTYPE_AP: | |
7461 | case NL80211_IFTYPE_AP_VLAN: | |
7462 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7463 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7464 | break; |
7465 | default: | |
f7ca38df | 7466 | return -EOPNOTSUPP; |
71bbc994 | 7467 | } |
f7ca38df JB |
7468 | |
7469 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7470 | ||
e35e4d28 | 7471 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7472 | } |
7473 | ||
ffb9eb3d KV |
7474 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7475 | { | |
4c476991 | 7476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7477 | struct wireless_dev *wdev; |
4c476991 | 7478 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7479 | u8 ps_state; |
7480 | bool state; | |
7481 | int err; | |
7482 | ||
4c476991 JB |
7483 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7484 | return -EINVAL; | |
ffb9eb3d KV |
7485 | |
7486 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7487 | ||
4c476991 JB |
7488 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7489 | return -EINVAL; | |
ffb9eb3d KV |
7490 | |
7491 | wdev = dev->ieee80211_ptr; | |
7492 | ||
4c476991 JB |
7493 | if (!rdev->ops->set_power_mgmt) |
7494 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7495 | |
7496 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7497 | ||
7498 | if (state == wdev->ps) | |
4c476991 | 7499 | return 0; |
ffb9eb3d | 7500 | |
e35e4d28 | 7501 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7502 | if (!err) |
7503 | wdev->ps = state; | |
ffb9eb3d KV |
7504 | return err; |
7505 | } | |
7506 | ||
7507 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7508 | { | |
4c476991 | 7509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7510 | enum nl80211_ps_state ps_state; |
7511 | struct wireless_dev *wdev; | |
4c476991 | 7512 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7513 | struct sk_buff *msg; |
7514 | void *hdr; | |
7515 | int err; | |
7516 | ||
ffb9eb3d KV |
7517 | wdev = dev->ieee80211_ptr; |
7518 | ||
4c476991 JB |
7519 | if (!rdev->ops->set_power_mgmt) |
7520 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7521 | |
7522 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7523 | if (!msg) |
7524 | return -ENOMEM; | |
ffb9eb3d | 7525 | |
15e47304 | 7526 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7527 | NL80211_CMD_GET_POWER_SAVE); |
7528 | if (!hdr) { | |
4c476991 | 7529 | err = -ENOBUFS; |
ffb9eb3d KV |
7530 | goto free_msg; |
7531 | } | |
7532 | ||
7533 | if (wdev->ps) | |
7534 | ps_state = NL80211_PS_ENABLED; | |
7535 | else | |
7536 | ps_state = NL80211_PS_DISABLED; | |
7537 | ||
9360ffd1 DM |
7538 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7539 | goto nla_put_failure; | |
ffb9eb3d KV |
7540 | |
7541 | genlmsg_end(msg, hdr); | |
4c476991 | 7542 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7543 | |
4c476991 | 7544 | nla_put_failure: |
ffb9eb3d | 7545 | err = -ENOBUFS; |
4c476991 | 7546 | free_msg: |
ffb9eb3d | 7547 | nlmsg_free(msg); |
ffb9eb3d KV |
7548 | return err; |
7549 | } | |
7550 | ||
d6dc1a38 JO |
7551 | static struct nla_policy |
7552 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7553 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7554 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7555 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7556 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7557 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7558 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7559 | }; |
7560 | ||
84f10708 | 7561 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7562 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7563 | { |
7564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7565 | struct wireless_dev *wdev; | |
7566 | struct net_device *dev = info->user_ptr[1]; | |
7567 | ||
d9d8b019 | 7568 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7569 | return -EINVAL; |
7570 | ||
7571 | wdev = dev->ieee80211_ptr; | |
7572 | ||
7573 | if (!rdev->ops->set_cqm_txe_config) | |
7574 | return -EOPNOTSUPP; | |
7575 | ||
7576 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7577 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7578 | return -EOPNOTSUPP; | |
7579 | ||
e35e4d28 | 7580 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7581 | } |
7582 | ||
d6dc1a38 JO |
7583 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7584 | s32 threshold, u32 hysteresis) | |
7585 | { | |
4c476991 | 7586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7587 | struct wireless_dev *wdev; |
4c476991 | 7588 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7589 | |
7590 | if (threshold > 0) | |
7591 | return -EINVAL; | |
7592 | ||
d6dc1a38 JO |
7593 | wdev = dev->ieee80211_ptr; |
7594 | ||
4c476991 JB |
7595 | if (!rdev->ops->set_cqm_rssi_config) |
7596 | return -EOPNOTSUPP; | |
d6dc1a38 | 7597 | |
074ac8df | 7598 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7599 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7600 | return -EOPNOTSUPP; | |
d6dc1a38 | 7601 | |
e35e4d28 | 7602 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7603 | } |
7604 | ||
7605 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7606 | { | |
7607 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7608 | struct nlattr *cqm; | |
7609 | int err; | |
7610 | ||
7611 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7612 | if (!cqm) { | |
7613 | err = -EINVAL; | |
7614 | goto out; | |
7615 | } | |
7616 | ||
7617 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7618 | nl80211_attr_cqm_policy); | |
7619 | if (err) | |
7620 | goto out; | |
7621 | ||
7622 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7623 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7624 | s32 threshold; | |
7625 | u32 hysteresis; | |
7626 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7627 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7628 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7629 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7630 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7631 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7632 | u32 rate, pkts, intvl; | |
7633 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7634 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7635 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7636 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7637 | } else |
7638 | err = -EINVAL; | |
7639 | ||
7640 | out: | |
7641 | return err; | |
7642 | } | |
7643 | ||
29cbe68c JB |
7644 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7645 | { | |
7646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7647 | struct net_device *dev = info->user_ptr[1]; | |
7648 | struct mesh_config cfg; | |
c80d545d | 7649 | struct mesh_setup setup; |
29cbe68c JB |
7650 | int err; |
7651 | ||
7652 | /* start with default */ | |
7653 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7654 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7655 | |
24bdd9f4 | 7656 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7657 | /* and parse parameters if given */ |
24bdd9f4 | 7658 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7659 | if (err) |
7660 | return err; | |
7661 | } | |
7662 | ||
7663 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7664 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7665 | return -EINVAL; | |
7666 | ||
c80d545d JC |
7667 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7668 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7669 | ||
4bb62344 CYY |
7670 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7671 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7672 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7673 | return -EINVAL; | |
7674 | ||
9bdbf04d MP |
7675 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7676 | setup.beacon_interval = | |
7677 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7678 | if (setup.beacon_interval < 10 || | |
7679 | setup.beacon_interval > 10000) | |
7680 | return -EINVAL; | |
7681 | } | |
7682 | ||
7683 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7684 | setup.dtim_period = | |
7685 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7686 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7687 | return -EINVAL; | |
7688 | } | |
7689 | ||
c80d545d JC |
7690 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7691 | /* parse additional setup parameters if given */ | |
7692 | err = nl80211_parse_mesh_setup(info, &setup); | |
7693 | if (err) | |
7694 | return err; | |
7695 | } | |
7696 | ||
d37bb18a TP |
7697 | if (setup.user_mpm) |
7698 | cfg.auto_open_plinks = false; | |
7699 | ||
cc1d2806 | 7700 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7701 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7702 | if (err) | |
7703 | return err; | |
cc1d2806 JB |
7704 | } else { |
7705 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7706 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7707 | } |
7708 | ||
ffb3cf30 AN |
7709 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7710 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7711 | int n_rates = | |
7712 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7713 | struct ieee80211_supported_band *sband; | |
7714 | ||
7715 | if (!setup.chandef.chan) | |
7716 | return -EINVAL; | |
7717 | ||
7718 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
7719 | ||
7720 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
7721 | &setup.basic_rates); | |
7722 | if (err) | |
7723 | return err; | |
7724 | } | |
7725 | ||
c80d545d | 7726 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7727 | } |
7728 | ||
7729 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7730 | { | |
7731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7732 | struct net_device *dev = info->user_ptr[1]; | |
7733 | ||
7734 | return cfg80211_leave_mesh(rdev, dev); | |
7735 | } | |
7736 | ||
dfb89c56 | 7737 | #ifdef CONFIG_PM |
bb92d199 AK |
7738 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7739 | struct cfg80211_registered_device *rdev) | |
7740 | { | |
6abb9cb9 | 7741 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
7742 | struct nlattr *nl_pats, *nl_pat; |
7743 | int i, pat_len; | |
7744 | ||
6abb9cb9 | 7745 | if (!wowlan->n_patterns) |
bb92d199 AK |
7746 | return 0; |
7747 | ||
7748 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7749 | if (!nl_pats) | |
7750 | return -ENOBUFS; | |
7751 | ||
6abb9cb9 | 7752 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
7753 | nl_pat = nla_nest_start(msg, i + 1); |
7754 | if (!nl_pat) | |
7755 | return -ENOBUFS; | |
6abb9cb9 | 7756 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 7757 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 7758 | wowlan->patterns[i].mask) || |
50ac6607 AK |
7759 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
7760 | wowlan->patterns[i].pattern) || | |
7761 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 7762 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
7763 | return -ENOBUFS; |
7764 | nla_nest_end(msg, nl_pat); | |
7765 | } | |
7766 | nla_nest_end(msg, nl_pats); | |
7767 | ||
7768 | return 0; | |
7769 | } | |
7770 | ||
2a0e047e JB |
7771 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7772 | struct cfg80211_wowlan_tcp *tcp) | |
7773 | { | |
7774 | struct nlattr *nl_tcp; | |
7775 | ||
7776 | if (!tcp) | |
7777 | return 0; | |
7778 | ||
7779 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7780 | if (!nl_tcp) | |
7781 | return -ENOBUFS; | |
7782 | ||
7783 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7784 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7785 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7786 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7787 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7788 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7789 | tcp->payload_len, tcp->payload) || | |
7790 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7791 | tcp->data_interval) || | |
7792 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7793 | tcp->wake_len, tcp->wake_data) || | |
7794 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7795 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7796 | return -ENOBUFS; | |
7797 | ||
7798 | if (tcp->payload_seq.len && | |
7799 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7800 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7801 | return -ENOBUFS; | |
7802 | ||
7803 | if (tcp->payload_tok.len && | |
7804 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7805 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7806 | &tcp->payload_tok)) | |
7807 | return -ENOBUFS; | |
7808 | ||
e248ad30 JB |
7809 | nla_nest_end(msg, nl_tcp); |
7810 | ||
2a0e047e JB |
7811 | return 0; |
7812 | } | |
7813 | ||
ff1b6e69 JB |
7814 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7815 | { | |
7816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7817 | struct sk_buff *msg; | |
7818 | void *hdr; | |
2a0e047e | 7819 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7820 | |
964dc9e2 | 7821 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
7822 | return -EOPNOTSUPP; |
7823 | ||
6abb9cb9 | 7824 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 7825 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
7826 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
7827 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
7828 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
7829 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
7830 | } |
7831 | ||
7832 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7833 | if (!msg) |
7834 | return -ENOMEM; | |
7835 | ||
15e47304 | 7836 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7837 | NL80211_CMD_GET_WOWLAN); |
7838 | if (!hdr) | |
7839 | goto nla_put_failure; | |
7840 | ||
6abb9cb9 | 7841 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
7842 | struct nlattr *nl_wowlan; |
7843 | ||
7844 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7845 | if (!nl_wowlan) | |
7846 | goto nla_put_failure; | |
7847 | ||
6abb9cb9 | 7848 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 7849 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 7850 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 7851 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 7852 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 7853 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 7854 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 7855 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 7856 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 7857 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 7858 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 7859 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 7860 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
7861 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
7862 | goto nla_put_failure; | |
2a0e047e | 7863 | |
bb92d199 AK |
7864 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7865 | goto nla_put_failure; | |
2a0e047e | 7866 | |
6abb9cb9 JB |
7867 | if (nl80211_send_wowlan_tcp(msg, |
7868 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
7869 | goto nla_put_failure; |
7870 | ||
ff1b6e69 JB |
7871 | nla_nest_end(msg, nl_wowlan); |
7872 | } | |
7873 | ||
7874 | genlmsg_end(msg, hdr); | |
7875 | return genlmsg_reply(msg, info); | |
7876 | ||
7877 | nla_put_failure: | |
7878 | nlmsg_free(msg); | |
7879 | return -ENOBUFS; | |
7880 | } | |
7881 | ||
2a0e047e JB |
7882 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7883 | struct nlattr *attr, | |
7884 | struct cfg80211_wowlan *trig) | |
7885 | { | |
7886 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7887 | struct cfg80211_wowlan_tcp *cfg; | |
7888 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7889 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7890 | u32 size; | |
7891 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7892 | int err, port; | |
7893 | ||
964dc9e2 | 7894 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
7895 | return -EINVAL; |
7896 | ||
7897 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7898 | nla_data(attr), nla_len(attr), | |
7899 | nl80211_wowlan_tcp_policy); | |
7900 | if (err) | |
7901 | return err; | |
7902 | ||
7903 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7904 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7905 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7906 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7907 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7908 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7909 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7910 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7911 | return -EINVAL; | |
7912 | ||
7913 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 7914 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
7915 | return -EINVAL; |
7916 | ||
7917 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 7918 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 7919 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
7920 | return -EINVAL; |
7921 | ||
7922 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 7923 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
7924 | return -EINVAL; |
7925 | ||
7926 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7927 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7928 | return -EINVAL; | |
7929 | ||
7930 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7931 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7932 | ||
7933 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7934 | tokens_size = tokln - sizeof(*tok); | |
7935 | ||
7936 | if (!tok->len || tokens_size % tok->len) | |
7937 | return -EINVAL; | |
964dc9e2 | 7938 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 7939 | return -EINVAL; |
964dc9e2 | 7940 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 7941 | return -EINVAL; |
964dc9e2 | 7942 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 7943 | return -EINVAL; |
964dc9e2 | 7944 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
7945 | return -EINVAL; |
7946 | if (tok->offset + tok->len > data_size) | |
7947 | return -EINVAL; | |
7948 | } | |
7949 | ||
7950 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7951 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 7952 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
7953 | return -EINVAL; |
7954 | if (seq->len == 0 || seq->len > 4) | |
7955 | return -EINVAL; | |
7956 | if (seq->len + seq->offset > data_size) | |
7957 | return -EINVAL; | |
7958 | } | |
7959 | ||
7960 | size = sizeof(*cfg); | |
7961 | size += data_size; | |
7962 | size += wake_size + wake_mask_size; | |
7963 | size += tokens_size; | |
7964 | ||
7965 | cfg = kzalloc(size, GFP_KERNEL); | |
7966 | if (!cfg) | |
7967 | return -ENOMEM; | |
7968 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7969 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7970 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7971 | ETH_ALEN); | |
7972 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7973 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7974 | else | |
7975 | port = 0; | |
7976 | #ifdef CONFIG_INET | |
7977 | /* allocate a socket and port for it and use it */ | |
7978 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7979 | IPPROTO_TCP, &cfg->sock, 1); | |
7980 | if (err) { | |
7981 | kfree(cfg); | |
7982 | return err; | |
7983 | } | |
7984 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7985 | sock_release(cfg->sock); | |
7986 | kfree(cfg); | |
7987 | return -EADDRINUSE; | |
7988 | } | |
7989 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7990 | #else | |
7991 | if (!port) { | |
7992 | kfree(cfg); | |
7993 | return -EINVAL; | |
7994 | } | |
7995 | cfg->src_port = port; | |
7996 | #endif | |
7997 | ||
7998 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7999 | cfg->payload_len = data_size; | |
8000 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8001 | memcpy((void *)cfg->payload, | |
8002 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8003 | data_size); | |
8004 | if (seq) | |
8005 | cfg->payload_seq = *seq; | |
8006 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8007 | cfg->wake_len = wake_size; | |
8008 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8009 | memcpy((void *)cfg->wake_data, | |
8010 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8011 | wake_size); | |
8012 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8013 | data_size + wake_size; | |
8014 | memcpy((void *)cfg->wake_mask, | |
8015 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8016 | wake_mask_size); | |
8017 | if (tok) { | |
8018 | cfg->tokens_size = tokens_size; | |
8019 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8020 | } | |
8021 | ||
8022 | trig->tcp = cfg; | |
8023 | ||
8024 | return 0; | |
8025 | } | |
8026 | ||
ff1b6e69 JB |
8027 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8028 | { | |
8029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8030 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8031 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8032 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8033 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8034 | int err, i; |
6abb9cb9 | 8035 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8036 | |
964dc9e2 | 8037 | if (!wowlan) |
ff1b6e69 JB |
8038 | return -EOPNOTSUPP; |
8039 | ||
ae33bd81 JB |
8040 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8041 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8042 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8043 | goto set_wakeup; |
8044 | } | |
ff1b6e69 JB |
8045 | |
8046 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8047 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8048 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8049 | nl80211_wowlan_policy); | |
8050 | if (err) | |
8051 | return err; | |
8052 | ||
8053 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8054 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8055 | return -EINVAL; | |
8056 | new_triggers.any = true; | |
8057 | } | |
8058 | ||
8059 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8060 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8061 | return -EINVAL; | |
8062 | new_triggers.disconnect = true; | |
8063 | } | |
8064 | ||
8065 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8066 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8067 | return -EINVAL; | |
8068 | new_triggers.magic_pkt = true; | |
8069 | } | |
8070 | ||
77dbbb13 JB |
8071 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8072 | return -EINVAL; | |
8073 | ||
8074 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8075 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8076 | return -EINVAL; | |
8077 | new_triggers.gtk_rekey_failure = true; | |
8078 | } | |
8079 | ||
8080 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8081 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8082 | return -EINVAL; | |
8083 | new_triggers.eap_identity_req = true; | |
8084 | } | |
8085 | ||
8086 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8087 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8088 | return -EINVAL; | |
8089 | new_triggers.four_way_handshake = true; | |
8090 | } | |
8091 | ||
8092 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8093 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8094 | return -EINVAL; | |
8095 | new_triggers.rfkill_release = true; | |
8096 | } | |
8097 | ||
ff1b6e69 JB |
8098 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8099 | struct nlattr *pat; | |
8100 | int n_patterns = 0; | |
bb92d199 | 8101 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8102 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8103 | |
8104 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8105 | rem) | |
8106 | n_patterns++; | |
8107 | if (n_patterns > wowlan->n_patterns) | |
8108 | return -EINVAL; | |
8109 | ||
8110 | new_triggers.patterns = kcalloc(n_patterns, | |
8111 | sizeof(new_triggers.patterns[0]), | |
8112 | GFP_KERNEL); | |
8113 | if (!new_triggers.patterns) | |
8114 | return -ENOMEM; | |
8115 | ||
8116 | new_triggers.n_patterns = n_patterns; | |
8117 | i = 0; | |
8118 | ||
8119 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8120 | rem) { | |
50ac6607 AK |
8121 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8122 | nla_len(pat), NULL); | |
ff1b6e69 | 8123 | err = -EINVAL; |
50ac6607 AK |
8124 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8125 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8126 | goto error; |
50ac6607 | 8127 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8128 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8129 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8130 | goto error; |
8131 | if (pat_len > wowlan->pattern_max_len || | |
8132 | pat_len < wowlan->pattern_min_len) | |
8133 | goto error; | |
8134 | ||
50ac6607 | 8135 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8136 | pkt_offset = 0; |
8137 | else | |
8138 | pkt_offset = nla_get_u32( | |
50ac6607 | 8139 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8140 | if (pkt_offset > wowlan->max_pkt_offset) |
8141 | goto error; | |
8142 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8143 | ||
ff1b6e69 JB |
8144 | new_triggers.patterns[i].mask = |
8145 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8146 | if (!new_triggers.patterns[i].mask) { | |
8147 | err = -ENOMEM; | |
8148 | goto error; | |
8149 | } | |
8150 | new_triggers.patterns[i].pattern = | |
8151 | new_triggers.patterns[i].mask + mask_len; | |
8152 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8153 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8154 | mask_len); |
8155 | new_triggers.patterns[i].pattern_len = pat_len; | |
8156 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8157 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8158 | pat_len); |
8159 | i++; | |
8160 | } | |
8161 | } | |
8162 | ||
2a0e047e JB |
8163 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8164 | err = nl80211_parse_wowlan_tcp( | |
8165 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8166 | &new_triggers); | |
8167 | if (err) | |
8168 | goto error; | |
8169 | } | |
8170 | ||
ae33bd81 JB |
8171 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8172 | if (!ntrig) { | |
8173 | err = -ENOMEM; | |
8174 | goto error; | |
ff1b6e69 | 8175 | } |
ae33bd81 | 8176 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8177 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8178 | |
ae33bd81 | 8179 | set_wakeup: |
6abb9cb9 JB |
8180 | if (rdev->ops->set_wakeup && |
8181 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8182 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8183 | |
ff1b6e69 JB |
8184 | return 0; |
8185 | error: | |
8186 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8187 | kfree(new_triggers.patterns[i].mask); | |
8188 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8189 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8190 | sock_release(new_triggers.tcp->sock); | |
8191 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8192 | return err; |
8193 | } | |
dfb89c56 | 8194 | #endif |
ff1b6e69 | 8195 | |
be29b99a AK |
8196 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8197 | struct cfg80211_registered_device *rdev) | |
8198 | { | |
8199 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8200 | int i, j, pat_len; | |
8201 | struct cfg80211_coalesce_rules *rule; | |
8202 | ||
8203 | if (!rdev->coalesce->n_rules) | |
8204 | return 0; | |
8205 | ||
8206 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8207 | if (!nl_rules) | |
8208 | return -ENOBUFS; | |
8209 | ||
8210 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8211 | nl_rule = nla_nest_start(msg, i + 1); | |
8212 | if (!nl_rule) | |
8213 | return -ENOBUFS; | |
8214 | ||
8215 | rule = &rdev->coalesce->rules[i]; | |
8216 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8217 | rule->delay)) | |
8218 | return -ENOBUFS; | |
8219 | ||
8220 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8221 | rule->condition)) | |
8222 | return -ENOBUFS; | |
8223 | ||
8224 | nl_pats = nla_nest_start(msg, | |
8225 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8226 | if (!nl_pats) | |
8227 | return -ENOBUFS; | |
8228 | ||
8229 | for (j = 0; j < rule->n_patterns; j++) { | |
8230 | nl_pat = nla_nest_start(msg, j + 1); | |
8231 | if (!nl_pat) | |
8232 | return -ENOBUFS; | |
8233 | pat_len = rule->patterns[j].pattern_len; | |
8234 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8235 | DIV_ROUND_UP(pat_len, 8), | |
8236 | rule->patterns[j].mask) || | |
8237 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8238 | rule->patterns[j].pattern) || | |
8239 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8240 | rule->patterns[j].pkt_offset)) | |
8241 | return -ENOBUFS; | |
8242 | nla_nest_end(msg, nl_pat); | |
8243 | } | |
8244 | nla_nest_end(msg, nl_pats); | |
8245 | nla_nest_end(msg, nl_rule); | |
8246 | } | |
8247 | nla_nest_end(msg, nl_rules); | |
8248 | ||
8249 | return 0; | |
8250 | } | |
8251 | ||
8252 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8253 | { | |
8254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8255 | struct sk_buff *msg; | |
8256 | void *hdr; | |
8257 | ||
8258 | if (!rdev->wiphy.coalesce) | |
8259 | return -EOPNOTSUPP; | |
8260 | ||
8261 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8262 | if (!msg) | |
8263 | return -ENOMEM; | |
8264 | ||
8265 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8266 | NL80211_CMD_GET_COALESCE); | |
8267 | if (!hdr) | |
8268 | goto nla_put_failure; | |
8269 | ||
8270 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8271 | goto nla_put_failure; | |
8272 | ||
8273 | genlmsg_end(msg, hdr); | |
8274 | return genlmsg_reply(msg, info); | |
8275 | ||
8276 | nla_put_failure: | |
8277 | nlmsg_free(msg); | |
8278 | return -ENOBUFS; | |
8279 | } | |
8280 | ||
8281 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8282 | { | |
8283 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8284 | int i, j; | |
8285 | struct cfg80211_coalesce_rules *rule; | |
8286 | ||
8287 | if (!coalesce) | |
8288 | return; | |
8289 | ||
8290 | for (i = 0; i < coalesce->n_rules; i++) { | |
8291 | rule = &coalesce->rules[i]; | |
8292 | for (j = 0; j < rule->n_patterns; j++) | |
8293 | kfree(rule->patterns[j].mask); | |
8294 | kfree(rule->patterns); | |
8295 | } | |
8296 | kfree(coalesce->rules); | |
8297 | kfree(coalesce); | |
8298 | rdev->coalesce = NULL; | |
8299 | } | |
8300 | ||
8301 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8302 | struct nlattr *rule, | |
8303 | struct cfg80211_coalesce_rules *new_rule) | |
8304 | { | |
8305 | int err, i; | |
8306 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8307 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8308 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8309 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8310 | ||
8311 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8312 | nla_len(rule), nl80211_coalesce_policy); | |
8313 | if (err) | |
8314 | return err; | |
8315 | ||
8316 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8317 | new_rule->delay = | |
8318 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8319 | if (new_rule->delay > coalesce->max_delay) | |
8320 | return -EINVAL; | |
8321 | ||
8322 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8323 | new_rule->condition = | |
8324 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8325 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8326 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8327 | return -EINVAL; | |
8328 | ||
8329 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8330 | return -EINVAL; | |
8331 | ||
8332 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8333 | rem) | |
8334 | n_patterns++; | |
8335 | if (n_patterns > coalesce->n_patterns) | |
8336 | return -EINVAL; | |
8337 | ||
8338 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8339 | GFP_KERNEL); | |
8340 | if (!new_rule->patterns) | |
8341 | return -ENOMEM; | |
8342 | ||
8343 | new_rule->n_patterns = n_patterns; | |
8344 | i = 0; | |
8345 | ||
8346 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8347 | rem) { | |
8348 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8349 | nla_len(pat), NULL); | |
8350 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8351 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8352 | return -EINVAL; | |
8353 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8354 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8355 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8356 | return -EINVAL; | |
8357 | if (pat_len > coalesce->pattern_max_len || | |
8358 | pat_len < coalesce->pattern_min_len) | |
8359 | return -EINVAL; | |
8360 | ||
8361 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8362 | pkt_offset = 0; | |
8363 | else | |
8364 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8365 | if (pkt_offset > coalesce->max_pkt_offset) | |
8366 | return -EINVAL; | |
8367 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8368 | ||
8369 | new_rule->patterns[i].mask = | |
8370 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8371 | if (!new_rule->patterns[i].mask) | |
8372 | return -ENOMEM; | |
8373 | new_rule->patterns[i].pattern = | |
8374 | new_rule->patterns[i].mask + mask_len; | |
8375 | memcpy(new_rule->patterns[i].mask, | |
8376 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8377 | new_rule->patterns[i].pattern_len = pat_len; | |
8378 | memcpy(new_rule->patterns[i].pattern, | |
8379 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8380 | i++; | |
8381 | } | |
8382 | ||
8383 | return 0; | |
8384 | } | |
8385 | ||
8386 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8387 | { | |
8388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8389 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8390 | struct cfg80211_coalesce new_coalesce = {}; | |
8391 | struct cfg80211_coalesce *n_coalesce; | |
8392 | int err, rem_rule, n_rules = 0, i, j; | |
8393 | struct nlattr *rule; | |
8394 | struct cfg80211_coalesce_rules *tmp_rule; | |
8395 | ||
8396 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8397 | return -EOPNOTSUPP; | |
8398 | ||
8399 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8400 | cfg80211_rdev_free_coalesce(rdev); | |
8401 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8402 | return 0; | |
8403 | } | |
8404 | ||
8405 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8406 | rem_rule) | |
8407 | n_rules++; | |
8408 | if (n_rules > coalesce->n_rules) | |
8409 | return -EINVAL; | |
8410 | ||
8411 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8412 | GFP_KERNEL); | |
8413 | if (!new_coalesce.rules) | |
8414 | return -ENOMEM; | |
8415 | ||
8416 | new_coalesce.n_rules = n_rules; | |
8417 | i = 0; | |
8418 | ||
8419 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8420 | rem_rule) { | |
8421 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8422 | &new_coalesce.rules[i]); | |
8423 | if (err) | |
8424 | goto error; | |
8425 | ||
8426 | i++; | |
8427 | } | |
8428 | ||
8429 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8430 | if (err) | |
8431 | goto error; | |
8432 | ||
8433 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8434 | if (!n_coalesce) { | |
8435 | err = -ENOMEM; | |
8436 | goto error; | |
8437 | } | |
8438 | cfg80211_rdev_free_coalesce(rdev); | |
8439 | rdev->coalesce = n_coalesce; | |
8440 | ||
8441 | return 0; | |
8442 | error: | |
8443 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8444 | tmp_rule = &new_coalesce.rules[i]; | |
8445 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8446 | kfree(tmp_rule->patterns[j].mask); | |
8447 | kfree(tmp_rule->patterns); | |
8448 | } | |
8449 | kfree(new_coalesce.rules); | |
8450 | ||
8451 | return err; | |
8452 | } | |
8453 | ||
e5497d76 JB |
8454 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8455 | { | |
8456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8457 | struct net_device *dev = info->user_ptr[1]; | |
8458 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8459 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8460 | struct cfg80211_gtk_rekey_data rekey_data; | |
8461 | int err; | |
8462 | ||
8463 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8464 | return -EINVAL; | |
8465 | ||
8466 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8467 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8468 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8469 | nl80211_rekey_policy); | |
8470 | if (err) | |
8471 | return err; | |
8472 | ||
8473 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8474 | return -ERANGE; | |
8475 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8476 | return -ERANGE; | |
8477 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8478 | return -ERANGE; | |
8479 | ||
8480 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8481 | NL80211_KEK_LEN); | |
8482 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8483 | NL80211_KCK_LEN); | |
8484 | memcpy(rekey_data.replay_ctr, | |
8485 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8486 | NL80211_REPLAY_CTR_LEN); | |
8487 | ||
8488 | wdev_lock(wdev); | |
8489 | if (!wdev->current_bss) { | |
8490 | err = -ENOTCONN; | |
8491 | goto out; | |
8492 | } | |
8493 | ||
8494 | if (!rdev->ops->set_rekey_data) { | |
8495 | err = -EOPNOTSUPP; | |
8496 | goto out; | |
8497 | } | |
8498 | ||
e35e4d28 | 8499 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8500 | out: |
8501 | wdev_unlock(wdev); | |
8502 | return err; | |
8503 | } | |
8504 | ||
28946da7 JB |
8505 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8506 | struct genl_info *info) | |
8507 | { | |
8508 | struct net_device *dev = info->user_ptr[1]; | |
8509 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8510 | ||
8511 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8512 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8513 | return -EINVAL; | |
8514 | ||
15e47304 | 8515 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8516 | return -EBUSY; |
8517 | ||
15e47304 | 8518 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8519 | return 0; |
8520 | } | |
8521 | ||
7f6cf311 JB |
8522 | static int nl80211_probe_client(struct sk_buff *skb, |
8523 | struct genl_info *info) | |
8524 | { | |
8525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8526 | struct net_device *dev = info->user_ptr[1]; | |
8527 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8528 | struct sk_buff *msg; | |
8529 | void *hdr; | |
8530 | const u8 *addr; | |
8531 | u64 cookie; | |
8532 | int err; | |
8533 | ||
8534 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8535 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8536 | return -EOPNOTSUPP; | |
8537 | ||
8538 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8539 | return -EINVAL; | |
8540 | ||
8541 | if (!rdev->ops->probe_client) | |
8542 | return -EOPNOTSUPP; | |
8543 | ||
8544 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8545 | if (!msg) | |
8546 | return -ENOMEM; | |
8547 | ||
15e47304 | 8548 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8549 | NL80211_CMD_PROBE_CLIENT); |
8550 | ||
8551 | if (IS_ERR(hdr)) { | |
8552 | err = PTR_ERR(hdr); | |
8553 | goto free_msg; | |
8554 | } | |
8555 | ||
8556 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8557 | ||
e35e4d28 | 8558 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8559 | if (err) |
8560 | goto free_msg; | |
8561 | ||
9360ffd1 DM |
8562 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8563 | goto nla_put_failure; | |
7f6cf311 JB |
8564 | |
8565 | genlmsg_end(msg, hdr); | |
8566 | ||
8567 | return genlmsg_reply(msg, info); | |
8568 | ||
8569 | nla_put_failure: | |
8570 | err = -ENOBUFS; | |
8571 | free_msg: | |
8572 | nlmsg_free(msg); | |
8573 | return err; | |
8574 | } | |
8575 | ||
5e760230 JB |
8576 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8577 | { | |
8578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8579 | struct cfg80211_beacon_registration *reg, *nreg; |
8580 | int rv; | |
5e760230 JB |
8581 | |
8582 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8583 | return -EOPNOTSUPP; | |
8584 | ||
37c73b5f BG |
8585 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8586 | if (!nreg) | |
8587 | return -ENOMEM; | |
8588 | ||
8589 | /* First, check if already registered. */ | |
8590 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8591 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8592 | if (reg->nlportid == info->snd_portid) { | |
8593 | rv = -EALREADY; | |
8594 | goto out_err; | |
8595 | } | |
8596 | } | |
8597 | /* Add it to the list */ | |
8598 | nreg->nlportid = info->snd_portid; | |
8599 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8600 | |
37c73b5f | 8601 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8602 | |
8603 | return 0; | |
37c73b5f BG |
8604 | out_err: |
8605 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8606 | kfree(nreg); | |
8607 | return rv; | |
5e760230 JB |
8608 | } |
8609 | ||
98104fde JB |
8610 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8611 | { | |
8612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8613 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8614 | int err; | |
8615 | ||
8616 | if (!rdev->ops->start_p2p_device) | |
8617 | return -EOPNOTSUPP; | |
8618 | ||
8619 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8620 | return -EOPNOTSUPP; | |
8621 | ||
8622 | if (wdev->p2p_started) | |
8623 | return 0; | |
8624 | ||
98104fde | 8625 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8626 | if (err) |
8627 | return err; | |
8628 | ||
eeb126e9 | 8629 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8630 | if (err) |
8631 | return err; | |
8632 | ||
8633 | wdev->p2p_started = true; | |
98104fde | 8634 | rdev->opencount++; |
98104fde JB |
8635 | |
8636 | return 0; | |
8637 | } | |
8638 | ||
8639 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8640 | { | |
8641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8642 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8643 | ||
8644 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8645 | return -EOPNOTSUPP; | |
8646 | ||
8647 | if (!rdev->ops->stop_p2p_device) | |
8648 | return -EOPNOTSUPP; | |
8649 | ||
f9f47529 | 8650 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8651 | |
8652 | return 0; | |
8653 | } | |
8654 | ||
3713b4e3 JB |
8655 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8656 | struct genl_info *info) | |
8657 | { | |
8658 | void *hdr; | |
8659 | struct sk_buff *msg; | |
8660 | ||
8661 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8662 | if (!msg) | |
8663 | return -ENOMEM; | |
8664 | ||
8665 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8666 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8667 | if (!hdr) | |
8668 | goto nla_put_failure; | |
8669 | ||
8670 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8671 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8672 | goto nla_put_failure; | |
8673 | ||
8674 | genlmsg_end(msg, hdr); | |
8675 | return genlmsg_reply(msg, info); | |
8676 | ||
8677 | nla_put_failure: | |
8678 | kfree_skb(msg); | |
8679 | return -ENOBUFS; | |
8680 | } | |
8681 | ||
355199e0 JM |
8682 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8683 | { | |
8684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8685 | struct cfg80211_update_ft_ies_params ft_params; | |
8686 | struct net_device *dev = info->user_ptr[1]; | |
8687 | ||
8688 | if (!rdev->ops->update_ft_ies) | |
8689 | return -EOPNOTSUPP; | |
8690 | ||
8691 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8692 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8693 | return -EINVAL; | |
8694 | ||
8695 | memset(&ft_params, 0, sizeof(ft_params)); | |
8696 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8697 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8698 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8699 | ||
8700 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8701 | } | |
8702 | ||
5de17984 AS |
8703 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8704 | struct genl_info *info) | |
8705 | { | |
8706 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8707 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8708 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8709 | u16 duration; | |
8710 | int ret; | |
8711 | ||
8712 | if (!rdev->ops->crit_proto_start) | |
8713 | return -EOPNOTSUPP; | |
8714 | ||
8715 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8716 | return -EINVAL; | |
8717 | ||
8718 | if (rdev->crit_proto_nlportid) | |
8719 | return -EBUSY; | |
8720 | ||
8721 | /* determine protocol if provided */ | |
8722 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8723 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8724 | ||
8725 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8726 | return -EINVAL; | |
8727 | ||
8728 | /* timeout must be provided */ | |
8729 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8730 | return -EINVAL; | |
8731 | ||
8732 | duration = | |
8733 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8734 | ||
8735 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8736 | return -ERANGE; | |
8737 | ||
8738 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8739 | if (!ret) | |
8740 | rdev->crit_proto_nlportid = info->snd_portid; | |
8741 | ||
8742 | return ret; | |
8743 | } | |
8744 | ||
8745 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8746 | struct genl_info *info) | |
8747 | { | |
8748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8749 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8750 | ||
8751 | if (!rdev->ops->crit_proto_stop) | |
8752 | return -EOPNOTSUPP; | |
8753 | ||
8754 | if (rdev->crit_proto_nlportid) { | |
8755 | rdev->crit_proto_nlportid = 0; | |
8756 | rdev_crit_proto_stop(rdev, wdev); | |
8757 | } | |
8758 | return 0; | |
8759 | } | |
8760 | ||
4c476991 JB |
8761 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8762 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8763 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8764 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8765 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8766 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8767 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8768 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8769 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8770 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8771 | |
8772 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8773 | struct genl_info *info) | |
8774 | { | |
8775 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8776 | struct wireless_dev *wdev; |
4c476991 | 8777 | struct net_device *dev; |
4c476991 JB |
8778 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8779 | ||
8780 | if (rtnl) | |
8781 | rtnl_lock(); | |
8782 | ||
8783 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8784 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8785 | if (IS_ERR(rdev)) { |
8786 | if (rtnl) | |
8787 | rtnl_unlock(); | |
8788 | return PTR_ERR(rdev); | |
8789 | } | |
8790 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8791 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8792 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
8793 | ASSERT_RTNL(); |
8794 | ||
89a54e48 JB |
8795 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
8796 | info->attrs); | |
8797 | if (IS_ERR(wdev)) { | |
4c476991 JB |
8798 | if (rtnl) |
8799 | rtnl_unlock(); | |
89a54e48 | 8800 | return PTR_ERR(wdev); |
4c476991 | 8801 | } |
89a54e48 | 8802 | |
89a54e48 JB |
8803 | dev = wdev->netdev; |
8804 | rdev = wiphy_to_dev(wdev->wiphy); | |
8805 | ||
1bf614ef JB |
8806 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8807 | if (!dev) { | |
1bf614ef JB |
8808 | if (rtnl) |
8809 | rtnl_unlock(); | |
8810 | return -EINVAL; | |
8811 | } | |
8812 | ||
8813 | info->user_ptr[1] = dev; | |
8814 | } else { | |
8815 | info->user_ptr[1] = wdev; | |
41265714 | 8816 | } |
1bf614ef JB |
8817 | |
8818 | if (dev) { | |
8819 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8820 | !netif_running(dev)) { | |
1bf614ef JB |
8821 | if (rtnl) |
8822 | rtnl_unlock(); | |
8823 | return -ENETDOWN; | |
8824 | } | |
8825 | ||
8826 | dev_hold(dev); | |
98104fde JB |
8827 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8828 | if (!wdev->p2p_started) { | |
98104fde JB |
8829 | if (rtnl) |
8830 | rtnl_unlock(); | |
8831 | return -ENETDOWN; | |
8832 | } | |
41265714 | 8833 | } |
89a54e48 | 8834 | |
4c476991 | 8835 | info->user_ptr[0] = rdev; |
4c476991 JB |
8836 | } |
8837 | ||
8838 | return 0; | |
8839 | } | |
8840 | ||
8841 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8842 | struct genl_info *info) | |
8843 | { | |
1bf614ef JB |
8844 | if (info->user_ptr[1]) { |
8845 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8846 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8847 | ||
8848 | if (wdev->netdev) | |
8849 | dev_put(wdev->netdev); | |
8850 | } else { | |
8851 | dev_put(info->user_ptr[1]); | |
8852 | } | |
8853 | } | |
4c476991 JB |
8854 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8855 | rtnl_unlock(); | |
8856 | } | |
8857 | ||
55682965 JB |
8858 | static struct genl_ops nl80211_ops[] = { |
8859 | { | |
8860 | .cmd = NL80211_CMD_GET_WIPHY, | |
8861 | .doit = nl80211_get_wiphy, | |
8862 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 8863 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
8864 | .policy = nl80211_policy, |
8865 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8866 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8867 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8868 | }, |
8869 | { | |
8870 | .cmd = NL80211_CMD_SET_WIPHY, | |
8871 | .doit = nl80211_set_wiphy, | |
8872 | .policy = nl80211_policy, | |
8873 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8874 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8875 | }, |
8876 | { | |
8877 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8878 | .doit = nl80211_get_interface, | |
8879 | .dumpit = nl80211_dump_interface, | |
8880 | .policy = nl80211_policy, | |
8881 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8882 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
8883 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8884 | }, |
8885 | { | |
8886 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8887 | .doit = nl80211_set_interface, | |
8888 | .policy = nl80211_policy, | |
8889 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8890 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8891 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8892 | }, |
8893 | { | |
8894 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8895 | .doit = nl80211_new_interface, | |
8896 | .policy = nl80211_policy, | |
8897 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8898 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8899 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8900 | }, |
8901 | { | |
8902 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8903 | .doit = nl80211_del_interface, | |
8904 | .policy = nl80211_policy, | |
41ade00f | 8905 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8906 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8907 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8908 | }, |
8909 | { | |
8910 | .cmd = NL80211_CMD_GET_KEY, | |
8911 | .doit = nl80211_get_key, | |
8912 | .policy = nl80211_policy, | |
8913 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8914 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8915 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8916 | }, |
8917 | { | |
8918 | .cmd = NL80211_CMD_SET_KEY, | |
8919 | .doit = nl80211_set_key, | |
8920 | .policy = nl80211_policy, | |
8921 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8922 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8923 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8924 | }, |
8925 | { | |
8926 | .cmd = NL80211_CMD_NEW_KEY, | |
8927 | .doit = nl80211_new_key, | |
8928 | .policy = nl80211_policy, | |
8929 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8930 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8931 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8932 | }, |
8933 | { | |
8934 | .cmd = NL80211_CMD_DEL_KEY, | |
8935 | .doit = nl80211_del_key, | |
8936 | .policy = nl80211_policy, | |
55682965 | 8937 | .flags = GENL_ADMIN_PERM, |
41265714 | 8938 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8939 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8940 | }, |
ed1b6cc7 JB |
8941 | { |
8942 | .cmd = NL80211_CMD_SET_BEACON, | |
8943 | .policy = nl80211_policy, | |
8944 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8945 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8947 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8948 | }, |
8949 | { | |
8860020e | 8950 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8951 | .policy = nl80211_policy, |
8952 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8953 | .doit = nl80211_start_ap, |
2b5f8b0b | 8954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8955 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8956 | }, |
8957 | { | |
8860020e | 8958 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8959 | .policy = nl80211_policy, |
8960 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8961 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8962 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8963 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8964 | }, |
5727ef1b JB |
8965 | { |
8966 | .cmd = NL80211_CMD_GET_STATION, | |
8967 | .doit = nl80211_get_station, | |
2ec600d6 | 8968 | .dumpit = nl80211_dump_station, |
5727ef1b | 8969 | .policy = nl80211_policy, |
4c476991 JB |
8970 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8971 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8972 | }, |
8973 | { | |
8974 | .cmd = NL80211_CMD_SET_STATION, | |
8975 | .doit = nl80211_set_station, | |
8976 | .policy = nl80211_policy, | |
8977 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8978 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8979 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8980 | }, |
8981 | { | |
8982 | .cmd = NL80211_CMD_NEW_STATION, | |
8983 | .doit = nl80211_new_station, | |
8984 | .policy = nl80211_policy, | |
8985 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8986 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8987 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8988 | }, |
8989 | { | |
8990 | .cmd = NL80211_CMD_DEL_STATION, | |
8991 | .doit = nl80211_del_station, | |
8992 | .policy = nl80211_policy, | |
2ec600d6 | 8993 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8995 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8996 | }, |
8997 | { | |
8998 | .cmd = NL80211_CMD_GET_MPATH, | |
8999 | .doit = nl80211_get_mpath, | |
9000 | .dumpit = nl80211_dump_mpath, | |
9001 | .policy = nl80211_policy, | |
9002 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9004 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9005 | }, |
9006 | { | |
9007 | .cmd = NL80211_CMD_SET_MPATH, | |
9008 | .doit = nl80211_set_mpath, | |
9009 | .policy = nl80211_policy, | |
9010 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9012 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9013 | }, |
9014 | { | |
9015 | .cmd = NL80211_CMD_NEW_MPATH, | |
9016 | .doit = nl80211_new_mpath, | |
9017 | .policy = nl80211_policy, | |
9018 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9020 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9021 | }, |
9022 | { | |
9023 | .cmd = NL80211_CMD_DEL_MPATH, | |
9024 | .doit = nl80211_del_mpath, | |
9025 | .policy = nl80211_policy, | |
9f1ba906 | 9026 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9028 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9029 | }, |
9030 | { | |
9031 | .cmd = NL80211_CMD_SET_BSS, | |
9032 | .doit = nl80211_set_bss, | |
9033 | .policy = nl80211_policy, | |
b2e1b302 | 9034 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9036 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9037 | }, |
f130347c LR |
9038 | { |
9039 | .cmd = NL80211_CMD_GET_REG, | |
9040 | .doit = nl80211_get_reg, | |
9041 | .policy = nl80211_policy, | |
5fe231e8 | 9042 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9043 | /* can be retrieved by unprivileged users */ |
9044 | }, | |
b2e1b302 LR |
9045 | { |
9046 | .cmd = NL80211_CMD_SET_REG, | |
9047 | .doit = nl80211_set_reg, | |
9048 | .policy = nl80211_policy, | |
9049 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9050 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9051 | }, |
9052 | { | |
9053 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9054 | .doit = nl80211_req_set_reg, | |
9055 | .policy = nl80211_policy, | |
93da9cc1 | 9056 | .flags = GENL_ADMIN_PERM, |
9057 | }, | |
9058 | { | |
24bdd9f4 JC |
9059 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9060 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9061 | .policy = nl80211_policy, |
9062 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9063 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9064 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9065 | }, |
9066 | { | |
24bdd9f4 JC |
9067 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9068 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9069 | .policy = nl80211_policy, |
9aed3cc1 | 9070 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9071 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9072 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9073 | }, |
2a519311 JB |
9074 | { |
9075 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9076 | .doit = nl80211_trigger_scan, | |
9077 | .policy = nl80211_policy, | |
9078 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9079 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9080 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9081 | }, |
9082 | { | |
9083 | .cmd = NL80211_CMD_GET_SCAN, | |
9084 | .policy = nl80211_policy, | |
9085 | .dumpit = nl80211_dump_scan, | |
9086 | }, | |
807f8a8c LC |
9087 | { |
9088 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9089 | .doit = nl80211_start_sched_scan, | |
9090 | .policy = nl80211_policy, | |
9091 | .flags = GENL_ADMIN_PERM, | |
9092 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9093 | NL80211_FLAG_NEED_RTNL, | |
9094 | }, | |
9095 | { | |
9096 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9097 | .doit = nl80211_stop_sched_scan, | |
9098 | .policy = nl80211_policy, | |
9099 | .flags = GENL_ADMIN_PERM, | |
9100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9101 | NL80211_FLAG_NEED_RTNL, | |
9102 | }, | |
636a5d36 JM |
9103 | { |
9104 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9105 | .doit = nl80211_authenticate, | |
9106 | .policy = nl80211_policy, | |
9107 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9108 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9109 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9110 | }, |
9111 | { | |
9112 | .cmd = NL80211_CMD_ASSOCIATE, | |
9113 | .doit = nl80211_associate, | |
9114 | .policy = nl80211_policy, | |
9115 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9117 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9118 | }, |
9119 | { | |
9120 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9121 | .doit = nl80211_deauthenticate, | |
9122 | .policy = nl80211_policy, | |
9123 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9124 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9125 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9126 | }, |
9127 | { | |
9128 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9129 | .doit = nl80211_disassociate, | |
9130 | .policy = nl80211_policy, | |
9131 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9132 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9133 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9134 | }, |
04a773ad JB |
9135 | { |
9136 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9137 | .doit = nl80211_join_ibss, | |
9138 | .policy = nl80211_policy, | |
9139 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9140 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9141 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9142 | }, |
9143 | { | |
9144 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9145 | .doit = nl80211_leave_ibss, | |
9146 | .policy = nl80211_policy, | |
9147 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9148 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9149 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9150 | }, |
aff89a9b JB |
9151 | #ifdef CONFIG_NL80211_TESTMODE |
9152 | { | |
9153 | .cmd = NL80211_CMD_TESTMODE, | |
9154 | .doit = nl80211_testmode_do, | |
71063f0e | 9155 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9156 | .policy = nl80211_policy, |
9157 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9158 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9159 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9160 | }, |
9161 | #endif | |
b23aa676 SO |
9162 | { |
9163 | .cmd = NL80211_CMD_CONNECT, | |
9164 | .doit = nl80211_connect, | |
9165 | .policy = nl80211_policy, | |
9166 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9167 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9168 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9169 | }, |
9170 | { | |
9171 | .cmd = NL80211_CMD_DISCONNECT, | |
9172 | .doit = nl80211_disconnect, | |
9173 | .policy = nl80211_policy, | |
9174 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9175 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9176 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9177 | }, |
463d0183 JB |
9178 | { |
9179 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9180 | .doit = nl80211_wiphy_netns, | |
9181 | .policy = nl80211_policy, | |
9182 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9183 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9184 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9185 | }, |
61fa713c HS |
9186 | { |
9187 | .cmd = NL80211_CMD_GET_SURVEY, | |
9188 | .policy = nl80211_policy, | |
9189 | .dumpit = nl80211_dump_survey, | |
9190 | }, | |
67fbb16b SO |
9191 | { |
9192 | .cmd = NL80211_CMD_SET_PMKSA, | |
9193 | .doit = nl80211_setdel_pmksa, | |
9194 | .policy = nl80211_policy, | |
9195 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9196 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9197 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9198 | }, |
9199 | { | |
9200 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9201 | .doit = nl80211_setdel_pmksa, | |
9202 | .policy = nl80211_policy, | |
9203 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9204 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9205 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9206 | }, |
9207 | { | |
9208 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9209 | .doit = nl80211_flush_pmksa, | |
9210 | .policy = nl80211_policy, | |
9211 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9212 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9213 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9214 | }, |
9588bbd5 JM |
9215 | { |
9216 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9217 | .doit = nl80211_remain_on_channel, | |
9218 | .policy = nl80211_policy, | |
9219 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9220 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9221 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9222 | }, |
9223 | { | |
9224 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9225 | .doit = nl80211_cancel_remain_on_channel, | |
9226 | .policy = nl80211_policy, | |
9227 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9228 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9229 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9230 | }, |
13ae75b1 JM |
9231 | { |
9232 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9233 | .doit = nl80211_set_tx_bitrate_mask, | |
9234 | .policy = nl80211_policy, | |
9235 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9236 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9237 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9238 | }, |
026331c4 | 9239 | { |
2e161f78 JB |
9240 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9241 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9242 | .policy = nl80211_policy, |
9243 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9244 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9245 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9246 | }, |
9247 | { | |
2e161f78 JB |
9248 | .cmd = NL80211_CMD_FRAME, |
9249 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9250 | .policy = nl80211_policy, |
f7ca38df | 9251 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9252 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9253 | NL80211_FLAG_NEED_RTNL, |
9254 | }, | |
9255 | { | |
9256 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9257 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9258 | .policy = nl80211_policy, | |
026331c4 | 9259 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9260 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9261 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9262 | }, |
ffb9eb3d KV |
9263 | { |
9264 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9265 | .doit = nl80211_set_power_save, | |
9266 | .policy = nl80211_policy, | |
9267 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9268 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9269 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9270 | }, |
9271 | { | |
9272 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9273 | .doit = nl80211_get_power_save, | |
9274 | .policy = nl80211_policy, | |
9275 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9276 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9277 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9278 | }, |
d6dc1a38 JO |
9279 | { |
9280 | .cmd = NL80211_CMD_SET_CQM, | |
9281 | .doit = nl80211_set_cqm, | |
9282 | .policy = nl80211_policy, | |
9283 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9284 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9285 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9286 | }, |
f444de05 JB |
9287 | { |
9288 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9289 | .doit = nl80211_set_channel, | |
9290 | .policy = nl80211_policy, | |
9291 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9292 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9293 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9294 | }, |
e8347eba BJ |
9295 | { |
9296 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9297 | .doit = nl80211_set_wds_peer, | |
9298 | .policy = nl80211_policy, | |
9299 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9300 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9301 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9302 | }, |
29cbe68c JB |
9303 | { |
9304 | .cmd = NL80211_CMD_JOIN_MESH, | |
9305 | .doit = nl80211_join_mesh, | |
9306 | .policy = nl80211_policy, | |
9307 | .flags = GENL_ADMIN_PERM, | |
9308 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9309 | NL80211_FLAG_NEED_RTNL, | |
9310 | }, | |
9311 | { | |
9312 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9313 | .doit = nl80211_leave_mesh, | |
9314 | .policy = nl80211_policy, | |
9315 | .flags = GENL_ADMIN_PERM, | |
9316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9317 | NL80211_FLAG_NEED_RTNL, | |
9318 | }, | |
dfb89c56 | 9319 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9320 | { |
9321 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9322 | .doit = nl80211_get_wowlan, | |
9323 | .policy = nl80211_policy, | |
9324 | /* can be retrieved by unprivileged users */ | |
9325 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9326 | NL80211_FLAG_NEED_RTNL, | |
9327 | }, | |
9328 | { | |
9329 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9330 | .doit = nl80211_set_wowlan, | |
9331 | .policy = nl80211_policy, | |
9332 | .flags = GENL_ADMIN_PERM, | |
9333 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9334 | NL80211_FLAG_NEED_RTNL, | |
9335 | }, | |
dfb89c56 | 9336 | #endif |
e5497d76 JB |
9337 | { |
9338 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9339 | .doit = nl80211_set_rekey_data, | |
9340 | .policy = nl80211_policy, | |
9341 | .flags = GENL_ADMIN_PERM, | |
9342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9343 | NL80211_FLAG_NEED_RTNL, | |
9344 | }, | |
109086ce AN |
9345 | { |
9346 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9347 | .doit = nl80211_tdls_mgmt, | |
9348 | .policy = nl80211_policy, | |
9349 | .flags = GENL_ADMIN_PERM, | |
9350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9351 | NL80211_FLAG_NEED_RTNL, | |
9352 | }, | |
9353 | { | |
9354 | .cmd = NL80211_CMD_TDLS_OPER, | |
9355 | .doit = nl80211_tdls_oper, | |
9356 | .policy = nl80211_policy, | |
9357 | .flags = GENL_ADMIN_PERM, | |
9358 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9359 | NL80211_FLAG_NEED_RTNL, | |
9360 | }, | |
28946da7 JB |
9361 | { |
9362 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9363 | .doit = nl80211_register_unexpected_frame, | |
9364 | .policy = nl80211_policy, | |
9365 | .flags = GENL_ADMIN_PERM, | |
9366 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9367 | NL80211_FLAG_NEED_RTNL, | |
9368 | }, | |
7f6cf311 JB |
9369 | { |
9370 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9371 | .doit = nl80211_probe_client, | |
9372 | .policy = nl80211_policy, | |
9373 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9375 | NL80211_FLAG_NEED_RTNL, |
9376 | }, | |
5e760230 JB |
9377 | { |
9378 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9379 | .doit = nl80211_register_beacons, | |
9380 | .policy = nl80211_policy, | |
9381 | .flags = GENL_ADMIN_PERM, | |
9382 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9383 | NL80211_FLAG_NEED_RTNL, | |
9384 | }, | |
1d9d9213 SW |
9385 | { |
9386 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9387 | .doit = nl80211_set_noack_map, | |
9388 | .policy = nl80211_policy, | |
9389 | .flags = GENL_ADMIN_PERM, | |
9390 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9391 | NL80211_FLAG_NEED_RTNL, | |
9392 | }, | |
98104fde JB |
9393 | { |
9394 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9395 | .doit = nl80211_start_p2p_device, | |
9396 | .policy = nl80211_policy, | |
9397 | .flags = GENL_ADMIN_PERM, | |
9398 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9399 | NL80211_FLAG_NEED_RTNL, | |
9400 | }, | |
9401 | { | |
9402 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9403 | .doit = nl80211_stop_p2p_device, | |
9404 | .policy = nl80211_policy, | |
9405 | .flags = GENL_ADMIN_PERM, | |
9406 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9407 | NL80211_FLAG_NEED_RTNL, | |
9408 | }, | |
f4e583c8 AQ |
9409 | { |
9410 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9411 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9412 | .policy = nl80211_policy, |
9413 | .flags = GENL_ADMIN_PERM, | |
9414 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9415 | NL80211_FLAG_NEED_RTNL, | |
9416 | }, | |
9417 | { | |
9418 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9419 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9420 | .policy = nl80211_policy, |
9421 | .flags = GENL_ADMIN_PERM, | |
9422 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9423 | NL80211_FLAG_NEED_RTNL, | |
9424 | }, | |
04f39047 SW |
9425 | { |
9426 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9427 | .doit = nl80211_start_radar_detection, | |
9428 | .policy = nl80211_policy, | |
9429 | .flags = GENL_ADMIN_PERM, | |
9430 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9431 | NL80211_FLAG_NEED_RTNL, | |
9432 | }, | |
3713b4e3 JB |
9433 | { |
9434 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9435 | .doit = nl80211_get_protocol_features, | |
9436 | .policy = nl80211_policy, | |
9437 | }, | |
355199e0 JM |
9438 | { |
9439 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9440 | .doit = nl80211_update_ft_ies, | |
9441 | .policy = nl80211_policy, | |
9442 | .flags = GENL_ADMIN_PERM, | |
9443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9444 | NL80211_FLAG_NEED_RTNL, | |
9445 | }, | |
5de17984 AS |
9446 | { |
9447 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9448 | .doit = nl80211_crit_protocol_start, | |
9449 | .policy = nl80211_policy, | |
9450 | .flags = GENL_ADMIN_PERM, | |
9451 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9452 | NL80211_FLAG_NEED_RTNL, | |
9453 | }, | |
9454 | { | |
9455 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9456 | .doit = nl80211_crit_protocol_stop, | |
9457 | .policy = nl80211_policy, | |
9458 | .flags = GENL_ADMIN_PERM, | |
9459 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9460 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9461 | }, |
9462 | { | |
9463 | .cmd = NL80211_CMD_GET_COALESCE, | |
9464 | .doit = nl80211_get_coalesce, | |
9465 | .policy = nl80211_policy, | |
9466 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9467 | NL80211_FLAG_NEED_RTNL, | |
9468 | }, | |
9469 | { | |
9470 | .cmd = NL80211_CMD_SET_COALESCE, | |
9471 | .doit = nl80211_set_coalesce, | |
9472 | .policy = nl80211_policy, | |
9473 | .flags = GENL_ADMIN_PERM, | |
9474 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9475 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
9476 | }, |
9477 | { | |
9478 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
9479 | .doit = nl80211_channel_switch, | |
9480 | .policy = nl80211_policy, | |
9481 | .flags = GENL_ADMIN_PERM, | |
9482 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9483 | NL80211_FLAG_NEED_RTNL, | |
9484 | }, | |
55682965 | 9485 | }; |
9588bbd5 | 9486 | |
6039f6d2 JM |
9487 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
9488 | .name = "mlme", | |
9489 | }; | |
55682965 JB |
9490 | |
9491 | /* multicast groups */ | |
9492 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
9493 | .name = "config", | |
9494 | }; | |
2a519311 JB |
9495 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
9496 | .name = "scan", | |
9497 | }; | |
73d54c9e LR |
9498 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
9499 | .name = "regulatory", | |
9500 | }; | |
55682965 JB |
9501 | |
9502 | /* notification functions */ | |
9503 | ||
9504 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9505 | { | |
9506 | struct sk_buff *msg; | |
86e8cf98 | 9507 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 9508 | |
fd2120ca | 9509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9510 | if (!msg) |
9511 | return; | |
9512 | ||
86e8cf98 | 9513 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
9514 | nlmsg_free(msg); |
9515 | return; | |
9516 | } | |
9517 | ||
463d0183 JB |
9518 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9519 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
9520 | } |
9521 | ||
362a415d JB |
9522 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9523 | struct cfg80211_registered_device *rdev) | |
9524 | { | |
9525 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9526 | struct nlattr *nest; | |
9527 | int i; | |
9528 | ||
9529 | if (WARN_ON(!req)) | |
9530 | return 0; | |
9531 | ||
9532 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9533 | if (!nest) | |
9534 | goto nla_put_failure; | |
9360ffd1 DM |
9535 | for (i = 0; i < req->n_ssids; i++) { |
9536 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9537 | goto nla_put_failure; | |
9538 | } | |
362a415d JB |
9539 | nla_nest_end(msg, nest); |
9540 | ||
9541 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9542 | if (!nest) | |
9543 | goto nla_put_failure; | |
9360ffd1 DM |
9544 | for (i = 0; i < req->n_channels; i++) { |
9545 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9546 | goto nla_put_failure; | |
9547 | } | |
362a415d JB |
9548 | nla_nest_end(msg, nest); |
9549 | ||
9360ffd1 DM |
9550 | if (req->ie && |
9551 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9552 | goto nla_put_failure; | |
362a415d | 9553 | |
ed473771 SL |
9554 | if (req->flags) |
9555 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9556 | ||
362a415d JB |
9557 | return 0; |
9558 | nla_put_failure: | |
9559 | return -ENOBUFS; | |
9560 | } | |
9561 | ||
a538e2d5 JB |
9562 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9563 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9564 | struct wireless_dev *wdev, |
15e47304 | 9565 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9566 | u32 cmd) |
2a519311 JB |
9567 | { |
9568 | void *hdr; | |
9569 | ||
15e47304 | 9570 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9571 | if (!hdr) |
9572 | return -1; | |
9573 | ||
9360ffd1 | 9574 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9575 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9576 | wdev->netdev->ifindex)) || | |
9577 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9578 | goto nla_put_failure; |
2a519311 | 9579 | |
362a415d JB |
9580 | /* ignore errors and send incomplete event anyway */ |
9581 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9582 | |
9583 | return genlmsg_end(msg, hdr); | |
9584 | ||
9585 | nla_put_failure: | |
9586 | genlmsg_cancel(msg, hdr); | |
9587 | return -EMSGSIZE; | |
9588 | } | |
9589 | ||
807f8a8c LC |
9590 | static int |
9591 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9592 | struct cfg80211_registered_device *rdev, | |
9593 | struct net_device *netdev, | |
15e47304 | 9594 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9595 | { |
9596 | void *hdr; | |
9597 | ||
15e47304 | 9598 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9599 | if (!hdr) |
9600 | return -1; | |
9601 | ||
9360ffd1 DM |
9602 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9603 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9604 | goto nla_put_failure; | |
807f8a8c LC |
9605 | |
9606 | return genlmsg_end(msg, hdr); | |
9607 | ||
9608 | nla_put_failure: | |
9609 | genlmsg_cancel(msg, hdr); | |
9610 | return -EMSGSIZE; | |
9611 | } | |
9612 | ||
a538e2d5 | 9613 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9614 | struct wireless_dev *wdev) |
a538e2d5 JB |
9615 | { |
9616 | struct sk_buff *msg; | |
9617 | ||
58050fce | 9618 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9619 | if (!msg) |
9620 | return; | |
9621 | ||
fd014284 | 9622 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9623 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9624 | nlmsg_free(msg); | |
9625 | return; | |
9626 | } | |
9627 | ||
463d0183 JB |
9628 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9629 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9630 | } |
9631 | ||
2a519311 | 9632 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9633 | struct wireless_dev *wdev) |
2a519311 JB |
9634 | { |
9635 | struct sk_buff *msg; | |
9636 | ||
fd2120ca | 9637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9638 | if (!msg) |
9639 | return; | |
9640 | ||
fd014284 | 9641 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9642 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9643 | nlmsg_free(msg); |
9644 | return; | |
9645 | } | |
9646 | ||
463d0183 JB |
9647 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9648 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9649 | } |
9650 | ||
9651 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9652 | struct wireless_dev *wdev) |
2a519311 JB |
9653 | { |
9654 | struct sk_buff *msg; | |
9655 | ||
fd2120ca | 9656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9657 | if (!msg) |
9658 | return; | |
9659 | ||
fd014284 | 9660 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9661 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9662 | nlmsg_free(msg); |
9663 | return; | |
9664 | } | |
9665 | ||
463d0183 JB |
9666 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9667 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9668 | } |
9669 | ||
807f8a8c LC |
9670 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9671 | struct net_device *netdev) | |
9672 | { | |
9673 | struct sk_buff *msg; | |
9674 | ||
9675 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9676 | if (!msg) | |
9677 | return; | |
9678 | ||
9679 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9680 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9681 | nlmsg_free(msg); | |
9682 | return; | |
9683 | } | |
9684 | ||
9685 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9686 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9687 | } | |
9688 | ||
9689 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9690 | struct net_device *netdev, u32 cmd) | |
9691 | { | |
9692 | struct sk_buff *msg; | |
9693 | ||
58050fce | 9694 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9695 | if (!msg) |
9696 | return; | |
9697 | ||
9698 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9699 | nlmsg_free(msg); | |
9700 | return; | |
9701 | } | |
9702 | ||
9703 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9704 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9705 | } | |
9706 | ||
73d54c9e LR |
9707 | /* |
9708 | * This can happen on global regulatory changes or device specific settings | |
9709 | * based on custom world regulatory domains. | |
9710 | */ | |
9711 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9712 | { | |
9713 | struct sk_buff *msg; | |
9714 | void *hdr; | |
9715 | ||
fd2120ca | 9716 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9717 | if (!msg) |
9718 | return; | |
9719 | ||
9720 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9721 | if (!hdr) { | |
9722 | nlmsg_free(msg); | |
9723 | return; | |
9724 | } | |
9725 | ||
9726 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9727 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9728 | goto nla_put_failure; | |
9729 | ||
9730 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9731 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9732 | NL80211_REGDOM_TYPE_WORLD)) | |
9733 | goto nla_put_failure; | |
9734 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9735 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9736 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9737 | goto nla_put_failure; | |
9738 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9739 | request->intersect) { | |
9740 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9741 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9742 | goto nla_put_failure; | |
9743 | } else { | |
9744 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9745 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9746 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9747 | request->alpha2)) | |
9748 | goto nla_put_failure; | |
9749 | } | |
9750 | ||
f4173766 | 9751 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9752 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9753 | goto nla_put_failure; | |
73d54c9e | 9754 | |
3b7b72ee | 9755 | genlmsg_end(msg, hdr); |
73d54c9e | 9756 | |
bc43b28c | 9757 | rcu_read_lock(); |
463d0183 | 9758 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9759 | GFP_ATOMIC); |
9760 | rcu_read_unlock(); | |
73d54c9e LR |
9761 | |
9762 | return; | |
9763 | ||
9764 | nla_put_failure: | |
9765 | genlmsg_cancel(msg, hdr); | |
9766 | nlmsg_free(msg); | |
9767 | } | |
9768 | ||
6039f6d2 JM |
9769 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9770 | struct net_device *netdev, | |
9771 | const u8 *buf, size_t len, | |
e6d6e342 | 9772 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9773 | { |
9774 | struct sk_buff *msg; | |
9775 | void *hdr; | |
9776 | ||
e6d6e342 | 9777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9778 | if (!msg) |
9779 | return; | |
9780 | ||
9781 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9782 | if (!hdr) { | |
9783 | nlmsg_free(msg); | |
9784 | return; | |
9785 | } | |
9786 | ||
9360ffd1 DM |
9787 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9788 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9789 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9790 | goto nla_put_failure; | |
6039f6d2 | 9791 | |
3b7b72ee | 9792 | genlmsg_end(msg, hdr); |
6039f6d2 | 9793 | |
463d0183 JB |
9794 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9795 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9796 | return; |
9797 | ||
9798 | nla_put_failure: | |
9799 | genlmsg_cancel(msg, hdr); | |
9800 | nlmsg_free(msg); | |
9801 | } | |
9802 | ||
9803 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9804 | struct net_device *netdev, const u8 *buf, |
9805 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9806 | { |
9807 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9808 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9809 | } |
9810 | ||
9811 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9812 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9813 | size_t len, gfp_t gfp) |
6039f6d2 | 9814 | { |
e6d6e342 JB |
9815 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9816 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9817 | } |
9818 | ||
53b46b84 | 9819 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9820 | struct net_device *netdev, const u8 *buf, |
9821 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9822 | { |
9823 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9824 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9825 | } |
9826 | ||
53b46b84 JM |
9827 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9828 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9829 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9830 | { |
9831 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9832 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9833 | } |
9834 | ||
6ff57cf8 JB |
9835 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
9836 | size_t len) | |
cf4e594e | 9837 | { |
947add36 JB |
9838 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9839 | struct wiphy *wiphy = wdev->wiphy; | |
9840 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
9841 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
9842 | u32 cmd; | |
947add36 | 9843 | |
6ff57cf8 JB |
9844 | if (WARN_ON(len < 2)) |
9845 | return; | |
cf4e594e | 9846 | |
6ff57cf8 JB |
9847 | if (ieee80211_is_deauth(mgmt->frame_control)) |
9848 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
9849 | else | |
9850 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 9851 | |
6ff57cf8 JB |
9852 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
9853 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 9854 | } |
6ff57cf8 | 9855 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 9856 | |
1b06bb40 LR |
9857 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9858 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9859 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9860 | { |
9861 | struct sk_buff *msg; | |
9862 | void *hdr; | |
9863 | ||
e6d6e342 | 9864 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9865 | if (!msg) |
9866 | return; | |
9867 | ||
9868 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9869 | if (!hdr) { | |
9870 | nlmsg_free(msg); | |
9871 | return; | |
9872 | } | |
9873 | ||
9360ffd1 DM |
9874 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9875 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9876 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9877 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9878 | goto nla_put_failure; | |
1965c853 | 9879 | |
3b7b72ee | 9880 | genlmsg_end(msg, hdr); |
1965c853 | 9881 | |
463d0183 JB |
9882 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9883 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9884 | return; |
9885 | ||
9886 | nla_put_failure: | |
9887 | genlmsg_cancel(msg, hdr); | |
9888 | nlmsg_free(msg); | |
9889 | } | |
9890 | ||
9891 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9892 | struct net_device *netdev, const u8 *addr, |
9893 | gfp_t gfp) | |
1965c853 JM |
9894 | { |
9895 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9896 | addr, gfp); |
1965c853 JM |
9897 | } |
9898 | ||
9899 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9900 | struct net_device *netdev, const u8 *addr, |
9901 | gfp_t gfp) | |
1965c853 | 9902 | { |
e6d6e342 JB |
9903 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9904 | addr, gfp); | |
1965c853 JM |
9905 | } |
9906 | ||
b23aa676 SO |
9907 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9908 | struct net_device *netdev, const u8 *bssid, | |
9909 | const u8 *req_ie, size_t req_ie_len, | |
9910 | const u8 *resp_ie, size_t resp_ie_len, | |
9911 | u16 status, gfp_t gfp) | |
9912 | { | |
9913 | struct sk_buff *msg; | |
9914 | void *hdr; | |
9915 | ||
58050fce | 9916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9917 | if (!msg) |
9918 | return; | |
9919 | ||
9920 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9921 | if (!hdr) { | |
9922 | nlmsg_free(msg); | |
9923 | return; | |
9924 | } | |
9925 | ||
9360ffd1 DM |
9926 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9927 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9928 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9929 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9930 | (req_ie && | |
9931 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9932 | (resp_ie && | |
9933 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9934 | goto nla_put_failure; | |
b23aa676 | 9935 | |
3b7b72ee | 9936 | genlmsg_end(msg, hdr); |
b23aa676 | 9937 | |
463d0183 JB |
9938 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9939 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9940 | return; |
9941 | ||
9942 | nla_put_failure: | |
9943 | genlmsg_cancel(msg, hdr); | |
9944 | nlmsg_free(msg); | |
9945 | ||
9946 | } | |
9947 | ||
9948 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9949 | struct net_device *netdev, const u8 *bssid, | |
9950 | const u8 *req_ie, size_t req_ie_len, | |
9951 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9952 | { | |
9953 | struct sk_buff *msg; | |
9954 | void *hdr; | |
9955 | ||
58050fce | 9956 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9957 | if (!msg) |
9958 | return; | |
9959 | ||
9960 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9961 | if (!hdr) { | |
9962 | nlmsg_free(msg); | |
9963 | return; | |
9964 | } | |
9965 | ||
9360ffd1 DM |
9966 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9967 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9968 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9969 | (req_ie && | |
9970 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9971 | (resp_ie && | |
9972 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9973 | goto nla_put_failure; | |
b23aa676 | 9974 | |
3b7b72ee | 9975 | genlmsg_end(msg, hdr); |
b23aa676 | 9976 | |
463d0183 JB |
9977 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9978 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9979 | return; |
9980 | ||
9981 | nla_put_failure: | |
9982 | genlmsg_cancel(msg, hdr); | |
9983 | nlmsg_free(msg); | |
9984 | ||
9985 | } | |
9986 | ||
9987 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9988 | struct net_device *netdev, u16 reason, | |
667503dd | 9989 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9990 | { |
9991 | struct sk_buff *msg; | |
9992 | void *hdr; | |
9993 | ||
58050fce | 9994 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9995 | if (!msg) |
9996 | return; | |
9997 | ||
9998 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9999 | if (!hdr) { | |
10000 | nlmsg_free(msg); | |
10001 | return; | |
10002 | } | |
10003 | ||
9360ffd1 DM |
10004 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10005 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10006 | (from_ap && reason && | |
10007 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10008 | (from_ap && | |
10009 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10010 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10011 | goto nla_put_failure; | |
b23aa676 | 10012 | |
3b7b72ee | 10013 | genlmsg_end(msg, hdr); |
b23aa676 | 10014 | |
463d0183 JB |
10015 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10016 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
10017 | return; |
10018 | ||
10019 | nla_put_failure: | |
10020 | genlmsg_cancel(msg, hdr); | |
10021 | nlmsg_free(msg); | |
10022 | ||
10023 | } | |
10024 | ||
04a773ad JB |
10025 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10026 | struct net_device *netdev, const u8 *bssid, | |
10027 | gfp_t gfp) | |
10028 | { | |
10029 | struct sk_buff *msg; | |
10030 | void *hdr; | |
10031 | ||
fd2120ca | 10032 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10033 | if (!msg) |
10034 | return; | |
10035 | ||
10036 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10037 | if (!hdr) { | |
10038 | nlmsg_free(msg); | |
10039 | return; | |
10040 | } | |
10041 | ||
9360ffd1 DM |
10042 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10043 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10044 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10045 | goto nla_put_failure; | |
04a773ad | 10046 | |
3b7b72ee | 10047 | genlmsg_end(msg, hdr); |
04a773ad | 10048 | |
463d0183 JB |
10049 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10050 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
10051 | return; |
10052 | ||
10053 | nla_put_failure: | |
10054 | genlmsg_cancel(msg, hdr); | |
10055 | nlmsg_free(msg); | |
10056 | } | |
10057 | ||
947add36 JB |
10058 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10059 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10060 | { |
947add36 JB |
10061 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10062 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
10063 | struct sk_buff *msg; |
10064 | void *hdr; | |
10065 | ||
947add36 JB |
10066 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10067 | return; | |
10068 | ||
10069 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10070 | ||
c93b5e71 JC |
10071 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10072 | if (!msg) | |
10073 | return; | |
10074 | ||
10075 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10076 | if (!hdr) { | |
10077 | nlmsg_free(msg); | |
10078 | return; | |
10079 | } | |
10080 | ||
9360ffd1 | 10081 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10082 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10083 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10084 | (ie_len && ie && |
10085 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10086 | goto nla_put_failure; | |
c93b5e71 | 10087 | |
3b7b72ee | 10088 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
10089 | |
10090 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10091 | nl80211_mlme_mcgrp.id, gfp); | |
10092 | return; | |
10093 | ||
10094 | nla_put_failure: | |
10095 | genlmsg_cancel(msg, hdr); | |
10096 | nlmsg_free(msg); | |
10097 | } | |
947add36 | 10098 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10099 | |
a3b8b056 JM |
10100 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10101 | struct net_device *netdev, const u8 *addr, | |
10102 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10103 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10104 | { |
10105 | struct sk_buff *msg; | |
10106 | void *hdr; | |
10107 | ||
e6d6e342 | 10108 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10109 | if (!msg) |
10110 | return; | |
10111 | ||
10112 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10113 | if (!hdr) { | |
10114 | nlmsg_free(msg); | |
10115 | return; | |
10116 | } | |
10117 | ||
9360ffd1 DM |
10118 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10119 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10120 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10121 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10122 | (key_id != -1 && | |
10123 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10124 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10125 | goto nla_put_failure; | |
a3b8b056 | 10126 | |
3b7b72ee | 10127 | genlmsg_end(msg, hdr); |
a3b8b056 | 10128 | |
463d0183 JB |
10129 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
10130 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
10131 | return; |
10132 | ||
10133 | nla_put_failure: | |
10134 | genlmsg_cancel(msg, hdr); | |
10135 | nlmsg_free(msg); | |
10136 | } | |
10137 | ||
6bad8766 LR |
10138 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10139 | struct ieee80211_channel *channel_before, | |
10140 | struct ieee80211_channel *channel_after) | |
10141 | { | |
10142 | struct sk_buff *msg; | |
10143 | void *hdr; | |
10144 | struct nlattr *nl_freq; | |
10145 | ||
fd2120ca | 10146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10147 | if (!msg) |
10148 | return; | |
10149 | ||
10150 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10151 | if (!hdr) { | |
10152 | nlmsg_free(msg); | |
10153 | return; | |
10154 | } | |
10155 | ||
10156 | /* | |
10157 | * Since we are applying the beacon hint to a wiphy we know its | |
10158 | * wiphy_idx is valid | |
10159 | */ | |
9360ffd1 DM |
10160 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10161 | goto nla_put_failure; | |
6bad8766 LR |
10162 | |
10163 | /* Before */ | |
10164 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10165 | if (!nl_freq) | |
10166 | goto nla_put_failure; | |
cdc89b97 | 10167 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10168 | goto nla_put_failure; |
10169 | nla_nest_end(msg, nl_freq); | |
10170 | ||
10171 | /* After */ | |
10172 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10173 | if (!nl_freq) | |
10174 | goto nla_put_failure; | |
cdc89b97 | 10175 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10176 | goto nla_put_failure; |
10177 | nla_nest_end(msg, nl_freq); | |
10178 | ||
3b7b72ee | 10179 | genlmsg_end(msg, hdr); |
6bad8766 | 10180 | |
463d0183 JB |
10181 | rcu_read_lock(); |
10182 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
10183 | GFP_ATOMIC); | |
10184 | rcu_read_unlock(); | |
6bad8766 LR |
10185 | |
10186 | return; | |
10187 | ||
10188 | nla_put_failure: | |
10189 | genlmsg_cancel(msg, hdr); | |
10190 | nlmsg_free(msg); | |
10191 | } | |
10192 | ||
9588bbd5 JM |
10193 | static void nl80211_send_remain_on_chan_event( |
10194 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10195 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10196 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10197 | unsigned int duration, gfp_t gfp) |
10198 | { | |
10199 | struct sk_buff *msg; | |
10200 | void *hdr; | |
10201 | ||
10202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10203 | if (!msg) | |
10204 | return; | |
10205 | ||
10206 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10207 | if (!hdr) { | |
10208 | nlmsg_free(msg); | |
10209 | return; | |
10210 | } | |
10211 | ||
9360ffd1 | 10212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10213 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10214 | wdev->netdev->ifindex)) || | |
00f53350 | 10215 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10216 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10217 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10218 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10219 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10220 | goto nla_put_failure; | |
9588bbd5 | 10221 | |
9360ffd1 DM |
10222 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10223 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10224 | goto nla_put_failure; | |
9588bbd5 | 10225 | |
3b7b72ee | 10226 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
10227 | |
10228 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10229 | nl80211_mlme_mcgrp.id, gfp); | |
10230 | return; | |
10231 | ||
10232 | nla_put_failure: | |
10233 | genlmsg_cancel(msg, hdr); | |
10234 | nlmsg_free(msg); | |
10235 | } | |
10236 | ||
947add36 JB |
10237 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10238 | struct ieee80211_channel *chan, | |
10239 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10240 | { |
947add36 JB |
10241 | struct wiphy *wiphy = wdev->wiphy; |
10242 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10243 | ||
10244 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10245 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10246 | rdev, wdev, cookie, chan, |
42d97a59 | 10247 | duration, gfp); |
9588bbd5 | 10248 | } |
947add36 | 10249 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10250 | |
947add36 JB |
10251 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10252 | struct ieee80211_channel *chan, | |
10253 | gfp_t gfp) | |
9588bbd5 | 10254 | { |
947add36 JB |
10255 | struct wiphy *wiphy = wdev->wiphy; |
10256 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10257 | ||
10258 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10259 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10260 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10261 | } |
947add36 | 10262 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10263 | |
947add36 JB |
10264 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10265 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10266 | { |
947add36 JB |
10267 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10268 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
10269 | struct sk_buff *msg; |
10270 | ||
947add36 JB |
10271 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10272 | ||
58050fce | 10273 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10274 | if (!msg) |
10275 | return; | |
10276 | ||
66266b3a JL |
10277 | if (nl80211_send_station(msg, 0, 0, 0, |
10278 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10279 | nlmsg_free(msg); |
10280 | return; | |
10281 | } | |
10282 | ||
10283 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10284 | nl80211_mlme_mcgrp.id, gfp); | |
10285 | } | |
947add36 | 10286 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10287 | |
947add36 | 10288 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10289 | { |
947add36 JB |
10290 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10291 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
10292 | struct sk_buff *msg; |
10293 | void *hdr; | |
10294 | ||
947add36 JB |
10295 | trace_cfg80211_del_sta(dev, mac_addr); |
10296 | ||
58050fce | 10297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10298 | if (!msg) |
10299 | return; | |
10300 | ||
10301 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10302 | if (!hdr) { | |
10303 | nlmsg_free(msg); | |
10304 | return; | |
10305 | } | |
10306 | ||
9360ffd1 DM |
10307 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10308 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10309 | goto nla_put_failure; | |
ec15e68b | 10310 | |
3b7b72ee | 10311 | genlmsg_end(msg, hdr); |
ec15e68b JM |
10312 | |
10313 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10314 | nl80211_mlme_mcgrp.id, gfp); | |
10315 | return; | |
10316 | ||
10317 | nla_put_failure: | |
10318 | genlmsg_cancel(msg, hdr); | |
10319 | nlmsg_free(msg); | |
10320 | } | |
947add36 | 10321 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10322 | |
947add36 JB |
10323 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10324 | enum nl80211_connect_failed_reason reason, | |
10325 | gfp_t gfp) | |
ed44a951 | 10326 | { |
947add36 JB |
10327 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10328 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10329 | struct sk_buff *msg; |
10330 | void *hdr; | |
10331 | ||
10332 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10333 | if (!msg) | |
10334 | return; | |
10335 | ||
10336 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10337 | if (!hdr) { | |
10338 | nlmsg_free(msg); | |
10339 | return; | |
10340 | } | |
10341 | ||
10342 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10343 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10344 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10345 | goto nla_put_failure; | |
10346 | ||
10347 | genlmsg_end(msg, hdr); | |
10348 | ||
10349 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10350 | nl80211_mlme_mcgrp.id, gfp); | |
10351 | return; | |
10352 | ||
10353 | nla_put_failure: | |
10354 | genlmsg_cancel(msg, hdr); | |
10355 | nlmsg_free(msg); | |
10356 | } | |
947add36 | 10357 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10358 | |
b92ab5d8 JB |
10359 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10360 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10361 | { |
10362 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10363 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10364 | struct sk_buff *msg; | |
10365 | void *hdr; | |
15e47304 | 10366 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10367 | |
15e47304 | 10368 | if (!nlportid) |
28946da7 JB |
10369 | return false; |
10370 | ||
10371 | msg = nlmsg_new(100, gfp); | |
10372 | if (!msg) | |
10373 | return true; | |
10374 | ||
b92ab5d8 | 10375 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10376 | if (!hdr) { |
10377 | nlmsg_free(msg); | |
10378 | return true; | |
10379 | } | |
10380 | ||
9360ffd1 DM |
10381 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10382 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10383 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10384 | goto nla_put_failure; | |
28946da7 | 10385 | |
9c90a9f6 | 10386 | genlmsg_end(msg, hdr); |
15e47304 | 10387 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10388 | return true; |
10389 | ||
10390 | nla_put_failure: | |
10391 | genlmsg_cancel(msg, hdr); | |
10392 | nlmsg_free(msg); | |
10393 | return true; | |
10394 | } | |
10395 | ||
947add36 JB |
10396 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10397 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10398 | { |
947add36 JB |
10399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10400 | bool ret; | |
10401 | ||
10402 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10403 | ||
10404 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10405 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10406 | trace_cfg80211_return_bool(false); | |
10407 | return false; | |
10408 | } | |
10409 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10410 | addr, gfp); | |
10411 | trace_cfg80211_return_bool(ret); | |
10412 | return ret; | |
b92ab5d8 | 10413 | } |
947add36 | 10414 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10415 | |
947add36 JB |
10416 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10417 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10418 | { |
947add36 JB |
10419 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10420 | bool ret; | |
10421 | ||
10422 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10423 | ||
10424 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10425 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10426 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10427 | trace_cfg80211_return_bool(false); | |
10428 | return false; | |
10429 | } | |
10430 | ret = __nl80211_unexpected_frame(dev, | |
10431 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10432 | addr, gfp); | |
10433 | trace_cfg80211_return_bool(ret); | |
10434 | return ret; | |
b92ab5d8 | 10435 | } |
947add36 | 10436 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10437 | |
2e161f78 | 10438 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10439 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
10440 | int freq, int sig_dbm, |
10441 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 10442 | { |
71bbc994 | 10443 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10444 | struct sk_buff *msg; |
10445 | void *hdr; | |
026331c4 JM |
10446 | |
10447 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10448 | if (!msg) | |
10449 | return -ENOMEM; | |
10450 | ||
2e161f78 | 10451 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10452 | if (!hdr) { |
10453 | nlmsg_free(msg); | |
10454 | return -ENOMEM; | |
10455 | } | |
10456 | ||
9360ffd1 | 10457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10458 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10459 | netdev->ifindex)) || | |
a838490b | 10460 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10461 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10462 | (sig_dbm && | |
10463 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10464 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10465 | goto nla_put_failure; | |
026331c4 | 10466 | |
3b7b72ee | 10467 | genlmsg_end(msg, hdr); |
026331c4 | 10468 | |
15e47304 | 10469 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10470 | |
10471 | nla_put_failure: | |
10472 | genlmsg_cancel(msg, hdr); | |
10473 | nlmsg_free(msg); | |
10474 | return -ENOBUFS; | |
10475 | } | |
10476 | ||
947add36 JB |
10477 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10478 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10479 | { |
947add36 JB |
10480 | struct wiphy *wiphy = wdev->wiphy; |
10481 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10482 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10483 | struct sk_buff *msg; |
10484 | void *hdr; | |
10485 | ||
947add36 JB |
10486 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10487 | ||
026331c4 JM |
10488 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10489 | if (!msg) | |
10490 | return; | |
10491 | ||
2e161f78 | 10492 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10493 | if (!hdr) { |
10494 | nlmsg_free(msg); | |
10495 | return; | |
10496 | } | |
10497 | ||
9360ffd1 | 10498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10499 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10500 | netdev->ifindex)) || | |
a838490b | 10501 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10502 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10503 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10504 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10505 | goto nla_put_failure; | |
026331c4 | 10506 | |
3b7b72ee | 10507 | genlmsg_end(msg, hdr); |
026331c4 JM |
10508 | |
10509 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
10510 | return; | |
10511 | ||
10512 | nla_put_failure: | |
10513 | genlmsg_cancel(msg, hdr); | |
10514 | nlmsg_free(msg); | |
10515 | } | |
947add36 | 10516 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10517 | |
947add36 JB |
10518 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10519 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10520 | gfp_t gfp) | |
d6dc1a38 | 10521 | { |
947add36 JB |
10522 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10523 | struct wiphy *wiphy = wdev->wiphy; | |
10524 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10525 | struct sk_buff *msg; |
10526 | struct nlattr *pinfoattr; | |
10527 | void *hdr; | |
10528 | ||
947add36 JB |
10529 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10530 | ||
58050fce | 10531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10532 | if (!msg) |
10533 | return; | |
10534 | ||
10535 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10536 | if (!hdr) { | |
10537 | nlmsg_free(msg); | |
10538 | return; | |
10539 | } | |
10540 | ||
9360ffd1 | 10541 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10542 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10543 | goto nla_put_failure; |
d6dc1a38 JO |
10544 | |
10545 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10546 | if (!pinfoattr) | |
10547 | goto nla_put_failure; | |
10548 | ||
9360ffd1 DM |
10549 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10550 | rssi_event)) | |
10551 | goto nla_put_failure; | |
d6dc1a38 JO |
10552 | |
10553 | nla_nest_end(msg, pinfoattr); | |
10554 | ||
3b7b72ee | 10555 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10556 | |
10557 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10558 | nl80211_mlme_mcgrp.id, gfp); | |
10559 | return; | |
10560 | ||
10561 | nla_put_failure: | |
10562 | genlmsg_cancel(msg, hdr); | |
10563 | nlmsg_free(msg); | |
10564 | } | |
947add36 | 10565 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10566 | |
947add36 JB |
10567 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10568 | struct net_device *netdev, const u8 *bssid, | |
10569 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10570 | { |
10571 | struct sk_buff *msg; | |
10572 | struct nlattr *rekey_attr; | |
10573 | void *hdr; | |
10574 | ||
58050fce | 10575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10576 | if (!msg) |
10577 | return; | |
10578 | ||
10579 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10580 | if (!hdr) { | |
10581 | nlmsg_free(msg); | |
10582 | return; | |
10583 | } | |
10584 | ||
9360ffd1 DM |
10585 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10586 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10587 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10588 | goto nla_put_failure; | |
e5497d76 JB |
10589 | |
10590 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10591 | if (!rekey_attr) | |
10592 | goto nla_put_failure; | |
10593 | ||
9360ffd1 DM |
10594 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10595 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10596 | goto nla_put_failure; | |
e5497d76 JB |
10597 | |
10598 | nla_nest_end(msg, rekey_attr); | |
10599 | ||
3b7b72ee | 10600 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10601 | |
10602 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10603 | nl80211_mlme_mcgrp.id, gfp); | |
10604 | return; | |
10605 | ||
10606 | nla_put_failure: | |
10607 | genlmsg_cancel(msg, hdr); | |
10608 | nlmsg_free(msg); | |
10609 | } | |
10610 | ||
947add36 JB |
10611 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10612 | const u8 *replay_ctr, gfp_t gfp) | |
10613 | { | |
10614 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10615 | struct wiphy *wiphy = wdev->wiphy; | |
10616 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10617 | ||
10618 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10619 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10620 | } | |
10621 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10622 | ||
10623 | static void | |
10624 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10625 | struct net_device *netdev, int index, | |
10626 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10627 | { |
10628 | struct sk_buff *msg; | |
10629 | struct nlattr *attr; | |
10630 | void *hdr; | |
10631 | ||
58050fce | 10632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10633 | if (!msg) |
10634 | return; | |
10635 | ||
10636 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10637 | if (!hdr) { | |
10638 | nlmsg_free(msg); | |
10639 | return; | |
10640 | } | |
10641 | ||
9360ffd1 DM |
10642 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10643 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10644 | goto nla_put_failure; | |
c9df56b4 JM |
10645 | |
10646 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10647 | if (!attr) | |
10648 | goto nla_put_failure; | |
10649 | ||
9360ffd1 DM |
10650 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10651 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10652 | (preauth && | |
10653 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10654 | goto nla_put_failure; | |
c9df56b4 JM |
10655 | |
10656 | nla_nest_end(msg, attr); | |
10657 | ||
3b7b72ee | 10658 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10659 | |
10660 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10661 | nl80211_mlme_mcgrp.id, gfp); | |
10662 | return; | |
10663 | ||
10664 | nla_put_failure: | |
10665 | genlmsg_cancel(msg, hdr); | |
10666 | nlmsg_free(msg); | |
10667 | } | |
10668 | ||
947add36 JB |
10669 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10670 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10671 | { | |
10672 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10673 | struct wiphy *wiphy = wdev->wiphy; | |
10674 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10675 | ||
10676 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10677 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10678 | } | |
10679 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10680 | ||
10681 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10682 | struct net_device *netdev, | |
10683 | struct cfg80211_chan_def *chandef, | |
10684 | gfp_t gfp) | |
5314526b TP |
10685 | { |
10686 | struct sk_buff *msg; | |
10687 | void *hdr; | |
10688 | ||
58050fce | 10689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10690 | if (!msg) |
10691 | return; | |
10692 | ||
10693 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10694 | if (!hdr) { | |
10695 | nlmsg_free(msg); | |
10696 | return; | |
10697 | } | |
10698 | ||
683b6d3b JB |
10699 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10700 | goto nla_put_failure; | |
10701 | ||
10702 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10703 | goto nla_put_failure; |
5314526b TP |
10704 | |
10705 | genlmsg_end(msg, hdr); | |
10706 | ||
10707 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10708 | nl80211_mlme_mcgrp.id, gfp); | |
10709 | return; | |
10710 | ||
10711 | nla_put_failure: | |
10712 | genlmsg_cancel(msg, hdr); | |
10713 | nlmsg_free(msg); | |
10714 | } | |
10715 | ||
947add36 JB |
10716 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10717 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10718 | { |
947add36 JB |
10719 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10720 | struct wiphy *wiphy = wdev->wiphy; | |
10721 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10722 | ||
10723 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10724 | ||
10725 | wdev_lock(wdev); | |
10726 | ||
10727 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10728 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10729 | goto out; | |
10730 | ||
10731 | wdev->channel = chandef->chan; | |
10732 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10733 | out: | |
10734 | wdev_unlock(wdev); | |
10735 | return; | |
10736 | } | |
10737 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10738 | ||
10739 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10740 | const u8 *peer, u32 num_packets, | |
10741 | u32 rate, u32 intvl, gfp_t gfp) | |
10742 | { | |
10743 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10744 | struct wiphy *wiphy = wdev->wiphy; | |
10745 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10746 | struct sk_buff *msg; |
10747 | struct nlattr *pinfoattr; | |
10748 | void *hdr; | |
10749 | ||
10750 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10751 | if (!msg) | |
10752 | return; | |
10753 | ||
10754 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10755 | if (!hdr) { | |
10756 | nlmsg_free(msg); | |
10757 | return; | |
10758 | } | |
10759 | ||
10760 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10761 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10762 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10763 | goto nla_put_failure; | |
10764 | ||
10765 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10766 | if (!pinfoattr) | |
10767 | goto nla_put_failure; | |
10768 | ||
10769 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10770 | goto nla_put_failure; | |
10771 | ||
10772 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10773 | goto nla_put_failure; | |
10774 | ||
10775 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10776 | goto nla_put_failure; | |
10777 | ||
10778 | nla_nest_end(msg, pinfoattr); | |
10779 | ||
10780 | genlmsg_end(msg, hdr); | |
10781 | ||
10782 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10783 | nl80211_mlme_mcgrp.id, gfp); | |
10784 | return; | |
10785 | ||
10786 | nla_put_failure: | |
10787 | genlmsg_cancel(msg, hdr); | |
10788 | nlmsg_free(msg); | |
10789 | } | |
947add36 | 10790 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10791 | |
04f39047 SW |
10792 | void |
10793 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10794 | struct cfg80211_chan_def *chandef, | |
10795 | enum nl80211_radar_event event, | |
10796 | struct net_device *netdev, gfp_t gfp) | |
10797 | { | |
10798 | struct sk_buff *msg; | |
10799 | void *hdr; | |
10800 | ||
10801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10802 | if (!msg) | |
10803 | return; | |
10804 | ||
10805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10806 | if (!hdr) { | |
10807 | nlmsg_free(msg); | |
10808 | return; | |
10809 | } | |
10810 | ||
10811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10812 | goto nla_put_failure; | |
10813 | ||
10814 | /* NOP and radar events don't need a netdev parameter */ | |
10815 | if (netdev) { | |
10816 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10817 | ||
10818 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10819 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10820 | goto nla_put_failure; | |
10821 | } | |
10822 | ||
10823 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10824 | goto nla_put_failure; | |
10825 | ||
10826 | if (nl80211_send_chandef(msg, chandef)) | |
10827 | goto nla_put_failure; | |
10828 | ||
9c90a9f6 | 10829 | genlmsg_end(msg, hdr); |
04f39047 SW |
10830 | |
10831 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10832 | nl80211_mlme_mcgrp.id, gfp); | |
10833 | return; | |
10834 | ||
10835 | nla_put_failure: | |
10836 | genlmsg_cancel(msg, hdr); | |
10837 | nlmsg_free(msg); | |
10838 | } | |
10839 | ||
947add36 JB |
10840 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10841 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10842 | { |
947add36 JB |
10843 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10844 | struct wiphy *wiphy = wdev->wiphy; | |
10845 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10846 | struct sk_buff *msg; |
10847 | struct nlattr *pinfoattr; | |
10848 | void *hdr; | |
10849 | ||
947add36 JB |
10850 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10851 | ||
58050fce | 10852 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10853 | if (!msg) |
10854 | return; | |
10855 | ||
10856 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10857 | if (!hdr) { | |
10858 | nlmsg_free(msg); | |
10859 | return; | |
10860 | } | |
10861 | ||
9360ffd1 | 10862 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10863 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10864 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10865 | goto nla_put_failure; | |
c063dbf5 JB |
10866 | |
10867 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10868 | if (!pinfoattr) | |
10869 | goto nla_put_failure; | |
10870 | ||
9360ffd1 DM |
10871 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10872 | goto nla_put_failure; | |
c063dbf5 JB |
10873 | |
10874 | nla_nest_end(msg, pinfoattr); | |
10875 | ||
3b7b72ee | 10876 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10877 | |
10878 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10879 | nl80211_mlme_mcgrp.id, gfp); | |
10880 | return; | |
10881 | ||
10882 | nla_put_failure: | |
10883 | genlmsg_cancel(msg, hdr); | |
10884 | nlmsg_free(msg); | |
10885 | } | |
947add36 | 10886 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10887 | |
7f6cf311 JB |
10888 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10889 | u64 cookie, bool acked, gfp_t gfp) | |
10890 | { | |
10891 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10892 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10893 | struct sk_buff *msg; | |
10894 | void *hdr; | |
7f6cf311 | 10895 | |
4ee3e063 BL |
10896 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10897 | ||
58050fce | 10898 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10899 | |
7f6cf311 JB |
10900 | if (!msg) |
10901 | return; | |
10902 | ||
10903 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10904 | if (!hdr) { | |
10905 | nlmsg_free(msg); | |
10906 | return; | |
10907 | } | |
10908 | ||
9360ffd1 DM |
10909 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10910 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10911 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10912 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10913 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10914 | goto nla_put_failure; | |
7f6cf311 | 10915 | |
9c90a9f6 | 10916 | genlmsg_end(msg, hdr); |
7f6cf311 JB |
10917 | |
10918 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10919 | nl80211_mlme_mcgrp.id, gfp); | |
10920 | return; | |
10921 | ||
10922 | nla_put_failure: | |
10923 | genlmsg_cancel(msg, hdr); | |
10924 | nlmsg_free(msg); | |
10925 | } | |
10926 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10927 | ||
5e760230 JB |
10928 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10929 | const u8 *frame, size_t len, | |
37c73b5f | 10930 | int freq, int sig_dbm) |
5e760230 JB |
10931 | { |
10932 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10933 | struct sk_buff *msg; | |
10934 | void *hdr; | |
37c73b5f | 10935 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10936 | |
4ee3e063 BL |
10937 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10938 | ||
37c73b5f BG |
10939 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10940 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10941 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10942 | if (!msg) { | |
10943 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10944 | return; | |
10945 | } | |
5e760230 | 10946 | |
37c73b5f BG |
10947 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10948 | if (!hdr) | |
10949 | goto nla_put_failure; | |
5e760230 | 10950 | |
37c73b5f BG |
10951 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10952 | (freq && | |
10953 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10954 | (sig_dbm && | |
10955 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10956 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10957 | goto nla_put_failure; | |
5e760230 | 10958 | |
37c73b5f | 10959 | genlmsg_end(msg, hdr); |
5e760230 | 10960 | |
37c73b5f BG |
10961 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10962 | } | |
10963 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10964 | return; |
10965 | ||
10966 | nla_put_failure: | |
37c73b5f BG |
10967 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10968 | if (hdr) | |
10969 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10970 | nlmsg_free(msg); |
10971 | } | |
10972 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10973 | ||
cd8f7cb4 JB |
10974 | #ifdef CONFIG_PM |
10975 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10976 | struct cfg80211_wowlan_wakeup *wakeup, | |
10977 | gfp_t gfp) | |
10978 | { | |
10979 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10980 | struct sk_buff *msg; | |
10981 | void *hdr; | |
9c90a9f6 | 10982 | int size = 200; |
cd8f7cb4 JB |
10983 | |
10984 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10985 | ||
10986 | if (wakeup) | |
10987 | size += wakeup->packet_present_len; | |
10988 | ||
10989 | msg = nlmsg_new(size, gfp); | |
10990 | if (!msg) | |
10991 | return; | |
10992 | ||
10993 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10994 | if (!hdr) | |
10995 | goto free_msg; | |
10996 | ||
10997 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10998 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10999 | goto free_msg; | |
11000 | ||
11001 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11002 | wdev->netdev->ifindex)) | |
11003 | goto free_msg; | |
11004 | ||
11005 | if (wakeup) { | |
11006 | struct nlattr *reasons; | |
11007 | ||
11008 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
11009 | ||
11010 | if (wakeup->disconnect && | |
11011 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11012 | goto free_msg; | |
11013 | if (wakeup->magic_pkt && | |
11014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11015 | goto free_msg; | |
11016 | if (wakeup->gtk_rekey_failure && | |
11017 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11018 | goto free_msg; | |
11019 | if (wakeup->eap_identity_req && | |
11020 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11021 | goto free_msg; | |
11022 | if (wakeup->four_way_handshake && | |
11023 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11024 | goto free_msg; | |
11025 | if (wakeup->rfkill_release && | |
11026 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11027 | goto free_msg; | |
11028 | ||
11029 | if (wakeup->pattern_idx >= 0 && | |
11030 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11031 | wakeup->pattern_idx)) | |
11032 | goto free_msg; | |
11033 | ||
2a0e047e JB |
11034 | if (wakeup->tcp_match) |
11035 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
11036 | ||
11037 | if (wakeup->tcp_connlost) | |
11038 | nla_put_flag(msg, | |
11039 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
11040 | ||
11041 | if (wakeup->tcp_nomoretokens) | |
11042 | nla_put_flag(msg, | |
11043 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
11044 | ||
cd8f7cb4 JB |
11045 | if (wakeup->packet) { |
11046 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11047 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11048 | ||
11049 | if (!wakeup->packet_80211) { | |
11050 | pkt_attr = | |
11051 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11052 | len_attr = | |
11053 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11054 | } | |
11055 | ||
11056 | if (wakeup->packet_len && | |
11057 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11058 | goto free_msg; | |
11059 | ||
11060 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11061 | wakeup->packet)) | |
11062 | goto free_msg; | |
11063 | } | |
11064 | ||
11065 | nla_nest_end(msg, reasons); | |
11066 | } | |
11067 | ||
9c90a9f6 | 11068 | genlmsg_end(msg, hdr); |
cd8f7cb4 JB |
11069 | |
11070 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11071 | nl80211_mlme_mcgrp.id, gfp); | |
11072 | return; | |
11073 | ||
11074 | free_msg: | |
11075 | nlmsg_free(msg); | |
11076 | } | |
11077 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11078 | #endif | |
11079 | ||
3475b094 JM |
11080 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11081 | enum nl80211_tdls_operation oper, | |
11082 | u16 reason_code, gfp_t gfp) | |
11083 | { | |
11084 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11085 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11086 | struct sk_buff *msg; | |
11087 | void *hdr; | |
3475b094 JM |
11088 | |
11089 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11090 | reason_code); | |
11091 | ||
11092 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11093 | if (!msg) | |
11094 | return; | |
11095 | ||
11096 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11097 | if (!hdr) { | |
11098 | nlmsg_free(msg); | |
11099 | return; | |
11100 | } | |
11101 | ||
11102 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11103 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11104 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11105 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11106 | (reason_code > 0 && | |
11107 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11108 | goto nla_put_failure; | |
11109 | ||
9c90a9f6 | 11110 | genlmsg_end(msg, hdr); |
3475b094 JM |
11111 | |
11112 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11113 | nl80211_mlme_mcgrp.id, gfp); | |
11114 | return; | |
11115 | ||
11116 | nla_put_failure: | |
11117 | genlmsg_cancel(msg, hdr); | |
11118 | nlmsg_free(msg); | |
11119 | } | |
11120 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11121 | ||
026331c4 JM |
11122 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11123 | unsigned long state, | |
11124 | void *_notify) | |
11125 | { | |
11126 | struct netlink_notify *notify = _notify; | |
11127 | struct cfg80211_registered_device *rdev; | |
11128 | struct wireless_dev *wdev; | |
37c73b5f | 11129 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11130 | |
11131 | if (state != NETLINK_URELEASE) | |
11132 | return NOTIFY_DONE; | |
11133 | ||
11134 | rcu_read_lock(); | |
11135 | ||
5e760230 | 11136 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 11137 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 11138 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
11139 | |
11140 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11141 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11142 | list) { | |
11143 | if (reg->nlportid == notify->portid) { | |
11144 | list_del(®->list); | |
11145 | kfree(reg); | |
11146 | break; | |
11147 | } | |
11148 | } | |
11149 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 11150 | } |
026331c4 JM |
11151 | |
11152 | rcu_read_unlock(); | |
11153 | ||
11154 | return NOTIFY_DONE; | |
11155 | } | |
11156 | ||
11157 | static struct notifier_block nl80211_netlink_notifier = { | |
11158 | .notifier_call = nl80211_netlink_notify, | |
11159 | }; | |
11160 | ||
355199e0 JM |
11161 | void cfg80211_ft_event(struct net_device *netdev, |
11162 | struct cfg80211_ft_event_params *ft_event) | |
11163 | { | |
11164 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
11165 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11166 | struct sk_buff *msg; | |
11167 | void *hdr; | |
355199e0 JM |
11168 | |
11169 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11170 | ||
11171 | if (!ft_event->target_ap) | |
11172 | return; | |
11173 | ||
11174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11175 | if (!msg) | |
11176 | return; | |
11177 | ||
11178 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
11179 | if (!hdr) { | |
11180 | nlmsg_free(msg); | |
11181 | return; | |
11182 | } | |
11183 | ||
11184 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
11185 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
11186 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
11187 | if (ft_event->ies) | |
11188 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
11189 | if (ft_event->ric_ies) | |
11190 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11191 | ft_event->ric_ies); | |
11192 | ||
9c90a9f6 | 11193 | genlmsg_end(msg, hdr); |
355199e0 JM |
11194 | |
11195 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
11196 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
11197 | } | |
11198 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11199 | ||
5de17984 AS |
11200 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11201 | { | |
11202 | struct cfg80211_registered_device *rdev; | |
11203 | struct sk_buff *msg; | |
11204 | void *hdr; | |
11205 | u32 nlportid; | |
11206 | ||
11207 | rdev = wiphy_to_dev(wdev->wiphy); | |
11208 | if (!rdev->crit_proto_nlportid) | |
11209 | return; | |
11210 | ||
11211 | nlportid = rdev->crit_proto_nlportid; | |
11212 | rdev->crit_proto_nlportid = 0; | |
11213 | ||
11214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11215 | if (!msg) | |
11216 | return; | |
11217 | ||
11218 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11219 | if (!hdr) | |
11220 | goto nla_put_failure; | |
11221 | ||
11222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11223 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11224 | goto nla_put_failure; | |
11225 | ||
11226 | genlmsg_end(msg, hdr); | |
11227 | ||
11228 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11229 | return; | |
11230 | ||
11231 | nla_put_failure: | |
11232 | if (hdr) | |
11233 | genlmsg_cancel(msg, hdr); | |
11234 | nlmsg_free(msg); | |
11235 | ||
11236 | } | |
11237 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11238 | ||
55682965 JB |
11239 | /* initialisation/exit functions */ |
11240 | ||
11241 | int nl80211_init(void) | |
11242 | { | |
0d63cbb5 | 11243 | int err; |
55682965 | 11244 | |
0d63cbb5 MM |
11245 | err = genl_register_family_with_ops(&nl80211_fam, |
11246 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
11247 | if (err) |
11248 | return err; | |
11249 | ||
55682965 JB |
11250 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
11251 | if (err) | |
11252 | goto err_out; | |
11253 | ||
2a519311 JB |
11254 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
11255 | if (err) | |
11256 | goto err_out; | |
11257 | ||
73d54c9e LR |
11258 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
11259 | if (err) | |
11260 | goto err_out; | |
11261 | ||
6039f6d2 JM |
11262 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
11263 | if (err) | |
11264 | goto err_out; | |
11265 | ||
aff89a9b JB |
11266 | #ifdef CONFIG_NL80211_TESTMODE |
11267 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
11268 | if (err) | |
11269 | goto err_out; | |
11270 | #endif | |
11271 | ||
026331c4 JM |
11272 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11273 | if (err) | |
11274 | goto err_out; | |
11275 | ||
55682965 JB |
11276 | return 0; |
11277 | err_out: | |
11278 | genl_unregister_family(&nl80211_fam); | |
11279 | return err; | |
11280 | } | |
11281 | ||
11282 | void nl80211_exit(void) | |
11283 | { | |
026331c4 | 11284 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11285 | genl_unregister_family(&nl80211_fam); |
11286 | } |