]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
11 | #include <linux/list.h> |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/ieee80211.h> | |
14 | #include <linux/nl80211.h> | |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/netlink.h> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
2a0e047e | 22 | #include <net/inet_connection_sock.h> |
55682965 JB |
23 | #include "core.h" |
24 | #include "nl80211.h" | |
b2e1b302 | 25 | #include "reg.h" |
e35e4d28 | 26 | #include "rdev-ops.h" |
55682965 | 27 | |
5fb628e9 JM |
28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
29 | struct genl_info *info, | |
30 | struct cfg80211_crypto_settings *settings, | |
31 | int cipher_limit); | |
32 | ||
4c476991 JB |
33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
34 | struct genl_info *info); | |
35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
36 | struct genl_info *info); | |
37 | ||
55682965 JB |
38 | /* the netlink family */ |
39 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
42 | .hdrsize = 0, /* no private header */ | |
43 | .version = 1, /* no particular meaning now */ | |
55682965 | 44 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 45 | .netnsok = true, |
4c476991 JB |
46 | .pre_doit = nl80211_pre_doit, |
47 | .post_doit = nl80211_post_doit, | |
55682965 JB |
48 | }; |
49 | ||
89a54e48 JB |
50 | /* returns ERR_PTR values */ |
51 | static struct wireless_dev * | |
52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 53 | { |
89a54e48 JB |
54 | struct cfg80211_registered_device *rdev; |
55 | struct wireless_dev *result = NULL; | |
56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
58 | u64 wdev_id; | |
59 | int wiphy_idx = -1; | |
60 | int ifidx = -1; | |
55682965 | 61 | |
5fe231e8 | 62 | ASSERT_RTNL(); |
55682965 | 63 | |
89a54e48 JB |
64 | if (!have_ifidx && !have_wdev_id) |
65 | return ERR_PTR(-EINVAL); | |
55682965 | 66 | |
89a54e48 JB |
67 | if (have_ifidx) |
68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
69 | if (have_wdev_id) { | |
70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
71 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
72 | } |
73 | ||
89a54e48 JB |
74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
75 | struct wireless_dev *wdev; | |
76 | ||
77 | if (wiphy_net(&rdev->wiphy) != netns) | |
78 | continue; | |
79 | ||
80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
81 | continue; | |
82 | ||
89a54e48 JB |
83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
84 | if (have_ifidx && wdev->netdev && | |
85 | wdev->netdev->ifindex == ifidx) { | |
86 | result = wdev; | |
87 | break; | |
88 | } | |
89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
90 | result = wdev; | |
91 | break; | |
92 | } | |
93 | } | |
89a54e48 JB |
94 | |
95 | if (result) | |
96 | break; | |
97 | } | |
98 | ||
99 | if (result) | |
100 | return result; | |
101 | return ERR_PTR(-ENODEV); | |
55682965 JB |
102 | } |
103 | ||
a9455408 | 104 | static struct cfg80211_registered_device * |
878d9ec7 | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 106 | { |
7fee4778 JB |
107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
108 | struct net_device *netdev; | |
a9455408 | 109 | |
5fe231e8 | 110 | ASSERT_RTNL(); |
a9455408 | 111 | |
878d9ec7 | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
113 | !attrs[NL80211_ATTR_IFINDEX] && |
114 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
115 | return ERR_PTR(-EINVAL); |
116 | ||
878d9ec7 | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 120 | |
89a54e48 JB |
121 | if (attrs[NL80211_ATTR_WDEV]) { |
122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
123 | struct wireless_dev *wdev; | |
124 | bool found = false; | |
125 | ||
126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
127 | if (tmp) { | |
128 | /* make sure wdev exists */ | |
89a54e48 JB |
129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
130 | if (wdev->identifier != (u32)wdev_id) | |
131 | continue; | |
132 | found = true; | |
133 | break; | |
134 | } | |
89a54e48 JB |
135 | |
136 | if (!found) | |
137 | tmp = NULL; | |
138 | ||
139 | if (rdev && tmp != rdev) | |
140 | return ERR_PTR(-EINVAL); | |
141 | rdev = tmp; | |
142 | } | |
143 | } | |
144 | ||
878d9ec7 JB |
145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
4f7eff10 | 147 | netdev = dev_get_by_index(netns, ifindex); |
7fee4778 JB |
148 | if (netdev) { |
149 | if (netdev->ieee80211_ptr) | |
150 | tmp = wiphy_to_dev( | |
151 | netdev->ieee80211_ptr->wiphy); | |
152 | else | |
153 | tmp = NULL; | |
154 | ||
155 | dev_put(netdev); | |
156 | ||
157 | /* not wireless device -- return error */ | |
158 | if (!tmp) | |
159 | return ERR_PTR(-EINVAL); | |
160 | ||
161 | /* mismatch -- return error */ | |
162 | if (rdev && tmp != rdev) | |
163 | return ERR_PTR(-EINVAL); | |
164 | ||
165 | rdev = tmp; | |
a9455408 | 166 | } |
a9455408 | 167 | } |
a9455408 | 168 | |
4f7eff10 JB |
169 | if (!rdev) |
170 | return ERR_PTR(-ENODEV); | |
a9455408 | 171 | |
4f7eff10 JB |
172 | if (netns != wiphy_net(&rdev->wiphy)) |
173 | return ERR_PTR(-ENODEV); | |
174 | ||
175 | return rdev; | |
a9455408 JB |
176 | } |
177 | ||
178 | /* | |
179 | * This function returns a pointer to the driver | |
180 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
181 | * |
182 | * The result of this can be a PTR_ERR and hence must | |
183 | * be checked with IS_ERR() for errors. | |
184 | */ | |
185 | static struct cfg80211_registered_device * | |
4f7eff10 | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 187 | { |
5fe231e8 | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
189 | } |
190 | ||
55682965 | 191 | /* policy for the attributes */ |
b54452b0 | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 195 | .len = 20-1 }, |
31888487 | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 197 | |
72bdcf34 | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
203 | ||
b9a5f8ca JM |
204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
209 | |
210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 213 | |
e007b857 EP |
214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 216 | |
b9454e83 | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
219 | .len = WLAN_MAX_KEY_LEN }, | |
220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
225 | |
226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
229 | .len = IEEE80211_MAX_DATA_LEN }, | |
230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
231 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
236 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 243 | |
b2e1b302 LR |
244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
246 | ||
9f1ba906 JM |
247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
251 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 253 | |
24bdd9f4 | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 256 | |
6c739419 | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
258 | |
259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
261 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
264 | |
265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
266 | .len = IEEE80211_MAX_SSID_LEN }, | |
267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
272 | [NL80211_ATTR_STA_FLAGS2] = { |
273 | .len = sizeof(struct nl80211_sta_flag_update), | |
274 | }, | |
3f77316c | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
284 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
289 | .len = IEEE80211_MAX_DATA_LEN }, | |
290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
312 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
323 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
327 | .len = NL80211_HT_CAPABILITY_LEN | |
328 | }, | |
1d9d9213 | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
346 | .len = NL80211_VHT_CAPABILITY_LEN, | |
347 | }, | |
355199e0 JM |
348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
350 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
55682965 JB |
352 | }; |
353 | ||
e31b8213 | 354 | /* policy for the key attributes */ |
b54452b0 | 355 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 356 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
357 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
358 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 359 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
360 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
361 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 362 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
363 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
364 | }; | |
365 | ||
366 | /* policy for the key default flags */ | |
367 | static const struct nla_policy | |
368 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
369 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
370 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
371 | }; |
372 | ||
ff1b6e69 JB |
373 | /* policy for WoWLAN attributes */ |
374 | static const struct nla_policy | |
375 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
376 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
377 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
378 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
379 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
380 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
381 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
382 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
383 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
384 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
385 | }; | |
386 | ||
387 | static const struct nla_policy | |
388 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
389 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
390 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
391 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
392 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
393 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
394 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
395 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
396 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
397 | }, | |
398 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
399 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
400 | }, | |
401 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
402 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
403 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
404 | }; |
405 | ||
e5497d76 JB |
406 | /* policy for GTK rekey offload attributes */ |
407 | static const struct nla_policy | |
408 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
409 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
410 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
411 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
412 | }; | |
413 | ||
a1f1c21c LC |
414 | static const struct nla_policy |
415 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 416 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 417 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 418 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
419 | }; |
420 | ||
97990a06 JB |
421 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
422 | struct netlink_callback *cb, | |
423 | struct cfg80211_registered_device **rdev, | |
424 | struct wireless_dev **wdev) | |
a043897a | 425 | { |
97990a06 | 426 | int err; |
a043897a | 427 | |
97990a06 | 428 | rtnl_lock(); |
a043897a | 429 | |
97990a06 JB |
430 | if (!cb->args[0]) { |
431 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
432 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
433 | nl80211_policy); | |
434 | if (err) | |
435 | goto out_unlock; | |
67748893 | 436 | |
97990a06 JB |
437 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
438 | nl80211_fam.attrbuf); | |
439 | if (IS_ERR(*wdev)) { | |
440 | err = PTR_ERR(*wdev); | |
441 | goto out_unlock; | |
442 | } | |
443 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
444 | cb->args[0] = (*rdev)->wiphy_idx; | |
445 | cb->args[1] = (*wdev)->identifier; | |
446 | } else { | |
447 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); | |
448 | struct wireless_dev *tmp; | |
67748893 | 449 | |
97990a06 JB |
450 | if (!wiphy) { |
451 | err = -ENODEV; | |
452 | goto out_unlock; | |
453 | } | |
454 | *rdev = wiphy_to_dev(wiphy); | |
455 | *wdev = NULL; | |
67748893 | 456 | |
97990a06 JB |
457 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
458 | if (tmp->identifier == cb->args[1]) { | |
459 | *wdev = tmp; | |
460 | break; | |
461 | } | |
462 | } | |
67748893 | 463 | |
97990a06 JB |
464 | if (!*wdev) { |
465 | err = -ENODEV; | |
466 | goto out_unlock; | |
467 | } | |
67748893 JB |
468 | } |
469 | ||
67748893 | 470 | return 0; |
97990a06 | 471 | out_unlock: |
67748893 JB |
472 | rtnl_unlock(); |
473 | return err; | |
474 | } | |
475 | ||
97990a06 | 476 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 477 | { |
67748893 JB |
478 | rtnl_unlock(); |
479 | } | |
480 | ||
f4a11bb0 JB |
481 | /* IE validation */ |
482 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
483 | { | |
484 | const u8 *pos; | |
485 | int len; | |
486 | ||
487 | if (!attr) | |
488 | return true; | |
489 | ||
490 | pos = nla_data(attr); | |
491 | len = nla_len(attr); | |
492 | ||
493 | while (len) { | |
494 | u8 elemlen; | |
495 | ||
496 | if (len < 2) | |
497 | return false; | |
498 | len -= 2; | |
499 | ||
500 | elemlen = pos[1]; | |
501 | if (elemlen > len) | |
502 | return false; | |
503 | ||
504 | len -= elemlen; | |
505 | pos += 2 + elemlen; | |
506 | } | |
507 | ||
508 | return true; | |
509 | } | |
510 | ||
55682965 | 511 | /* message building helper */ |
15e47304 | 512 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
513 | int flags, u8 cmd) |
514 | { | |
515 | /* since there is no private header just add the generic one */ | |
15e47304 | 516 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
517 | } |
518 | ||
5dab3b8a | 519 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
520 | struct ieee80211_channel *chan, |
521 | bool large) | |
5dab3b8a | 522 | { |
9360ffd1 DM |
523 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
524 | chan->center_freq)) | |
525 | goto nla_put_failure; | |
5dab3b8a | 526 | |
9360ffd1 DM |
527 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
529 | goto nla_put_failure; | |
530 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
532 | goto nla_put_failure; | |
533 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
534 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
535 | goto nla_put_failure; | |
cdc89b97 JB |
536 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
537 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
538 | goto nla_put_failure; | |
539 | if (large) { | |
540 | u32 time; | |
541 | ||
542 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
543 | ||
544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
545 | chan->dfs_state)) | |
546 | goto nla_put_failure; | |
547 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
548 | time)) | |
549 | goto nla_put_failure; | |
550 | } | |
551 | } | |
5dab3b8a | 552 | |
fe1abafd JB |
553 | if (large) { |
554 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
556 | goto nla_put_failure; | |
557 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
559 | goto nla_put_failure; | |
560 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
562 | goto nla_put_failure; | |
563 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
565 | goto nla_put_failure; | |
566 | } | |
567 | ||
9360ffd1 DM |
568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
569 | DBM_TO_MBM(chan->max_power))) | |
570 | goto nla_put_failure; | |
5dab3b8a LR |
571 | |
572 | return 0; | |
573 | ||
574 | nla_put_failure: | |
575 | return -ENOBUFS; | |
576 | } | |
577 | ||
55682965 JB |
578 | /* netlink command implementations */ |
579 | ||
b9454e83 JB |
580 | struct key_parse { |
581 | struct key_params p; | |
582 | int idx; | |
e31b8213 | 583 | int type; |
b9454e83 | 584 | bool def, defmgmt; |
dbd2fd65 | 585 | bool def_uni, def_multi; |
b9454e83 JB |
586 | }; |
587 | ||
588 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
589 | { | |
590 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
591 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
592 | nl80211_key_policy); | |
593 | if (err) | |
594 | return err; | |
595 | ||
596 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
597 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
598 | ||
dbd2fd65 JB |
599 | if (k->def) { |
600 | k->def_uni = true; | |
601 | k->def_multi = true; | |
602 | } | |
603 | if (k->defmgmt) | |
604 | k->def_multi = true; | |
605 | ||
b9454e83 JB |
606 | if (tb[NL80211_KEY_IDX]) |
607 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
608 | ||
609 | if (tb[NL80211_KEY_DATA]) { | |
610 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
611 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
612 | } | |
613 | ||
614 | if (tb[NL80211_KEY_SEQ]) { | |
615 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
616 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
617 | } | |
618 | ||
619 | if (tb[NL80211_KEY_CIPHER]) | |
620 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
621 | ||
e31b8213 JB |
622 | if (tb[NL80211_KEY_TYPE]) { |
623 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
624 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
625 | return -EINVAL; | |
626 | } | |
627 | ||
dbd2fd65 JB |
628 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
629 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
630 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
631 | tb[NL80211_KEY_DEFAULT_TYPES], | |
632 | nl80211_key_default_policy); | |
dbd2fd65 JB |
633 | if (err) |
634 | return err; | |
635 | ||
636 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
637 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
638 | } | |
639 | ||
b9454e83 JB |
640 | return 0; |
641 | } | |
642 | ||
643 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
644 | { | |
645 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
646 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
647 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
648 | } | |
649 | ||
650 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
651 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
652 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
653 | } | |
654 | ||
655 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
656 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
657 | ||
658 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
659 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
660 | ||
661 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
662 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
663 | ||
dbd2fd65 JB |
664 | if (k->def) { |
665 | k->def_uni = true; | |
666 | k->def_multi = true; | |
667 | } | |
668 | if (k->defmgmt) | |
669 | k->def_multi = true; | |
670 | ||
e31b8213 JB |
671 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
672 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
673 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
674 | return -EINVAL; | |
675 | } | |
676 | ||
dbd2fd65 JB |
677 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
678 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
679 | int err = nla_parse_nested( | |
680 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
681 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
682 | nl80211_key_default_policy); | |
683 | if (err) | |
684 | return err; | |
685 | ||
686 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
687 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
688 | } | |
689 | ||
b9454e83 JB |
690 | return 0; |
691 | } | |
692 | ||
693 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
694 | { | |
695 | int err; | |
696 | ||
697 | memset(k, 0, sizeof(*k)); | |
698 | k->idx = -1; | |
e31b8213 | 699 | k->type = -1; |
b9454e83 JB |
700 | |
701 | if (info->attrs[NL80211_ATTR_KEY]) | |
702 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
703 | else | |
704 | err = nl80211_parse_key_old(info, k); | |
705 | ||
706 | if (err) | |
707 | return err; | |
708 | ||
709 | if (k->def && k->defmgmt) | |
710 | return -EINVAL; | |
711 | ||
dbd2fd65 JB |
712 | if (k->defmgmt) { |
713 | if (k->def_uni || !k->def_multi) | |
714 | return -EINVAL; | |
715 | } | |
716 | ||
b9454e83 JB |
717 | if (k->idx != -1) { |
718 | if (k->defmgmt) { | |
719 | if (k->idx < 4 || k->idx > 5) | |
720 | return -EINVAL; | |
721 | } else if (k->def) { | |
722 | if (k->idx < 0 || k->idx > 3) | |
723 | return -EINVAL; | |
724 | } else { | |
725 | if (k->idx < 0 || k->idx > 5) | |
726 | return -EINVAL; | |
727 | } | |
728 | } | |
729 | ||
730 | return 0; | |
731 | } | |
732 | ||
fffd0934 JB |
733 | static struct cfg80211_cached_keys * |
734 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 735 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
736 | { |
737 | struct key_parse parse; | |
738 | struct nlattr *key; | |
739 | struct cfg80211_cached_keys *result; | |
740 | int rem, err, def = 0; | |
741 | ||
742 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
743 | if (!result) | |
744 | return ERR_PTR(-ENOMEM); | |
745 | ||
746 | result->def = -1; | |
747 | result->defmgmt = -1; | |
748 | ||
749 | nla_for_each_nested(key, keys, rem) { | |
750 | memset(&parse, 0, sizeof(parse)); | |
751 | parse.idx = -1; | |
752 | ||
753 | err = nl80211_parse_key_new(key, &parse); | |
754 | if (err) | |
755 | goto error; | |
756 | err = -EINVAL; | |
757 | if (!parse.p.key) | |
758 | goto error; | |
759 | if (parse.idx < 0 || parse.idx > 4) | |
760 | goto error; | |
761 | if (parse.def) { | |
762 | if (def) | |
763 | goto error; | |
764 | def = 1; | |
765 | result->def = parse.idx; | |
dbd2fd65 JB |
766 | if (!parse.def_uni || !parse.def_multi) |
767 | goto error; | |
fffd0934 JB |
768 | } else if (parse.defmgmt) |
769 | goto error; | |
770 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 771 | parse.idx, false, NULL); |
fffd0934 JB |
772 | if (err) |
773 | goto error; | |
774 | result->params[parse.idx].cipher = parse.p.cipher; | |
775 | result->params[parse.idx].key_len = parse.p.key_len; | |
776 | result->params[parse.idx].key = result->data[parse.idx]; | |
777 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
778 | |
779 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
780 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
781 | if (no_ht) | |
782 | *no_ht = true; | |
783 | } | |
fffd0934 JB |
784 | } |
785 | ||
786 | return result; | |
787 | error: | |
788 | kfree(result); | |
789 | return ERR_PTR(err); | |
790 | } | |
791 | ||
792 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
793 | { | |
794 | ASSERT_WDEV_LOCK(wdev); | |
795 | ||
fffd0934 JB |
796 | switch (wdev->iftype) { |
797 | case NL80211_IFTYPE_AP: | |
798 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 799 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 800 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
801 | break; |
802 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 803 | case NL80211_IFTYPE_STATION: |
074ac8df | 804 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 805 | if (!wdev->current_bss) |
fffd0934 JB |
806 | return -ENOLINK; |
807 | break; | |
808 | default: | |
809 | return -EINVAL; | |
810 | } | |
811 | ||
812 | return 0; | |
813 | } | |
814 | ||
7527a782 JB |
815 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
816 | { | |
817 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
818 | int i; | |
819 | ||
820 | if (!nl_modes) | |
821 | goto nla_put_failure; | |
822 | ||
823 | i = 0; | |
824 | while (ifmodes) { | |
9360ffd1 DM |
825 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
826 | goto nla_put_failure; | |
7527a782 JB |
827 | ifmodes >>= 1; |
828 | i++; | |
829 | } | |
830 | ||
831 | nla_nest_end(msg, nl_modes); | |
832 | return 0; | |
833 | ||
834 | nla_put_failure: | |
835 | return -ENOBUFS; | |
836 | } | |
837 | ||
838 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
839 | struct sk_buff *msg, |
840 | bool large) | |
7527a782 JB |
841 | { |
842 | struct nlattr *nl_combis; | |
843 | int i, j; | |
844 | ||
845 | nl_combis = nla_nest_start(msg, | |
846 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
847 | if (!nl_combis) | |
848 | goto nla_put_failure; | |
849 | ||
850 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
851 | const struct ieee80211_iface_combination *c; | |
852 | struct nlattr *nl_combi, *nl_limits; | |
853 | ||
854 | c = &wiphy->iface_combinations[i]; | |
855 | ||
856 | nl_combi = nla_nest_start(msg, i + 1); | |
857 | if (!nl_combi) | |
858 | goto nla_put_failure; | |
859 | ||
860 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
861 | if (!nl_limits) | |
862 | goto nla_put_failure; | |
863 | ||
864 | for (j = 0; j < c->n_limits; j++) { | |
865 | struct nlattr *nl_limit; | |
866 | ||
867 | nl_limit = nla_nest_start(msg, j + 1); | |
868 | if (!nl_limit) | |
869 | goto nla_put_failure; | |
9360ffd1 DM |
870 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
871 | c->limits[j].max)) | |
872 | goto nla_put_failure; | |
7527a782 JB |
873 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
874 | c->limits[j].types)) | |
875 | goto nla_put_failure; | |
876 | nla_nest_end(msg, nl_limit); | |
877 | } | |
878 | ||
879 | nla_nest_end(msg, nl_limits); | |
880 | ||
9360ffd1 DM |
881 | if (c->beacon_int_infra_match && |
882 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
883 | goto nla_put_failure; | |
884 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
885 | c->num_different_channels) || | |
886 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
887 | c->max_interfaces)) | |
888 | goto nla_put_failure; | |
cdc89b97 JB |
889 | if (large && |
890 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
891 | c->radar_detect_widths)) | |
892 | goto nla_put_failure; | |
7527a782 JB |
893 | |
894 | nla_nest_end(msg, nl_combi); | |
895 | } | |
896 | ||
897 | nla_nest_end(msg, nl_combis); | |
898 | ||
899 | return 0; | |
900 | nla_put_failure: | |
901 | return -ENOBUFS; | |
902 | } | |
903 | ||
3713b4e3 | 904 | #ifdef CONFIG_PM |
b56cf720 JB |
905 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
906 | struct sk_buff *msg) | |
907 | { | |
964dc9e2 | 908 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
909 | struct nlattr *nl_tcp; |
910 | ||
911 | if (!tcp) | |
912 | return 0; | |
913 | ||
914 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
915 | if (!nl_tcp) | |
916 | return -ENOBUFS; | |
917 | ||
918 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
919 | tcp->data_payload_max)) | |
920 | return -ENOBUFS; | |
921 | ||
922 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
923 | tcp->data_payload_max)) | |
924 | return -ENOBUFS; | |
925 | ||
926 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
927 | return -ENOBUFS; | |
928 | ||
929 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
930 | sizeof(*tcp->tok), tcp->tok)) | |
931 | return -ENOBUFS; | |
932 | ||
933 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
934 | tcp->data_interval_max)) | |
935 | return -ENOBUFS; | |
936 | ||
937 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
938 | tcp->wake_payload_max)) | |
939 | return -ENOBUFS; | |
940 | ||
941 | nla_nest_end(msg, nl_tcp); | |
942 | return 0; | |
943 | } | |
944 | ||
3713b4e3 | 945 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
946 | struct cfg80211_registered_device *dev, |
947 | bool large) | |
55682965 | 948 | { |
3713b4e3 | 949 | struct nlattr *nl_wowlan; |
55682965 | 950 | |
964dc9e2 | 951 | if (!dev->wiphy.wowlan) |
3713b4e3 | 952 | return 0; |
55682965 | 953 | |
3713b4e3 JB |
954 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
955 | if (!nl_wowlan) | |
956 | return -ENOBUFS; | |
9360ffd1 | 957 | |
964dc9e2 | 958 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
964dc9e2 | 960 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
964dc9e2 | 962 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 963 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
964dc9e2 | 964 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 965 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
964dc9e2 | 966 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
964dc9e2 | 968 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
964dc9e2 | 970 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
964dc9e2 | 972 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
973 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
974 | return -ENOBUFS; | |
9360ffd1 | 975 | |
964dc9e2 | 976 | if (dev->wiphy.wowlan->n_patterns) { |
3713b4e3 | 977 | struct nl80211_wowlan_pattern_support pat = { |
964dc9e2 JB |
978 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
979 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, | |
980 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, | |
981 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 982 | }; |
9360ffd1 | 983 | |
3713b4e3 JB |
984 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
985 | sizeof(pat), &pat)) | |
986 | return -ENOBUFS; | |
987 | } | |
9360ffd1 | 988 | |
b56cf720 JB |
989 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
990 | return -ENOBUFS; | |
991 | ||
3713b4e3 | 992 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 993 | |
3713b4e3 JB |
994 | return 0; |
995 | } | |
996 | #endif | |
9360ffd1 | 997 | |
3713b4e3 JB |
998 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
999 | struct ieee80211_supported_band *sband) | |
1000 | { | |
1001 | struct nlattr *nl_rates, *nl_rate; | |
1002 | struct ieee80211_rate *rate; | |
1003 | int i; | |
87bbbe22 | 1004 | |
3713b4e3 JB |
1005 | /* add HT info */ |
1006 | if (sband->ht_cap.ht_supported && | |
1007 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1008 | sizeof(sband->ht_cap.mcs), | |
1009 | &sband->ht_cap.mcs) || | |
1010 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1011 | sband->ht_cap.cap) || | |
1012 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1013 | sband->ht_cap.ampdu_factor) || | |
1014 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1015 | sband->ht_cap.ampdu_density))) | |
1016 | return -ENOBUFS; | |
afe0cbf8 | 1017 | |
3713b4e3 JB |
1018 | /* add VHT info */ |
1019 | if (sband->vht_cap.vht_supported && | |
1020 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1021 | sizeof(sband->vht_cap.vht_mcs), | |
1022 | &sband->vht_cap.vht_mcs) || | |
1023 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1024 | sband->vht_cap.cap))) | |
1025 | return -ENOBUFS; | |
f59ac048 | 1026 | |
3713b4e3 JB |
1027 | /* add bitrates */ |
1028 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1029 | if (!nl_rates) | |
1030 | return -ENOBUFS; | |
ee688b00 | 1031 | |
3713b4e3 JB |
1032 | for (i = 0; i < sband->n_bitrates; i++) { |
1033 | nl_rate = nla_nest_start(msg, i); | |
1034 | if (!nl_rate) | |
1035 | return -ENOBUFS; | |
ee688b00 | 1036 | |
3713b4e3 JB |
1037 | rate = &sband->bitrates[i]; |
1038 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1039 | rate->bitrate)) | |
1040 | return -ENOBUFS; | |
1041 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1042 | nla_put_flag(msg, | |
1043 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1044 | return -ENOBUFS; | |
ee688b00 | 1045 | |
3713b4e3 JB |
1046 | nla_nest_end(msg, nl_rate); |
1047 | } | |
d51626df | 1048 | |
3713b4e3 | 1049 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1050 | |
3713b4e3 JB |
1051 | return 0; |
1052 | } | |
ee688b00 | 1053 | |
3713b4e3 JB |
1054 | static int |
1055 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1056 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1057 | { | |
1058 | u16 stypes; | |
1059 | struct nlattr *nl_ftypes, *nl_ifs; | |
1060 | enum nl80211_iftype ift; | |
1061 | int i; | |
ee688b00 | 1062 | |
3713b4e3 JB |
1063 | if (!mgmt_stypes) |
1064 | return 0; | |
5dab3b8a | 1065 | |
3713b4e3 JB |
1066 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1067 | if (!nl_ifs) | |
1068 | return -ENOBUFS; | |
e2f367f2 | 1069 | |
3713b4e3 JB |
1070 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1071 | nl_ftypes = nla_nest_start(msg, ift); | |
1072 | if (!nl_ftypes) | |
1073 | return -ENOBUFS; | |
1074 | i = 0; | |
1075 | stypes = mgmt_stypes[ift].tx; | |
1076 | while (stypes) { | |
1077 | if ((stypes & 1) && | |
1078 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1079 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1080 | return -ENOBUFS; | |
1081 | stypes >>= 1; | |
1082 | i++; | |
ee688b00 | 1083 | } |
3713b4e3 JB |
1084 | nla_nest_end(msg, nl_ftypes); |
1085 | } | |
ee688b00 | 1086 | |
3713b4e3 | 1087 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1088 | |
3713b4e3 JB |
1089 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1090 | if (!nl_ifs) | |
1091 | return -ENOBUFS; | |
ee688b00 | 1092 | |
3713b4e3 JB |
1093 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1094 | nl_ftypes = nla_nest_start(msg, ift); | |
1095 | if (!nl_ftypes) | |
1096 | return -ENOBUFS; | |
1097 | i = 0; | |
1098 | stypes = mgmt_stypes[ift].rx; | |
1099 | while (stypes) { | |
1100 | if ((stypes & 1) && | |
1101 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1102 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1103 | return -ENOBUFS; | |
1104 | stypes >>= 1; | |
1105 | i++; | |
1106 | } | |
1107 | nla_nest_end(msg, nl_ftypes); | |
1108 | } | |
1109 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1110 | |
3713b4e3 JB |
1111 | return 0; |
1112 | } | |
ee688b00 | 1113 | |
3713b4e3 JB |
1114 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1115 | struct sk_buff *msg, u32 portid, u32 seq, | |
1116 | int flags, bool split, long *split_start, | |
1117 | long *band_start, long *chan_start) | |
1118 | { | |
1119 | void *hdr; | |
1120 | struct nlattr *nl_bands, *nl_band; | |
1121 | struct nlattr *nl_freqs, *nl_freq; | |
1122 | struct nlattr *nl_cmds; | |
1123 | enum ieee80211_band band; | |
1124 | struct ieee80211_channel *chan; | |
1125 | int i; | |
1126 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1127 | dev->wiphy.mgmt_stypes; | |
1128 | long start = 0, start_chan = 0, start_band = 0; | |
fe1abafd | 1129 | u32 features; |
ee688b00 | 1130 | |
3713b4e3 JB |
1131 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1132 | if (!hdr) | |
1133 | return -ENOBUFS; | |
ee688b00 | 1134 | |
3713b4e3 JB |
1135 | /* allow always using the variables */ |
1136 | if (!split) { | |
1137 | split_start = &start; | |
1138 | band_start = &start_band; | |
1139 | chan_start = &start_chan; | |
ee688b00 | 1140 | } |
ee688b00 | 1141 | |
3713b4e3 JB |
1142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1143 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1144 | wiphy_name(&dev->wiphy)) || | |
1145 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1146 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1147 | goto nla_put_failure; |
1148 | ||
3713b4e3 JB |
1149 | switch (*split_start) { |
1150 | case 0: | |
1151 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1152 | dev->wiphy.retry_short) || | |
1153 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1154 | dev->wiphy.retry_long) || | |
1155 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1156 | dev->wiphy.frag_threshold) || | |
1157 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1158 | dev->wiphy.rts_threshold) || | |
1159 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1160 | dev->wiphy.coverage_class) || | |
1161 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1162 | dev->wiphy.max_scan_ssids) || | |
1163 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1164 | dev->wiphy.max_sched_scan_ssids) || | |
1165 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1166 | dev->wiphy.max_scan_ie_len) || | |
1167 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1168 | dev->wiphy.max_sched_scan_ie_len) || | |
1169 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1170 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1171 | goto nla_put_failure; |
3713b4e3 JB |
1172 | |
1173 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1174 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1175 | goto nla_put_failure; |
3713b4e3 JB |
1176 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1177 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1178 | goto nla_put_failure; | |
1179 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1180 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1181 | goto nla_put_failure; | |
1182 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1183 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1184 | goto nla_put_failure; | |
1185 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1186 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1187 | goto nla_put_failure; | |
1188 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1189 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1190 | goto nla_put_failure; |
2f301ab2 SW |
1191 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
1192 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1193 | goto nla_put_failure; | |
8fdc621d | 1194 | |
3713b4e3 JB |
1195 | (*split_start)++; |
1196 | if (split) | |
1197 | break; | |
1198 | case 1: | |
1199 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1200 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1201 | dev->wiphy.cipher_suites)) | |
1202 | goto nla_put_failure; | |
4745fc09 | 1203 | |
3713b4e3 JB |
1204 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1205 | dev->wiphy.max_num_pmkids)) | |
1206 | goto nla_put_failure; | |
b23aa676 | 1207 | |
3713b4e3 JB |
1208 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1209 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1210 | goto nla_put_failure; |
b23aa676 | 1211 | |
3713b4e3 JB |
1212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1213 | dev->wiphy.available_antennas_tx) || | |
1214 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1215 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1216 | goto nla_put_failure; |
b23aa676 | 1217 | |
3713b4e3 JB |
1218 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1219 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1220 | dev->wiphy.probe_resp_offload)) | |
1221 | goto nla_put_failure; | |
8fdc621d | 1222 | |
3713b4e3 JB |
1223 | if ((dev->wiphy.available_antennas_tx || |
1224 | dev->wiphy.available_antennas_rx) && | |
1225 | dev->ops->get_antenna) { | |
1226 | u32 tx_ant = 0, rx_ant = 0; | |
1227 | int res; | |
1228 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1229 | if (!res) { | |
1230 | if (nla_put_u32(msg, | |
1231 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1232 | tx_ant) || | |
1233 | nla_put_u32(msg, | |
1234 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1235 | rx_ant)) | |
1236 | goto nla_put_failure; | |
1237 | } | |
1238 | } | |
a293911d | 1239 | |
3713b4e3 JB |
1240 | (*split_start)++; |
1241 | if (split) | |
1242 | break; | |
1243 | case 2: | |
1244 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1245 | dev->wiphy.interface_modes)) | |
1246 | goto nla_put_failure; | |
1247 | (*split_start)++; | |
1248 | if (split) | |
1249 | break; | |
1250 | case 3: | |
1251 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1252 | if (!nl_bands) | |
1253 | goto nla_put_failure; | |
f7ca38df | 1254 | |
3713b4e3 JB |
1255 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
1256 | struct ieee80211_supported_band *sband; | |
2e161f78 | 1257 | |
3713b4e3 | 1258 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1259 | |
3713b4e3 JB |
1260 | if (!sband) |
1261 | continue; | |
1262 | ||
1263 | nl_band = nla_nest_start(msg, band); | |
1264 | if (!nl_band) | |
2e161f78 | 1265 | goto nla_put_failure; |
3713b4e3 JB |
1266 | |
1267 | switch (*chan_start) { | |
1268 | case 0: | |
1269 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1270 | goto nla_put_failure; |
3713b4e3 JB |
1271 | (*chan_start)++; |
1272 | if (split) | |
1273 | break; | |
1274 | default: | |
1275 | /* add frequencies */ | |
1276 | nl_freqs = nla_nest_start( | |
1277 | msg, NL80211_BAND_ATTR_FREQS); | |
1278 | if (!nl_freqs) | |
1279 | goto nla_put_failure; | |
1280 | ||
1281 | for (i = *chan_start - 1; | |
1282 | i < sband->n_channels; | |
1283 | i++) { | |
1284 | nl_freq = nla_nest_start(msg, i); | |
1285 | if (!nl_freq) | |
1286 | goto nla_put_failure; | |
1287 | ||
1288 | chan = &sband->channels[i]; | |
1289 | ||
cdc89b97 JB |
1290 | if (nl80211_msg_put_channel(msg, chan, |
1291 | split)) | |
3713b4e3 JB |
1292 | goto nla_put_failure; |
1293 | ||
1294 | nla_nest_end(msg, nl_freq); | |
1295 | if (split) | |
1296 | break; | |
1297 | } | |
1298 | if (i < sband->n_channels) | |
1299 | *chan_start = i + 2; | |
1300 | else | |
1301 | *chan_start = 0; | |
1302 | nla_nest_end(msg, nl_freqs); | |
1303 | } | |
1304 | ||
1305 | nla_nest_end(msg, nl_band); | |
1306 | ||
1307 | if (split) { | |
1308 | /* start again here */ | |
1309 | if (*chan_start) | |
1310 | band--; | |
1311 | break; | |
2e161f78 | 1312 | } |
2e161f78 | 1313 | } |
3713b4e3 | 1314 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1315 | |
3713b4e3 JB |
1316 | if (band < IEEE80211_NUM_BANDS) |
1317 | *band_start = band + 1; | |
1318 | else | |
1319 | *band_start = 0; | |
74b70a4e | 1320 | |
3713b4e3 JB |
1321 | /* if bands & channels are done, continue outside */ |
1322 | if (*band_start == 0 && *chan_start == 0) | |
1323 | (*split_start)++; | |
1324 | if (split) | |
1325 | break; | |
1326 | case 4: | |
1327 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1328 | if (!nl_cmds) | |
2e161f78 JB |
1329 | goto nla_put_failure; |
1330 | ||
3713b4e3 JB |
1331 | i = 0; |
1332 | #define CMD(op, n) \ | |
1333 | do { \ | |
1334 | if (dev->ops->op) { \ | |
1335 | i++; \ | |
1336 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1337 | goto nla_put_failure; \ | |
1338 | } \ | |
1339 | } while (0) | |
1340 | ||
1341 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1342 | CMD(change_virtual_intf, SET_INTERFACE); | |
1343 | CMD(add_key, NEW_KEY); | |
1344 | CMD(start_ap, START_AP); | |
1345 | CMD(add_station, NEW_STATION); | |
1346 | CMD(add_mpath, NEW_MPATH); | |
1347 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1348 | CMD(change_bss, SET_BSS); | |
1349 | CMD(auth, AUTHENTICATE); | |
1350 | CMD(assoc, ASSOCIATE); | |
1351 | CMD(deauth, DEAUTHENTICATE); | |
1352 | CMD(disassoc, DISASSOCIATE); | |
1353 | CMD(join_ibss, JOIN_IBSS); | |
1354 | CMD(join_mesh, JOIN_MESH); | |
1355 | CMD(set_pmksa, SET_PMKSA); | |
1356 | CMD(del_pmksa, DEL_PMKSA); | |
1357 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1358 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1359 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1360 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1361 | CMD(mgmt_tx, FRAME); | |
1362 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1363 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1364 | i++; | |
1365 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1366 | goto nla_put_failure; |
2e161f78 | 1367 | } |
3713b4e3 JB |
1368 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1369 | dev->ops->join_mesh) { | |
1370 | i++; | |
1371 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1372 | goto nla_put_failure; | |
1373 | } | |
1374 | CMD(set_wds_peer, SET_WDS_PEER); | |
1375 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1376 | CMD(tdls_mgmt, TDLS_MGMT); | |
1377 | CMD(tdls_oper, TDLS_OPER); | |
1378 | } | |
1379 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1380 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1381 | CMD(probe_client, PROBE_CLIENT); | |
1382 | CMD(set_noack_map, SET_NOACK_MAP); | |
1383 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1384 | i++; | |
1385 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1386 | goto nla_put_failure; | |
1387 | } | |
1388 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1389 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
5de17984 AS |
1390 | if (split) { |
1391 | CMD(crit_proto_start, CRIT_PROTOCOL_START); | |
1392 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1393 | } | |
2e161f78 | 1394 | |
3713b4e3 JB |
1395 | #ifdef CONFIG_NL80211_TESTMODE |
1396 | CMD(testmode_cmd, TESTMODE); | |
1397 | #endif | |
ff1b6e69 | 1398 | |
3713b4e3 | 1399 | #undef CMD |
ff1b6e69 | 1400 | |
3713b4e3 JB |
1401 | if (dev->ops->connect || dev->ops->auth) { |
1402 | i++; | |
1403 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1404 | goto nla_put_failure; |
ff1b6e69 JB |
1405 | } |
1406 | ||
3713b4e3 JB |
1407 | if (dev->ops->disconnect || dev->ops->deauth) { |
1408 | i++; | |
1409 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1410 | goto nla_put_failure; | |
1411 | } | |
1412 | ||
1413 | nla_nest_end(msg, nl_cmds); | |
1414 | (*split_start)++; | |
1415 | if (split) | |
1416 | break; | |
1417 | case 5: | |
1418 | if (dev->ops->remain_on_channel && | |
1419 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1420 | nla_put_u32(msg, | |
1421 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1422 | dev->wiphy.max_remain_on_channel_duration)) | |
1423 | goto nla_put_failure; | |
1424 | ||
1425 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1426 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1427 | goto nla_put_failure; | |
1428 | ||
1429 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1430 | goto nla_put_failure; | |
1431 | (*split_start)++; | |
1432 | if (split) | |
1433 | break; | |
1434 | case 6: | |
1435 | #ifdef CONFIG_PM | |
b56cf720 | 1436 | if (nl80211_send_wowlan(msg, dev, split)) |
3713b4e3 JB |
1437 | goto nla_put_failure; |
1438 | (*split_start)++; | |
1439 | if (split) | |
1440 | break; | |
1441 | #else | |
1442 | (*split_start)++; | |
dfb89c56 | 1443 | #endif |
3713b4e3 JB |
1444 | case 7: |
1445 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1446 | dev->wiphy.software_iftypes)) | |
1447 | goto nla_put_failure; | |
ff1b6e69 | 1448 | |
cdc89b97 | 1449 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
3713b4e3 | 1450 | goto nla_put_failure; |
7527a782 | 1451 | |
3713b4e3 JB |
1452 | (*split_start)++; |
1453 | if (split) | |
1454 | break; | |
1455 | case 8: | |
1456 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1457 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1458 | dev->wiphy.ap_sme_capa)) | |
1459 | goto nla_put_failure; | |
7527a782 | 1460 | |
fe1abafd JB |
1461 | features = dev->wiphy.features; |
1462 | /* | |
1463 | * We can only add the per-channel limit information if the | |
1464 | * dump is split, otherwise it makes it too big. Therefore | |
1465 | * only advertise it in that case. | |
1466 | */ | |
1467 | if (split) | |
1468 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | |
1469 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1470 | goto nla_put_failure; |
562a7480 | 1471 | |
3713b4e3 JB |
1472 | if (dev->wiphy.ht_capa_mod_mask && |
1473 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1474 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1475 | dev->wiphy.ht_capa_mod_mask)) | |
1476 | goto nla_put_failure; | |
1f074bd8 | 1477 | |
3713b4e3 JB |
1478 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1479 | dev->wiphy.max_acl_mac_addrs && | |
1480 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1481 | dev->wiphy.max_acl_mac_addrs)) | |
1482 | goto nla_put_failure; | |
7e7c8926 | 1483 | |
3713b4e3 JB |
1484 | /* |
1485 | * Any information below this point is only available to | |
1486 | * applications that can deal with it being split. This | |
1487 | * helps ensure that newly added capabilities don't break | |
1488 | * older tools by overrunning their buffers. | |
1489 | * | |
1490 | * We still increment split_start so that in the split | |
1491 | * case we'll continue with more data in the next round, | |
1492 | * but break unconditionally so unsplit data stops here. | |
1493 | */ | |
1494 | (*split_start)++; | |
1495 | break; | |
1496 | case 9: | |
fe1abafd JB |
1497 | if (dev->wiphy.extended_capabilities && |
1498 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1499 | dev->wiphy.extended_capabilities_len, | |
1500 | dev->wiphy.extended_capabilities) || | |
1501 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1502 | dev->wiphy.extended_capabilities_len, | |
1503 | dev->wiphy.extended_capabilities_mask))) | |
1504 | goto nla_put_failure; | |
a50df0c4 | 1505 | |
ee2aca34 JB |
1506 | if (dev->wiphy.vht_capa_mod_mask && |
1507 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1508 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1509 | dev->wiphy.vht_capa_mod_mask)) | |
1510 | goto nla_put_failure; | |
1511 | ||
3713b4e3 JB |
1512 | /* done */ |
1513 | *split_start = 0; | |
1514 | break; | |
1515 | } | |
55682965 JB |
1516 | return genlmsg_end(msg, hdr); |
1517 | ||
1518 | nla_put_failure: | |
bc3ed28c TG |
1519 | genlmsg_cancel(msg, hdr); |
1520 | return -EMSGSIZE; | |
55682965 JB |
1521 | } |
1522 | ||
1523 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1524 | { | |
645e77de | 1525 | int idx = 0, ret; |
55682965 JB |
1526 | int start = cb->args[0]; |
1527 | struct cfg80211_registered_device *dev; | |
3713b4e3 JB |
1528 | s64 filter_wiphy = -1; |
1529 | bool split = false; | |
3a5a423b | 1530 | struct nlattr **tb; |
3713b4e3 | 1531 | int res; |
55682965 | 1532 | |
3a5a423b JB |
1533 | /* will be zeroed in nlmsg_parse() */ |
1534 | tb = kmalloc(sizeof(*tb) * (NL80211_ATTR_MAX + 1), GFP_KERNEL); | |
1535 | if (!tb) | |
1536 | return -ENOMEM; | |
1537 | ||
5fe231e8 | 1538 | rtnl_lock(); |
3713b4e3 | 1539 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
3a5a423b | 1540 | tb, NL80211_ATTR_MAX, nl80211_policy); |
3713b4e3 JB |
1541 | if (res == 0) { |
1542 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1543 | if (tb[NL80211_ATTR_WIPHY]) | |
1544 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1545 | if (tb[NL80211_ATTR_WDEV]) | |
1546 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1547 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1548 | struct net_device *netdev; | |
1549 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1550 | ||
1551 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); | |
940d0ac9 JB |
1552 | if (!netdev) { |
1553 | rtnl_unlock(); | |
3a5a423b | 1554 | kfree(tb); |
3713b4e3 | 1555 | return -ENODEV; |
940d0ac9 | 1556 | } |
3713b4e3 JB |
1557 | if (netdev->ieee80211_ptr) { |
1558 | dev = wiphy_to_dev( | |
1559 | netdev->ieee80211_ptr->wiphy); | |
1560 | filter_wiphy = dev->wiphy_idx; | |
1561 | } | |
1562 | dev_put(netdev); | |
1563 | } | |
1564 | } | |
3a5a423b | 1565 | kfree(tb); |
3713b4e3 | 1566 | |
79c97e97 | 1567 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1568 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1569 | continue; | |
b4637271 | 1570 | if (++idx <= start) |
55682965 | 1571 | continue; |
3713b4e3 JB |
1572 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
1573 | continue; | |
1574 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1575 | do { | |
1576 | ret = nl80211_send_wiphy(dev, skb, | |
1577 | NETLINK_CB(cb->skb).portid, | |
1578 | cb->nlh->nlmsg_seq, | |
1579 | NLM_F_MULTI, | |
1580 | split, &cb->args[1], | |
1581 | &cb->args[2], | |
1582 | &cb->args[3]); | |
1583 | if (ret < 0) { | |
1584 | /* | |
1585 | * If sending the wiphy data didn't fit (ENOBUFS | |
1586 | * or EMSGSIZE returned), this SKB is still | |
1587 | * empty (so it's not too big because another | |
1588 | * wiphy dataset is already in the skb) and | |
1589 | * we've not tried to adjust the dump allocation | |
1590 | * yet ... then adjust the alloc size to be | |
1591 | * bigger, and return 1 but with the empty skb. | |
1592 | * This results in an empty message being RX'ed | |
1593 | * in userspace, but that is ignored. | |
1594 | * | |
1595 | * We can then retry with the larger buffer. | |
1596 | */ | |
1597 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
1598 | !skb->len && | |
1599 | cb->min_dump_alloc < 4096) { | |
1600 | cb->min_dump_alloc = 4096; | |
940d0ac9 | 1601 | rtnl_unlock(); |
3713b4e3 JB |
1602 | return 1; |
1603 | } | |
1604 | idx--; | |
1605 | break; | |
645e77de | 1606 | } |
3713b4e3 JB |
1607 | } while (cb->args[1] > 0); |
1608 | break; | |
55682965 | 1609 | } |
5fe231e8 | 1610 | rtnl_unlock(); |
55682965 JB |
1611 | |
1612 | cb->args[0] = idx; | |
1613 | ||
1614 | return skb->len; | |
1615 | } | |
1616 | ||
1617 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1618 | { | |
1619 | struct sk_buff *msg; | |
4c476991 | 1620 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1621 | |
645e77de | 1622 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1623 | if (!msg) |
4c476991 | 1624 | return -ENOMEM; |
55682965 | 1625 | |
3713b4e3 JB |
1626 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
1627 | false, NULL, NULL, NULL) < 0) { | |
4c476991 JB |
1628 | nlmsg_free(msg); |
1629 | return -ENOBUFS; | |
1630 | } | |
55682965 | 1631 | |
134e6375 | 1632 | return genlmsg_reply(msg, info); |
55682965 JB |
1633 | } |
1634 | ||
31888487 JM |
1635 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1636 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1637 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1638 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1639 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1640 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1641 | }; | |
1642 | ||
1643 | static int parse_txq_params(struct nlattr *tb[], | |
1644 | struct ieee80211_txq_params *txq_params) | |
1645 | { | |
a3304b0a | 1646 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1647 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1648 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1649 | return -EINVAL; | |
1650 | ||
a3304b0a | 1651 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1652 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1653 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1654 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1655 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1656 | ||
a3304b0a JB |
1657 | if (txq_params->ac >= NL80211_NUM_ACS) |
1658 | return -EINVAL; | |
1659 | ||
31888487 JM |
1660 | return 0; |
1661 | } | |
1662 | ||
f444de05 JB |
1663 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1664 | { | |
1665 | /* | |
cc1d2806 JB |
1666 | * You can only set the channel explicitly for WDS interfaces, |
1667 | * all others have their channel managed via their respective | |
1668 | * "establish a connection" command (connect, join, ...) | |
1669 | * | |
1670 | * For AP/GO and mesh mode, the channel can be set with the | |
1671 | * channel userspace API, but is only stored and passed to the | |
1672 | * low-level driver when the AP starts or the mesh is joined. | |
1673 | * This is for backward compatibility, userspace can also give | |
1674 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1675 | * |
1676 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1677 | * whatever else is going on, so they have their own special |
1678 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1679 | */ |
1680 | return !wdev || | |
1681 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1682 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1683 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1684 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1685 | } |
1686 | ||
683b6d3b JB |
1687 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1688 | struct genl_info *info, | |
1689 | struct cfg80211_chan_def *chandef) | |
1690 | { | |
dbeca2ea | 1691 | u32 control_freq; |
683b6d3b JB |
1692 | |
1693 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1694 | return -EINVAL; | |
1695 | ||
1696 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1697 | ||
1698 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1699 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1700 | chandef->center_freq1 = control_freq; | |
1701 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1702 | |
1703 | /* Primary channel not allowed */ | |
1704 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1705 | return -EINVAL; | |
1706 | ||
3d9d1d66 JB |
1707 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1708 | enum nl80211_channel_type chantype; | |
1709 | ||
1710 | chantype = nla_get_u32( | |
1711 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1712 | ||
1713 | switch (chantype) { | |
1714 | case NL80211_CHAN_NO_HT: | |
1715 | case NL80211_CHAN_HT20: | |
1716 | case NL80211_CHAN_HT40PLUS: | |
1717 | case NL80211_CHAN_HT40MINUS: | |
1718 | cfg80211_chandef_create(chandef, chandef->chan, | |
1719 | chantype); | |
1720 | break; | |
1721 | default: | |
1722 | return -EINVAL; | |
1723 | } | |
1724 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1725 | chandef->width = | |
1726 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1727 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1728 | chandef->center_freq1 = | |
1729 | nla_get_u32( | |
1730 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1731 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1732 | chandef->center_freq2 = | |
1733 | nla_get_u32( | |
1734 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1735 | } | |
1736 | ||
9f5e8f6e | 1737 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1738 | return -EINVAL; |
1739 | ||
9f5e8f6e JB |
1740 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1741 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1742 | return -EINVAL; |
1743 | ||
2f301ab2 SW |
1744 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1745 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1746 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1747 | return -EINVAL; | |
1748 | ||
683b6d3b JB |
1749 | return 0; |
1750 | } | |
1751 | ||
f444de05 JB |
1752 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1753 | struct wireless_dev *wdev, | |
1754 | struct genl_info *info) | |
1755 | { | |
683b6d3b | 1756 | struct cfg80211_chan_def chandef; |
f444de05 | 1757 | int result; |
e8c9bd5b JB |
1758 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1759 | ||
1760 | if (wdev) | |
1761 | iftype = wdev->iftype; | |
f444de05 | 1762 | |
f444de05 JB |
1763 | if (!nl80211_can_set_dev_channel(wdev)) |
1764 | return -EOPNOTSUPP; | |
1765 | ||
683b6d3b JB |
1766 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1767 | if (result) | |
1768 | return result; | |
f444de05 | 1769 | |
e8c9bd5b | 1770 | switch (iftype) { |
aa430da4 JB |
1771 | case NL80211_IFTYPE_AP: |
1772 | case NL80211_IFTYPE_P2P_GO: | |
1773 | if (wdev->beacon_interval) { | |
1774 | result = -EBUSY; | |
1775 | break; | |
1776 | } | |
683b6d3b | 1777 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1778 | result = -EINVAL; |
1779 | break; | |
1780 | } | |
683b6d3b | 1781 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1782 | result = 0; |
1783 | break; | |
cc1d2806 | 1784 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1785 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1786 | break; |
e8c9bd5b | 1787 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1788 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1789 | break; |
aa430da4 | 1790 | default: |
e8c9bd5b | 1791 | result = -EINVAL; |
f444de05 | 1792 | } |
f444de05 JB |
1793 | |
1794 | return result; | |
1795 | } | |
1796 | ||
1797 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1798 | { | |
4c476991 JB |
1799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1800 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1801 | |
4c476991 | 1802 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1803 | } |
1804 | ||
e8347eba BJ |
1805 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1806 | { | |
43b19952 JB |
1807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1808 | struct net_device *dev = info->user_ptr[1]; | |
1809 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1810 | const u8 *bssid; |
e8347eba BJ |
1811 | |
1812 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1813 | return -EINVAL; | |
1814 | ||
43b19952 JB |
1815 | if (netif_running(dev)) |
1816 | return -EBUSY; | |
e8347eba | 1817 | |
43b19952 JB |
1818 | if (!rdev->ops->set_wds_peer) |
1819 | return -EOPNOTSUPP; | |
e8347eba | 1820 | |
43b19952 JB |
1821 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1822 | return -EOPNOTSUPP; | |
e8347eba BJ |
1823 | |
1824 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1825 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1826 | } |
1827 | ||
1828 | ||
55682965 JB |
1829 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1830 | { | |
1831 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1832 | struct net_device *netdev = NULL; |
1833 | struct wireless_dev *wdev; | |
a1e567c8 | 1834 | int result = 0, rem_txq_params = 0; |
31888487 | 1835 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1836 | u32 changed; |
1837 | u8 retry_short = 0, retry_long = 0; | |
1838 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1839 | u8 coverage_class = 0; |
55682965 | 1840 | |
5fe231e8 JB |
1841 | ASSERT_RTNL(); |
1842 | ||
f444de05 JB |
1843 | /* |
1844 | * Try to find the wiphy and netdev. Normally this | |
1845 | * function shouldn't need the netdev, but this is | |
1846 | * done for backward compatibility -- previously | |
1847 | * setting the channel was done per wiphy, but now | |
1848 | * it is per netdev. Previous userland like hostapd | |
1849 | * also passed a netdev to set_wiphy, so that it is | |
1850 | * possible to let that go to the right netdev! | |
1851 | */ | |
4bbf4d56 | 1852 | |
f444de05 JB |
1853 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1854 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1855 | ||
1856 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
5fe231e8 | 1857 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 1858 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 1859 | else |
f444de05 | 1860 | netdev = NULL; |
4bbf4d56 JB |
1861 | } |
1862 | ||
f444de05 | 1863 | if (!netdev) { |
878d9ec7 JB |
1864 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1865 | info->attrs); | |
5fe231e8 | 1866 | if (IS_ERR(rdev)) |
4c476991 | 1867 | return PTR_ERR(rdev); |
f444de05 JB |
1868 | wdev = NULL; |
1869 | netdev = NULL; | |
1870 | result = 0; | |
71fe96bf | 1871 | } else |
f444de05 | 1872 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
1873 | |
1874 | /* | |
1875 | * end workaround code, by now the rdev is available | |
1876 | * and locked, and wdev may or may not be NULL. | |
1877 | */ | |
4bbf4d56 JB |
1878 | |
1879 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1880 | result = cfg80211_dev_rename( |
1881 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 1882 | |
4bbf4d56 JB |
1883 | if (result) |
1884 | goto bad_res; | |
31888487 JM |
1885 | |
1886 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1887 | struct ieee80211_txq_params txq_params; | |
1888 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1889 | ||
1890 | if (!rdev->ops->set_txq_params) { | |
1891 | result = -EOPNOTSUPP; | |
1892 | goto bad_res; | |
1893 | } | |
1894 | ||
f70f01c2 EP |
1895 | if (!netdev) { |
1896 | result = -EINVAL; | |
1897 | goto bad_res; | |
1898 | } | |
1899 | ||
133a3ff2 JB |
1900 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1901 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1902 | result = -EINVAL; | |
1903 | goto bad_res; | |
1904 | } | |
1905 | ||
2b5f8b0b JB |
1906 | if (!netif_running(netdev)) { |
1907 | result = -ENETDOWN; | |
1908 | goto bad_res; | |
1909 | } | |
1910 | ||
31888487 JM |
1911 | nla_for_each_nested(nl_txq_params, |
1912 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1913 | rem_txq_params) { | |
1914 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1915 | nla_data(nl_txq_params), | |
1916 | nla_len(nl_txq_params), | |
1917 | txq_params_policy); | |
1918 | result = parse_txq_params(tb, &txq_params); | |
1919 | if (result) | |
1920 | goto bad_res; | |
1921 | ||
e35e4d28 HG |
1922 | result = rdev_set_txq_params(rdev, netdev, |
1923 | &txq_params); | |
31888487 JM |
1924 | if (result) |
1925 | goto bad_res; | |
1926 | } | |
1927 | } | |
55682965 | 1928 | |
72bdcf34 | 1929 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
1930 | result = __nl80211_set_channel(rdev, |
1931 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
1932 | info); | |
72bdcf34 JM |
1933 | if (result) |
1934 | goto bad_res; | |
1935 | } | |
1936 | ||
98d2ff8b | 1937 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 1938 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
1939 | enum nl80211_tx_power_setting type; |
1940 | int idx, mbm = 0; | |
1941 | ||
c8442118 JB |
1942 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
1943 | txp_wdev = NULL; | |
1944 | ||
98d2ff8b | 1945 | if (!rdev->ops->set_tx_power) { |
60ea385f | 1946 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1947 | goto bad_res; |
1948 | } | |
1949 | ||
1950 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1951 | type = nla_get_u32(info->attrs[idx]); | |
1952 | ||
1953 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1954 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1955 | result = -EINVAL; | |
1956 | goto bad_res; | |
1957 | } | |
1958 | ||
1959 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1960 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1961 | mbm = nla_get_u32(info->attrs[idx]); | |
1962 | } | |
1963 | ||
c8442118 | 1964 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b JO |
1965 | if (result) |
1966 | goto bad_res; | |
1967 | } | |
1968 | ||
afe0cbf8 BR |
1969 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1970 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1971 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1972 | if ((!rdev->wiphy.available_antennas_tx && |
1973 | !rdev->wiphy.available_antennas_rx) || | |
1974 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1975 | result = -EOPNOTSUPP; |
1976 | goto bad_res; | |
1977 | } | |
1978 | ||
1979 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1980 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
1981 | ||
a7ffac95 | 1982 | /* reject antenna configurations which don't match the |
7f531e03 BR |
1983 | * available antenna masks, except for the "all" mask */ |
1984 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
1985 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
1986 | result = -EINVAL; |
1987 | goto bad_res; | |
1988 | } | |
1989 | ||
7f531e03 BR |
1990 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
1991 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 1992 | |
e35e4d28 | 1993 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 BR |
1994 | if (result) |
1995 | goto bad_res; | |
1996 | } | |
1997 | ||
b9a5f8ca JM |
1998 | changed = 0; |
1999 | ||
2000 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2001 | retry_short = nla_get_u8( | |
2002 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
2003 | if (retry_short == 0) { | |
2004 | result = -EINVAL; | |
2005 | goto bad_res; | |
2006 | } | |
2007 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
2008 | } | |
2009 | ||
2010 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2011 | retry_long = nla_get_u8( | |
2012 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
2013 | if (retry_long == 0) { | |
2014 | result = -EINVAL; | |
2015 | goto bad_res; | |
2016 | } | |
2017 | changed |= WIPHY_PARAM_RETRY_LONG; | |
2018 | } | |
2019 | ||
2020 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2021 | frag_threshold = nla_get_u32( | |
2022 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
2023 | if (frag_threshold < 256) { | |
2024 | result = -EINVAL; | |
2025 | goto bad_res; | |
2026 | } | |
2027 | if (frag_threshold != (u32) -1) { | |
2028 | /* | |
2029 | * Fragments (apart from the last one) are required to | |
2030 | * have even length. Make the fragmentation code | |
2031 | * simpler by stripping LSB should someone try to use | |
2032 | * odd threshold value. | |
2033 | */ | |
2034 | frag_threshold &= ~0x1; | |
2035 | } | |
2036 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2037 | } | |
2038 | ||
2039 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2040 | rts_threshold = nla_get_u32( | |
2041 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2042 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2043 | } | |
2044 | ||
81077e82 LT |
2045 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2046 | coverage_class = nla_get_u8( | |
2047 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2048 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2049 | } | |
2050 | ||
b9a5f8ca JM |
2051 | if (changed) { |
2052 | u8 old_retry_short, old_retry_long; | |
2053 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2054 | u8 old_coverage_class; |
b9a5f8ca JM |
2055 | |
2056 | if (!rdev->ops->set_wiphy_params) { | |
2057 | result = -EOPNOTSUPP; | |
2058 | goto bad_res; | |
2059 | } | |
2060 | ||
2061 | old_retry_short = rdev->wiphy.retry_short; | |
2062 | old_retry_long = rdev->wiphy.retry_long; | |
2063 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2064 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2065 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2066 | |
2067 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2068 | rdev->wiphy.retry_short = retry_short; | |
2069 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2070 | rdev->wiphy.retry_long = retry_long; | |
2071 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2072 | rdev->wiphy.frag_threshold = frag_threshold; | |
2073 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2074 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2075 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2076 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2077 | |
e35e4d28 | 2078 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2079 | if (result) { |
2080 | rdev->wiphy.retry_short = old_retry_short; | |
2081 | rdev->wiphy.retry_long = old_retry_long; | |
2082 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2083 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2084 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2085 | } |
2086 | } | |
72bdcf34 | 2087 | |
306d6112 | 2088 | bad_res: |
f444de05 JB |
2089 | if (netdev) |
2090 | dev_put(netdev); | |
55682965 JB |
2091 | return result; |
2092 | } | |
2093 | ||
71bbc994 JB |
2094 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2095 | { | |
2096 | return (u64)wdev->identifier | | |
2097 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2098 | } | |
55682965 | 2099 | |
683b6d3b JB |
2100 | static int nl80211_send_chandef(struct sk_buff *msg, |
2101 | struct cfg80211_chan_def *chandef) | |
2102 | { | |
9f5e8f6e | 2103 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2104 | |
683b6d3b JB |
2105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2106 | chandef->chan->center_freq)) | |
2107 | return -ENOBUFS; | |
3d9d1d66 JB |
2108 | switch (chandef->width) { |
2109 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2110 | case NL80211_CHAN_WIDTH_20: | |
2111 | case NL80211_CHAN_WIDTH_40: | |
2112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2113 | cfg80211_get_chandef_type(chandef))) | |
2114 | return -ENOBUFS; | |
2115 | break; | |
2116 | default: | |
2117 | break; | |
2118 | } | |
2119 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2120 | return -ENOBUFS; | |
2121 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2122 | return -ENOBUFS; | |
2123 | if (chandef->center_freq2 && | |
2124 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2125 | return -ENOBUFS; |
2126 | return 0; | |
2127 | } | |
2128 | ||
15e47304 | 2129 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2130 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2131 | struct wireless_dev *wdev) |
55682965 | 2132 | { |
72fb2abc | 2133 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2134 | void *hdr; |
2135 | ||
15e47304 | 2136 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2137 | if (!hdr) |
2138 | return -1; | |
2139 | ||
72fb2abc JB |
2140 | if (dev && |
2141 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2142 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2143 | goto nla_put_failure; |
2144 | ||
2145 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2146 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2147 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2148 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2149 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2150 | rdev->devlist_generation ^ | |
2151 | (cfg80211_rdev_list_generation << 2))) | |
2152 | goto nla_put_failure; | |
f5ea9120 | 2153 | |
5b7ccaf3 | 2154 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2155 | int ret; |
2156 | struct cfg80211_chan_def chandef; | |
2157 | ||
2158 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2159 | if (ret == 0) { | |
2160 | if (nl80211_send_chandef(msg, &chandef)) | |
2161 | goto nla_put_failure; | |
2162 | } | |
d91df0e3 PF |
2163 | } |
2164 | ||
b84e7a05 AQ |
2165 | if (wdev->ssid_len) { |
2166 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2167 | goto nla_put_failure; | |
2168 | } | |
2169 | ||
55682965 JB |
2170 | return genlmsg_end(msg, hdr); |
2171 | ||
2172 | nla_put_failure: | |
bc3ed28c TG |
2173 | genlmsg_cancel(msg, hdr); |
2174 | return -EMSGSIZE; | |
55682965 JB |
2175 | } |
2176 | ||
2177 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2178 | { | |
2179 | int wp_idx = 0; | |
2180 | int if_idx = 0; | |
2181 | int wp_start = cb->args[0]; | |
2182 | int if_start = cb->args[1]; | |
f5ea9120 | 2183 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2184 | struct wireless_dev *wdev; |
2185 | ||
5fe231e8 | 2186 | rtnl_lock(); |
f5ea9120 JB |
2187 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2188 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2189 | continue; |
bba95fef JB |
2190 | if (wp_idx < wp_start) { |
2191 | wp_idx++; | |
55682965 | 2192 | continue; |
bba95fef | 2193 | } |
55682965 JB |
2194 | if_idx = 0; |
2195 | ||
89a54e48 | 2196 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2197 | if (if_idx < if_start) { |
2198 | if_idx++; | |
55682965 | 2199 | continue; |
bba95fef | 2200 | } |
15e47304 | 2201 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2202 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2203 | rdev, wdev) < 0) { |
bba95fef JB |
2204 | goto out; |
2205 | } | |
2206 | if_idx++; | |
55682965 | 2207 | } |
bba95fef JB |
2208 | |
2209 | wp_idx++; | |
55682965 | 2210 | } |
bba95fef | 2211 | out: |
5fe231e8 | 2212 | rtnl_unlock(); |
55682965 JB |
2213 | |
2214 | cb->args[0] = wp_idx; | |
2215 | cb->args[1] = if_idx; | |
2216 | ||
2217 | return skb->len; | |
2218 | } | |
2219 | ||
2220 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2221 | { | |
2222 | struct sk_buff *msg; | |
4c476991 | 2223 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2224 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2225 | |
fd2120ca | 2226 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2227 | if (!msg) |
4c476991 | 2228 | return -ENOMEM; |
55682965 | 2229 | |
15e47304 | 2230 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2231 | dev, wdev) < 0) { |
4c476991 JB |
2232 | nlmsg_free(msg); |
2233 | return -ENOBUFS; | |
2234 | } | |
55682965 | 2235 | |
134e6375 | 2236 | return genlmsg_reply(msg, info); |
55682965 JB |
2237 | } |
2238 | ||
66f7ac50 MW |
2239 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2240 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2241 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2242 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2243 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2244 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2245 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2246 | }; |
2247 | ||
2248 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2249 | { | |
2250 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2251 | int flag; | |
2252 | ||
2253 | *mntrflags = 0; | |
2254 | ||
2255 | if (!nla) | |
2256 | return -EINVAL; | |
2257 | ||
2258 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2259 | nla, mntr_flags_policy)) | |
2260 | return -EINVAL; | |
2261 | ||
2262 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2263 | if (flags[flag]) | |
2264 | *mntrflags |= (1<<flag); | |
2265 | ||
2266 | return 0; | |
2267 | } | |
2268 | ||
9bc383de | 2269 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2270 | struct net_device *netdev, u8 use_4addr, |
2271 | enum nl80211_iftype iftype) | |
9bc383de | 2272 | { |
ad4bb6f8 | 2273 | if (!use_4addr) { |
f350a0a8 | 2274 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2275 | return -EBUSY; |
9bc383de | 2276 | return 0; |
ad4bb6f8 | 2277 | } |
9bc383de JB |
2278 | |
2279 | switch (iftype) { | |
2280 | case NL80211_IFTYPE_AP_VLAN: | |
2281 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2282 | return 0; | |
2283 | break; | |
2284 | case NL80211_IFTYPE_STATION: | |
2285 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2286 | return 0; | |
2287 | break; | |
2288 | default: | |
2289 | break; | |
2290 | } | |
2291 | ||
2292 | return -EOPNOTSUPP; | |
2293 | } | |
2294 | ||
55682965 JB |
2295 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2296 | { | |
4c476991 | 2297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2298 | struct vif_params params; |
e36d56b6 | 2299 | int err; |
04a773ad | 2300 | enum nl80211_iftype otype, ntype; |
4c476991 | 2301 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2302 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2303 | bool change = false; |
55682965 | 2304 | |
2ec600d6 LCC |
2305 | memset(¶ms, 0, sizeof(params)); |
2306 | ||
04a773ad | 2307 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2308 | |
723b038d | 2309 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2310 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2311 | if (otype != ntype) |
ac7f9cfa | 2312 | change = true; |
4c476991 JB |
2313 | if (ntype > NL80211_IFTYPE_MAX) |
2314 | return -EINVAL; | |
723b038d JB |
2315 | } |
2316 | ||
92ffe055 | 2317 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2319 | ||
4c476991 JB |
2320 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2321 | return -EINVAL; | |
29cbe68c JB |
2322 | if (netif_running(dev)) |
2323 | return -EBUSY; | |
2324 | ||
2325 | wdev_lock(wdev); | |
2326 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2327 | IEEE80211_MAX_MESH_ID_LEN); | |
2328 | wdev->mesh_id_up_len = | |
2329 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2330 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2331 | wdev->mesh_id_up_len); | |
2332 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2333 | } |
2334 | ||
8b787643 FF |
2335 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2336 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2337 | change = true; | |
ad4bb6f8 | 2338 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2339 | if (err) |
4c476991 | 2340 | return err; |
8b787643 FF |
2341 | } else { |
2342 | params.use_4addr = -1; | |
2343 | } | |
2344 | ||
92ffe055 | 2345 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2346 | if (ntype != NL80211_IFTYPE_MONITOR) |
2347 | return -EINVAL; | |
92ffe055 JB |
2348 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2349 | &_flags); | |
ac7f9cfa | 2350 | if (err) |
4c476991 | 2351 | return err; |
ac7f9cfa JB |
2352 | |
2353 | flags = &_flags; | |
2354 | change = true; | |
92ffe055 | 2355 | } |
3b85875a | 2356 | |
e057d3c3 FF |
2357 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
2358 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2359 | return -EOPNOTSUPP; | |
2360 | ||
ac7f9cfa | 2361 | if (change) |
3d54d255 | 2362 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2363 | else |
2364 | err = 0; | |
60719ffd | 2365 | |
9bc383de JB |
2366 | if (!err && params.use_4addr != -1) |
2367 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2368 | ||
55682965 JB |
2369 | return err; |
2370 | } | |
2371 | ||
2372 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2373 | { | |
4c476991 | 2374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2375 | struct vif_params params; |
84efbb84 | 2376 | struct wireless_dev *wdev; |
1c90f9d4 | 2377 | struct sk_buff *msg; |
55682965 JB |
2378 | int err; |
2379 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2380 | u32 flags; |
55682965 | 2381 | |
2ec600d6 LCC |
2382 | memset(¶ms, 0, sizeof(params)); |
2383 | ||
55682965 JB |
2384 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2385 | return -EINVAL; | |
2386 | ||
2387 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2388 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2389 | if (type > NL80211_IFTYPE_MAX) | |
2390 | return -EINVAL; | |
2391 | } | |
2392 | ||
79c97e97 | 2393 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2394 | !(rdev->wiphy.interface_modes & (1 << type))) |
2395 | return -EOPNOTSUPP; | |
55682965 | 2396 | |
1c18f145 AS |
2397 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2398 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2399 | ETH_ALEN); | |
2400 | if (!is_valid_ether_addr(params.macaddr)) | |
2401 | return -EADDRNOTAVAIL; | |
2402 | } | |
2403 | ||
9bc383de | 2404 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2405 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2406 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2407 | if (err) |
4c476991 | 2408 | return err; |
9bc383de | 2409 | } |
8b787643 | 2410 | |
1c90f9d4 JB |
2411 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2412 | if (!msg) | |
2413 | return -ENOMEM; | |
2414 | ||
66f7ac50 MW |
2415 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2416 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2417 | &flags); | |
e057d3c3 FF |
2418 | |
2419 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && | |
2420 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2421 | return -EOPNOTSUPP; | |
2422 | ||
e35e4d28 HG |
2423 | wdev = rdev_add_virtual_intf(rdev, |
2424 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2425 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2426 | if (IS_ERR(wdev)) { |
2427 | nlmsg_free(msg); | |
84efbb84 | 2428 | return PTR_ERR(wdev); |
1c90f9d4 | 2429 | } |
2ec600d6 | 2430 | |
98104fde JB |
2431 | switch (type) { |
2432 | case NL80211_IFTYPE_MESH_POINT: | |
2433 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2434 | break; | |
29cbe68c JB |
2435 | wdev_lock(wdev); |
2436 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2437 | IEEE80211_MAX_MESH_ID_LEN); | |
2438 | wdev->mesh_id_up_len = | |
2439 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2440 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2441 | wdev->mesh_id_up_len); | |
2442 | wdev_unlock(wdev); | |
98104fde JB |
2443 | break; |
2444 | case NL80211_IFTYPE_P2P_DEVICE: | |
2445 | /* | |
2446 | * P2P Device doesn't have a netdev, so doesn't go | |
2447 | * through the netdev notifier and must be added here | |
2448 | */ | |
2449 | mutex_init(&wdev->mtx); | |
2450 | INIT_LIST_HEAD(&wdev->event_list); | |
2451 | spin_lock_init(&wdev->event_lock); | |
2452 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2453 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2454 | ||
98104fde JB |
2455 | wdev->identifier = ++rdev->wdev_id; |
2456 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2457 | rdev->devlist_generation++; | |
98104fde JB |
2458 | break; |
2459 | default: | |
2460 | break; | |
29cbe68c JB |
2461 | } |
2462 | ||
15e47304 | 2463 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2464 | rdev, wdev) < 0) { |
2465 | nlmsg_free(msg); | |
2466 | return -ENOBUFS; | |
2467 | } | |
2468 | ||
2469 | return genlmsg_reply(msg, info); | |
55682965 JB |
2470 | } |
2471 | ||
2472 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2473 | { | |
4c476991 | 2474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2475 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2476 | |
4c476991 JB |
2477 | if (!rdev->ops->del_virtual_intf) |
2478 | return -EOPNOTSUPP; | |
55682965 | 2479 | |
84efbb84 JB |
2480 | /* |
2481 | * If we remove a wireless device without a netdev then clear | |
2482 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2483 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2484 | * since the wdev has been freed, unlike with a netdev where | |
2485 | * we need the dev_put() for the netdev to really be freed. | |
2486 | */ | |
2487 | if (!wdev->netdev) | |
2488 | info->user_ptr[1] = NULL; | |
2489 | ||
e35e4d28 | 2490 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2491 | } |
2492 | ||
1d9d9213 SW |
2493 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2494 | { | |
2495 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2496 | struct net_device *dev = info->user_ptr[1]; | |
2497 | u16 noack_map; | |
2498 | ||
2499 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2500 | return -EINVAL; | |
2501 | ||
2502 | if (!rdev->ops->set_noack_map) | |
2503 | return -EOPNOTSUPP; | |
2504 | ||
2505 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2506 | ||
e35e4d28 | 2507 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2508 | } |
2509 | ||
41ade00f JB |
2510 | struct get_key_cookie { |
2511 | struct sk_buff *msg; | |
2512 | int error; | |
b9454e83 | 2513 | int idx; |
41ade00f JB |
2514 | }; |
2515 | ||
2516 | static void get_key_callback(void *c, struct key_params *params) | |
2517 | { | |
b9454e83 | 2518 | struct nlattr *key; |
41ade00f JB |
2519 | struct get_key_cookie *cookie = c; |
2520 | ||
9360ffd1 DM |
2521 | if ((params->key && |
2522 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2523 | params->key_len, params->key)) || | |
2524 | (params->seq && | |
2525 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2526 | params->seq_len, params->seq)) || | |
2527 | (params->cipher && | |
2528 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2529 | params->cipher))) | |
2530 | goto nla_put_failure; | |
41ade00f | 2531 | |
b9454e83 JB |
2532 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2533 | if (!key) | |
2534 | goto nla_put_failure; | |
2535 | ||
9360ffd1 DM |
2536 | if ((params->key && |
2537 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2538 | params->key_len, params->key)) || | |
2539 | (params->seq && | |
2540 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2541 | params->seq_len, params->seq)) || | |
2542 | (params->cipher && | |
2543 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2544 | params->cipher))) | |
2545 | goto nla_put_failure; | |
b9454e83 | 2546 | |
9360ffd1 DM |
2547 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2548 | goto nla_put_failure; | |
b9454e83 JB |
2549 | |
2550 | nla_nest_end(cookie->msg, key); | |
2551 | ||
41ade00f JB |
2552 | return; |
2553 | nla_put_failure: | |
2554 | cookie->error = 1; | |
2555 | } | |
2556 | ||
2557 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2558 | { | |
4c476991 | 2559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2560 | int err; |
4c476991 | 2561 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2562 | u8 key_idx = 0; |
e31b8213 JB |
2563 | const u8 *mac_addr = NULL; |
2564 | bool pairwise; | |
41ade00f JB |
2565 | struct get_key_cookie cookie = { |
2566 | .error = 0, | |
2567 | }; | |
2568 | void *hdr; | |
2569 | struct sk_buff *msg; | |
2570 | ||
2571 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2572 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2573 | ||
3cfcf6ac | 2574 | if (key_idx > 5) |
41ade00f JB |
2575 | return -EINVAL; |
2576 | ||
2577 | if (info->attrs[NL80211_ATTR_MAC]) | |
2578 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2579 | ||
e31b8213 JB |
2580 | pairwise = !!mac_addr; |
2581 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2582 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2583 | if (kt >= NUM_NL80211_KEYTYPES) | |
2584 | return -EINVAL; | |
2585 | if (kt != NL80211_KEYTYPE_GROUP && | |
2586 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2587 | return -EINVAL; | |
2588 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2589 | } | |
2590 | ||
4c476991 JB |
2591 | if (!rdev->ops->get_key) |
2592 | return -EOPNOTSUPP; | |
41ade00f | 2593 | |
fd2120ca | 2594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2595 | if (!msg) |
2596 | return -ENOMEM; | |
41ade00f | 2597 | |
15e47304 | 2598 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2599 | NL80211_CMD_NEW_KEY); |
4c476991 JB |
2600 | if (IS_ERR(hdr)) |
2601 | return PTR_ERR(hdr); | |
41ade00f JB |
2602 | |
2603 | cookie.msg = msg; | |
b9454e83 | 2604 | cookie.idx = key_idx; |
41ade00f | 2605 | |
9360ffd1 DM |
2606 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2607 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2608 | goto nla_put_failure; | |
2609 | if (mac_addr && | |
2610 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2611 | goto nla_put_failure; | |
41ade00f | 2612 | |
e31b8213 JB |
2613 | if (pairwise && mac_addr && |
2614 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2615 | return -ENOENT; | |
2616 | ||
e35e4d28 HG |
2617 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2618 | get_key_callback); | |
41ade00f JB |
2619 | |
2620 | if (err) | |
6c95e2a2 | 2621 | goto free_msg; |
41ade00f JB |
2622 | |
2623 | if (cookie.error) | |
2624 | goto nla_put_failure; | |
2625 | ||
2626 | genlmsg_end(msg, hdr); | |
4c476991 | 2627 | return genlmsg_reply(msg, info); |
41ade00f JB |
2628 | |
2629 | nla_put_failure: | |
2630 | err = -ENOBUFS; | |
6c95e2a2 | 2631 | free_msg: |
41ade00f | 2632 | nlmsg_free(msg); |
41ade00f JB |
2633 | return err; |
2634 | } | |
2635 | ||
2636 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2637 | { | |
4c476991 | 2638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2639 | struct key_parse key; |
41ade00f | 2640 | int err; |
4c476991 | 2641 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2642 | |
b9454e83 JB |
2643 | err = nl80211_parse_key(info, &key); |
2644 | if (err) | |
2645 | return err; | |
41ade00f | 2646 | |
b9454e83 | 2647 | if (key.idx < 0) |
41ade00f JB |
2648 | return -EINVAL; |
2649 | ||
b9454e83 JB |
2650 | /* only support setting default key */ |
2651 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2652 | return -EINVAL; |
2653 | ||
dbd2fd65 | 2654 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2655 | |
dbd2fd65 JB |
2656 | if (key.def) { |
2657 | if (!rdev->ops->set_default_key) { | |
2658 | err = -EOPNOTSUPP; | |
2659 | goto out; | |
2660 | } | |
41ade00f | 2661 | |
dbd2fd65 JB |
2662 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2663 | if (err) | |
2664 | goto out; | |
2665 | ||
e35e4d28 | 2666 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2667 | key.def_uni, key.def_multi); |
2668 | ||
2669 | if (err) | |
2670 | goto out; | |
fffd0934 | 2671 | |
3d23e349 | 2672 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2673 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2674 | #endif | |
2675 | } else { | |
2676 | if (key.def_uni || !key.def_multi) { | |
2677 | err = -EINVAL; | |
2678 | goto out; | |
2679 | } | |
2680 | ||
2681 | if (!rdev->ops->set_default_mgmt_key) { | |
2682 | err = -EOPNOTSUPP; | |
2683 | goto out; | |
2684 | } | |
2685 | ||
2686 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2687 | if (err) | |
2688 | goto out; | |
2689 | ||
e35e4d28 | 2690 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2691 | if (err) |
2692 | goto out; | |
2693 | ||
2694 | #ifdef CONFIG_CFG80211_WEXT | |
2695 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2696 | #endif |
dbd2fd65 JB |
2697 | } |
2698 | ||
2699 | out: | |
fffd0934 | 2700 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2701 | |
41ade00f JB |
2702 | return err; |
2703 | } | |
2704 | ||
2705 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2706 | { | |
4c476991 | 2707 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2708 | int err; |
4c476991 | 2709 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2710 | struct key_parse key; |
e31b8213 | 2711 | const u8 *mac_addr = NULL; |
41ade00f | 2712 | |
b9454e83 JB |
2713 | err = nl80211_parse_key(info, &key); |
2714 | if (err) | |
2715 | return err; | |
41ade00f | 2716 | |
b9454e83 | 2717 | if (!key.p.key) |
41ade00f JB |
2718 | return -EINVAL; |
2719 | ||
41ade00f JB |
2720 | if (info->attrs[NL80211_ATTR_MAC]) |
2721 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2722 | ||
e31b8213 JB |
2723 | if (key.type == -1) { |
2724 | if (mac_addr) | |
2725 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2726 | else | |
2727 | key.type = NL80211_KEYTYPE_GROUP; | |
2728 | } | |
2729 | ||
2730 | /* for now */ | |
2731 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2732 | key.type != NL80211_KEYTYPE_GROUP) | |
2733 | return -EINVAL; | |
2734 | ||
4c476991 JB |
2735 | if (!rdev->ops->add_key) |
2736 | return -EOPNOTSUPP; | |
25e47c18 | 2737 | |
e31b8213 JB |
2738 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2739 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2740 | mac_addr)) | |
4c476991 | 2741 | return -EINVAL; |
41ade00f | 2742 | |
fffd0934 JB |
2743 | wdev_lock(dev->ieee80211_ptr); |
2744 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2745 | if (!err) | |
e35e4d28 HG |
2746 | err = rdev_add_key(rdev, dev, key.idx, |
2747 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2748 | mac_addr, &key.p); | |
fffd0934 | 2749 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2750 | |
41ade00f JB |
2751 | return err; |
2752 | } | |
2753 | ||
2754 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2755 | { | |
4c476991 | 2756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2757 | int err; |
4c476991 | 2758 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2759 | u8 *mac_addr = NULL; |
b9454e83 | 2760 | struct key_parse key; |
41ade00f | 2761 | |
b9454e83 JB |
2762 | err = nl80211_parse_key(info, &key); |
2763 | if (err) | |
2764 | return err; | |
41ade00f JB |
2765 | |
2766 | if (info->attrs[NL80211_ATTR_MAC]) | |
2767 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2768 | ||
e31b8213 JB |
2769 | if (key.type == -1) { |
2770 | if (mac_addr) | |
2771 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2772 | else | |
2773 | key.type = NL80211_KEYTYPE_GROUP; | |
2774 | } | |
2775 | ||
2776 | /* for now */ | |
2777 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2778 | key.type != NL80211_KEYTYPE_GROUP) | |
2779 | return -EINVAL; | |
2780 | ||
4c476991 JB |
2781 | if (!rdev->ops->del_key) |
2782 | return -EOPNOTSUPP; | |
41ade00f | 2783 | |
fffd0934 JB |
2784 | wdev_lock(dev->ieee80211_ptr); |
2785 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2786 | |
2787 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2788 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2789 | err = -ENOENT; | |
2790 | ||
fffd0934 | 2791 | if (!err) |
e35e4d28 HG |
2792 | err = rdev_del_key(rdev, dev, key.idx, |
2793 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2794 | mac_addr); | |
41ade00f | 2795 | |
3d23e349 | 2796 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2797 | if (!err) { |
b9454e83 | 2798 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2799 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2800 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2801 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2802 | } | |
2803 | #endif | |
fffd0934 | 2804 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2805 | |
41ade00f JB |
2806 | return err; |
2807 | } | |
2808 | ||
77765eaf VT |
2809 | /* This function returns an error or the number of nested attributes */ |
2810 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2811 | { | |
2812 | struct nlattr *attr; | |
2813 | int n_entries = 0, tmp; | |
2814 | ||
2815 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2816 | if (nla_len(attr) != ETH_ALEN) | |
2817 | return -EINVAL; | |
2818 | ||
2819 | n_entries++; | |
2820 | } | |
2821 | ||
2822 | return n_entries; | |
2823 | } | |
2824 | ||
2825 | /* | |
2826 | * This function parses ACL information and allocates memory for ACL data. | |
2827 | * On successful return, the calling function is responsible to free the | |
2828 | * ACL buffer returned by this function. | |
2829 | */ | |
2830 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2831 | struct genl_info *info) | |
2832 | { | |
2833 | enum nl80211_acl_policy acl_policy; | |
2834 | struct nlattr *attr; | |
2835 | struct cfg80211_acl_data *acl; | |
2836 | int i = 0, n_entries, tmp; | |
2837 | ||
2838 | if (!wiphy->max_acl_mac_addrs) | |
2839 | return ERR_PTR(-EOPNOTSUPP); | |
2840 | ||
2841 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2842 | return ERR_PTR(-EINVAL); | |
2843 | ||
2844 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2845 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2846 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2847 | return ERR_PTR(-EINVAL); | |
2848 | ||
2849 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2850 | return ERR_PTR(-EINVAL); | |
2851 | ||
2852 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2853 | if (n_entries < 0) | |
2854 | return ERR_PTR(n_entries); | |
2855 | ||
2856 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2857 | return ERR_PTR(-ENOTSUPP); | |
2858 | ||
2859 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2860 | GFP_KERNEL); | |
2861 | if (!acl) | |
2862 | return ERR_PTR(-ENOMEM); | |
2863 | ||
2864 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2865 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2866 | i++; | |
2867 | } | |
2868 | ||
2869 | acl->n_acl_entries = n_entries; | |
2870 | acl->acl_policy = acl_policy; | |
2871 | ||
2872 | return acl; | |
2873 | } | |
2874 | ||
2875 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2876 | { | |
2877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2878 | struct net_device *dev = info->user_ptr[1]; | |
2879 | struct cfg80211_acl_data *acl; | |
2880 | int err; | |
2881 | ||
2882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2883 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2884 | return -EOPNOTSUPP; | |
2885 | ||
2886 | if (!dev->ieee80211_ptr->beacon_interval) | |
2887 | return -EINVAL; | |
2888 | ||
2889 | acl = parse_acl_data(&rdev->wiphy, info); | |
2890 | if (IS_ERR(acl)) | |
2891 | return PTR_ERR(acl); | |
2892 | ||
2893 | err = rdev_set_mac_acl(rdev, dev, acl); | |
2894 | ||
2895 | kfree(acl); | |
2896 | ||
2897 | return err; | |
2898 | } | |
2899 | ||
a1193be8 | 2900 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 2901 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 2902 | { |
8860020e | 2903 | bool haveinfo = false; |
ed1b6cc7 | 2904 | |
a1193be8 SW |
2905 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
2906 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
2907 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2908 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2909 | return -EINVAL; |
2910 | ||
8860020e | 2911 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2912 | |
a1193be8 SW |
2913 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
2914 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
2915 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
2916 | if (!bcn->head_len) |
2917 | return -EINVAL; | |
2918 | haveinfo = true; | |
ed1b6cc7 JB |
2919 | } |
2920 | ||
a1193be8 SW |
2921 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
2922 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
2923 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 2924 | haveinfo = true; |
ed1b6cc7 JB |
2925 | } |
2926 | ||
4c476991 JB |
2927 | if (!haveinfo) |
2928 | return -EINVAL; | |
3b85875a | 2929 | |
a1193be8 SW |
2930 | if (attrs[NL80211_ATTR_IE]) { |
2931 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
2932 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2933 | } |
2934 | ||
a1193be8 | 2935 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 2936 | bcn->proberesp_ies = |
a1193be8 | 2937 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2938 | bcn->proberesp_ies_len = |
a1193be8 | 2939 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
2940 | } |
2941 | ||
a1193be8 | 2942 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 2943 | bcn->assocresp_ies = |
a1193be8 | 2944 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2945 | bcn->assocresp_ies_len = |
a1193be8 | 2946 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
2947 | } |
2948 | ||
a1193be8 SW |
2949 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
2950 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
2951 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
2952 | } |
2953 | ||
8860020e JB |
2954 | return 0; |
2955 | } | |
2956 | ||
46c1dd0c FF |
2957 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2958 | struct cfg80211_ap_settings *params) | |
2959 | { | |
2960 | struct wireless_dev *wdev; | |
2961 | bool ret = false; | |
2962 | ||
89a54e48 | 2963 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
2964 | if (wdev->iftype != NL80211_IFTYPE_AP && |
2965 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2966 | continue; | |
2967 | ||
683b6d3b | 2968 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
2969 | continue; |
2970 | ||
683b6d3b | 2971 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
2972 | ret = true; |
2973 | break; | |
2974 | } | |
2975 | ||
46c1dd0c FF |
2976 | return ret; |
2977 | } | |
2978 | ||
e39e5b5e JM |
2979 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
2980 | enum nl80211_auth_type auth_type, | |
2981 | enum nl80211_commands cmd) | |
2982 | { | |
2983 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
2984 | return false; | |
2985 | ||
2986 | switch (cmd) { | |
2987 | case NL80211_CMD_AUTHENTICATE: | |
2988 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
2989 | auth_type == NL80211_AUTHTYPE_SAE) | |
2990 | return false; | |
2991 | return true; | |
2992 | case NL80211_CMD_CONNECT: | |
2993 | case NL80211_CMD_START_AP: | |
2994 | /* SAE not supported yet */ | |
2995 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
2996 | return false; | |
2997 | return true; | |
2998 | default: | |
2999 | return false; | |
3000 | } | |
3001 | } | |
3002 | ||
8860020e JB |
3003 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3004 | { | |
3005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3006 | struct net_device *dev = info->user_ptr[1]; | |
3007 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3008 | struct cfg80211_ap_settings params; | |
3009 | int err; | |
04f39047 | 3010 | u8 radar_detect_width = 0; |
8860020e JB |
3011 | |
3012 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3013 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3014 | return -EOPNOTSUPP; | |
3015 | ||
3016 | if (!rdev->ops->start_ap) | |
3017 | return -EOPNOTSUPP; | |
3018 | ||
3019 | if (wdev->beacon_interval) | |
3020 | return -EALREADY; | |
3021 | ||
3022 | memset(¶ms, 0, sizeof(params)); | |
3023 | ||
3024 | /* these are required for START_AP */ | |
3025 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3026 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3027 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3028 | return -EINVAL; | |
3029 | ||
a1193be8 | 3030 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3031 | if (err) |
3032 | return err; | |
3033 | ||
3034 | params.beacon_interval = | |
3035 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3036 | params.dtim_period = | |
3037 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3038 | ||
3039 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3040 | if (err) | |
3041 | return err; | |
3042 | ||
3043 | /* | |
3044 | * In theory, some of these attributes should be required here | |
3045 | * but since they were not used when the command was originally | |
3046 | * added, keep them optional for old user space programs to let | |
3047 | * them continue to work with drivers that do not need the | |
3048 | * additional information -- drivers must check! | |
3049 | */ | |
3050 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3051 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3052 | params.ssid_len = | |
3053 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3054 | if (params.ssid_len == 0 || | |
3055 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3056 | return -EINVAL; | |
3057 | } | |
3058 | ||
3059 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3060 | params.hidden_ssid = nla_get_u32( | |
3061 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3062 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3063 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3064 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3065 | return -EINVAL; | |
3066 | } | |
3067 | ||
3068 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3069 | ||
3070 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3071 | params.auth_type = nla_get_u32( | |
3072 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3073 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3074 | NL80211_CMD_START_AP)) | |
8860020e JB |
3075 | return -EINVAL; |
3076 | } else | |
3077 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3078 | ||
3079 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3080 | NL80211_MAX_NR_CIPHER_SUITES); | |
3081 | if (err) | |
3082 | return err; | |
3083 | ||
1b658f11 VT |
3084 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3085 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3086 | return -EOPNOTSUPP; | |
3087 | params.inactivity_timeout = nla_get_u16( | |
3088 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3089 | } | |
3090 | ||
53cabad7 JB |
3091 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3092 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3093 | return -EINVAL; | |
3094 | params.p2p_ctwindow = | |
3095 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3096 | if (params.p2p_ctwindow > 127) | |
3097 | return -EINVAL; | |
3098 | if (params.p2p_ctwindow != 0 && | |
3099 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3100 | return -EINVAL; | |
3101 | } | |
3102 | ||
3103 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3104 | u8 tmp; | |
3105 | ||
3106 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3107 | return -EINVAL; | |
3108 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3109 | if (tmp > 1) | |
3110 | return -EINVAL; | |
3111 | params.p2p_opp_ps = tmp; | |
3112 | if (params.p2p_opp_ps != 0 && | |
3113 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3114 | return -EINVAL; | |
3115 | } | |
3116 | ||
aa430da4 | 3117 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3118 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3119 | if (err) | |
3120 | return err; | |
3121 | } else if (wdev->preset_chandef.chan) { | |
3122 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3123 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3124 | return -EINVAL; |
3125 | ||
683b6d3b | 3126 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3127 | return -EINVAL; |
3128 | ||
04f39047 SW |
3129 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3130 | if (err < 0) | |
3131 | return err; | |
3132 | if (err) { | |
3133 | radar_detect_width = BIT(params.chandef.width); | |
3134 | params.radar_required = true; | |
3135 | } | |
3136 | ||
04f39047 SW |
3137 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3138 | params.chandef.chan, | |
3139 | CHAN_MODE_SHARED, | |
3140 | radar_detect_width); | |
e4e32459 MK |
3141 | if (err) |
3142 | return err; | |
3143 | ||
77765eaf VT |
3144 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3145 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3146 | if (IS_ERR(params.acl)) | |
3147 | return PTR_ERR(params.acl); | |
3148 | } | |
3149 | ||
e35e4d28 | 3150 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3151 | if (!err) { |
683b6d3b | 3152 | wdev->preset_chandef = params.chandef; |
8860020e | 3153 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3154 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3155 | wdev->ssid_len = params.ssid_len; |
3156 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3157 | } |
77765eaf VT |
3158 | |
3159 | kfree(params.acl); | |
3160 | ||
56d1893d | 3161 | return err; |
ed1b6cc7 JB |
3162 | } |
3163 | ||
8860020e JB |
3164 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3165 | { | |
3166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3167 | struct net_device *dev = info->user_ptr[1]; | |
3168 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3169 | struct cfg80211_beacon_data params; | |
3170 | int err; | |
3171 | ||
3172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3174 | return -EOPNOTSUPP; | |
3175 | ||
3176 | if (!rdev->ops->change_beacon) | |
3177 | return -EOPNOTSUPP; | |
3178 | ||
3179 | if (!wdev->beacon_interval) | |
3180 | return -EINVAL; | |
3181 | ||
a1193be8 | 3182 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3183 | if (err) |
3184 | return err; | |
3185 | ||
e35e4d28 | 3186 | return rdev_change_beacon(rdev, dev, ¶ms); |
8860020e JB |
3187 | } |
3188 | ||
3189 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3190 | { |
4c476991 JB |
3191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3192 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3193 | |
60771780 | 3194 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3195 | } |
3196 | ||
5727ef1b JB |
3197 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3198 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3199 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3200 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3201 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3202 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3203 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3204 | }; |
3205 | ||
eccb8e8f | 3206 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3207 | enum nl80211_iftype iftype, |
eccb8e8f | 3208 | struct station_parameters *params) |
5727ef1b JB |
3209 | { |
3210 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3211 | struct nlattr *nla; |
5727ef1b JB |
3212 | int flag; |
3213 | ||
eccb8e8f JB |
3214 | /* |
3215 | * Try parsing the new attribute first so userspace | |
3216 | * can specify both for older kernels. | |
3217 | */ | |
3218 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3219 | if (nla) { | |
3220 | struct nl80211_sta_flag_update *sta_flags; | |
3221 | ||
3222 | sta_flags = nla_data(nla); | |
3223 | params->sta_flags_mask = sta_flags->mask; | |
3224 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3225 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3226 | if ((params->sta_flags_mask | |
3227 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3228 | return -EINVAL; | |
3229 | return 0; | |
3230 | } | |
3231 | ||
3232 | /* if present, parse the old attribute */ | |
5727ef1b | 3233 | |
eccb8e8f | 3234 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3235 | if (!nla) |
3236 | return 0; | |
3237 | ||
3238 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3239 | nla, sta_flags_policy)) | |
3240 | return -EINVAL; | |
3241 | ||
bdd3ae3d JB |
3242 | /* |
3243 | * Only allow certain flags for interface types so that | |
3244 | * other attributes are silently ignored. Remember that | |
3245 | * this is backward compatibility code with old userspace | |
3246 | * and shouldn't be hit in other cases anyway. | |
3247 | */ | |
3248 | switch (iftype) { | |
3249 | case NL80211_IFTYPE_AP: | |
3250 | case NL80211_IFTYPE_AP_VLAN: | |
3251 | case NL80211_IFTYPE_P2P_GO: | |
3252 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3253 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3254 | BIT(NL80211_STA_FLAG_WME) | | |
3255 | BIT(NL80211_STA_FLAG_MFP); | |
3256 | break; | |
3257 | case NL80211_IFTYPE_P2P_CLIENT: | |
3258 | case NL80211_IFTYPE_STATION: | |
3259 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3260 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3261 | break; | |
3262 | case NL80211_IFTYPE_MESH_POINT: | |
3263 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3264 | BIT(NL80211_STA_FLAG_MFP) | | |
3265 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3266 | default: | |
3267 | return -EINVAL; | |
3268 | } | |
5727ef1b | 3269 | |
3383b5a6 JB |
3270 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3271 | if (flags[flag]) { | |
eccb8e8f | 3272 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3273 | |
3383b5a6 JB |
3274 | /* no longer support new API additions in old API */ |
3275 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3276 | return -EINVAL; | |
3277 | } | |
3278 | } | |
3279 | ||
5727ef1b JB |
3280 | return 0; |
3281 | } | |
3282 | ||
c8dcfd8a FF |
3283 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3284 | int attr) | |
3285 | { | |
3286 | struct nlattr *rate; | |
8eb41c8d VK |
3287 | u32 bitrate; |
3288 | u16 bitrate_compat; | |
c8dcfd8a FF |
3289 | |
3290 | rate = nla_nest_start(msg, attr); | |
3291 | if (!rate) | |
db9c64cf | 3292 | return false; |
c8dcfd8a FF |
3293 | |
3294 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3295 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3296 | /* report 16-bit bitrate only if we can */ |
3297 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3298 | if (bitrate > 0 && |
3299 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3300 | return false; | |
3301 | if (bitrate_compat > 0 && | |
3302 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3303 | return false; | |
3304 | ||
3305 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3306 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3307 | return false; | |
3308 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3309 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3310 | return false; | |
3311 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3312 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3313 | return false; | |
3314 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3315 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3316 | return false; | |
3317 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3318 | return false; | |
3319 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3320 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3321 | return false; | |
3322 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3323 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3324 | return false; | |
3325 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3326 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3327 | return false; | |
3328 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3329 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3330 | return false; | |
3331 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3332 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3333 | return false; | |
3334 | } | |
c8dcfd8a FF |
3335 | |
3336 | nla_nest_end(msg, rate); | |
3337 | return true; | |
c8dcfd8a FF |
3338 | } |
3339 | ||
119363c7 FF |
3340 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3341 | int id) | |
3342 | { | |
3343 | void *attr; | |
3344 | int i = 0; | |
3345 | ||
3346 | if (!mask) | |
3347 | return true; | |
3348 | ||
3349 | attr = nla_nest_start(msg, id); | |
3350 | if (!attr) | |
3351 | return false; | |
3352 | ||
3353 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3354 | if (!(mask & BIT(i))) | |
3355 | continue; | |
3356 | ||
3357 | if (nla_put_u8(msg, i, signal[i])) | |
3358 | return false; | |
3359 | } | |
3360 | ||
3361 | nla_nest_end(msg, attr); | |
3362 | ||
3363 | return true; | |
3364 | } | |
3365 | ||
15e47304 | 3366 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3367 | int flags, |
3368 | struct cfg80211_registered_device *rdev, | |
3369 | struct net_device *dev, | |
98b62183 | 3370 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3371 | { |
3372 | void *hdr; | |
f4263c98 | 3373 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3374 | |
15e47304 | 3375 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3376 | if (!hdr) |
3377 | return -1; | |
3378 | ||
9360ffd1 DM |
3379 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3380 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3381 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3382 | goto nla_put_failure; | |
f5ea9120 | 3383 | |
2ec600d6 LCC |
3384 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3385 | if (!sinfoattr) | |
fd5b74dc | 3386 | goto nla_put_failure; |
9360ffd1 DM |
3387 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3388 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3389 | sinfo->connected_time)) | |
3390 | goto nla_put_failure; | |
3391 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3392 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3393 | sinfo->inactive_time)) | |
3394 | goto nla_put_failure; | |
42745e03 VK |
3395 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3396 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3397 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3398 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3399 | goto nla_put_failure; |
42745e03 | 3400 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3401 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3402 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3403 | (u32)sinfo->tx_bytes)) |
3404 | goto nla_put_failure; | |
3405 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3406 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3407 | sinfo->rx_bytes)) | |
3408 | goto nla_put_failure; | |
3409 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3410 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3411 | sinfo->tx_bytes)) |
3412 | goto nla_put_failure; | |
3413 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3414 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3415 | goto nla_put_failure; | |
3416 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3417 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3418 | goto nla_put_failure; | |
3419 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3420 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3421 | sinfo->plink_state)) | |
3422 | goto nla_put_failure; | |
66266b3a JL |
3423 | switch (rdev->wiphy.signal_type) { |
3424 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3425 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3426 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3427 | sinfo->signal)) | |
3428 | goto nla_put_failure; | |
3429 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3430 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3431 | sinfo->signal_avg)) | |
3432 | goto nla_put_failure; | |
66266b3a JL |
3433 | break; |
3434 | default: | |
3435 | break; | |
3436 | } | |
119363c7 FF |
3437 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3438 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3439 | sinfo->chain_signal, | |
3440 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3441 | goto nla_put_failure; | |
3442 | } | |
3443 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3444 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3445 | sinfo->chain_signal_avg, | |
3446 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3447 | goto nla_put_failure; | |
3448 | } | |
420e7fab | 3449 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3450 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3451 | NL80211_STA_INFO_TX_BITRATE)) | |
3452 | goto nla_put_failure; | |
3453 | } | |
3454 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3455 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3456 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3457 | goto nla_put_failure; |
420e7fab | 3458 | } |
9360ffd1 DM |
3459 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3460 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3461 | sinfo->rx_packets)) | |
3462 | goto nla_put_failure; | |
3463 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3464 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3465 | sinfo->tx_packets)) | |
3466 | goto nla_put_failure; | |
3467 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3468 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3469 | sinfo->tx_retries)) | |
3470 | goto nla_put_failure; | |
3471 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3472 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3473 | sinfo->tx_failed)) | |
3474 | goto nla_put_failure; | |
3475 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3476 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3477 | sinfo->beacon_loss_count)) | |
3478 | goto nla_put_failure; | |
3b1c5a53 MP |
3479 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3480 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3481 | sinfo->local_pm)) | |
3482 | goto nla_put_failure; | |
3483 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3484 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3485 | sinfo->peer_pm)) | |
3486 | goto nla_put_failure; | |
3487 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3488 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3489 | sinfo->nonpeer_pm)) | |
3490 | goto nla_put_failure; | |
f4263c98 PS |
3491 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3492 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3493 | if (!bss_param) | |
3494 | goto nla_put_failure; | |
3495 | ||
9360ffd1 DM |
3496 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3497 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3498 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3499 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3500 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3501 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3502 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3503 | sinfo->bss_param.dtim_period) || | |
3504 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3505 | sinfo->bss_param.beacon_interval)) | |
3506 | goto nla_put_failure; | |
f4263c98 PS |
3507 | |
3508 | nla_nest_end(msg, bss_param); | |
3509 | } | |
9360ffd1 DM |
3510 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3511 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3512 | sizeof(struct nl80211_sta_flag_update), | |
3513 | &sinfo->sta_flags)) | |
3514 | goto nla_put_failure; | |
7eab0f64 JL |
3515 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3516 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3517 | sinfo->t_offset)) | |
3518 | goto nla_put_failure; | |
2ec600d6 | 3519 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3520 | |
9360ffd1 DM |
3521 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3522 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3523 | sinfo->assoc_req_ies)) | |
3524 | goto nla_put_failure; | |
50d3dfb7 | 3525 | |
fd5b74dc JB |
3526 | return genlmsg_end(msg, hdr); |
3527 | ||
3528 | nla_put_failure: | |
bc3ed28c TG |
3529 | genlmsg_cancel(msg, hdr); |
3530 | return -EMSGSIZE; | |
fd5b74dc JB |
3531 | } |
3532 | ||
2ec600d6 | 3533 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3534 | struct netlink_callback *cb) |
2ec600d6 | 3535 | { |
2ec600d6 LCC |
3536 | struct station_info sinfo; |
3537 | struct cfg80211_registered_device *dev; | |
97990a06 | 3538 | struct wireless_dev *wdev; |
2ec600d6 | 3539 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3540 | int sta_idx = cb->args[2]; |
2ec600d6 | 3541 | int err; |
2ec600d6 | 3542 | |
97990a06 | 3543 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3544 | if (err) |
3545 | return err; | |
bba95fef | 3546 | |
97990a06 JB |
3547 | if (!wdev->netdev) { |
3548 | err = -EINVAL; | |
3549 | goto out_err; | |
3550 | } | |
3551 | ||
bba95fef | 3552 | if (!dev->ops->dump_station) { |
eec60b03 | 3553 | err = -EOPNOTSUPP; |
bba95fef JB |
3554 | goto out_err; |
3555 | } | |
3556 | ||
bba95fef | 3557 | while (1) { |
f612cedf | 3558 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3559 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3560 | mac_addr, &sinfo); |
bba95fef JB |
3561 | if (err == -ENOENT) |
3562 | break; | |
3563 | if (err) | |
3b85875a | 3564 | goto out_err; |
bba95fef JB |
3565 | |
3566 | if (nl80211_send_station(skb, | |
15e47304 | 3567 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3568 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3569 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3570 | &sinfo) < 0) |
3571 | goto out; | |
3572 | ||
3573 | sta_idx++; | |
3574 | } | |
3575 | ||
3576 | ||
3577 | out: | |
97990a06 | 3578 | cb->args[2] = sta_idx; |
bba95fef | 3579 | err = skb->len; |
bba95fef | 3580 | out_err: |
97990a06 | 3581 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3582 | |
3583 | return err; | |
2ec600d6 | 3584 | } |
fd5b74dc | 3585 | |
5727ef1b JB |
3586 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3587 | { | |
4c476991 JB |
3588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3589 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3590 | struct station_info sinfo; |
fd5b74dc JB |
3591 | struct sk_buff *msg; |
3592 | u8 *mac_addr = NULL; | |
4c476991 | 3593 | int err; |
fd5b74dc | 3594 | |
2ec600d6 | 3595 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3596 | |
3597 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3598 | return -EINVAL; | |
3599 | ||
3600 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3601 | ||
4c476991 JB |
3602 | if (!rdev->ops->get_station) |
3603 | return -EOPNOTSUPP; | |
3b85875a | 3604 | |
e35e4d28 | 3605 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3606 | if (err) |
4c476991 | 3607 | return err; |
2ec600d6 | 3608 | |
fd2120ca | 3609 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3610 | if (!msg) |
4c476991 | 3611 | return -ENOMEM; |
fd5b74dc | 3612 | |
15e47304 | 3613 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3614 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3615 | nlmsg_free(msg); |
3616 | return -ENOBUFS; | |
3617 | } | |
3b85875a | 3618 | |
4c476991 | 3619 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3620 | } |
3621 | ||
77ee7c89 JB |
3622 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3623 | struct station_parameters *params, | |
3624 | enum cfg80211_station_type statype) | |
3625 | { | |
3626 | if (params->listen_interval != -1) | |
3627 | return -EINVAL; | |
3628 | if (params->aid) | |
3629 | return -EINVAL; | |
3630 | ||
3631 | /* When you run into this, adjust the code below for the new flag */ | |
3632 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3633 | ||
3634 | switch (statype) { | |
eef941e6 TP |
3635 | case CFG80211_STA_MESH_PEER_KERNEL: |
3636 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3637 | /* |
3638 | * No ignoring the TDLS flag here -- the userspace mesh | |
3639 | * code doesn't have the bug of including TDLS in the | |
3640 | * mask everywhere. | |
3641 | */ | |
3642 | if (params->sta_flags_mask & | |
3643 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3644 | BIT(NL80211_STA_FLAG_MFP) | | |
3645 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3646 | return -EINVAL; | |
3647 | break; | |
3648 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3649 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3650 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3651 | return -EINVAL; | |
3652 | /* ignore since it can't change */ | |
3653 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3654 | break; | |
3655 | default: | |
3656 | /* disallow mesh-specific things */ | |
3657 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3658 | return -EINVAL; | |
3659 | if (params->local_pm) | |
3660 | return -EINVAL; | |
3661 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3662 | return -EINVAL; | |
3663 | } | |
3664 | ||
3665 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3666 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3667 | /* TDLS can't be set, ... */ | |
3668 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3669 | return -EINVAL; | |
3670 | /* | |
3671 | * ... but don't bother the driver with it. This works around | |
3672 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3673 | * TLDS_PEER flag in the mask even for AP mode. | |
3674 | */ | |
3675 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3676 | } | |
3677 | ||
3678 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3679 | /* reject other things that can't change */ | |
3680 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3681 | return -EINVAL; | |
3682 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3683 | return -EINVAL; | |
3684 | if (params->supported_rates) | |
3685 | return -EINVAL; | |
3686 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3687 | return -EINVAL; | |
3688 | } | |
3689 | ||
3690 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3691 | if (params->vlan) | |
3692 | return -EINVAL; | |
3693 | } | |
3694 | ||
3695 | switch (statype) { | |
3696 | case CFG80211_STA_AP_MLME_CLIENT: | |
3697 | /* Use this only for authorizing/unauthorizing a station */ | |
3698 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3699 | return -EOPNOTSUPP; | |
3700 | break; | |
3701 | case CFG80211_STA_AP_CLIENT: | |
3702 | /* accept only the listed bits */ | |
3703 | if (params->sta_flags_mask & | |
3704 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3705 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3706 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3707 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3708 | BIT(NL80211_STA_FLAG_WME) | | |
3709 | BIT(NL80211_STA_FLAG_MFP))) | |
3710 | return -EINVAL; | |
3711 | ||
3712 | /* but authenticated/associated only if driver handles it */ | |
3713 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3714 | params->sta_flags_mask & | |
3715 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3716 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3717 | return -EINVAL; | |
3718 | break; | |
3719 | case CFG80211_STA_IBSS: | |
3720 | case CFG80211_STA_AP_STA: | |
3721 | /* reject any changes other than AUTHORIZED */ | |
3722 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3723 | return -EINVAL; | |
3724 | break; | |
3725 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3726 | /* reject any changes other than AUTHORIZED or WME */ | |
3727 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3728 | BIT(NL80211_STA_FLAG_WME))) | |
3729 | return -EINVAL; | |
3730 | /* force (at least) rates when authorizing */ | |
3731 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3732 | !params->supported_rates) | |
3733 | return -EINVAL; | |
3734 | break; | |
3735 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3736 | /* reject any changes */ | |
3737 | return -EINVAL; | |
eef941e6 | 3738 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3739 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3740 | return -EINVAL; | |
3741 | break; | |
eef941e6 | 3742 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3743 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3744 | return -EINVAL; | |
3745 | break; | |
3746 | } | |
3747 | ||
3748 | return 0; | |
3749 | } | |
3750 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3751 | ||
5727ef1b | 3752 | /* |
c258d2de | 3753 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3754 | */ |
80b99899 JB |
3755 | static struct net_device *get_vlan(struct genl_info *info, |
3756 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3757 | { |
463d0183 | 3758 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3759 | struct net_device *v; |
3760 | int ret; | |
3761 | ||
3762 | if (!vlanattr) | |
3763 | return NULL; | |
3764 | ||
3765 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3766 | if (!v) | |
3767 | return ERR_PTR(-ENODEV); | |
3768 | ||
3769 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3770 | ret = -EINVAL; | |
3771 | goto error; | |
5727ef1b | 3772 | } |
80b99899 | 3773 | |
77ee7c89 JB |
3774 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3775 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3776 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3777 | ret = -EINVAL; | |
3778 | goto error; | |
3779 | } | |
3780 | ||
80b99899 JB |
3781 | if (!netif_running(v)) { |
3782 | ret = -ENETDOWN; | |
3783 | goto error; | |
3784 | } | |
3785 | ||
3786 | return v; | |
3787 | error: | |
3788 | dev_put(v); | |
3789 | return ERR_PTR(ret); | |
5727ef1b JB |
3790 | } |
3791 | ||
df881293 JM |
3792 | static struct nla_policy |
3793 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3794 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3795 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3796 | }; | |
3797 | ||
ff276691 JB |
3798 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3799 | struct station_parameters *params) | |
df881293 | 3800 | { |
df881293 JM |
3801 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3802 | struct nlattr *nla; | |
3803 | int err; | |
3804 | ||
df881293 JM |
3805 | /* parse WME attributes if present */ |
3806 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3807 | return 0; | |
3808 | ||
3809 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3810 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3811 | nl80211_sta_wme_policy); | |
3812 | if (err) | |
3813 | return err; | |
3814 | ||
3815 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3816 | params->uapsd_queues = nla_get_u8( | |
3817 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3818 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3819 | return -EINVAL; | |
3820 | ||
3821 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3822 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3823 | ||
3824 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3825 | return -EINVAL; | |
3826 | ||
3827 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3828 | ||
3829 | return 0; | |
3830 | } | |
3831 | ||
ff276691 JB |
3832 | static int nl80211_set_station_tdls(struct genl_info *info, |
3833 | struct station_parameters *params) | |
3834 | { | |
3835 | /* Dummy STA entry gets updated once the peer capabilities are known */ | |
5e4b6f56 JM |
3836 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
3837 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
3838 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3839 | params->ht_capa = | |
3840 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3841 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3842 | params->vht_capa = | |
3843 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3844 | ||
3845 | return nl80211_parse_sta_wme(info, params); | |
3846 | } | |
3847 | ||
5727ef1b JB |
3848 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
3849 | { | |
4c476991 | 3850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3851 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 3852 | struct station_parameters params; |
77ee7c89 JB |
3853 | u8 *mac_addr; |
3854 | int err; | |
5727ef1b JB |
3855 | |
3856 | memset(¶ms, 0, sizeof(params)); | |
3857 | ||
3858 | params.listen_interval = -1; | |
3859 | ||
77ee7c89 JB |
3860 | if (!rdev->ops->change_station) |
3861 | return -EOPNOTSUPP; | |
3862 | ||
5727ef1b JB |
3863 | if (info->attrs[NL80211_ATTR_STA_AID]) |
3864 | return -EINVAL; | |
3865 | ||
3866 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3867 | return -EINVAL; | |
3868 | ||
3869 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3870 | ||
3871 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
3872 | params.supported_rates = | |
3873 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3874 | params.supported_rates_len = | |
3875 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3876 | } | |
3877 | ||
9d62a986 JM |
3878 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3879 | params.capability = | |
3880 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
3881 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
3882 | } | |
3883 | ||
3884 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
3885 | params.ext_capab = | |
3886 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3887 | params.ext_capab_len = | |
3888 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
3889 | } | |
3890 | ||
df881293 | 3891 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 3892 | return -EINVAL; |
36aedc90 | 3893 | |
bdd3ae3d | 3894 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3895 | return -EINVAL; |
3896 | ||
f8bacc21 | 3897 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 3898 | params.plink_action = |
f8bacc21 JB |
3899 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
3900 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
3901 | return -EINVAL; | |
3902 | } | |
2ec600d6 | 3903 | |
f8bacc21 | 3904 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 3905 | params.plink_state = |
f8bacc21 JB |
3906 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
3907 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
3908 | return -EINVAL; | |
3909 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
3910 | } | |
9c3990aa | 3911 | |
3b1c5a53 MP |
3912 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
3913 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
3914 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
3915 | ||
3916 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
3917 | pm > NL80211_MESH_POWER_MAX) | |
3918 | return -EINVAL; | |
3919 | ||
3920 | params.local_pm = pm; | |
3921 | } | |
3922 | ||
77ee7c89 JB |
3923 | /* Include parameters for TDLS peer (will check later) */ |
3924 | err = nl80211_set_station_tdls(info, ¶ms); | |
3925 | if (err) | |
3926 | return err; | |
3927 | ||
3928 | params.vlan = get_vlan(info, rdev); | |
3929 | if (IS_ERR(params.vlan)) | |
3930 | return PTR_ERR(params.vlan); | |
3931 | ||
a97f4424 JB |
3932 | switch (dev->ieee80211_ptr->iftype) { |
3933 | case NL80211_IFTYPE_AP: | |
3934 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 3935 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 3936 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 3937 | case NL80211_IFTYPE_STATION: |
267335d6 | 3938 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 3939 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
3940 | break; |
3941 | default: | |
77ee7c89 JB |
3942 | err = -EOPNOTSUPP; |
3943 | goto out_put_vlan; | |
034d655e JB |
3944 | } |
3945 | ||
77ee7c89 | 3946 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 3947 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 3948 | |
77ee7c89 | 3949 | out_put_vlan: |
5727ef1b JB |
3950 | if (params.vlan) |
3951 | dev_put(params.vlan); | |
3b85875a | 3952 | |
5727ef1b JB |
3953 | return err; |
3954 | } | |
3955 | ||
3956 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
3957 | { | |
4c476991 | 3958 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3959 | int err; |
4c476991 | 3960 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3961 | struct station_parameters params; |
3962 | u8 *mac_addr = NULL; | |
3963 | ||
3964 | memset(¶ms, 0, sizeof(params)); | |
3965 | ||
984c311b JB |
3966 | if (!rdev->ops->add_station) |
3967 | return -EOPNOTSUPP; | |
3968 | ||
5727ef1b JB |
3969 | if (!info->attrs[NL80211_ATTR_MAC]) |
3970 | return -EINVAL; | |
3971 | ||
5727ef1b JB |
3972 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3973 | return -EINVAL; | |
3974 | ||
3975 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3976 | return -EINVAL; | |
3977 | ||
5e4b6f56 JM |
3978 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
3979 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
3980 | return -EINVAL; |
3981 | ||
5727ef1b JB |
3982 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3983 | params.supported_rates = | |
3984 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3985 | params.supported_rates_len = | |
3986 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3987 | params.listen_interval = | |
3988 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3989 | |
3d124ea2 | 3990 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 3991 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
3992 | else |
3993 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
3994 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
3995 | return -EINVAL; | |
51b50fbe | 3996 | |
9d62a986 JM |
3997 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
3998 | params.capability = | |
3999 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4000 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4001 | } | |
4002 | ||
4003 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4004 | params.ext_capab = | |
4005 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4006 | params.ext_capab_len = | |
4007 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4008 | } | |
4009 | ||
36aedc90 JM |
4010 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4011 | params.ht_capa = | |
4012 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4013 | |
f461be3e MP |
4014 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4015 | params.vht_capa = | |
4016 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4017 | ||
f8bacc21 | 4018 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4019 | params.plink_action = |
f8bacc21 JB |
4020 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4021 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4022 | return -EINVAL; | |
4023 | } | |
96b78dff | 4024 | |
ff276691 JB |
4025 | err = nl80211_parse_sta_wme(info, ¶ms); |
4026 | if (err) | |
4027 | return err; | |
bdd90d5e | 4028 | |
bdd3ae3d | 4029 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4030 | return -EINVAL; |
4031 | ||
77ee7c89 JB |
4032 | /* When you run into this, adjust the code below for the new flag */ |
4033 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4034 | ||
bdd90d5e JB |
4035 | switch (dev->ieee80211_ptr->iftype) { |
4036 | case NL80211_IFTYPE_AP: | |
4037 | case NL80211_IFTYPE_AP_VLAN: | |
4038 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4039 | /* ignore WME attributes if iface/sta is not capable */ |
4040 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4041 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4042 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4043 | |
bdd90d5e | 4044 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4045 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4046 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4047 | return -EINVAL; |
bdd90d5e JB |
4048 | /* but don't bother the driver with it */ |
4049 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4050 | |
d582cffb JB |
4051 | /* allow authenticated/associated only if driver handles it */ |
4052 | if (!(rdev->wiphy.features & | |
4053 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4054 | params.sta_flags_mask & | |
4055 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4056 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4057 | return -EINVAL; | |
4058 | ||
bdd90d5e JB |
4059 | /* must be last in here for error handling */ |
4060 | params.vlan = get_vlan(info, rdev); | |
4061 | if (IS_ERR(params.vlan)) | |
4062 | return PTR_ERR(params.vlan); | |
4063 | break; | |
4064 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4065 | /* ignore uAPSD data */ |
4066 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4067 | ||
d582cffb JB |
4068 | /* associated is disallowed */ |
4069 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4070 | return -EINVAL; | |
bdd90d5e | 4071 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4072 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4073 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4074 | return -EINVAL; |
4075 | break; | |
4076 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4077 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4078 | /* ignore uAPSD data */ |
4079 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4080 | ||
77ee7c89 JB |
4081 | /* these are disallowed */ |
4082 | if (params.sta_flags_mask & | |
4083 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4084 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4085 | return -EINVAL; |
bdd90d5e JB |
4086 | /* Only TDLS peers can be added */ |
4087 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4088 | return -EINVAL; | |
4089 | /* Can only add if TDLS ... */ | |
4090 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4091 | return -EOPNOTSUPP; | |
4092 | /* ... with external setup is supported */ | |
4093 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4094 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4095 | /* |
4096 | * Older wpa_supplicant versions always mark the TDLS peer | |
4097 | * as authorized, but it shouldn't yet be. | |
4098 | */ | |
4099 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4100 | break; |
4101 | default: | |
4102 | return -EOPNOTSUPP; | |
c75786c9 EP |
4103 | } |
4104 | ||
bdd90d5e | 4105 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4106 | |
e35e4d28 | 4107 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4108 | |
5727ef1b JB |
4109 | if (params.vlan) |
4110 | dev_put(params.vlan); | |
5727ef1b JB |
4111 | return err; |
4112 | } | |
4113 | ||
4114 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4115 | { | |
4c476991 JB |
4116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4117 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4118 | u8 *mac_addr = NULL; |
4119 | ||
4120 | if (info->attrs[NL80211_ATTR_MAC]) | |
4121 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4122 | ||
e80cf853 | 4123 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4124 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4125 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4126 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4127 | return -EINVAL; | |
5727ef1b | 4128 | |
4c476991 JB |
4129 | if (!rdev->ops->del_station) |
4130 | return -EOPNOTSUPP; | |
3b85875a | 4131 | |
e35e4d28 | 4132 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4133 | } |
4134 | ||
15e47304 | 4135 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4136 | int flags, struct net_device *dev, |
4137 | u8 *dst, u8 *next_hop, | |
4138 | struct mpath_info *pinfo) | |
4139 | { | |
4140 | void *hdr; | |
4141 | struct nlattr *pinfoattr; | |
4142 | ||
15e47304 | 4143 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4144 | if (!hdr) |
4145 | return -1; | |
4146 | ||
9360ffd1 DM |
4147 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4148 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4149 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4150 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4151 | goto nla_put_failure; | |
f5ea9120 | 4152 | |
2ec600d6 LCC |
4153 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4154 | if (!pinfoattr) | |
4155 | goto nla_put_failure; | |
9360ffd1 DM |
4156 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4157 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4158 | pinfo->frame_qlen)) | |
4159 | goto nla_put_failure; | |
4160 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4161 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4162 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4163 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4164 | pinfo->metric)) || | |
4165 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4166 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4167 | pinfo->exptime)) || | |
4168 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4169 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4170 | pinfo->flags)) || | |
4171 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4172 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4173 | pinfo->discovery_timeout)) || | |
4174 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4175 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4176 | pinfo->discovery_retries))) | |
4177 | goto nla_put_failure; | |
2ec600d6 LCC |
4178 | |
4179 | nla_nest_end(msg, pinfoattr); | |
4180 | ||
4181 | return genlmsg_end(msg, hdr); | |
4182 | ||
4183 | nla_put_failure: | |
bc3ed28c TG |
4184 | genlmsg_cancel(msg, hdr); |
4185 | return -EMSGSIZE; | |
2ec600d6 LCC |
4186 | } |
4187 | ||
4188 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4189 | struct netlink_callback *cb) |
2ec600d6 | 4190 | { |
2ec600d6 LCC |
4191 | struct mpath_info pinfo; |
4192 | struct cfg80211_registered_device *dev; | |
97990a06 | 4193 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4194 | u8 dst[ETH_ALEN]; |
4195 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4196 | int path_idx = cb->args[2]; |
2ec600d6 | 4197 | int err; |
2ec600d6 | 4198 | |
97990a06 | 4199 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4200 | if (err) |
4201 | return err; | |
bba95fef JB |
4202 | |
4203 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4204 | err = -EOPNOTSUPP; |
bba95fef JB |
4205 | goto out_err; |
4206 | } | |
4207 | ||
97990a06 | 4208 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4209 | err = -EOPNOTSUPP; |
0448b5fc | 4210 | goto out_err; |
eec60b03 JM |
4211 | } |
4212 | ||
bba95fef | 4213 | while (1) { |
97990a06 JB |
4214 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4215 | next_hop, &pinfo); | |
bba95fef | 4216 | if (err == -ENOENT) |
2ec600d6 | 4217 | break; |
bba95fef | 4218 | if (err) |
3b85875a | 4219 | goto out_err; |
2ec600d6 | 4220 | |
15e47304 | 4221 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4222 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4223 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4224 | &pinfo) < 0) |
4225 | goto out; | |
2ec600d6 | 4226 | |
bba95fef | 4227 | path_idx++; |
2ec600d6 | 4228 | } |
2ec600d6 | 4229 | |
2ec600d6 | 4230 | |
bba95fef | 4231 | out: |
97990a06 | 4232 | cb->args[2] = path_idx; |
bba95fef | 4233 | err = skb->len; |
bba95fef | 4234 | out_err: |
97990a06 | 4235 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4236 | return err; |
2ec600d6 LCC |
4237 | } |
4238 | ||
4239 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4240 | { | |
4c476991 | 4241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4242 | int err; |
4c476991 | 4243 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4244 | struct mpath_info pinfo; |
4245 | struct sk_buff *msg; | |
4246 | u8 *dst = NULL; | |
4247 | u8 next_hop[ETH_ALEN]; | |
4248 | ||
4249 | memset(&pinfo, 0, sizeof(pinfo)); | |
4250 | ||
4251 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4252 | return -EINVAL; | |
4253 | ||
4254 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4255 | ||
4c476991 JB |
4256 | if (!rdev->ops->get_mpath) |
4257 | return -EOPNOTSUPP; | |
2ec600d6 | 4258 | |
4c476991 JB |
4259 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4260 | return -EOPNOTSUPP; | |
eec60b03 | 4261 | |
e35e4d28 | 4262 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4263 | if (err) |
4c476991 | 4264 | return err; |
2ec600d6 | 4265 | |
fd2120ca | 4266 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4267 | if (!msg) |
4c476991 | 4268 | return -ENOMEM; |
2ec600d6 | 4269 | |
15e47304 | 4270 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4271 | dev, dst, next_hop, &pinfo) < 0) { |
4272 | nlmsg_free(msg); | |
4273 | return -ENOBUFS; | |
4274 | } | |
3b85875a | 4275 | |
4c476991 | 4276 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4277 | } |
4278 | ||
4279 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4280 | { | |
4c476991 JB |
4281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4282 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4283 | u8 *dst = NULL; |
4284 | u8 *next_hop = NULL; | |
4285 | ||
4286 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4287 | return -EINVAL; | |
4288 | ||
4289 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4290 | return -EINVAL; | |
4291 | ||
4292 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4293 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4294 | ||
4c476991 JB |
4295 | if (!rdev->ops->change_mpath) |
4296 | return -EOPNOTSUPP; | |
35a8efe1 | 4297 | |
4c476991 JB |
4298 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4299 | return -EOPNOTSUPP; | |
2ec600d6 | 4300 | |
e35e4d28 | 4301 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4302 | } |
4c476991 | 4303 | |
2ec600d6 LCC |
4304 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4305 | { | |
4c476991 JB |
4306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4307 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4308 | u8 *dst = NULL; |
4309 | u8 *next_hop = NULL; | |
4310 | ||
4311 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4312 | return -EINVAL; | |
4313 | ||
4314 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4315 | return -EINVAL; | |
4316 | ||
4317 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4318 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4319 | ||
4c476991 JB |
4320 | if (!rdev->ops->add_mpath) |
4321 | return -EOPNOTSUPP; | |
35a8efe1 | 4322 | |
4c476991 JB |
4323 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4324 | return -EOPNOTSUPP; | |
2ec600d6 | 4325 | |
e35e4d28 | 4326 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4327 | } |
4328 | ||
4329 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4330 | { | |
4c476991 JB |
4331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4332 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4333 | u8 *dst = NULL; |
4334 | ||
4335 | if (info->attrs[NL80211_ATTR_MAC]) | |
4336 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4337 | ||
4c476991 JB |
4338 | if (!rdev->ops->del_mpath) |
4339 | return -EOPNOTSUPP; | |
3b85875a | 4340 | |
e35e4d28 | 4341 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4342 | } |
4343 | ||
9f1ba906 JM |
4344 | static int nl80211_set_bss(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]; | |
9f1ba906 JM |
4348 | struct bss_parameters params; |
4349 | ||
4350 | memset(¶ms, 0, sizeof(params)); | |
4351 | /* default to not changing parameters */ | |
4352 | params.use_cts_prot = -1; | |
4353 | params.use_short_preamble = -1; | |
4354 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4355 | params.ap_isolate = -1; |
50b12f59 | 4356 | params.ht_opmode = -1; |
53cabad7 JB |
4357 | params.p2p_ctwindow = -1; |
4358 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4359 | |
4360 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4361 | params.use_cts_prot = | |
4362 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4363 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4364 | params.use_short_preamble = | |
4365 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4366 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4367 | params.use_short_slot_time = | |
4368 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4369 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4370 | params.basic_rates = | |
4371 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4372 | params.basic_rates_len = | |
4373 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4374 | } | |
fd8aaaf3 FF |
4375 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4376 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4377 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4378 | params.ht_opmode = | |
4379 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4380 | |
53cabad7 JB |
4381 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4382 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4383 | return -EINVAL; | |
4384 | params.p2p_ctwindow = | |
4385 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4386 | if (params.p2p_ctwindow < 0) | |
4387 | return -EINVAL; | |
4388 | if (params.p2p_ctwindow != 0 && | |
4389 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4390 | return -EINVAL; | |
4391 | } | |
4392 | ||
4393 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4394 | u8 tmp; | |
4395 | ||
4396 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4397 | return -EINVAL; | |
4398 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4399 | if (tmp > 1) | |
4400 | return -EINVAL; | |
4401 | params.p2p_opp_ps = tmp; | |
4402 | if (params.p2p_opp_ps && | |
4403 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4404 | return -EINVAL; | |
4405 | } | |
4406 | ||
4c476991 JB |
4407 | if (!rdev->ops->change_bss) |
4408 | return -EOPNOTSUPP; | |
9f1ba906 | 4409 | |
074ac8df | 4410 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4411 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4412 | return -EOPNOTSUPP; | |
3b85875a | 4413 | |
e35e4d28 | 4414 | return rdev_change_bss(rdev, dev, ¶ms); |
9f1ba906 JM |
4415 | } |
4416 | ||
b54452b0 | 4417 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4418 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4419 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4420 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4421 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4422 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4423 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4424 | }; | |
4425 | ||
4426 | static int parse_reg_rule(struct nlattr *tb[], | |
4427 | struct ieee80211_reg_rule *reg_rule) | |
4428 | { | |
4429 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4430 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4431 | ||
4432 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4433 | return -EINVAL; | |
4434 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4435 | return -EINVAL; | |
4436 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4437 | return -EINVAL; | |
4438 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4439 | return -EINVAL; | |
4440 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4441 | return -EINVAL; | |
4442 | ||
4443 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4444 | ||
4445 | freq_range->start_freq_khz = | |
4446 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4447 | freq_range->end_freq_khz = | |
4448 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4449 | freq_range->max_bandwidth_khz = | |
4450 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4451 | ||
4452 | power_rule->max_eirp = | |
4453 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4454 | ||
4455 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4456 | power_rule->max_antenna_gain = | |
4457 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4458 | ||
4459 | return 0; | |
4460 | } | |
4461 | ||
4462 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4463 | { | |
4464 | int r; | |
4465 | char *data = NULL; | |
57b5ce07 | 4466 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4467 | |
80778f18 LR |
4468 | /* |
4469 | * You should only get this when cfg80211 hasn't yet initialized | |
4470 | * completely when built-in to the kernel right between the time | |
4471 | * window between nl80211_init() and regulatory_init(), if that is | |
4472 | * even possible. | |
4473 | */ | |
458f4f9e | 4474 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4475 | return -EINPROGRESS; |
80778f18 | 4476 | |
fe33eb39 LR |
4477 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4478 | return -EINVAL; | |
b2e1b302 LR |
4479 | |
4480 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4481 | ||
57b5ce07 LR |
4482 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4483 | user_reg_hint_type = | |
4484 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4485 | else | |
4486 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4487 | ||
4488 | switch (user_reg_hint_type) { | |
4489 | case NL80211_USER_REG_HINT_USER: | |
4490 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4491 | break; | |
4492 | default: | |
4493 | return -EINVAL; | |
4494 | } | |
4495 | ||
4496 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4497 | |
b2e1b302 LR |
4498 | return r; |
4499 | } | |
4500 | ||
24bdd9f4 | 4501 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4502 | struct genl_info *info) |
93da9cc1 | 4503 | { |
4c476991 | 4504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4505 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4506 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4507 | struct mesh_config cur_params; | |
4508 | int err = 0; | |
93da9cc1 | 4509 | void *hdr; |
4510 | struct nlattr *pinfoattr; | |
4511 | struct sk_buff *msg; | |
4512 | ||
29cbe68c JB |
4513 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4514 | return -EOPNOTSUPP; | |
4515 | ||
24bdd9f4 | 4516 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4517 | return -EOPNOTSUPP; |
f3f92586 | 4518 | |
29cbe68c JB |
4519 | wdev_lock(wdev); |
4520 | /* If not connected, get default parameters */ | |
4521 | if (!wdev->mesh_id_len) | |
4522 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4523 | else | |
e35e4d28 | 4524 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4525 | wdev_unlock(wdev); |
4526 | ||
93da9cc1 | 4527 | if (err) |
4c476991 | 4528 | return err; |
93da9cc1 | 4529 | |
4530 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4532 | if (!msg) |
4533 | return -ENOMEM; | |
15e47304 | 4534 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4535 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4536 | if (!hdr) |
efe1cf0c | 4537 | goto out; |
24bdd9f4 | 4538 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4539 | if (!pinfoattr) |
4540 | goto nla_put_failure; | |
9360ffd1 DM |
4541 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4542 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4543 | cur_params.dot11MeshRetryTimeout) || | |
4544 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4545 | cur_params.dot11MeshConfirmTimeout) || | |
4546 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4547 | cur_params.dot11MeshHoldingTimeout) || | |
4548 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4549 | cur_params.dot11MeshMaxPeerLinks) || | |
4550 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4551 | cur_params.dot11MeshMaxRetries) || | |
4552 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4553 | cur_params.dot11MeshTTL) || | |
4554 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4555 | cur_params.element_ttl) || | |
4556 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4557 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4558 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4559 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4560 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4561 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4562 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4563 | cur_params.path_refresh_time) || | |
4564 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4565 | cur_params.min_discovery_timeout) || | |
4566 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4567 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4568 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4569 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4570 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4571 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4572 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4573 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4574 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4575 | cur_params.dot11MeshHWMPRootMode) || | |
4576 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4577 | cur_params.dot11MeshHWMPRannInterval) || | |
4578 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4579 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4580 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4581 | cur_params.dot11MeshForwarding) || | |
4582 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4583 | cur_params.rssi_threshold) || |
4584 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4585 | cur_params.ht_opmode) || |
4586 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4587 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4588 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4589 | cur_params.dot11MeshHWMProotInterval) || |
4590 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4591 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4592 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4593 | cur_params.power_mode) || | |
4594 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4595 | cur_params.dot11MeshAwakeWindowDuration) || |
4596 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4597 | cur_params.plink_timeout)) | |
9360ffd1 | 4598 | goto nla_put_failure; |
93da9cc1 | 4599 | nla_nest_end(msg, pinfoattr); |
4600 | genlmsg_end(msg, hdr); | |
4c476991 | 4601 | return genlmsg_reply(msg, info); |
93da9cc1 | 4602 | |
3b85875a | 4603 | nla_put_failure: |
93da9cc1 | 4604 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4605 | out: |
d080e275 | 4606 | nlmsg_free(msg); |
4c476991 | 4607 | return -ENOBUFS; |
93da9cc1 | 4608 | } |
4609 | ||
b54452b0 | 4610 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4611 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4612 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4613 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4614 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4615 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4616 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4617 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4618 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4619 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4620 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4621 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4622 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4623 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4624 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4625 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4626 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4627 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4628 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4629 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4630 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4631 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4632 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4633 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4634 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4635 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4636 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4637 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4638 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4639 | }; |
4640 | ||
c80d545d JC |
4641 | static const struct nla_policy |
4642 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4643 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4644 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4645 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4646 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4647 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4648 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4649 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4650 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4651 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4652 | }; |
4653 | ||
24bdd9f4 | 4654 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4655 | struct mesh_config *cfg, |
4656 | u32 *mask_out) | |
93da9cc1 | 4657 | { |
93da9cc1 | 4658 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4659 | u32 mask = 0; |
93da9cc1 | 4660 | |
ea54fba2 MP |
4661 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4662 | do { \ | |
4663 | if (tb[attr]) { \ | |
4664 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4665 | return -EINVAL; \ | |
4666 | cfg->param = fn(tb[attr]); \ | |
4667 | mask |= (1 << (attr - 1)); \ | |
4668 | } \ | |
4669 | } while (0) | |
bd90fdcc JB |
4670 | |
4671 | ||
24bdd9f4 | 4672 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4673 | return -EINVAL; |
4674 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4675 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4676 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4677 | return -EINVAL; |
4678 | ||
93da9cc1 | 4679 | /* This makes sure that there aren't more than 32 mesh config |
4680 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4681 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4682 | ||
4683 | /* Fill in the params struct */ | |
ea54fba2 | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4685 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4686 | nla_get_u16); | |
ea54fba2 | 4687 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4688 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4689 | nla_get_u16); | |
ea54fba2 | 4690 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4691 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4692 | nla_get_u16); | |
ea54fba2 | 4693 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4694 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4695 | nla_get_u16); | |
ea54fba2 | 4696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4697 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4698 | nla_get_u8); | |
ea54fba2 | 4699 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4700 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4702 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4703 | nla_get_u8); | |
ea54fba2 | 4704 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4705 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4706 | nla_get_u8); | |
ea54fba2 MP |
4707 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4708 | 1, 255, mask, | |
a4f606ea CYY |
4709 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4710 | nla_get_u32); | |
ea54fba2 | 4711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4712 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4713 | nla_get_u8); | |
ea54fba2 | 4714 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4715 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4716 | nla_get_u32); | |
ea54fba2 | 4717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4718 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4719 | nla_get_u16); | |
ea54fba2 MP |
4720 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4721 | 1, 65535, mask, | |
a4f606ea CYY |
4722 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4723 | nla_get_u32); | |
93da9cc1 | 4724 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4725 | 1, 65535, mask, |
4726 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4727 | nla_get_u16); |
dca7e943 | 4728 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4729 | 1, 65535, mask, |
4730 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4731 | nla_get_u16); |
93da9cc1 | 4732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4733 | dot11MeshHWMPnetDiameterTraversalTime, |
4734 | 1, 65535, mask, | |
a4f606ea CYY |
4735 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4736 | nla_get_u16); | |
ea54fba2 MP |
4737 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4738 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4739 | nla_get_u8); | |
4740 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4741 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4742 | nla_get_u16); |
63c5723b | 4743 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4744 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4745 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4746 | nla_get_u8); |
ea54fba2 | 4747 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4748 | mask, NL80211_MESHCONF_FORWARDING, |
4749 | nla_get_u8); | |
ea54fba2 | 4750 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
a4f606ea CYY |
4751 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
4752 | nla_get_u32); | |
ea54fba2 | 4753 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4754 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4755 | nla_get_u16); |
4756 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4757 | 1, 65535, mask, |
ac1073a6 CYY |
4758 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4759 | nla_get_u32); | |
ea54fba2 | 4760 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4761 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4762 | nla_get_u16); |
4763 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4764 | dot11MeshHWMPconfirmationInterval, |
4765 | 1, 65535, mask, | |
728b19e5 | 4766 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4767 | nla_get_u16); |
3b1c5a53 MP |
4768 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4769 | NL80211_MESH_POWER_ACTIVE, | |
4770 | NL80211_MESH_POWER_MAX, | |
4771 | mask, NL80211_MESHCONF_POWER_MODE, | |
4772 | nla_get_u32); | |
4773 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4774 | 0, 65535, mask, | |
4775 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
4776 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
4777 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4778 | nla_get_u32); | |
bd90fdcc JB |
4779 | if (mask_out) |
4780 | *mask_out = mask; | |
c80d545d | 4781 | |
bd90fdcc JB |
4782 | return 0; |
4783 | ||
4784 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4785 | } | |
4786 | ||
c80d545d JC |
4787 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4788 | struct mesh_setup *setup) | |
4789 | { | |
bb2798d4 | 4790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4791 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4792 | ||
4793 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4794 | return -EINVAL; | |
4795 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4796 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4797 | nl80211_mesh_setup_params_policy)) | |
4798 | return -EINVAL; | |
4799 | ||
d299a1f2 JC |
4800 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4801 | setup->sync_method = | |
4802 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4803 | IEEE80211_SYNC_METHOD_VENDOR : | |
4804 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4805 | ||
c80d545d JC |
4806 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4807 | setup->path_sel_proto = | |
4808 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4809 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4810 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4811 | ||
4812 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4813 | setup->path_metric = | |
4814 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4815 | IEEE80211_PATH_METRIC_VENDOR : | |
4816 | IEEE80211_PATH_METRIC_AIRTIME; | |
4817 | ||
581a8b0f JC |
4818 | |
4819 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4820 | struct nlattr *ieattr = |
581a8b0f | 4821 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4822 | if (!is_valid_ie_attr(ieattr)) |
4823 | return -EINVAL; | |
581a8b0f JC |
4824 | setup->ie = nla_data(ieattr); |
4825 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4826 | } |
bb2798d4 TP |
4827 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4828 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4829 | return -EINVAL; | |
4830 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
4831 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
4832 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
4833 | if (setup->is_secure) |
4834 | setup->user_mpm = true; | |
c80d545d | 4835 | |
6e16d90b CT |
4836 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
4837 | if (!setup->user_mpm) | |
4838 | return -EINVAL; | |
4839 | setup->auth_id = | |
4840 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
4841 | } | |
4842 | ||
c80d545d JC |
4843 | return 0; |
4844 | } | |
4845 | ||
24bdd9f4 | 4846 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 4847 | struct genl_info *info) |
bd90fdcc JB |
4848 | { |
4849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4850 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 4851 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
4852 | struct mesh_config cfg; |
4853 | u32 mask; | |
4854 | int err; | |
4855 | ||
29cbe68c JB |
4856 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4857 | return -EOPNOTSUPP; | |
4858 | ||
24bdd9f4 | 4859 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
4860 | return -EOPNOTSUPP; |
4861 | ||
24bdd9f4 | 4862 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
4863 | if (err) |
4864 | return err; | |
4865 | ||
29cbe68c JB |
4866 | wdev_lock(wdev); |
4867 | if (!wdev->mesh_id_len) | |
4868 | err = -ENOLINK; | |
4869 | ||
4870 | if (!err) | |
e35e4d28 | 4871 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
4872 | |
4873 | wdev_unlock(wdev); | |
4874 | ||
4875 | return err; | |
93da9cc1 | 4876 | } |
4877 | ||
f130347c LR |
4878 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
4879 | { | |
458f4f9e | 4880 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
4881 | struct sk_buff *msg; |
4882 | void *hdr = NULL; | |
4883 | struct nlattr *nl_reg_rules; | |
4884 | unsigned int i; | |
f130347c LR |
4885 | |
4886 | if (!cfg80211_regdomain) | |
5fe231e8 | 4887 | return -EINVAL; |
f130347c | 4888 | |
fd2120ca | 4889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
4890 | if (!msg) |
4891 | return -ENOBUFS; | |
f130347c | 4892 | |
15e47304 | 4893 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
4894 | NL80211_CMD_GET_REG); |
4895 | if (!hdr) | |
efe1cf0c | 4896 | goto put_failure; |
f130347c | 4897 | |
57b5ce07 LR |
4898 | if (reg_last_request_cell_base() && |
4899 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
4900 | NL80211_USER_REG_HINT_CELL_BASE)) | |
4901 | goto nla_put_failure; | |
4902 | ||
458f4f9e JB |
4903 | rcu_read_lock(); |
4904 | regdom = rcu_dereference(cfg80211_regdomain); | |
4905 | ||
4906 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
4907 | (regdom->dfs_region && | |
4908 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
4909 | goto nla_put_failure_rcu; | |
4910 | ||
f130347c LR |
4911 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
4912 | if (!nl_reg_rules) | |
458f4f9e | 4913 | goto nla_put_failure_rcu; |
f130347c | 4914 | |
458f4f9e | 4915 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
4916 | struct nlattr *nl_reg_rule; |
4917 | const struct ieee80211_reg_rule *reg_rule; | |
4918 | const struct ieee80211_freq_range *freq_range; | |
4919 | const struct ieee80211_power_rule *power_rule; | |
4920 | ||
458f4f9e | 4921 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
4922 | freq_range = ®_rule->freq_range; |
4923 | power_rule = ®_rule->power_rule; | |
4924 | ||
4925 | nl_reg_rule = nla_nest_start(msg, i); | |
4926 | if (!nl_reg_rule) | |
458f4f9e | 4927 | goto nla_put_failure_rcu; |
f130347c | 4928 | |
9360ffd1 DM |
4929 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
4930 | reg_rule->flags) || | |
4931 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
4932 | freq_range->start_freq_khz) || | |
4933 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
4934 | freq_range->end_freq_khz) || | |
4935 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
4936 | freq_range->max_bandwidth_khz) || | |
4937 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
4938 | power_rule->max_antenna_gain) || | |
4939 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
4940 | power_rule->max_eirp)) | |
458f4f9e | 4941 | goto nla_put_failure_rcu; |
f130347c LR |
4942 | |
4943 | nla_nest_end(msg, nl_reg_rule); | |
4944 | } | |
458f4f9e | 4945 | rcu_read_unlock(); |
f130347c LR |
4946 | |
4947 | nla_nest_end(msg, nl_reg_rules); | |
4948 | ||
4949 | genlmsg_end(msg, hdr); | |
5fe231e8 | 4950 | return genlmsg_reply(msg, info); |
f130347c | 4951 | |
458f4f9e JB |
4952 | nla_put_failure_rcu: |
4953 | rcu_read_unlock(); | |
f130347c LR |
4954 | nla_put_failure: |
4955 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 4956 | put_failure: |
d080e275 | 4957 | nlmsg_free(msg); |
5fe231e8 | 4958 | return -EMSGSIZE; |
f130347c LR |
4959 | } |
4960 | ||
b2e1b302 LR |
4961 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
4962 | { | |
4963 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
4964 | struct nlattr *nl_reg_rule; | |
4965 | char *alpha2 = NULL; | |
4966 | int rem_reg_rules = 0, r = 0; | |
4967 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 4968 | u8 dfs_region = 0; |
b2e1b302 LR |
4969 | struct ieee80211_regdomain *rd = NULL; |
4970 | ||
4971 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
4972 | return -EINVAL; | |
4973 | ||
4974 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
4975 | return -EINVAL; | |
4976 | ||
4977 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4978 | ||
8b60b078 LR |
4979 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
4980 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
4981 | ||
b2e1b302 | 4982 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 4983 | rem_reg_rules) { |
b2e1b302 LR |
4984 | num_rules++; |
4985 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 4986 | return -EINVAL; |
b2e1b302 LR |
4987 | } |
4988 | ||
b2e1b302 | 4989 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 4990 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
4991 | |
4992 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
4993 | if (!rd) |
4994 | return -ENOMEM; | |
b2e1b302 LR |
4995 | |
4996 | rd->n_reg_rules = num_rules; | |
4997 | rd->alpha2[0] = alpha2[0]; | |
4998 | rd->alpha2[1] = alpha2[1]; | |
4999 | ||
8b60b078 LR |
5000 | /* |
5001 | * Disable DFS master mode if the DFS region was | |
5002 | * not supported or known on this kernel. | |
5003 | */ | |
5004 | if (reg_supported_dfs_region(dfs_region)) | |
5005 | rd->dfs_region = dfs_region; | |
5006 | ||
b2e1b302 | 5007 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5008 | rem_reg_rules) { |
b2e1b302 | 5009 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
5010 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
5011 | reg_rule_policy); | |
b2e1b302 LR |
5012 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5013 | if (r) | |
5014 | goto bad_reg; | |
5015 | ||
5016 | rule_idx++; | |
5017 | ||
d0e18f83 LR |
5018 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5019 | r = -EINVAL; | |
b2e1b302 | 5020 | goto bad_reg; |
d0e18f83 | 5021 | } |
b2e1b302 LR |
5022 | } |
5023 | ||
b2e1b302 | 5024 | r = set_regdom(rd); |
6913b49a | 5025 | /* set_regdom took ownership */ |
1a919318 | 5026 | rd = NULL; |
b2e1b302 | 5027 | |
d2372b31 | 5028 | bad_reg: |
b2e1b302 | 5029 | kfree(rd); |
d0e18f83 | 5030 | return r; |
b2e1b302 LR |
5031 | } |
5032 | ||
83f5e2cf JB |
5033 | static int validate_scan_freqs(struct nlattr *freqs) |
5034 | { | |
5035 | struct nlattr *attr1, *attr2; | |
5036 | int n_channels = 0, tmp1, tmp2; | |
5037 | ||
5038 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5039 | n_channels++; | |
5040 | /* | |
5041 | * Some hardware has a limited channel list for | |
5042 | * scanning, and it is pretty much nonsensical | |
5043 | * to scan for a channel twice, so disallow that | |
5044 | * and don't require drivers to check that the | |
5045 | * channel list they get isn't longer than what | |
5046 | * they can scan, as long as they can scan all | |
5047 | * the channels they registered at once. | |
5048 | */ | |
5049 | nla_for_each_nested(attr2, freqs, tmp2) | |
5050 | if (attr1 != attr2 && | |
5051 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5052 | return 0; | |
5053 | } | |
5054 | ||
5055 | return n_channels; | |
5056 | } | |
5057 | ||
2a519311 JB |
5058 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5059 | { | |
4c476991 | 5060 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5061 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5062 | struct cfg80211_scan_request *request; |
2a519311 JB |
5063 | struct nlattr *attr; |
5064 | struct wiphy *wiphy; | |
83f5e2cf | 5065 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5066 | size_t ie_len; |
2a519311 | 5067 | |
f4a11bb0 JB |
5068 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5069 | return -EINVAL; | |
5070 | ||
79c97e97 | 5071 | wiphy = &rdev->wiphy; |
2a519311 | 5072 | |
4c476991 JB |
5073 | if (!rdev->ops->scan) |
5074 | return -EOPNOTSUPP; | |
2a519311 | 5075 | |
f9f47529 JB |
5076 | if (rdev->scan_req) { |
5077 | err = -EBUSY; | |
5078 | goto unlock; | |
5079 | } | |
2a519311 JB |
5080 | |
5081 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5082 | n_channels = validate_scan_freqs( |
5083 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5084 | if (!n_channels) { |
5085 | err = -EINVAL; | |
5086 | goto unlock; | |
5087 | } | |
2a519311 | 5088 | } else { |
34850ab2 | 5089 | enum ieee80211_band band; |
83f5e2cf JB |
5090 | n_channels = 0; |
5091 | ||
2a519311 JB |
5092 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
5093 | if (wiphy->bands[band]) | |
5094 | n_channels += wiphy->bands[band]->n_channels; | |
5095 | } | |
5096 | ||
5097 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5098 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5099 | n_ssids++; | |
5100 | ||
f9f47529 JB |
5101 | if (n_ssids > wiphy->max_scan_ssids) { |
5102 | err = -EINVAL; | |
5103 | goto unlock; | |
5104 | } | |
2a519311 | 5105 | |
70692ad2 JM |
5106 | if (info->attrs[NL80211_ATTR_IE]) |
5107 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5108 | else | |
5109 | ie_len = 0; | |
5110 | ||
f9f47529 JB |
5111 | if (ie_len > wiphy->max_scan_ie_len) { |
5112 | err = -EINVAL; | |
5113 | goto unlock; | |
5114 | } | |
18a83659 | 5115 | |
2a519311 | 5116 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5117 | + sizeof(*request->ssids) * n_ssids |
5118 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5119 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5120 | if (!request) { |
5121 | err = -ENOMEM; | |
5122 | goto unlock; | |
5123 | } | |
2a519311 | 5124 | |
2a519311 | 5125 | if (n_ssids) |
5ba63533 | 5126 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5127 | request->n_ssids = n_ssids; |
70692ad2 JM |
5128 | if (ie_len) { |
5129 | if (request->ssids) | |
5130 | request->ie = (void *)(request->ssids + n_ssids); | |
5131 | else | |
5132 | request->ie = (void *)(request->channels + n_channels); | |
5133 | } | |
2a519311 | 5134 | |
584991dc | 5135 | i = 0; |
2a519311 JB |
5136 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5137 | /* user specified, bail out if channel not found */ | |
2a519311 | 5138 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5139 | struct ieee80211_channel *chan; |
5140 | ||
5141 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5142 | ||
5143 | if (!chan) { | |
2a519311 JB |
5144 | err = -EINVAL; |
5145 | goto out_free; | |
5146 | } | |
584991dc JB |
5147 | |
5148 | /* ignore disabled channels */ | |
5149 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5150 | continue; | |
5151 | ||
5152 | request->channels[i] = chan; | |
2a519311 JB |
5153 | i++; |
5154 | } | |
5155 | } else { | |
34850ab2 JB |
5156 | enum ieee80211_band band; |
5157 | ||
2a519311 | 5158 | /* all channels */ |
2a519311 JB |
5159 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5160 | int j; | |
5161 | if (!wiphy->bands[band]) | |
5162 | continue; | |
5163 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5164 | struct ieee80211_channel *chan; |
5165 | ||
5166 | chan = &wiphy->bands[band]->channels[j]; | |
5167 | ||
5168 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5169 | continue; | |
5170 | ||
5171 | request->channels[i] = chan; | |
2a519311 JB |
5172 | i++; |
5173 | } | |
5174 | } | |
5175 | } | |
5176 | ||
584991dc JB |
5177 | if (!i) { |
5178 | err = -EINVAL; | |
5179 | goto out_free; | |
5180 | } | |
5181 | ||
5182 | request->n_channels = i; | |
5183 | ||
2a519311 JB |
5184 | i = 0; |
5185 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5186 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5187 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5188 | err = -EINVAL; |
5189 | goto out_free; | |
5190 | } | |
57a27e1d | 5191 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5192 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5193 | i++; |
5194 | } | |
5195 | } | |
5196 | ||
70692ad2 JM |
5197 | if (info->attrs[NL80211_ATTR_IE]) { |
5198 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5199 | memcpy((void *)request->ie, |
5200 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5201 | request->ie_len); |
5202 | } | |
5203 | ||
34850ab2 | 5204 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5205 | if (wiphy->bands[i]) |
5206 | request->rates[i] = | |
5207 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5208 | |
5209 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5210 | nla_for_each_nested(attr, | |
5211 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5212 | tmp) { | |
5213 | enum ieee80211_band band = nla_type(attr); | |
5214 | ||
84404623 | 5215 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5216 | err = -EINVAL; |
5217 | goto out_free; | |
5218 | } | |
5219 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
5220 | nla_data(attr), | |
5221 | nla_len(attr), | |
5222 | &request->rates[band]); | |
5223 | if (err) | |
5224 | goto out_free; | |
5225 | } | |
5226 | } | |
5227 | ||
46856bbf | 5228 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5229 | request->flags = nla_get_u32( |
5230 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5231 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5232 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5233 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5234 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5235 | err = -EOPNOTSUPP; |
5236 | goto out_free; | |
5237 | } | |
5238 | } | |
ed473771 | 5239 | |
e9f935e3 RM |
5240 | request->no_cck = |
5241 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5242 | ||
fd014284 | 5243 | request->wdev = wdev; |
79c97e97 | 5244 | request->wiphy = &rdev->wiphy; |
15d6030b | 5245 | request->scan_start = jiffies; |
2a519311 | 5246 | |
79c97e97 | 5247 | rdev->scan_req = request; |
e35e4d28 | 5248 | err = rdev_scan(rdev, request); |
2a519311 | 5249 | |
463d0183 | 5250 | if (!err) { |
fd014284 JB |
5251 | nl80211_send_scan_start(rdev, wdev); |
5252 | if (wdev->netdev) | |
5253 | dev_hold(wdev->netdev); | |
4c476991 | 5254 | } else { |
2a519311 | 5255 | out_free: |
79c97e97 | 5256 | rdev->scan_req = NULL; |
2a519311 JB |
5257 | kfree(request); |
5258 | } | |
3b85875a | 5259 | |
f9f47529 | 5260 | unlock: |
2a519311 JB |
5261 | return err; |
5262 | } | |
5263 | ||
807f8a8c LC |
5264 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5265 | struct genl_info *info) | |
5266 | { | |
5267 | struct cfg80211_sched_scan_request *request; | |
5268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5269 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5270 | struct nlattr *attr; |
5271 | struct wiphy *wiphy; | |
a1f1c21c | 5272 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5273 | u32 interval; |
807f8a8c LC |
5274 | enum ieee80211_band band; |
5275 | size_t ie_len; | |
a1f1c21c | 5276 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5277 | |
5278 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5279 | !rdev->ops->sched_scan_start) | |
5280 | return -EOPNOTSUPP; | |
5281 | ||
5282 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5283 | return -EINVAL; | |
5284 | ||
bbe6ad6d LC |
5285 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5286 | return -EINVAL; | |
5287 | ||
5288 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5289 | if (interval == 0) | |
5290 | return -EINVAL; | |
5291 | ||
807f8a8c LC |
5292 | wiphy = &rdev->wiphy; |
5293 | ||
5294 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5295 | n_channels = validate_scan_freqs( | |
5296 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5297 | if (!n_channels) | |
5298 | return -EINVAL; | |
5299 | } else { | |
5300 | n_channels = 0; | |
5301 | ||
5302 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
5303 | if (wiphy->bands[band]) | |
5304 | n_channels += wiphy->bands[band]->n_channels; | |
5305 | } | |
5306 | ||
5307 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5308 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5309 | tmp) | |
5310 | n_ssids++; | |
5311 | ||
93b6aa69 | 5312 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5313 | return -EINVAL; |
5314 | ||
a1f1c21c LC |
5315 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5316 | nla_for_each_nested(attr, | |
5317 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5318 | tmp) | |
5319 | n_match_sets++; | |
5320 | ||
5321 | if (n_match_sets > wiphy->max_match_sets) | |
5322 | return -EINVAL; | |
5323 | ||
807f8a8c LC |
5324 | if (info->attrs[NL80211_ATTR_IE]) |
5325 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5326 | else | |
5327 | ie_len = 0; | |
5328 | ||
5a865bad | 5329 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5330 | return -EINVAL; |
5331 | ||
c10841ca LC |
5332 | if (rdev->sched_scan_req) { |
5333 | err = -EINPROGRESS; | |
5334 | goto out; | |
5335 | } | |
5336 | ||
807f8a8c | 5337 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5338 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5339 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5340 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5341 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5342 | if (!request) { |
5343 | err = -ENOMEM; | |
5344 | goto out; | |
5345 | } | |
807f8a8c LC |
5346 | |
5347 | if (n_ssids) | |
5348 | request->ssids = (void *)&request->channels[n_channels]; | |
5349 | request->n_ssids = n_ssids; | |
5350 | if (ie_len) { | |
5351 | if (request->ssids) | |
5352 | request->ie = (void *)(request->ssids + n_ssids); | |
5353 | else | |
5354 | request->ie = (void *)(request->channels + n_channels); | |
5355 | } | |
5356 | ||
a1f1c21c LC |
5357 | if (n_match_sets) { |
5358 | if (request->ie) | |
5359 | request->match_sets = (void *)(request->ie + ie_len); | |
5360 | else if (request->ssids) | |
5361 | request->match_sets = | |
5362 | (void *)(request->ssids + n_ssids); | |
5363 | else | |
5364 | request->match_sets = | |
5365 | (void *)(request->channels + n_channels); | |
5366 | } | |
5367 | request->n_match_sets = n_match_sets; | |
5368 | ||
807f8a8c LC |
5369 | i = 0; |
5370 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5371 | /* user specified, bail out if channel not found */ | |
5372 | nla_for_each_nested(attr, | |
5373 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5374 | tmp) { | |
5375 | struct ieee80211_channel *chan; | |
5376 | ||
5377 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5378 | ||
5379 | if (!chan) { | |
5380 | err = -EINVAL; | |
5381 | goto out_free; | |
5382 | } | |
5383 | ||
5384 | /* ignore disabled channels */ | |
5385 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5386 | continue; | |
5387 | ||
5388 | request->channels[i] = chan; | |
5389 | i++; | |
5390 | } | |
5391 | } else { | |
5392 | /* all channels */ | |
5393 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5394 | int j; | |
5395 | if (!wiphy->bands[band]) | |
5396 | continue; | |
5397 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5398 | struct ieee80211_channel *chan; | |
5399 | ||
5400 | chan = &wiphy->bands[band]->channels[j]; | |
5401 | ||
5402 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5403 | continue; | |
5404 | ||
5405 | request->channels[i] = chan; | |
5406 | i++; | |
5407 | } | |
5408 | } | |
5409 | } | |
5410 | ||
5411 | if (!i) { | |
5412 | err = -EINVAL; | |
5413 | goto out_free; | |
5414 | } | |
5415 | ||
5416 | request->n_channels = i; | |
5417 | ||
5418 | i = 0; | |
5419 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5420 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5421 | tmp) { | |
57a27e1d | 5422 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5423 | err = -EINVAL; |
5424 | goto out_free; | |
5425 | } | |
57a27e1d | 5426 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5427 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5428 | nla_len(attr)); | |
807f8a8c LC |
5429 | i++; |
5430 | } | |
5431 | } | |
5432 | ||
a1f1c21c LC |
5433 | i = 0; |
5434 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5435 | nla_for_each_nested(attr, | |
5436 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5437 | tmp) { | |
88e920b4 | 5438 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5439 | |
5440 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5441 | nla_data(attr), nla_len(attr), | |
5442 | nl80211_match_policy); | |
4a4ab0d7 | 5443 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5444 | if (ssid) { |
5445 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5446 | err = -EINVAL; | |
5447 | goto out_free; | |
5448 | } | |
5449 | memcpy(request->match_sets[i].ssid.ssid, | |
5450 | nla_data(ssid), nla_len(ssid)); | |
5451 | request->match_sets[i].ssid.ssid_len = | |
5452 | nla_len(ssid); | |
5453 | } | |
88e920b4 TP |
5454 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5455 | if (rssi) | |
5456 | request->rssi_thold = nla_get_u32(rssi); | |
5457 | else | |
5458 | request->rssi_thold = | |
5459 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5460 | i++; |
5461 | } | |
5462 | } | |
5463 | ||
807f8a8c LC |
5464 | if (info->attrs[NL80211_ATTR_IE]) { |
5465 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5466 | memcpy((void *)request->ie, | |
5467 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5468 | request->ie_len); | |
5469 | } | |
5470 | ||
46856bbf | 5471 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5472 | request->flags = nla_get_u32( |
5473 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
15d6030b SL |
5474 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5475 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
5476 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && | |
5477 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { | |
46856bbf SL |
5478 | err = -EOPNOTSUPP; |
5479 | goto out_free; | |
5480 | } | |
5481 | } | |
ed473771 | 5482 | |
807f8a8c LC |
5483 | request->dev = dev; |
5484 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5485 | request->interval = interval; |
15d6030b | 5486 | request->scan_start = jiffies; |
807f8a8c | 5487 | |
e35e4d28 | 5488 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5489 | if (!err) { |
5490 | rdev->sched_scan_req = request; | |
5491 | nl80211_send_sched_scan(rdev, dev, | |
5492 | NL80211_CMD_START_SCHED_SCAN); | |
5493 | goto out; | |
5494 | } | |
5495 | ||
5496 | out_free: | |
5497 | kfree(request); | |
5498 | out: | |
5499 | return err; | |
5500 | } | |
5501 | ||
5502 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5503 | struct genl_info *info) | |
5504 | { | |
5505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5506 | ||
5507 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5508 | !rdev->ops->sched_scan_stop) | |
5509 | return -EOPNOTSUPP; | |
5510 | ||
5fe231e8 | 5511 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5512 | } |
5513 | ||
04f39047 SW |
5514 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5515 | struct genl_info *info) | |
5516 | { | |
5517 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5518 | struct net_device *dev = info->user_ptr[1]; | |
5519 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5520 | struct cfg80211_chan_def chandef; | |
5521 | int err; | |
5522 | ||
5523 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
5524 | if (err) | |
5525 | return err; | |
5526 | ||
5527 | if (wdev->cac_started) | |
5528 | return -EBUSY; | |
5529 | ||
5530 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5531 | if (err < 0) | |
5532 | return err; | |
5533 | ||
5534 | if (err == 0) | |
5535 | return -EINVAL; | |
5536 | ||
5537 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) | |
5538 | return -EINVAL; | |
5539 | ||
5540 | if (!rdev->ops->start_radar_detection) | |
5541 | return -EOPNOTSUPP; | |
5542 | ||
04f39047 SW |
5543 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5544 | chandef.chan, CHAN_MODE_SHARED, | |
5545 | BIT(chandef.width)); | |
5546 | if (err) | |
5fe231e8 | 5547 | return err; |
04f39047 SW |
5548 | |
5549 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5550 | if (!err) { | |
5551 | wdev->channel = chandef.chan; | |
5552 | wdev->cac_started = true; | |
5553 | wdev->cac_start_time = jiffies; | |
5554 | } | |
04f39047 SW |
5555 | return err; |
5556 | } | |
5557 | ||
9720bb3a JB |
5558 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5559 | u32 seq, int flags, | |
2a519311 | 5560 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5561 | struct wireless_dev *wdev, |
5562 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5563 | { |
48ab905d | 5564 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5565 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5566 | void *hdr; |
5567 | struct nlattr *bss; | |
8cef2c9d | 5568 | bool tsf = false; |
48ab905d JB |
5569 | |
5570 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5571 | |
15e47304 | 5572 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5573 | NL80211_CMD_NEW_SCAN_RESULTS); |
5574 | if (!hdr) | |
5575 | return -1; | |
5576 | ||
9720bb3a JB |
5577 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5578 | ||
97990a06 JB |
5579 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5580 | goto nla_put_failure; | |
5581 | if (wdev->netdev && | |
9360ffd1 DM |
5582 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5583 | goto nla_put_failure; | |
97990a06 JB |
5584 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5585 | goto nla_put_failure; | |
2a519311 JB |
5586 | |
5587 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5588 | if (!bss) | |
5589 | goto nla_put_failure; | |
9360ffd1 | 5590 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5591 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5592 | goto nla_put_failure; |
9caf0364 JB |
5593 | |
5594 | rcu_read_lock(); | |
5595 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5596 | if (ies) { |
5597 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5598 | goto fail_unlock_rcu; | |
5599 | tsf = true; | |
5600 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5601 | ies->len, ies->data)) | |
5602 | goto fail_unlock_rcu; | |
9caf0364 JB |
5603 | } |
5604 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5605 | if (ies) { |
5606 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5607 | goto fail_unlock_rcu; | |
5608 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5609 | ies->len, ies->data)) | |
5610 | goto fail_unlock_rcu; | |
9caf0364 JB |
5611 | } |
5612 | rcu_read_unlock(); | |
5613 | ||
9360ffd1 DM |
5614 | if (res->beacon_interval && |
5615 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5616 | goto nla_put_failure; | |
5617 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5618 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
5619 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
5620 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5621 | goto nla_put_failure; | |
2a519311 | 5622 | |
77965c97 | 5623 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5624 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5625 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5626 | goto nla_put_failure; | |
2a519311 JB |
5627 | break; |
5628 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5629 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5630 | goto nla_put_failure; | |
2a519311 JB |
5631 | break; |
5632 | default: | |
5633 | break; | |
5634 | } | |
5635 | ||
48ab905d | 5636 | switch (wdev->iftype) { |
074ac8df | 5637 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5638 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5639 | if (intbss == wdev->current_bss && |
5640 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5641 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5642 | goto nla_put_failure; | |
48ab905d JB |
5643 | break; |
5644 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5645 | if (intbss == wdev->current_bss && |
5646 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5647 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5648 | goto nla_put_failure; | |
48ab905d JB |
5649 | break; |
5650 | default: | |
5651 | break; | |
5652 | } | |
5653 | ||
2a519311 JB |
5654 | nla_nest_end(msg, bss); |
5655 | ||
5656 | return genlmsg_end(msg, hdr); | |
5657 | ||
8cef2c9d JB |
5658 | fail_unlock_rcu: |
5659 | rcu_read_unlock(); | |
2a519311 JB |
5660 | nla_put_failure: |
5661 | genlmsg_cancel(msg, hdr); | |
5662 | return -EMSGSIZE; | |
5663 | } | |
5664 | ||
97990a06 | 5665 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5666 | { |
48ab905d | 5667 | struct cfg80211_registered_device *rdev; |
2a519311 | 5668 | struct cfg80211_internal_bss *scan; |
48ab905d | 5669 | struct wireless_dev *wdev; |
97990a06 | 5670 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5671 | int err; |
5672 | ||
97990a06 | 5673 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5674 | if (err) |
5675 | return err; | |
2a519311 | 5676 | |
48ab905d JB |
5677 | wdev_lock(wdev); |
5678 | spin_lock_bh(&rdev->bss_lock); | |
5679 | cfg80211_bss_expire(rdev); | |
5680 | ||
9720bb3a JB |
5681 | cb->seq = rdev->bss_generation; |
5682 | ||
48ab905d | 5683 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5684 | if (++idx <= start) |
5685 | continue; | |
9720bb3a | 5686 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5687 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5688 | rdev, wdev, scan) < 0) { |
2a519311 | 5689 | idx--; |
67748893 | 5690 | break; |
2a519311 JB |
5691 | } |
5692 | } | |
5693 | ||
48ab905d JB |
5694 | spin_unlock_bh(&rdev->bss_lock); |
5695 | wdev_unlock(wdev); | |
2a519311 | 5696 | |
97990a06 JB |
5697 | cb->args[2] = idx; |
5698 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5699 | |
67748893 | 5700 | return skb->len; |
2a519311 JB |
5701 | } |
5702 | ||
15e47304 | 5703 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
5704 | int flags, struct net_device *dev, |
5705 | struct survey_info *survey) | |
5706 | { | |
5707 | void *hdr; | |
5708 | struct nlattr *infoattr; | |
5709 | ||
15e47304 | 5710 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
5711 | NL80211_CMD_NEW_SURVEY_RESULTS); |
5712 | if (!hdr) | |
5713 | return -ENOMEM; | |
5714 | ||
9360ffd1 DM |
5715 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
5716 | goto nla_put_failure; | |
61fa713c HS |
5717 | |
5718 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
5719 | if (!infoattr) | |
5720 | goto nla_put_failure; | |
5721 | ||
9360ffd1 DM |
5722 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
5723 | survey->channel->center_freq)) | |
5724 | goto nla_put_failure; | |
5725 | ||
5726 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
5727 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
5728 | goto nla_put_failure; | |
5729 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
5730 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
5731 | goto nla_put_failure; | |
5732 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
5733 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
5734 | survey->channel_time)) | |
5735 | goto nla_put_failure; | |
5736 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
5737 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
5738 | survey->channel_time_busy)) | |
5739 | goto nla_put_failure; | |
5740 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
5741 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
5742 | survey->channel_time_ext_busy)) | |
5743 | goto nla_put_failure; | |
5744 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
5745 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
5746 | survey->channel_time_rx)) | |
5747 | goto nla_put_failure; | |
5748 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
5749 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
5750 | survey->channel_time_tx)) | |
5751 | goto nla_put_failure; | |
61fa713c HS |
5752 | |
5753 | nla_nest_end(msg, infoattr); | |
5754 | ||
5755 | return genlmsg_end(msg, hdr); | |
5756 | ||
5757 | nla_put_failure: | |
5758 | genlmsg_cancel(msg, hdr); | |
5759 | return -EMSGSIZE; | |
5760 | } | |
5761 | ||
5762 | static int nl80211_dump_survey(struct sk_buff *skb, | |
5763 | struct netlink_callback *cb) | |
5764 | { | |
5765 | struct survey_info survey; | |
5766 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
5767 | struct wireless_dev *wdev; |
5768 | int survey_idx = cb->args[2]; | |
61fa713c HS |
5769 | int res; |
5770 | ||
97990a06 | 5771 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
5772 | if (res) |
5773 | return res; | |
61fa713c | 5774 | |
97990a06 JB |
5775 | if (!wdev->netdev) { |
5776 | res = -EINVAL; | |
5777 | goto out_err; | |
5778 | } | |
5779 | ||
61fa713c HS |
5780 | if (!dev->ops->dump_survey) { |
5781 | res = -EOPNOTSUPP; | |
5782 | goto out_err; | |
5783 | } | |
5784 | ||
5785 | while (1) { | |
180cdc79 LR |
5786 | struct ieee80211_channel *chan; |
5787 | ||
97990a06 | 5788 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
5789 | if (res == -ENOENT) |
5790 | break; | |
5791 | if (res) | |
5792 | goto out_err; | |
5793 | ||
180cdc79 LR |
5794 | /* Survey without a channel doesn't make sense */ |
5795 | if (!survey.channel) { | |
5796 | res = -EINVAL; | |
5797 | goto out; | |
5798 | } | |
5799 | ||
5800 | chan = ieee80211_get_channel(&dev->wiphy, | |
5801 | survey.channel->center_freq); | |
5802 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
5803 | survey_idx++; | |
5804 | continue; | |
5805 | } | |
5806 | ||
61fa713c | 5807 | if (nl80211_send_survey(skb, |
15e47304 | 5808 | NETLINK_CB(cb->skb).portid, |
61fa713c | 5809 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5810 | wdev->netdev, &survey) < 0) |
61fa713c HS |
5811 | goto out; |
5812 | survey_idx++; | |
5813 | } | |
5814 | ||
5815 | out: | |
97990a06 | 5816 | cb->args[2] = survey_idx; |
61fa713c HS |
5817 | res = skb->len; |
5818 | out_err: | |
97990a06 | 5819 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
5820 | return res; |
5821 | } | |
5822 | ||
b23aa676 SO |
5823 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
5824 | { | |
5825 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
5826 | NL80211_WPA_VERSION_2)); | |
5827 | } | |
5828 | ||
636a5d36 JM |
5829 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
5830 | { | |
4c476991 JB |
5831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5832 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5833 | struct ieee80211_channel *chan; |
e39e5b5e JM |
5834 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
5835 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 5836 | enum nl80211_auth_type auth_type; |
fffd0934 | 5837 | struct key_parse key; |
d5cdfacb | 5838 | bool local_state_change; |
636a5d36 | 5839 | |
f4a11bb0 JB |
5840 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5841 | return -EINVAL; | |
5842 | ||
5843 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5844 | return -EINVAL; | |
5845 | ||
1778092e JM |
5846 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
5847 | return -EINVAL; | |
5848 | ||
19957bb3 JB |
5849 | if (!info->attrs[NL80211_ATTR_SSID]) |
5850 | return -EINVAL; | |
5851 | ||
5852 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5853 | return -EINVAL; | |
5854 | ||
fffd0934 JB |
5855 | err = nl80211_parse_key(info, &key); |
5856 | if (err) | |
5857 | return err; | |
5858 | ||
5859 | if (key.idx >= 0) { | |
e31b8213 JB |
5860 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
5861 | return -EINVAL; | |
fffd0934 JB |
5862 | if (!key.p.key || !key.p.key_len) |
5863 | return -EINVAL; | |
5864 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
5865 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
5866 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
5867 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
5868 | return -EINVAL; | |
5869 | if (key.idx > 4) | |
5870 | return -EINVAL; | |
5871 | } else { | |
5872 | key.p.key_len = 0; | |
5873 | key.p.key = NULL; | |
5874 | } | |
5875 | ||
afea0b7a JB |
5876 | if (key.idx >= 0) { |
5877 | int i; | |
5878 | bool ok = false; | |
5879 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
5880 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
5881 | ok = true; | |
5882 | break; | |
5883 | } | |
5884 | } | |
4c476991 JB |
5885 | if (!ok) |
5886 | return -EINVAL; | |
afea0b7a JB |
5887 | } |
5888 | ||
4c476991 JB |
5889 | if (!rdev->ops->auth) |
5890 | return -EOPNOTSUPP; | |
636a5d36 | 5891 | |
074ac8df | 5892 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5893 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5894 | return -EOPNOTSUPP; | |
eec60b03 | 5895 | |
19957bb3 | 5896 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 5897 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 5898 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
5899 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
5900 | return -EINVAL; | |
636a5d36 | 5901 | |
19957bb3 JB |
5902 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5903 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
5904 | |
5905 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5906 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5907 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5908 | } |
5909 | ||
19957bb3 | 5910 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 5911 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 5912 | return -EINVAL; |
636a5d36 | 5913 | |
e39e5b5e JM |
5914 | if (auth_type == NL80211_AUTHTYPE_SAE && |
5915 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
5916 | return -EINVAL; | |
5917 | ||
5918 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
5919 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
5920 | return -EINVAL; | |
5921 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5922 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
5923 | /* need to include at least Auth Transaction and Status Code */ | |
5924 | if (sae_data_len < 4) | |
5925 | return -EINVAL; | |
5926 | } | |
5927 | ||
d5cdfacb JM |
5928 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5929 | ||
95de817b JB |
5930 | /* |
5931 | * Since we no longer track auth state, ignore | |
5932 | * requests to only change local state. | |
5933 | */ | |
5934 | if (local_state_change) | |
5935 | return 0; | |
5936 | ||
91bf9b26 JB |
5937 | wdev_lock(dev->ieee80211_ptr); |
5938 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
5939 | ssid, ssid_len, ie, ie_len, | |
5940 | key.p.key, key.p.key_len, key.idx, | |
5941 | sae_data, sae_data_len); | |
5942 | wdev_unlock(dev->ieee80211_ptr); | |
5943 | return err; | |
636a5d36 JM |
5944 | } |
5945 | ||
c0692b8f JB |
5946 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
5947 | struct genl_info *info, | |
3dc27d25 JB |
5948 | struct cfg80211_crypto_settings *settings, |
5949 | int cipher_limit) | |
b23aa676 | 5950 | { |
c0b2bbd8 JB |
5951 | memset(settings, 0, sizeof(*settings)); |
5952 | ||
b23aa676 SO |
5953 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
5954 | ||
c0692b8f JB |
5955 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
5956 | u16 proto; | |
5957 | proto = nla_get_u16( | |
5958 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
5959 | settings->control_port_ethertype = cpu_to_be16(proto); | |
5960 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
5961 | proto != ETH_P_PAE) | |
5962 | return -EINVAL; | |
5963 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
5964 | settings->control_port_no_encrypt = true; | |
5965 | } else | |
5966 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
5967 | ||
b23aa676 SO |
5968 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
5969 | void *data; | |
5970 | int len, i; | |
5971 | ||
5972 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5973 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
5974 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
5975 | ||
5976 | if (len % sizeof(u32)) | |
5977 | return -EINVAL; | |
5978 | ||
3dc27d25 | 5979 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
5980 | return -EINVAL; |
5981 | ||
5982 | memcpy(settings->ciphers_pairwise, data, len); | |
5983 | ||
5984 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
5985 | if (!cfg80211_supported_cipher_suite( |
5986 | &rdev->wiphy, | |
b23aa676 SO |
5987 | settings->ciphers_pairwise[i])) |
5988 | return -EINVAL; | |
5989 | } | |
5990 | ||
5991 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
5992 | settings->cipher_group = | |
5993 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
5994 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
5995 | settings->cipher_group)) | |
b23aa676 SO |
5996 | return -EINVAL; |
5997 | } | |
5998 | ||
5999 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6000 | settings->wpa_versions = | |
6001 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6002 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6003 | return -EINVAL; | |
6004 | } | |
6005 | ||
6006 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6007 | void *data; | |
6d30240e | 6008 | int len; |
b23aa676 SO |
6009 | |
6010 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6011 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6012 | settings->n_akm_suites = len / sizeof(u32); | |
6013 | ||
6014 | if (len % sizeof(u32)) | |
6015 | return -EINVAL; | |
6016 | ||
1b9ca027 JM |
6017 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6018 | return -EINVAL; | |
6019 | ||
b23aa676 | 6020 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6021 | } |
6022 | ||
6023 | return 0; | |
6024 | } | |
6025 | ||
636a5d36 JM |
6026 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6027 | { | |
4c476991 JB |
6028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6029 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6030 | struct ieee80211_channel *chan; |
f62fab73 JB |
6031 | struct cfg80211_assoc_request req = {}; |
6032 | const u8 *bssid, *ssid; | |
6033 | int err, ssid_len = 0; | |
636a5d36 | 6034 | |
f4a11bb0 JB |
6035 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6036 | return -EINVAL; | |
6037 | ||
6038 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6039 | !info->attrs[NL80211_ATTR_SSID] || |
6040 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6041 | return -EINVAL; |
6042 | ||
4c476991 JB |
6043 | if (!rdev->ops->assoc) |
6044 | return -EOPNOTSUPP; | |
636a5d36 | 6045 | |
074ac8df | 6046 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6047 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6048 | return -EOPNOTSUPP; | |
eec60b03 | 6049 | |
19957bb3 | 6050 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6051 | |
19957bb3 JB |
6052 | chan = ieee80211_get_channel(&rdev->wiphy, |
6053 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6054 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6055 | return -EINVAL; | |
636a5d36 | 6056 | |
19957bb3 JB |
6057 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6058 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6059 | |
6060 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6061 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6062 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6063 | } |
6064 | ||
dc6382ce | 6065 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6066 | enum nl80211_mfp mfp = |
dc6382ce | 6067 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6068 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6069 | req.use_mfp = true; |
4c476991 JB |
6070 | else if (mfp != NL80211_MFP_NO) |
6071 | return -EINVAL; | |
dc6382ce JM |
6072 | } |
6073 | ||
3e5d7649 | 6074 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6075 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6076 | |
7e7c8926 | 6077 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6078 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6079 | |
6080 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6081 | memcpy(&req.ht_capa_mask, |
6082 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6083 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6084 | |
6085 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6086 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6087 | return -EINVAL; |
f62fab73 JB |
6088 | memcpy(&req.ht_capa, |
6089 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6090 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6091 | } |
6092 | ||
ee2aca34 | 6093 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6094 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6095 | |
6096 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6097 | memcpy(&req.vht_capa_mask, |
6098 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6099 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6100 | |
6101 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6102 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6103 | return -EINVAL; |
f62fab73 JB |
6104 | memcpy(&req.vht_capa, |
6105 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6106 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6107 | } |
6108 | ||
f62fab73 | 6109 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6110 | if (!err) { |
6111 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6112 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6113 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6114 | wdev_unlock(dev->ieee80211_ptr); |
6115 | } | |
636a5d36 | 6116 | |
636a5d36 JM |
6117 | return err; |
6118 | } | |
6119 | ||
6120 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6121 | { | |
4c476991 JB |
6122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6123 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6124 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6125 | int ie_len = 0, err; |
19957bb3 | 6126 | u16 reason_code; |
d5cdfacb | 6127 | bool local_state_change; |
636a5d36 | 6128 | |
f4a11bb0 JB |
6129 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6130 | return -EINVAL; | |
6131 | ||
6132 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6133 | return -EINVAL; | |
6134 | ||
6135 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6136 | return -EINVAL; | |
6137 | ||
4c476991 JB |
6138 | if (!rdev->ops->deauth) |
6139 | return -EOPNOTSUPP; | |
636a5d36 | 6140 | |
074ac8df | 6141 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6142 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6143 | return -EOPNOTSUPP; | |
eec60b03 | 6144 | |
19957bb3 | 6145 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6146 | |
19957bb3 JB |
6147 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6148 | if (reason_code == 0) { | |
f4a11bb0 | 6149 | /* Reason Code 0 is reserved */ |
4c476991 | 6150 | return -EINVAL; |
255e737e | 6151 | } |
636a5d36 JM |
6152 | |
6153 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6154 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6155 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6156 | } |
6157 | ||
d5cdfacb JM |
6158 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6159 | ||
91bf9b26 JB |
6160 | wdev_lock(dev->ieee80211_ptr); |
6161 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6162 | local_state_change); | |
6163 | wdev_unlock(dev->ieee80211_ptr); | |
6164 | return err; | |
636a5d36 JM |
6165 | } |
6166 | ||
6167 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6168 | { | |
4c476991 JB |
6169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6170 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6171 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6172 | int ie_len = 0, err; |
19957bb3 | 6173 | u16 reason_code; |
d5cdfacb | 6174 | bool local_state_change; |
636a5d36 | 6175 | |
f4a11bb0 JB |
6176 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6177 | return -EINVAL; | |
6178 | ||
6179 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6180 | return -EINVAL; | |
6181 | ||
6182 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6183 | return -EINVAL; | |
6184 | ||
4c476991 JB |
6185 | if (!rdev->ops->disassoc) |
6186 | return -EOPNOTSUPP; | |
636a5d36 | 6187 | |
074ac8df | 6188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6189 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6190 | return -EOPNOTSUPP; | |
eec60b03 | 6191 | |
19957bb3 | 6192 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6193 | |
19957bb3 JB |
6194 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6195 | if (reason_code == 0) { | |
f4a11bb0 | 6196 | /* Reason Code 0 is reserved */ |
4c476991 | 6197 | return -EINVAL; |
255e737e | 6198 | } |
636a5d36 JM |
6199 | |
6200 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6201 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6202 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6203 | } |
6204 | ||
d5cdfacb JM |
6205 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6206 | ||
91bf9b26 JB |
6207 | wdev_lock(dev->ieee80211_ptr); |
6208 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6209 | local_state_change); | |
6210 | wdev_unlock(dev->ieee80211_ptr); | |
6211 | return err; | |
636a5d36 JM |
6212 | } |
6213 | ||
dd5b4cc7 FF |
6214 | static bool |
6215 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6216 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6217 | int rateval) | |
6218 | { | |
6219 | struct wiphy *wiphy = &rdev->wiphy; | |
6220 | bool found = false; | |
6221 | int band, i; | |
6222 | ||
6223 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6224 | struct ieee80211_supported_band *sband; | |
6225 | ||
6226 | sband = wiphy->bands[band]; | |
6227 | if (!sband) | |
6228 | continue; | |
6229 | ||
6230 | for (i = 0; i < sband->n_bitrates; i++) { | |
6231 | if (sband->bitrates[i].bitrate == rateval) { | |
6232 | mcast_rate[band] = i + 1; | |
6233 | found = true; | |
6234 | break; | |
6235 | } | |
6236 | } | |
6237 | } | |
6238 | ||
6239 | return found; | |
6240 | } | |
6241 | ||
04a773ad JB |
6242 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6243 | { | |
4c476991 JB |
6244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6245 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6246 | struct cfg80211_ibss_params ibss; |
6247 | struct wiphy *wiphy; | |
fffd0934 | 6248 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6249 | int err; |
6250 | ||
8e30bc55 JB |
6251 | memset(&ibss, 0, sizeof(ibss)); |
6252 | ||
04a773ad JB |
6253 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6254 | return -EINVAL; | |
6255 | ||
683b6d3b | 6256 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6257 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6258 | return -EINVAL; | |
6259 | ||
8e30bc55 JB |
6260 | ibss.beacon_interval = 100; |
6261 | ||
6262 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6263 | ibss.beacon_interval = | |
6264 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6265 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6266 | return -EINVAL; | |
6267 | } | |
6268 | ||
4c476991 JB |
6269 | if (!rdev->ops->join_ibss) |
6270 | return -EOPNOTSUPP; | |
04a773ad | 6271 | |
4c476991 JB |
6272 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6273 | return -EOPNOTSUPP; | |
04a773ad | 6274 | |
79c97e97 | 6275 | wiphy = &rdev->wiphy; |
04a773ad | 6276 | |
39193498 | 6277 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6278 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6279 | |
6280 | if (!is_valid_ether_addr(ibss.bssid)) | |
6281 | return -EINVAL; | |
6282 | } | |
04a773ad JB |
6283 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6284 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6285 | ||
6286 | if (info->attrs[NL80211_ATTR_IE]) { | |
6287 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6288 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6289 | } | |
6290 | ||
683b6d3b JB |
6291 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6292 | if (err) | |
6293 | return err; | |
04a773ad | 6294 | |
683b6d3b | 6295 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6296 | return -EINVAL; |
6297 | ||
2f301ab2 SW |
6298 | switch (ibss.chandef.width) { |
6299 | case NL80211_CHAN_WIDTH_20_NOHT: | |
6300 | break; | |
6301 | case NL80211_CHAN_WIDTH_20: | |
6302 | case NL80211_CHAN_WIDTH_40: | |
6303 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6304 | break; | |
6305 | default: | |
c04d6150 | 6306 | return -EINVAL; |
2f301ab2 | 6307 | } |
db9c64cf | 6308 | |
04a773ad | 6309 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6310 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6311 | ||
fbd2c8dc TP |
6312 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6313 | u8 *rates = | |
6314 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6315 | int n_rates = | |
6316 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6317 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6318 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6319 | |
34850ab2 JB |
6320 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6321 | &ibss.basic_rates); | |
6322 | if (err) | |
6323 | return err; | |
fbd2c8dc | 6324 | } |
dd5b4cc7 FF |
6325 | |
6326 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
6327 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6328 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6329 | return -EINVAL; | |
fbd2c8dc | 6330 | |
4c476991 | 6331 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6332 | bool no_ht = false; |
6333 | ||
4c476991 | 6334 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6335 | info->attrs[NL80211_ATTR_KEYS], |
6336 | &no_ht); | |
4c476991 JB |
6337 | if (IS_ERR(connkeys)) |
6338 | return PTR_ERR(connkeys); | |
de7044ee | 6339 | |
3d9d1d66 JB |
6340 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6341 | no_ht) { | |
de7044ee SM |
6342 | kfree(connkeys); |
6343 | return -EINVAL; | |
6344 | } | |
4c476991 | 6345 | } |
04a773ad | 6346 | |
267335d6 AQ |
6347 | ibss.control_port = |
6348 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6349 | ||
4c476991 | 6350 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6351 | if (err) |
6352 | kfree(connkeys); | |
04a773ad JB |
6353 | return err; |
6354 | } | |
6355 | ||
6356 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6357 | { | |
4c476991 JB |
6358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6359 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6360 | |
4c476991 JB |
6361 | if (!rdev->ops->leave_ibss) |
6362 | return -EOPNOTSUPP; | |
04a773ad | 6363 | |
4c476991 JB |
6364 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6365 | return -EOPNOTSUPP; | |
04a773ad | 6366 | |
4c476991 | 6367 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6368 | } |
6369 | ||
f4e583c8 AQ |
6370 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6371 | { | |
6372 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6373 | struct net_device *dev = info->user_ptr[1]; | |
6374 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6375 | u32 nla_rate; | |
6376 | int err; | |
6377 | ||
6378 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6379 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6380 | return -EOPNOTSUPP; | |
6381 | ||
6382 | if (!rdev->ops->set_mcast_rate) | |
6383 | return -EOPNOTSUPP; | |
6384 | ||
6385 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6386 | ||
6387 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6388 | return -EINVAL; | |
6389 | ||
6390 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6391 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6392 | return -EINVAL; | |
6393 | ||
6394 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6395 | ||
6396 | return err; | |
6397 | } | |
6398 | ||
6399 | ||
aff89a9b JB |
6400 | #ifdef CONFIG_NL80211_TESTMODE |
6401 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
6402 | .name = "testmode", | |
6403 | }; | |
6404 | ||
6405 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
6406 | { | |
4c476991 | 6407 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
6408 | int err; |
6409 | ||
6410 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
6411 | return -EINVAL; | |
6412 | ||
aff89a9b JB |
6413 | err = -EOPNOTSUPP; |
6414 | if (rdev->ops->testmode_cmd) { | |
6415 | rdev->testmode_info = info; | |
e35e4d28 | 6416 | err = rdev_testmode_cmd(rdev, |
aff89a9b JB |
6417 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6418 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
6419 | rdev->testmode_info = NULL; | |
6420 | } | |
6421 | ||
aff89a9b JB |
6422 | return err; |
6423 | } | |
6424 | ||
71063f0e WYG |
6425 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6426 | struct netlink_callback *cb) | |
6427 | { | |
00918d33 | 6428 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6429 | int err; |
6430 | long phy_idx; | |
6431 | void *data = NULL; | |
6432 | int data_len = 0; | |
6433 | ||
5fe231e8 JB |
6434 | rtnl_lock(); |
6435 | ||
71063f0e WYG |
6436 | if (cb->args[0]) { |
6437 | /* | |
6438 | * 0 is a valid index, but not valid for args[0], | |
6439 | * so we need to offset by 1. | |
6440 | */ | |
6441 | phy_idx = cb->args[0] - 1; | |
6442 | } else { | |
6443 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6444 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6445 | nl80211_policy); | |
6446 | if (err) | |
5fe231e8 | 6447 | goto out_err; |
00918d33 | 6448 | |
2bd7e35d JB |
6449 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6450 | nl80211_fam.attrbuf); | |
6451 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6452 | err = PTR_ERR(rdev); |
6453 | goto out_err; | |
00918d33 | 6454 | } |
2bd7e35d JB |
6455 | phy_idx = rdev->wiphy_idx; |
6456 | rdev = NULL; | |
2bd7e35d | 6457 | |
71063f0e WYG |
6458 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6459 | cb->args[1] = | |
6460 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6461 | } | |
6462 | ||
6463 | if (cb->args[1]) { | |
6464 | data = nla_data((void *)cb->args[1]); | |
6465 | data_len = nla_len((void *)cb->args[1]); | |
6466 | } | |
6467 | ||
00918d33 JB |
6468 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6469 | if (!rdev) { | |
5fe231e8 JB |
6470 | err = -ENOENT; |
6471 | goto out_err; | |
71063f0e | 6472 | } |
71063f0e | 6473 | |
00918d33 | 6474 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6475 | err = -EOPNOTSUPP; |
6476 | goto out_err; | |
6477 | } | |
6478 | ||
6479 | while (1) { | |
15e47304 | 6480 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6481 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6482 | NL80211_CMD_TESTMODE); | |
6483 | struct nlattr *tmdata; | |
6484 | ||
9360ffd1 | 6485 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6486 | genlmsg_cancel(skb, hdr); |
6487 | break; | |
6488 | } | |
6489 | ||
6490 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6491 | if (!tmdata) { | |
6492 | genlmsg_cancel(skb, hdr); | |
6493 | break; | |
6494 | } | |
e35e4d28 | 6495 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6496 | nla_nest_end(skb, tmdata); |
6497 | ||
6498 | if (err == -ENOBUFS || err == -ENOENT) { | |
6499 | genlmsg_cancel(skb, hdr); | |
6500 | break; | |
6501 | } else if (err) { | |
6502 | genlmsg_cancel(skb, hdr); | |
6503 | goto out_err; | |
6504 | } | |
6505 | ||
6506 | genlmsg_end(skb, hdr); | |
6507 | } | |
6508 | ||
6509 | err = skb->len; | |
6510 | /* see above */ | |
6511 | cb->args[0] = phy_idx + 1; | |
6512 | out_err: | |
5fe231e8 | 6513 | rtnl_unlock(); |
71063f0e WYG |
6514 | return err; |
6515 | } | |
6516 | ||
aff89a9b JB |
6517 | static struct sk_buff * |
6518 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
15e47304 | 6519 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
aff89a9b JB |
6520 | { |
6521 | struct sk_buff *skb; | |
6522 | void *hdr; | |
6523 | struct nlattr *data; | |
6524 | ||
6525 | skb = nlmsg_new(approxlen + 100, gfp); | |
6526 | if (!skb) | |
6527 | return NULL; | |
6528 | ||
15e47304 | 6529 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
aff89a9b JB |
6530 | if (!hdr) { |
6531 | kfree_skb(skb); | |
6532 | return NULL; | |
6533 | } | |
6534 | ||
9360ffd1 DM |
6535 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
6536 | goto nla_put_failure; | |
aff89a9b JB |
6537 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
6538 | ||
6539 | ((void **)skb->cb)[0] = rdev; | |
6540 | ((void **)skb->cb)[1] = hdr; | |
6541 | ((void **)skb->cb)[2] = data; | |
6542 | ||
6543 | return skb; | |
6544 | ||
6545 | nla_put_failure: | |
6546 | kfree_skb(skb); | |
6547 | return NULL; | |
6548 | } | |
6549 | ||
6550 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
6551 | int approxlen) | |
6552 | { | |
6553 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6554 | ||
6555 | if (WARN_ON(!rdev->testmode_info)) | |
6556 | return NULL; | |
6557 | ||
6558 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
15e47304 | 6559 | rdev->testmode_info->snd_portid, |
aff89a9b JB |
6560 | rdev->testmode_info->snd_seq, |
6561 | GFP_KERNEL); | |
6562 | } | |
6563 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
6564 | ||
6565 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
6566 | { | |
6567 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6568 | void *hdr = ((void **)skb->cb)[1]; | |
6569 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6570 | ||
6571 | if (WARN_ON(!rdev->testmode_info)) { | |
6572 | kfree_skb(skb); | |
6573 | return -EINVAL; | |
6574 | } | |
6575 | ||
6576 | nla_nest_end(skb, data); | |
6577 | genlmsg_end(skb, hdr); | |
6578 | return genlmsg_reply(skb, rdev->testmode_info); | |
6579 | } | |
6580 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
6581 | ||
6582 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
6583 | int approxlen, gfp_t gfp) | |
6584 | { | |
6585 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6586 | ||
6587 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
6588 | } | |
6589 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
6590 | ||
6591 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
6592 | { | |
6593 | void *hdr = ((void **)skb->cb)[1]; | |
6594 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6595 | ||
6596 | nla_nest_end(skb, data); | |
6597 | genlmsg_end(skb, hdr); | |
6598 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
6599 | } | |
6600 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
6601 | #endif | |
6602 | ||
b23aa676 SO |
6603 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6604 | { | |
4c476991 JB |
6605 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6606 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6607 | struct cfg80211_connect_params connect; |
6608 | struct wiphy *wiphy; | |
fffd0934 | 6609 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6610 | int err; |
6611 | ||
6612 | memset(&connect, 0, sizeof(connect)); | |
6613 | ||
6614 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6615 | return -EINVAL; | |
6616 | ||
6617 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6618 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6619 | return -EINVAL; | |
6620 | ||
6621 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6622 | connect.auth_type = | |
6623 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6624 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6625 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6626 | return -EINVAL; |
6627 | } else | |
6628 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6629 | ||
6630 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6631 | ||
c0692b8f | 6632 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6633 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6634 | if (err) |
6635 | return err; | |
b23aa676 | 6636 | |
074ac8df | 6637 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6638 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6639 | return -EOPNOTSUPP; | |
b23aa676 | 6640 | |
79c97e97 | 6641 | wiphy = &rdev->wiphy; |
b23aa676 | 6642 | |
4486ea98 BS |
6643 | connect.bg_scan_period = -1; |
6644 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6645 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6646 | connect.bg_scan_period = | |
6647 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6648 | } | |
6649 | ||
b23aa676 SO |
6650 | if (info->attrs[NL80211_ATTR_MAC]) |
6651 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6652 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6653 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6654 | ||
6655 | if (info->attrs[NL80211_ATTR_IE]) { | |
6656 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6657 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6658 | } | |
6659 | ||
cee00a95 JM |
6660 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6661 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6662 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6663 | connect.mfp != NL80211_MFP_NO) | |
6664 | return -EINVAL; | |
6665 | } else { | |
6666 | connect.mfp = NL80211_MFP_NO; | |
6667 | } | |
6668 | ||
b23aa676 SO |
6669 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6670 | connect.channel = | |
6671 | ieee80211_get_channel(wiphy, | |
6672 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
6673 | if (!connect.channel || | |
4c476991 JB |
6674 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
6675 | return -EINVAL; | |
b23aa676 SO |
6676 | } |
6677 | ||
fffd0934 JB |
6678 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
6679 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 6680 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
6681 | if (IS_ERR(connkeys)) |
6682 | return PTR_ERR(connkeys); | |
fffd0934 JB |
6683 | } |
6684 | ||
7e7c8926 BG |
6685 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
6686 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
6687 | ||
6688 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6689 | memcpy(&connect.ht_capa_mask, | |
6690 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6691 | sizeof(connect.ht_capa_mask)); | |
6692 | ||
6693 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
6694 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
6695 | kfree(connkeys); | |
7e7c8926 | 6696 | return -EINVAL; |
b4e4f47e | 6697 | } |
7e7c8926 BG |
6698 | memcpy(&connect.ht_capa, |
6699 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6700 | sizeof(connect.ht_capa)); | |
6701 | } | |
6702 | ||
ee2aca34 JB |
6703 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
6704 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
6705 | ||
6706 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
6707 | memcpy(&connect.vht_capa_mask, | |
6708 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6709 | sizeof(connect.vht_capa_mask)); | |
6710 | ||
6711 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
6712 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
6713 | kfree(connkeys); | |
6714 | return -EINVAL; | |
6715 | } | |
6716 | memcpy(&connect.vht_capa, | |
6717 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6718 | sizeof(connect.vht_capa)); | |
6719 | } | |
6720 | ||
83739b03 JB |
6721 | wdev_lock(dev->ieee80211_ptr); |
6722 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
6723 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
6724 | if (err) |
6725 | kfree(connkeys); | |
b23aa676 SO |
6726 | return err; |
6727 | } | |
6728 | ||
6729 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
6730 | { | |
4c476991 JB |
6731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6732 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 6733 | u16 reason; |
83739b03 | 6734 | int ret; |
b23aa676 SO |
6735 | |
6736 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6737 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
6738 | else | |
6739 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
6740 | ||
6741 | if (reason == 0) | |
6742 | return -EINVAL; | |
6743 | ||
074ac8df | 6744 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6745 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6746 | return -EOPNOTSUPP; | |
b23aa676 | 6747 | |
83739b03 JB |
6748 | wdev_lock(dev->ieee80211_ptr); |
6749 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
6750 | wdev_unlock(dev->ieee80211_ptr); | |
6751 | return ret; | |
b23aa676 SO |
6752 | } |
6753 | ||
463d0183 JB |
6754 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
6755 | { | |
4c476991 | 6756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
6757 | struct net *net; |
6758 | int err; | |
6759 | u32 pid; | |
6760 | ||
6761 | if (!info->attrs[NL80211_ATTR_PID]) | |
6762 | return -EINVAL; | |
6763 | ||
6764 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
6765 | ||
463d0183 | 6766 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
6767 | if (IS_ERR(net)) |
6768 | return PTR_ERR(net); | |
463d0183 JB |
6769 | |
6770 | err = 0; | |
6771 | ||
6772 | /* check if anything to do */ | |
4c476991 JB |
6773 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
6774 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 6775 | |
463d0183 | 6776 | put_net(net); |
463d0183 JB |
6777 | return err; |
6778 | } | |
6779 | ||
67fbb16b SO |
6780 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
6781 | { | |
4c476991 | 6782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
6783 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
6784 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 6785 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
6786 | struct cfg80211_pmksa pmksa; |
6787 | ||
6788 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
6789 | ||
6790 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6791 | return -EINVAL; | |
6792 | ||
6793 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
6794 | return -EINVAL; | |
6795 | ||
67fbb16b SO |
6796 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
6797 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6798 | ||
074ac8df | 6799 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6800 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6801 | return -EOPNOTSUPP; | |
67fbb16b SO |
6802 | |
6803 | switch (info->genlhdr->cmd) { | |
6804 | case NL80211_CMD_SET_PMKSA: | |
6805 | rdev_ops = rdev->ops->set_pmksa; | |
6806 | break; | |
6807 | case NL80211_CMD_DEL_PMKSA: | |
6808 | rdev_ops = rdev->ops->del_pmksa; | |
6809 | break; | |
6810 | default: | |
6811 | WARN_ON(1); | |
6812 | break; | |
6813 | } | |
6814 | ||
4c476991 JB |
6815 | if (!rdev_ops) |
6816 | return -EOPNOTSUPP; | |
67fbb16b | 6817 | |
4c476991 | 6818 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
6819 | } |
6820 | ||
6821 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
6822 | { | |
4c476991 JB |
6823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6824 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 6825 | |
074ac8df | 6826 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6827 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6828 | return -EOPNOTSUPP; | |
67fbb16b | 6829 | |
4c476991 JB |
6830 | if (!rdev->ops->flush_pmksa) |
6831 | return -EOPNOTSUPP; | |
67fbb16b | 6832 | |
e35e4d28 | 6833 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
6834 | } |
6835 | ||
109086ce AN |
6836 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
6837 | { | |
6838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6839 | struct net_device *dev = info->user_ptr[1]; | |
6840 | u8 action_code, dialog_token; | |
6841 | u16 status_code; | |
6842 | u8 *peer; | |
6843 | ||
6844 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6845 | !rdev->ops->tdls_mgmt) | |
6846 | return -EOPNOTSUPP; | |
6847 | ||
6848 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
6849 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
6850 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
6851 | !info->attrs[NL80211_ATTR_IE] || | |
6852 | !info->attrs[NL80211_ATTR_MAC]) | |
6853 | return -EINVAL; | |
6854 | ||
6855 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6856 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
6857 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
6858 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
6859 | ||
e35e4d28 HG |
6860 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
6861 | dialog_token, status_code, | |
6862 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
6863 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
6864 | } |
6865 | ||
6866 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
6867 | { | |
6868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6869 | struct net_device *dev = info->user_ptr[1]; | |
6870 | enum nl80211_tdls_operation operation; | |
6871 | u8 *peer; | |
6872 | ||
6873 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
6874 | !rdev->ops->tdls_oper) | |
6875 | return -EOPNOTSUPP; | |
6876 | ||
6877 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
6878 | !info->attrs[NL80211_ATTR_MAC]) | |
6879 | return -EINVAL; | |
6880 | ||
6881 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
6882 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6883 | ||
e35e4d28 | 6884 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
6885 | } |
6886 | ||
9588bbd5 JM |
6887 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
6888 | struct genl_info *info) | |
6889 | { | |
4c476991 | 6890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6891 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 6892 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
6893 | struct sk_buff *msg; |
6894 | void *hdr; | |
6895 | u64 cookie; | |
683b6d3b | 6896 | u32 duration; |
9588bbd5 JM |
6897 | int err; |
6898 | ||
6899 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6900 | !info->attrs[NL80211_ATTR_DURATION]) | |
6901 | return -EINVAL; | |
6902 | ||
6903 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
6904 | ||
ebf348fc JB |
6905 | if (!rdev->ops->remain_on_channel || |
6906 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
6907 | return -EOPNOTSUPP; | |
6908 | ||
9588bbd5 | 6909 | /* |
ebf348fc JB |
6910 | * We should be on that channel for at least a minimum amount of |
6911 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 6912 | */ |
ebf348fc | 6913 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 6914 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
6915 | return -EINVAL; |
6916 | ||
683b6d3b JB |
6917 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6918 | if (err) | |
6919 | return err; | |
9588bbd5 JM |
6920 | |
6921 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6922 | if (!msg) |
6923 | return -ENOMEM; | |
9588bbd5 | 6924 | |
15e47304 | 6925 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 JM |
6926 | NL80211_CMD_REMAIN_ON_CHANNEL); |
6927 | ||
6928 | if (IS_ERR(hdr)) { | |
6929 | err = PTR_ERR(hdr); | |
6930 | goto free_msg; | |
6931 | } | |
6932 | ||
683b6d3b JB |
6933 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
6934 | duration, &cookie); | |
9588bbd5 JM |
6935 | |
6936 | if (err) | |
6937 | goto free_msg; | |
6938 | ||
9360ffd1 DM |
6939 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6940 | goto nla_put_failure; | |
9588bbd5 JM |
6941 | |
6942 | genlmsg_end(msg, hdr); | |
4c476991 JB |
6943 | |
6944 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
6945 | |
6946 | nla_put_failure: | |
6947 | err = -ENOBUFS; | |
6948 | free_msg: | |
6949 | nlmsg_free(msg); | |
9588bbd5 JM |
6950 | return err; |
6951 | } | |
6952 | ||
6953 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
6954 | struct genl_info *info) | |
6955 | { | |
4c476991 | 6956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 6957 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 6958 | u64 cookie; |
9588bbd5 JM |
6959 | |
6960 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6961 | return -EINVAL; | |
6962 | ||
4c476991 JB |
6963 | if (!rdev->ops->cancel_remain_on_channel) |
6964 | return -EOPNOTSUPP; | |
9588bbd5 | 6965 | |
9588bbd5 JM |
6966 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
6967 | ||
e35e4d28 | 6968 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
6969 | } |
6970 | ||
13ae75b1 JM |
6971 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
6972 | u8 *rates, u8 rates_len) | |
6973 | { | |
6974 | u8 i; | |
6975 | u32 mask = 0; | |
6976 | ||
6977 | for (i = 0; i < rates_len; i++) { | |
6978 | int rate = (rates[i] & 0x7f) * 5; | |
6979 | int ridx; | |
6980 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
6981 | struct ieee80211_rate *srate = | |
6982 | &sband->bitrates[ridx]; | |
6983 | if (rate == srate->bitrate) { | |
6984 | mask |= 1 << ridx; | |
6985 | break; | |
6986 | } | |
6987 | } | |
6988 | if (ridx == sband->n_bitrates) | |
6989 | return 0; /* rate not found */ | |
6990 | } | |
6991 | ||
6992 | return mask; | |
6993 | } | |
6994 | ||
24db78c0 SW |
6995 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
6996 | u8 *rates, u8 rates_len, | |
6997 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
6998 | { | |
6999 | u8 i; | |
7000 | ||
7001 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7002 | ||
7003 | for (i = 0; i < rates_len; i++) { | |
7004 | int ridx, rbit; | |
7005 | ||
7006 | ridx = rates[i] / 8; | |
7007 | rbit = BIT(rates[i] % 8); | |
7008 | ||
7009 | /* check validity */ | |
910570b5 | 7010 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7011 | return false; |
7012 | ||
7013 | /* check availability */ | |
7014 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7015 | mcs[ridx] |= rbit; | |
7016 | else | |
7017 | return false; | |
7018 | } | |
7019 | ||
7020 | return true; | |
7021 | } | |
7022 | ||
b54452b0 | 7023 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7024 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7025 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
7026 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
7027 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
7028 | }; |
7029 | ||
7030 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7031 | struct genl_info *info) | |
7032 | { | |
7033 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7035 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7036 | int rem, i; |
7037 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7038 | struct nlattr *tx_rates; |
7039 | struct ieee80211_supported_band *sband; | |
7040 | ||
7041 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
7042 | return -EINVAL; | |
7043 | ||
4c476991 JB |
7044 | if (!rdev->ops->set_bitrate_mask) |
7045 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7046 | |
7047 | memset(&mask, 0, sizeof(mask)); | |
7048 | /* Default to all rates enabled */ | |
7049 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7050 | sband = rdev->wiphy.bands[i]; | |
7051 | mask.control[i].legacy = | |
7052 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
7053 | if (sband) |
7054 | memcpy(mask.control[i].mcs, | |
7055 | sband->ht_cap.mcs.rx_mask, | |
7056 | sizeof(mask.control[i].mcs)); | |
7057 | else | |
7058 | memset(mask.control[i].mcs, 0, | |
7059 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
7060 | } |
7061 | ||
7062 | /* | |
7063 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7064 | * directly to the enum ieee80211_band values used in cfg80211. | |
7065 | */ | |
24db78c0 | 7066 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7067 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7068 | { | |
7069 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7070 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7071 | return -EINVAL; | |
13ae75b1 | 7072 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7073 | if (sband == NULL) |
7074 | return -EINVAL; | |
13ae75b1 JM |
7075 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7076 | nla_len(tx_rates), nl80211_txattr_policy); | |
7077 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7078 | mask.control[band].legacy = rateset_to_mask( | |
7079 | sband, | |
7080 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7081 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7082 | if ((mask.control[band].legacy == 0) && |
7083 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7084 | return -EINVAL; | |
24db78c0 SW |
7085 | } |
7086 | if (tb[NL80211_TXRATE_MCS]) { | |
7087 | if (!ht_rateset_to_mask( | |
7088 | sband, | |
7089 | nla_data(tb[NL80211_TXRATE_MCS]), | |
7090 | nla_len(tb[NL80211_TXRATE_MCS]), | |
7091 | mask.control[band].mcs)) | |
7092 | return -EINVAL; | |
7093 | } | |
7094 | ||
7095 | if (mask.control[band].legacy == 0) { | |
7096 | /* don't allow empty legacy rates if HT | |
7097 | * is not even supported. */ | |
7098 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
7099 | return -EINVAL; | |
7100 | ||
7101 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
7102 | if (mask.control[band].mcs[i]) | |
7103 | break; | |
7104 | ||
7105 | /* legacy and mcs rates may not be both empty */ | |
7106 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 7107 | return -EINVAL; |
13ae75b1 JM |
7108 | } |
7109 | } | |
7110 | ||
e35e4d28 | 7111 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7112 | } |
7113 | ||
2e161f78 | 7114 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7115 | { |
4c476991 | 7116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7117 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7118 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7119 | |
7120 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7121 | return -EINVAL; | |
7122 | ||
2e161f78 JB |
7123 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7124 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7125 | |
71bbc994 JB |
7126 | switch (wdev->iftype) { |
7127 | case NL80211_IFTYPE_STATION: | |
7128 | case NL80211_IFTYPE_ADHOC: | |
7129 | case NL80211_IFTYPE_P2P_CLIENT: | |
7130 | case NL80211_IFTYPE_AP: | |
7131 | case NL80211_IFTYPE_AP_VLAN: | |
7132 | case NL80211_IFTYPE_MESH_POINT: | |
7133 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7134 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7135 | break; |
7136 | default: | |
4c476991 | 7137 | return -EOPNOTSUPP; |
71bbc994 | 7138 | } |
026331c4 JM |
7139 | |
7140 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7141 | if (!rdev->ops->mgmt_tx) |
7142 | return -EOPNOTSUPP; | |
026331c4 | 7143 | |
15e47304 | 7144 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7145 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7146 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7147 | } |
7148 | ||
2e161f78 | 7149 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7150 | { |
4c476991 | 7151 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7152 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7153 | struct cfg80211_chan_def chandef; |
026331c4 | 7154 | int err; |
d64d373f | 7155 | void *hdr = NULL; |
026331c4 | 7156 | u64 cookie; |
e247bd90 | 7157 | struct sk_buff *msg = NULL; |
f7ca38df | 7158 | unsigned int wait = 0; |
e247bd90 JB |
7159 | bool offchan, no_cck, dont_wait_for_ack; |
7160 | ||
7161 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 | 7162 | |
683b6d3b | 7163 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7164 | return -EINVAL; |
7165 | ||
4c476991 JB |
7166 | if (!rdev->ops->mgmt_tx) |
7167 | return -EOPNOTSUPP; | |
026331c4 | 7168 | |
71bbc994 | 7169 | switch (wdev->iftype) { |
ea141b75 AQ |
7170 | case NL80211_IFTYPE_P2P_DEVICE: |
7171 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7172 | return -EINVAL; | |
71bbc994 JB |
7173 | case NL80211_IFTYPE_STATION: |
7174 | case NL80211_IFTYPE_ADHOC: | |
7175 | case NL80211_IFTYPE_P2P_CLIENT: | |
7176 | case NL80211_IFTYPE_AP: | |
7177 | case NL80211_IFTYPE_AP_VLAN: | |
7178 | case NL80211_IFTYPE_MESH_POINT: | |
7179 | case NL80211_IFTYPE_P2P_GO: | |
7180 | break; | |
7181 | default: | |
4c476991 | 7182 | return -EOPNOTSUPP; |
71bbc994 | 7183 | } |
026331c4 | 7184 | |
f7ca38df | 7185 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7186 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
7187 | return -EINVAL; |
7188 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
7189 | |
7190 | /* | |
7191 | * We should wait on the channel for at least a minimum amount | |
7192 | * of time (10ms) but no longer than the driver supports. | |
7193 | */ | |
7194 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
7195 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
7196 | return -EINVAL; | |
7197 | ||
f7ca38df JB |
7198 | } |
7199 | ||
f7ca38df JB |
7200 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
7201 | ||
7c4ef712 JB |
7202 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7203 | return -EINVAL; | |
7204 | ||
e9f935e3 RM |
7205 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
7206 | ||
ea141b75 AQ |
7207 | /* get the channel if any has been specified, otherwise pass NULL to |
7208 | * the driver. The latter will use the current one | |
7209 | */ | |
7210 | chandef.chan = NULL; | |
7211 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7212 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7213 | if (err) | |
7214 | return err; | |
7215 | } | |
7216 | ||
7217 | if (!chandef.chan && offchan) | |
7218 | return -EINVAL; | |
026331c4 | 7219 | |
e247bd90 JB |
7220 | if (!dont_wait_for_ack) { |
7221 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7222 | if (!msg) | |
7223 | return -ENOMEM; | |
026331c4 | 7224 | |
15e47304 | 7225 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7226 | NL80211_CMD_FRAME); |
026331c4 | 7227 | |
e247bd90 JB |
7228 | if (IS_ERR(hdr)) { |
7229 | err = PTR_ERR(hdr); | |
7230 | goto free_msg; | |
7231 | } | |
026331c4 | 7232 | } |
e247bd90 | 7233 | |
683b6d3b | 7234 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
2e161f78 JB |
7235 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
7236 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 7237 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
7238 | if (err) |
7239 | goto free_msg; | |
7240 | ||
e247bd90 | 7241 | if (msg) { |
9360ffd1 DM |
7242 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7243 | goto nla_put_failure; | |
026331c4 | 7244 | |
e247bd90 JB |
7245 | genlmsg_end(msg, hdr); |
7246 | return genlmsg_reply(msg, info); | |
7247 | } | |
7248 | ||
7249 | return 0; | |
026331c4 JM |
7250 | |
7251 | nla_put_failure: | |
7252 | err = -ENOBUFS; | |
7253 | free_msg: | |
7254 | nlmsg_free(msg); | |
026331c4 JM |
7255 | return err; |
7256 | } | |
7257 | ||
f7ca38df JB |
7258 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7259 | { | |
7260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7261 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7262 | u64 cookie; |
7263 | ||
7264 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7265 | return -EINVAL; | |
7266 | ||
7267 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7268 | return -EOPNOTSUPP; | |
7269 | ||
71bbc994 JB |
7270 | switch (wdev->iftype) { |
7271 | case NL80211_IFTYPE_STATION: | |
7272 | case NL80211_IFTYPE_ADHOC: | |
7273 | case NL80211_IFTYPE_P2P_CLIENT: | |
7274 | case NL80211_IFTYPE_AP: | |
7275 | case NL80211_IFTYPE_AP_VLAN: | |
7276 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7277 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7278 | break; |
7279 | default: | |
f7ca38df | 7280 | return -EOPNOTSUPP; |
71bbc994 | 7281 | } |
f7ca38df JB |
7282 | |
7283 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7284 | ||
e35e4d28 | 7285 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7286 | } |
7287 | ||
ffb9eb3d KV |
7288 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7289 | { | |
4c476991 | 7290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7291 | struct wireless_dev *wdev; |
4c476991 | 7292 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7293 | u8 ps_state; |
7294 | bool state; | |
7295 | int err; | |
7296 | ||
4c476991 JB |
7297 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7298 | return -EINVAL; | |
ffb9eb3d KV |
7299 | |
7300 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7301 | ||
4c476991 JB |
7302 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7303 | return -EINVAL; | |
ffb9eb3d KV |
7304 | |
7305 | wdev = dev->ieee80211_ptr; | |
7306 | ||
4c476991 JB |
7307 | if (!rdev->ops->set_power_mgmt) |
7308 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7309 | |
7310 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7311 | ||
7312 | if (state == wdev->ps) | |
4c476991 | 7313 | return 0; |
ffb9eb3d | 7314 | |
e35e4d28 | 7315 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7316 | if (!err) |
7317 | wdev->ps = state; | |
ffb9eb3d KV |
7318 | return err; |
7319 | } | |
7320 | ||
7321 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7322 | { | |
4c476991 | 7323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7324 | enum nl80211_ps_state ps_state; |
7325 | struct wireless_dev *wdev; | |
4c476991 | 7326 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7327 | struct sk_buff *msg; |
7328 | void *hdr; | |
7329 | int err; | |
7330 | ||
ffb9eb3d KV |
7331 | wdev = dev->ieee80211_ptr; |
7332 | ||
4c476991 JB |
7333 | if (!rdev->ops->set_power_mgmt) |
7334 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7335 | |
7336 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7337 | if (!msg) |
7338 | return -ENOMEM; | |
ffb9eb3d | 7339 | |
15e47304 | 7340 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7341 | NL80211_CMD_GET_POWER_SAVE); |
7342 | if (!hdr) { | |
4c476991 | 7343 | err = -ENOBUFS; |
ffb9eb3d KV |
7344 | goto free_msg; |
7345 | } | |
7346 | ||
7347 | if (wdev->ps) | |
7348 | ps_state = NL80211_PS_ENABLED; | |
7349 | else | |
7350 | ps_state = NL80211_PS_DISABLED; | |
7351 | ||
9360ffd1 DM |
7352 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7353 | goto nla_put_failure; | |
ffb9eb3d KV |
7354 | |
7355 | genlmsg_end(msg, hdr); | |
4c476991 | 7356 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7357 | |
4c476991 | 7358 | nla_put_failure: |
ffb9eb3d | 7359 | err = -ENOBUFS; |
4c476991 | 7360 | free_msg: |
ffb9eb3d | 7361 | nlmsg_free(msg); |
ffb9eb3d KV |
7362 | return err; |
7363 | } | |
7364 | ||
d6dc1a38 JO |
7365 | static struct nla_policy |
7366 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7367 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7368 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7369 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7370 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7371 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7372 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7373 | }; |
7374 | ||
84f10708 | 7375 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7376 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7377 | { |
7378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7379 | struct wireless_dev *wdev; | |
7380 | struct net_device *dev = info->user_ptr[1]; | |
7381 | ||
d9d8b019 | 7382 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7383 | return -EINVAL; |
7384 | ||
7385 | wdev = dev->ieee80211_ptr; | |
7386 | ||
7387 | if (!rdev->ops->set_cqm_txe_config) | |
7388 | return -EOPNOTSUPP; | |
7389 | ||
7390 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7391 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7392 | return -EOPNOTSUPP; | |
7393 | ||
e35e4d28 | 7394 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7395 | } |
7396 | ||
d6dc1a38 JO |
7397 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7398 | s32 threshold, u32 hysteresis) | |
7399 | { | |
4c476991 | 7400 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 7401 | struct wireless_dev *wdev; |
4c476991 | 7402 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
7403 | |
7404 | if (threshold > 0) | |
7405 | return -EINVAL; | |
7406 | ||
d6dc1a38 JO |
7407 | wdev = dev->ieee80211_ptr; |
7408 | ||
4c476991 JB |
7409 | if (!rdev->ops->set_cqm_rssi_config) |
7410 | return -EOPNOTSUPP; | |
d6dc1a38 | 7411 | |
074ac8df | 7412 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7413 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7414 | return -EOPNOTSUPP; | |
d6dc1a38 | 7415 | |
e35e4d28 | 7416 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7417 | } |
7418 | ||
7419 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7420 | { | |
7421 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7422 | struct nlattr *cqm; | |
7423 | int err; | |
7424 | ||
7425 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
7426 | if (!cqm) { | |
7427 | err = -EINVAL; | |
7428 | goto out; | |
7429 | } | |
7430 | ||
7431 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7432 | nl80211_attr_cqm_policy); | |
7433 | if (err) | |
7434 | goto out; | |
7435 | ||
7436 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7437 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
7438 | s32 threshold; | |
7439 | u32 hysteresis; | |
7440 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
7441 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
7442 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
84f10708 TP |
7443 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
7444 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7445 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7446 | u32 rate, pkts, intvl; | |
7447 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7448 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7449 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7450 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
d6dc1a38 JO |
7451 | } else |
7452 | err = -EINVAL; | |
7453 | ||
7454 | out: | |
7455 | return err; | |
7456 | } | |
7457 | ||
29cbe68c JB |
7458 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7459 | { | |
7460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7461 | struct net_device *dev = info->user_ptr[1]; | |
7462 | struct mesh_config cfg; | |
c80d545d | 7463 | struct mesh_setup setup; |
29cbe68c JB |
7464 | int err; |
7465 | ||
7466 | /* start with default */ | |
7467 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7468 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7469 | |
24bdd9f4 | 7470 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7471 | /* and parse parameters if given */ |
24bdd9f4 | 7472 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7473 | if (err) |
7474 | return err; | |
7475 | } | |
7476 | ||
7477 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7478 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7479 | return -EINVAL; | |
7480 | ||
c80d545d JC |
7481 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7482 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7483 | ||
4bb62344 CYY |
7484 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7485 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7486 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7487 | return -EINVAL; | |
7488 | ||
9bdbf04d MP |
7489 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7490 | setup.beacon_interval = | |
7491 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7492 | if (setup.beacon_interval < 10 || | |
7493 | setup.beacon_interval > 10000) | |
7494 | return -EINVAL; | |
7495 | } | |
7496 | ||
7497 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7498 | setup.dtim_period = | |
7499 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7500 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7501 | return -EINVAL; | |
7502 | } | |
7503 | ||
c80d545d JC |
7504 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7505 | /* parse additional setup parameters if given */ | |
7506 | err = nl80211_parse_mesh_setup(info, &setup); | |
7507 | if (err) | |
7508 | return err; | |
7509 | } | |
7510 | ||
d37bb18a TP |
7511 | if (setup.user_mpm) |
7512 | cfg.auto_open_plinks = false; | |
7513 | ||
cc1d2806 | 7514 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7515 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7516 | if (err) | |
7517 | return err; | |
cc1d2806 JB |
7518 | } else { |
7519 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7520 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7521 | } |
7522 | ||
ffb3cf30 AN |
7523 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7524 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7525 | int n_rates = | |
7526 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7527 | struct ieee80211_supported_band *sband; | |
7528 | ||
7529 | if (!setup.chandef.chan) | |
7530 | return -EINVAL; | |
7531 | ||
7532 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
7533 | ||
7534 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
7535 | &setup.basic_rates); | |
7536 | if (err) | |
7537 | return err; | |
7538 | } | |
7539 | ||
c80d545d | 7540 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7541 | } |
7542 | ||
7543 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7544 | { | |
7545 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7546 | struct net_device *dev = info->user_ptr[1]; | |
7547 | ||
7548 | return cfg80211_leave_mesh(rdev, dev); | |
7549 | } | |
7550 | ||
dfb89c56 | 7551 | #ifdef CONFIG_PM |
bb92d199 AK |
7552 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7553 | struct cfg80211_registered_device *rdev) | |
7554 | { | |
6abb9cb9 | 7555 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
7556 | struct nlattr *nl_pats, *nl_pat; |
7557 | int i, pat_len; | |
7558 | ||
6abb9cb9 | 7559 | if (!wowlan->n_patterns) |
bb92d199 AK |
7560 | return 0; |
7561 | ||
7562 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7563 | if (!nl_pats) | |
7564 | return -ENOBUFS; | |
7565 | ||
6abb9cb9 | 7566 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
7567 | nl_pat = nla_nest_start(msg, i + 1); |
7568 | if (!nl_pat) | |
7569 | return -ENOBUFS; | |
6abb9cb9 | 7570 | pat_len = wowlan->patterns[i].pattern_len; |
bb92d199 AK |
7571 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
7572 | DIV_ROUND_UP(pat_len, 8), | |
6abb9cb9 | 7573 | wowlan->patterns[i].mask) || |
bb92d199 | 7574 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
6abb9cb9 | 7575 | pat_len, wowlan->patterns[i].pattern) || |
bb92d199 | 7576 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
6abb9cb9 | 7577 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
7578 | return -ENOBUFS; |
7579 | nla_nest_end(msg, nl_pat); | |
7580 | } | |
7581 | nla_nest_end(msg, nl_pats); | |
7582 | ||
7583 | return 0; | |
7584 | } | |
7585 | ||
2a0e047e JB |
7586 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7587 | struct cfg80211_wowlan_tcp *tcp) | |
7588 | { | |
7589 | struct nlattr *nl_tcp; | |
7590 | ||
7591 | if (!tcp) | |
7592 | return 0; | |
7593 | ||
7594 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
7595 | if (!nl_tcp) | |
7596 | return -ENOBUFS; | |
7597 | ||
7598 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
7599 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
7600 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
7601 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
7602 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
7603 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
7604 | tcp->payload_len, tcp->payload) || | |
7605 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
7606 | tcp->data_interval) || | |
7607 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
7608 | tcp->wake_len, tcp->wake_data) || | |
7609 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
7610 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
7611 | return -ENOBUFS; | |
7612 | ||
7613 | if (tcp->payload_seq.len && | |
7614 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
7615 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
7616 | return -ENOBUFS; | |
7617 | ||
7618 | if (tcp->payload_tok.len && | |
7619 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
7620 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
7621 | &tcp->payload_tok)) | |
7622 | return -ENOBUFS; | |
7623 | ||
e248ad30 JB |
7624 | nla_nest_end(msg, nl_tcp); |
7625 | ||
2a0e047e JB |
7626 | return 0; |
7627 | } | |
7628 | ||
ff1b6e69 JB |
7629 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
7630 | { | |
7631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7632 | struct sk_buff *msg; | |
7633 | void *hdr; | |
2a0e047e | 7634 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 7635 | |
964dc9e2 | 7636 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
7637 | return -EOPNOTSUPP; |
7638 | ||
6abb9cb9 | 7639 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 7640 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
7641 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
7642 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
7643 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
7644 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
7645 | } |
7646 | ||
7647 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
7648 | if (!msg) |
7649 | return -ENOMEM; | |
7650 | ||
15e47304 | 7651 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
7652 | NL80211_CMD_GET_WOWLAN); |
7653 | if (!hdr) | |
7654 | goto nla_put_failure; | |
7655 | ||
6abb9cb9 | 7656 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
7657 | struct nlattr *nl_wowlan; |
7658 | ||
7659 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7660 | if (!nl_wowlan) | |
7661 | goto nla_put_failure; | |
7662 | ||
6abb9cb9 | 7663 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 7664 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 7665 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 7666 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 7667 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 7668 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 7669 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 7670 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 7671 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 7672 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 7673 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 7674 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 7675 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
7676 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
7677 | goto nla_put_failure; | |
2a0e047e | 7678 | |
bb92d199 AK |
7679 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
7680 | goto nla_put_failure; | |
2a0e047e | 7681 | |
6abb9cb9 JB |
7682 | if (nl80211_send_wowlan_tcp(msg, |
7683 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
7684 | goto nla_put_failure; |
7685 | ||
ff1b6e69 JB |
7686 | nla_nest_end(msg, nl_wowlan); |
7687 | } | |
7688 | ||
7689 | genlmsg_end(msg, hdr); | |
7690 | return genlmsg_reply(msg, info); | |
7691 | ||
7692 | nla_put_failure: | |
7693 | nlmsg_free(msg); | |
7694 | return -ENOBUFS; | |
7695 | } | |
7696 | ||
2a0e047e JB |
7697 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
7698 | struct nlattr *attr, | |
7699 | struct cfg80211_wowlan *trig) | |
7700 | { | |
7701 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
7702 | struct cfg80211_wowlan_tcp *cfg; | |
7703 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
7704 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
7705 | u32 size; | |
7706 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
7707 | int err, port; | |
7708 | ||
964dc9e2 | 7709 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
7710 | return -EINVAL; |
7711 | ||
7712 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
7713 | nla_data(attr), nla_len(attr), | |
7714 | nl80211_wowlan_tcp_policy); | |
7715 | if (err) | |
7716 | return err; | |
7717 | ||
7718 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
7719 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
7720 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
7721 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
7722 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
7723 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
7724 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
7725 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
7726 | return -EINVAL; | |
7727 | ||
7728 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 7729 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
7730 | return -EINVAL; |
7731 | ||
7732 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 7733 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 7734 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
7735 | return -EINVAL; |
7736 | ||
7737 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 7738 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
7739 | return -EINVAL; |
7740 | ||
7741 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
7742 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
7743 | return -EINVAL; | |
7744 | ||
7745 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
7746 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7747 | ||
7748 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
7749 | tokens_size = tokln - sizeof(*tok); | |
7750 | ||
7751 | if (!tok->len || tokens_size % tok->len) | |
7752 | return -EINVAL; | |
964dc9e2 | 7753 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 7754 | return -EINVAL; |
964dc9e2 | 7755 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 7756 | return -EINVAL; |
964dc9e2 | 7757 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 7758 | return -EINVAL; |
964dc9e2 | 7759 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
7760 | return -EINVAL; |
7761 | if (tok->offset + tok->len > data_size) | |
7762 | return -EINVAL; | |
7763 | } | |
7764 | ||
7765 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
7766 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 7767 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
7768 | return -EINVAL; |
7769 | if (seq->len == 0 || seq->len > 4) | |
7770 | return -EINVAL; | |
7771 | if (seq->len + seq->offset > data_size) | |
7772 | return -EINVAL; | |
7773 | } | |
7774 | ||
7775 | size = sizeof(*cfg); | |
7776 | size += data_size; | |
7777 | size += wake_size + wake_mask_size; | |
7778 | size += tokens_size; | |
7779 | ||
7780 | cfg = kzalloc(size, GFP_KERNEL); | |
7781 | if (!cfg) | |
7782 | return -ENOMEM; | |
7783 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
7784 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
7785 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
7786 | ETH_ALEN); | |
7787 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
7788 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
7789 | else | |
7790 | port = 0; | |
7791 | #ifdef CONFIG_INET | |
7792 | /* allocate a socket and port for it and use it */ | |
7793 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
7794 | IPPROTO_TCP, &cfg->sock, 1); | |
7795 | if (err) { | |
7796 | kfree(cfg); | |
7797 | return err; | |
7798 | } | |
7799 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
7800 | sock_release(cfg->sock); | |
7801 | kfree(cfg); | |
7802 | return -EADDRINUSE; | |
7803 | } | |
7804 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
7805 | #else | |
7806 | if (!port) { | |
7807 | kfree(cfg); | |
7808 | return -EINVAL; | |
7809 | } | |
7810 | cfg->src_port = port; | |
7811 | #endif | |
7812 | ||
7813 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
7814 | cfg->payload_len = data_size; | |
7815 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
7816 | memcpy((void *)cfg->payload, | |
7817 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
7818 | data_size); | |
7819 | if (seq) | |
7820 | cfg->payload_seq = *seq; | |
7821 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
7822 | cfg->wake_len = wake_size; | |
7823 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
7824 | memcpy((void *)cfg->wake_data, | |
7825 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
7826 | wake_size); | |
7827 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
7828 | data_size + wake_size; | |
7829 | memcpy((void *)cfg->wake_mask, | |
7830 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
7831 | wake_mask_size); | |
7832 | if (tok) { | |
7833 | cfg->tokens_size = tokens_size; | |
7834 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
7835 | } | |
7836 | ||
7837 | trig->tcp = cfg; | |
7838 | ||
7839 | return 0; | |
7840 | } | |
7841 | ||
ff1b6e69 JB |
7842 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
7843 | { | |
7844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7845 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 7846 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 7847 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 7848 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 7849 | int err, i; |
6abb9cb9 | 7850 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 7851 | |
964dc9e2 | 7852 | if (!wowlan) |
ff1b6e69 JB |
7853 | return -EOPNOTSUPP; |
7854 | ||
ae33bd81 JB |
7855 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
7856 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 7857 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
7858 | goto set_wakeup; |
7859 | } | |
ff1b6e69 JB |
7860 | |
7861 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
7862 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7863 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
7864 | nl80211_wowlan_policy); | |
7865 | if (err) | |
7866 | return err; | |
7867 | ||
7868 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
7869 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
7870 | return -EINVAL; | |
7871 | new_triggers.any = true; | |
7872 | } | |
7873 | ||
7874 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
7875 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
7876 | return -EINVAL; | |
7877 | new_triggers.disconnect = true; | |
7878 | } | |
7879 | ||
7880 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
7881 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
7882 | return -EINVAL; | |
7883 | new_triggers.magic_pkt = true; | |
7884 | } | |
7885 | ||
77dbbb13 JB |
7886 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
7887 | return -EINVAL; | |
7888 | ||
7889 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
7890 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
7891 | return -EINVAL; | |
7892 | new_triggers.gtk_rekey_failure = true; | |
7893 | } | |
7894 | ||
7895 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
7896 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
7897 | return -EINVAL; | |
7898 | new_triggers.eap_identity_req = true; | |
7899 | } | |
7900 | ||
7901 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
7902 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
7903 | return -EINVAL; | |
7904 | new_triggers.four_way_handshake = true; | |
7905 | } | |
7906 | ||
7907 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
7908 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
7909 | return -EINVAL; | |
7910 | new_triggers.rfkill_release = true; | |
7911 | } | |
7912 | ||
ff1b6e69 JB |
7913 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
7914 | struct nlattr *pat; | |
7915 | int n_patterns = 0; | |
bb92d199 | 7916 | int rem, pat_len, mask_len, pkt_offset; |
ff1b6e69 JB |
7917 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
7918 | ||
7919 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7920 | rem) | |
7921 | n_patterns++; | |
7922 | if (n_patterns > wowlan->n_patterns) | |
7923 | return -EINVAL; | |
7924 | ||
7925 | new_triggers.patterns = kcalloc(n_patterns, | |
7926 | sizeof(new_triggers.patterns[0]), | |
7927 | GFP_KERNEL); | |
7928 | if (!new_triggers.patterns) | |
7929 | return -ENOMEM; | |
7930 | ||
7931 | new_triggers.n_patterns = n_patterns; | |
7932 | i = 0; | |
7933 | ||
7934 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
7935 | rem) { | |
7936 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
7937 | nla_data(pat), nla_len(pat), NULL); | |
7938 | err = -EINVAL; | |
7939 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
7940 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
7941 | goto error; | |
7942 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
7943 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
7944 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
7945 | mask_len) | |
7946 | goto error; | |
7947 | if (pat_len > wowlan->pattern_max_len || | |
7948 | pat_len < wowlan->pattern_min_len) | |
7949 | goto error; | |
7950 | ||
bb92d199 AK |
7951 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
7952 | pkt_offset = 0; | |
7953 | else | |
7954 | pkt_offset = nla_get_u32( | |
7955 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); | |
7956 | if (pkt_offset > wowlan->max_pkt_offset) | |
7957 | goto error; | |
7958 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
7959 | ||
ff1b6e69 JB |
7960 | new_triggers.patterns[i].mask = |
7961 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
7962 | if (!new_triggers.patterns[i].mask) { | |
7963 | err = -ENOMEM; | |
7964 | goto error; | |
7965 | } | |
7966 | new_triggers.patterns[i].pattern = | |
7967 | new_triggers.patterns[i].mask + mask_len; | |
7968 | memcpy(new_triggers.patterns[i].mask, | |
7969 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
7970 | mask_len); | |
7971 | new_triggers.patterns[i].pattern_len = pat_len; | |
7972 | memcpy(new_triggers.patterns[i].pattern, | |
7973 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
7974 | pat_len); | |
7975 | i++; | |
7976 | } | |
7977 | } | |
7978 | ||
2a0e047e JB |
7979 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
7980 | err = nl80211_parse_wowlan_tcp( | |
7981 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
7982 | &new_triggers); | |
7983 | if (err) | |
7984 | goto error; | |
7985 | } | |
7986 | ||
ae33bd81 JB |
7987 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
7988 | if (!ntrig) { | |
7989 | err = -ENOMEM; | |
7990 | goto error; | |
ff1b6e69 | 7991 | } |
ae33bd81 | 7992 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 7993 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 7994 | |
ae33bd81 | 7995 | set_wakeup: |
6abb9cb9 JB |
7996 | if (rdev->ops->set_wakeup && |
7997 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
7998 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 7999 | |
ff1b6e69 JB |
8000 | return 0; |
8001 | error: | |
8002 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8003 | kfree(new_triggers.patterns[i].mask); | |
8004 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8005 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8006 | sock_release(new_triggers.tcp->sock); | |
8007 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8008 | return err; |
8009 | } | |
dfb89c56 | 8010 | #endif |
ff1b6e69 | 8011 | |
e5497d76 JB |
8012 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8013 | { | |
8014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8015 | struct net_device *dev = info->user_ptr[1]; | |
8016 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8017 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8018 | struct cfg80211_gtk_rekey_data rekey_data; | |
8019 | int err; | |
8020 | ||
8021 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8022 | return -EINVAL; | |
8023 | ||
8024 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8025 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8026 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8027 | nl80211_rekey_policy); | |
8028 | if (err) | |
8029 | return err; | |
8030 | ||
8031 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8032 | return -ERANGE; | |
8033 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8034 | return -ERANGE; | |
8035 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8036 | return -ERANGE; | |
8037 | ||
8038 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8039 | NL80211_KEK_LEN); | |
8040 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8041 | NL80211_KCK_LEN); | |
8042 | memcpy(rekey_data.replay_ctr, | |
8043 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8044 | NL80211_REPLAY_CTR_LEN); | |
8045 | ||
8046 | wdev_lock(wdev); | |
8047 | if (!wdev->current_bss) { | |
8048 | err = -ENOTCONN; | |
8049 | goto out; | |
8050 | } | |
8051 | ||
8052 | if (!rdev->ops->set_rekey_data) { | |
8053 | err = -EOPNOTSUPP; | |
8054 | goto out; | |
8055 | } | |
8056 | ||
e35e4d28 | 8057 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8058 | out: |
8059 | wdev_unlock(wdev); | |
8060 | return err; | |
8061 | } | |
8062 | ||
28946da7 JB |
8063 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8064 | struct genl_info *info) | |
8065 | { | |
8066 | struct net_device *dev = info->user_ptr[1]; | |
8067 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8068 | ||
8069 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8070 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8071 | return -EINVAL; | |
8072 | ||
15e47304 | 8073 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8074 | return -EBUSY; |
8075 | ||
15e47304 | 8076 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8077 | return 0; |
8078 | } | |
8079 | ||
7f6cf311 JB |
8080 | static int nl80211_probe_client(struct sk_buff *skb, |
8081 | struct genl_info *info) | |
8082 | { | |
8083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8084 | struct net_device *dev = info->user_ptr[1]; | |
8085 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8086 | struct sk_buff *msg; | |
8087 | void *hdr; | |
8088 | const u8 *addr; | |
8089 | u64 cookie; | |
8090 | int err; | |
8091 | ||
8092 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8093 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8094 | return -EOPNOTSUPP; | |
8095 | ||
8096 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8097 | return -EINVAL; | |
8098 | ||
8099 | if (!rdev->ops->probe_client) | |
8100 | return -EOPNOTSUPP; | |
8101 | ||
8102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8103 | if (!msg) | |
8104 | return -ENOMEM; | |
8105 | ||
15e47304 | 8106 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 JB |
8107 | NL80211_CMD_PROBE_CLIENT); |
8108 | ||
8109 | if (IS_ERR(hdr)) { | |
8110 | err = PTR_ERR(hdr); | |
8111 | goto free_msg; | |
8112 | } | |
8113 | ||
8114 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8115 | ||
e35e4d28 | 8116 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8117 | if (err) |
8118 | goto free_msg; | |
8119 | ||
9360ffd1 DM |
8120 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8121 | goto nla_put_failure; | |
7f6cf311 JB |
8122 | |
8123 | genlmsg_end(msg, hdr); | |
8124 | ||
8125 | return genlmsg_reply(msg, info); | |
8126 | ||
8127 | nla_put_failure: | |
8128 | err = -ENOBUFS; | |
8129 | free_msg: | |
8130 | nlmsg_free(msg); | |
8131 | return err; | |
8132 | } | |
8133 | ||
5e760230 JB |
8134 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8135 | { | |
8136 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8137 | struct cfg80211_beacon_registration *reg, *nreg; |
8138 | int rv; | |
5e760230 JB |
8139 | |
8140 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8141 | return -EOPNOTSUPP; | |
8142 | ||
37c73b5f BG |
8143 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8144 | if (!nreg) | |
8145 | return -ENOMEM; | |
8146 | ||
8147 | /* First, check if already registered. */ | |
8148 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8149 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8150 | if (reg->nlportid == info->snd_portid) { | |
8151 | rv = -EALREADY; | |
8152 | goto out_err; | |
8153 | } | |
8154 | } | |
8155 | /* Add it to the list */ | |
8156 | nreg->nlportid = info->snd_portid; | |
8157 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8158 | |
37c73b5f | 8159 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8160 | |
8161 | return 0; | |
37c73b5f BG |
8162 | out_err: |
8163 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8164 | kfree(nreg); | |
8165 | return rv; | |
5e760230 JB |
8166 | } |
8167 | ||
98104fde JB |
8168 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8169 | { | |
8170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8171 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8172 | int err; | |
8173 | ||
8174 | if (!rdev->ops->start_p2p_device) | |
8175 | return -EOPNOTSUPP; | |
8176 | ||
8177 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8178 | return -EOPNOTSUPP; | |
8179 | ||
8180 | if (wdev->p2p_started) | |
8181 | return 0; | |
8182 | ||
98104fde | 8183 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8184 | if (err) |
8185 | return err; | |
8186 | ||
eeb126e9 | 8187 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8188 | if (err) |
8189 | return err; | |
8190 | ||
8191 | wdev->p2p_started = true; | |
98104fde | 8192 | rdev->opencount++; |
98104fde JB |
8193 | |
8194 | return 0; | |
8195 | } | |
8196 | ||
8197 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8198 | { | |
8199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8200 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8201 | ||
8202 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8203 | return -EOPNOTSUPP; | |
8204 | ||
8205 | if (!rdev->ops->stop_p2p_device) | |
8206 | return -EOPNOTSUPP; | |
8207 | ||
f9f47529 | 8208 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8209 | |
8210 | return 0; | |
8211 | } | |
8212 | ||
3713b4e3 JB |
8213 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8214 | struct genl_info *info) | |
8215 | { | |
8216 | void *hdr; | |
8217 | struct sk_buff *msg; | |
8218 | ||
8219 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8220 | if (!msg) | |
8221 | return -ENOMEM; | |
8222 | ||
8223 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8224 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8225 | if (!hdr) | |
8226 | goto nla_put_failure; | |
8227 | ||
8228 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8229 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8230 | goto nla_put_failure; | |
8231 | ||
8232 | genlmsg_end(msg, hdr); | |
8233 | return genlmsg_reply(msg, info); | |
8234 | ||
8235 | nla_put_failure: | |
8236 | kfree_skb(msg); | |
8237 | return -ENOBUFS; | |
8238 | } | |
8239 | ||
355199e0 JM |
8240 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8241 | { | |
8242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8243 | struct cfg80211_update_ft_ies_params ft_params; | |
8244 | struct net_device *dev = info->user_ptr[1]; | |
8245 | ||
8246 | if (!rdev->ops->update_ft_ies) | |
8247 | return -EOPNOTSUPP; | |
8248 | ||
8249 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8250 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8251 | return -EINVAL; | |
8252 | ||
8253 | memset(&ft_params, 0, sizeof(ft_params)); | |
8254 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8255 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8256 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8257 | ||
8258 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8259 | } | |
8260 | ||
5de17984 AS |
8261 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8262 | struct genl_info *info) | |
8263 | { | |
8264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8265 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8266 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8267 | u16 duration; | |
8268 | int ret; | |
8269 | ||
8270 | if (!rdev->ops->crit_proto_start) | |
8271 | return -EOPNOTSUPP; | |
8272 | ||
8273 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8274 | return -EINVAL; | |
8275 | ||
8276 | if (rdev->crit_proto_nlportid) | |
8277 | return -EBUSY; | |
8278 | ||
8279 | /* determine protocol if provided */ | |
8280 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8281 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8282 | ||
8283 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8284 | return -EINVAL; | |
8285 | ||
8286 | /* timeout must be provided */ | |
8287 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8288 | return -EINVAL; | |
8289 | ||
8290 | duration = | |
8291 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8292 | ||
8293 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8294 | return -ERANGE; | |
8295 | ||
8296 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8297 | if (!ret) | |
8298 | rdev->crit_proto_nlportid = info->snd_portid; | |
8299 | ||
8300 | return ret; | |
8301 | } | |
8302 | ||
8303 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8304 | struct genl_info *info) | |
8305 | { | |
8306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8307 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8308 | ||
8309 | if (!rdev->ops->crit_proto_stop) | |
8310 | return -EOPNOTSUPP; | |
8311 | ||
8312 | if (rdev->crit_proto_nlportid) { | |
8313 | rdev->crit_proto_nlportid = 0; | |
8314 | rdev_crit_proto_stop(rdev, wdev); | |
8315 | } | |
8316 | return 0; | |
8317 | } | |
8318 | ||
4c476991 JB |
8319 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
8320 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
8321 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
8322 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
8323 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
8324 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 8325 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 8326 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
8327 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
8328 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
8329 | |
8330 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8331 | struct genl_info *info) | |
8332 | { | |
8333 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 8334 | struct wireless_dev *wdev; |
4c476991 | 8335 | struct net_device *dev; |
4c476991 JB |
8336 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
8337 | ||
8338 | if (rtnl) | |
8339 | rtnl_lock(); | |
8340 | ||
8341 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 8342 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
8343 | if (IS_ERR(rdev)) { |
8344 | if (rtnl) | |
8345 | rtnl_unlock(); | |
8346 | return PTR_ERR(rdev); | |
8347 | } | |
8348 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
8349 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
8350 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
8351 | ASSERT_RTNL(); |
8352 | ||
89a54e48 JB |
8353 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
8354 | info->attrs); | |
8355 | if (IS_ERR(wdev)) { | |
4c476991 JB |
8356 | if (rtnl) |
8357 | rtnl_unlock(); | |
89a54e48 | 8358 | return PTR_ERR(wdev); |
4c476991 | 8359 | } |
89a54e48 | 8360 | |
89a54e48 JB |
8361 | dev = wdev->netdev; |
8362 | rdev = wiphy_to_dev(wdev->wiphy); | |
8363 | ||
1bf614ef JB |
8364 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
8365 | if (!dev) { | |
1bf614ef JB |
8366 | if (rtnl) |
8367 | rtnl_unlock(); | |
8368 | return -EINVAL; | |
8369 | } | |
8370 | ||
8371 | info->user_ptr[1] = dev; | |
8372 | } else { | |
8373 | info->user_ptr[1] = wdev; | |
41265714 | 8374 | } |
1bf614ef JB |
8375 | |
8376 | if (dev) { | |
8377 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
8378 | !netif_running(dev)) { | |
1bf614ef JB |
8379 | if (rtnl) |
8380 | rtnl_unlock(); | |
8381 | return -ENETDOWN; | |
8382 | } | |
8383 | ||
8384 | dev_hold(dev); | |
98104fde JB |
8385 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
8386 | if (!wdev->p2p_started) { | |
98104fde JB |
8387 | if (rtnl) |
8388 | rtnl_unlock(); | |
8389 | return -ENETDOWN; | |
8390 | } | |
41265714 | 8391 | } |
89a54e48 | 8392 | |
4c476991 | 8393 | info->user_ptr[0] = rdev; |
4c476991 JB |
8394 | } |
8395 | ||
8396 | return 0; | |
8397 | } | |
8398 | ||
8399 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
8400 | struct genl_info *info) | |
8401 | { | |
1bf614ef JB |
8402 | if (info->user_ptr[1]) { |
8403 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
8404 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8405 | ||
8406 | if (wdev->netdev) | |
8407 | dev_put(wdev->netdev); | |
8408 | } else { | |
8409 | dev_put(info->user_ptr[1]); | |
8410 | } | |
8411 | } | |
4c476991 JB |
8412 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
8413 | rtnl_unlock(); | |
8414 | } | |
8415 | ||
55682965 JB |
8416 | static struct genl_ops nl80211_ops[] = { |
8417 | { | |
8418 | .cmd = NL80211_CMD_GET_WIPHY, | |
8419 | .doit = nl80211_get_wiphy, | |
8420 | .dumpit = nl80211_dump_wiphy, | |
8421 | .policy = nl80211_policy, | |
8422 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8423 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8424 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8425 | }, |
8426 | { | |
8427 | .cmd = NL80211_CMD_SET_WIPHY, | |
8428 | .doit = nl80211_set_wiphy, | |
8429 | .policy = nl80211_policy, | |
8430 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 8431 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
8432 | }, |
8433 | { | |
8434 | .cmd = NL80211_CMD_GET_INTERFACE, | |
8435 | .doit = nl80211_get_interface, | |
8436 | .dumpit = nl80211_dump_interface, | |
8437 | .policy = nl80211_policy, | |
8438 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
8439 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
8440 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8441 | }, |
8442 | { | |
8443 | .cmd = NL80211_CMD_SET_INTERFACE, | |
8444 | .doit = nl80211_set_interface, | |
8445 | .policy = nl80211_policy, | |
8446 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8447 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8448 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8449 | }, |
8450 | { | |
8451 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
8452 | .doit = nl80211_new_interface, | |
8453 | .policy = nl80211_policy, | |
8454 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8455 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8456 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
8457 | }, |
8458 | { | |
8459 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
8460 | .doit = nl80211_del_interface, | |
8461 | .policy = nl80211_policy, | |
41ade00f | 8462 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 8463 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8464 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8465 | }, |
8466 | { | |
8467 | .cmd = NL80211_CMD_GET_KEY, | |
8468 | .doit = nl80211_get_key, | |
8469 | .policy = nl80211_policy, | |
8470 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8472 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8473 | }, |
8474 | { | |
8475 | .cmd = NL80211_CMD_SET_KEY, | |
8476 | .doit = nl80211_set_key, | |
8477 | .policy = nl80211_policy, | |
8478 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8479 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8480 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8481 | }, |
8482 | { | |
8483 | .cmd = NL80211_CMD_NEW_KEY, | |
8484 | .doit = nl80211_new_key, | |
8485 | .policy = nl80211_policy, | |
8486 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8487 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8488 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
8489 | }, |
8490 | { | |
8491 | .cmd = NL80211_CMD_DEL_KEY, | |
8492 | .doit = nl80211_del_key, | |
8493 | .policy = nl80211_policy, | |
55682965 | 8494 | .flags = GENL_ADMIN_PERM, |
41265714 | 8495 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8496 | NL80211_FLAG_NEED_RTNL, |
55682965 | 8497 | }, |
ed1b6cc7 JB |
8498 | { |
8499 | .cmd = NL80211_CMD_SET_BEACON, | |
8500 | .policy = nl80211_policy, | |
8501 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8502 | .doit = nl80211_set_beacon, |
2b5f8b0b | 8503 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8504 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8505 | }, |
8506 | { | |
8860020e | 8507 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
8508 | .policy = nl80211_policy, |
8509 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8510 | .doit = nl80211_start_ap, |
2b5f8b0b | 8511 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8512 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
8513 | }, |
8514 | { | |
8860020e | 8515 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
8516 | .policy = nl80211_policy, |
8517 | .flags = GENL_ADMIN_PERM, | |
8860020e | 8518 | .doit = nl80211_stop_ap, |
2b5f8b0b | 8519 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8520 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 8521 | }, |
5727ef1b JB |
8522 | { |
8523 | .cmd = NL80211_CMD_GET_STATION, | |
8524 | .doit = nl80211_get_station, | |
2ec600d6 | 8525 | .dumpit = nl80211_dump_station, |
5727ef1b | 8526 | .policy = nl80211_policy, |
4c476991 JB |
8527 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8528 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
8529 | }, |
8530 | { | |
8531 | .cmd = NL80211_CMD_SET_STATION, | |
8532 | .doit = nl80211_set_station, | |
8533 | .policy = nl80211_policy, | |
8534 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8536 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8537 | }, |
8538 | { | |
8539 | .cmd = NL80211_CMD_NEW_STATION, | |
8540 | .doit = nl80211_new_station, | |
8541 | .policy = nl80211_policy, | |
8542 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8543 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8544 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
8545 | }, |
8546 | { | |
8547 | .cmd = NL80211_CMD_DEL_STATION, | |
8548 | .doit = nl80211_del_station, | |
8549 | .policy = nl80211_policy, | |
2ec600d6 | 8550 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8551 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8552 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8553 | }, |
8554 | { | |
8555 | .cmd = NL80211_CMD_GET_MPATH, | |
8556 | .doit = nl80211_get_mpath, | |
8557 | .dumpit = nl80211_dump_mpath, | |
8558 | .policy = nl80211_policy, | |
8559 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8560 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8561 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8562 | }, |
8563 | { | |
8564 | .cmd = NL80211_CMD_SET_MPATH, | |
8565 | .doit = nl80211_set_mpath, | |
8566 | .policy = nl80211_policy, | |
8567 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8568 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8569 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8570 | }, |
8571 | { | |
8572 | .cmd = NL80211_CMD_NEW_MPATH, | |
8573 | .doit = nl80211_new_mpath, | |
8574 | .policy = nl80211_policy, | |
8575 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8576 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8577 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
8578 | }, |
8579 | { | |
8580 | .cmd = NL80211_CMD_DEL_MPATH, | |
8581 | .doit = nl80211_del_mpath, | |
8582 | .policy = nl80211_policy, | |
9f1ba906 | 8583 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8585 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
8586 | }, |
8587 | { | |
8588 | .cmd = NL80211_CMD_SET_BSS, | |
8589 | .doit = nl80211_set_bss, | |
8590 | .policy = nl80211_policy, | |
b2e1b302 | 8591 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 8592 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8593 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 8594 | }, |
f130347c LR |
8595 | { |
8596 | .cmd = NL80211_CMD_GET_REG, | |
8597 | .doit = nl80211_get_reg, | |
8598 | .policy = nl80211_policy, | |
5fe231e8 | 8599 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
8600 | /* can be retrieved by unprivileged users */ |
8601 | }, | |
b2e1b302 LR |
8602 | { |
8603 | .cmd = NL80211_CMD_SET_REG, | |
8604 | .doit = nl80211_set_reg, | |
8605 | .policy = nl80211_policy, | |
8606 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 8607 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
8608 | }, |
8609 | { | |
8610 | .cmd = NL80211_CMD_REQ_SET_REG, | |
8611 | .doit = nl80211_req_set_reg, | |
8612 | .policy = nl80211_policy, | |
93da9cc1 | 8613 | .flags = GENL_ADMIN_PERM, |
8614 | }, | |
8615 | { | |
24bdd9f4 JC |
8616 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
8617 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 8618 | .policy = nl80211_policy, |
8619 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 8620 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8621 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 8622 | }, |
8623 | { | |
24bdd9f4 JC |
8624 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
8625 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 8626 | .policy = nl80211_policy, |
9aed3cc1 | 8627 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 8628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8629 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 8630 | }, |
2a519311 JB |
8631 | { |
8632 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
8633 | .doit = nl80211_trigger_scan, | |
8634 | .policy = nl80211_policy, | |
8635 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 8636 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8637 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
8638 | }, |
8639 | { | |
8640 | .cmd = NL80211_CMD_GET_SCAN, | |
8641 | .policy = nl80211_policy, | |
8642 | .dumpit = nl80211_dump_scan, | |
8643 | }, | |
807f8a8c LC |
8644 | { |
8645 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
8646 | .doit = nl80211_start_sched_scan, | |
8647 | .policy = nl80211_policy, | |
8648 | .flags = GENL_ADMIN_PERM, | |
8649 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8650 | NL80211_FLAG_NEED_RTNL, | |
8651 | }, | |
8652 | { | |
8653 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
8654 | .doit = nl80211_stop_sched_scan, | |
8655 | .policy = nl80211_policy, | |
8656 | .flags = GENL_ADMIN_PERM, | |
8657 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8658 | NL80211_FLAG_NEED_RTNL, | |
8659 | }, | |
636a5d36 JM |
8660 | { |
8661 | .cmd = NL80211_CMD_AUTHENTICATE, | |
8662 | .doit = nl80211_authenticate, | |
8663 | .policy = nl80211_policy, | |
8664 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8665 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8666 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8667 | }, |
8668 | { | |
8669 | .cmd = NL80211_CMD_ASSOCIATE, | |
8670 | .doit = nl80211_associate, | |
8671 | .policy = nl80211_policy, | |
8672 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8673 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8674 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8675 | }, |
8676 | { | |
8677 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
8678 | .doit = nl80211_deauthenticate, | |
8679 | .policy = nl80211_policy, | |
8680 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8681 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8682 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
8683 | }, |
8684 | { | |
8685 | .cmd = NL80211_CMD_DISASSOCIATE, | |
8686 | .doit = nl80211_disassociate, | |
8687 | .policy = nl80211_policy, | |
8688 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8689 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8690 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 8691 | }, |
04a773ad JB |
8692 | { |
8693 | .cmd = NL80211_CMD_JOIN_IBSS, | |
8694 | .doit = nl80211_join_ibss, | |
8695 | .policy = nl80211_policy, | |
8696 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8697 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8698 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
8699 | }, |
8700 | { | |
8701 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
8702 | .doit = nl80211_leave_ibss, | |
8703 | .policy = nl80211_policy, | |
8704 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8705 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8706 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 8707 | }, |
aff89a9b JB |
8708 | #ifdef CONFIG_NL80211_TESTMODE |
8709 | { | |
8710 | .cmd = NL80211_CMD_TESTMODE, | |
8711 | .doit = nl80211_testmode_do, | |
71063f0e | 8712 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
8713 | .policy = nl80211_policy, |
8714 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8715 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8716 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
8717 | }, |
8718 | #endif | |
b23aa676 SO |
8719 | { |
8720 | .cmd = NL80211_CMD_CONNECT, | |
8721 | .doit = nl80211_connect, | |
8722 | .policy = nl80211_policy, | |
8723 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8724 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8725 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
8726 | }, |
8727 | { | |
8728 | .cmd = NL80211_CMD_DISCONNECT, | |
8729 | .doit = nl80211_disconnect, | |
8730 | .policy = nl80211_policy, | |
8731 | .flags = GENL_ADMIN_PERM, | |
41265714 | 8732 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8733 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 8734 | }, |
463d0183 JB |
8735 | { |
8736 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
8737 | .doit = nl80211_wiphy_netns, | |
8738 | .policy = nl80211_policy, | |
8739 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8740 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
8741 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 8742 | }, |
61fa713c HS |
8743 | { |
8744 | .cmd = NL80211_CMD_GET_SURVEY, | |
8745 | .policy = nl80211_policy, | |
8746 | .dumpit = nl80211_dump_survey, | |
8747 | }, | |
67fbb16b SO |
8748 | { |
8749 | .cmd = NL80211_CMD_SET_PMKSA, | |
8750 | .doit = nl80211_setdel_pmksa, | |
8751 | .policy = nl80211_policy, | |
8752 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8754 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8755 | }, |
8756 | { | |
8757 | .cmd = NL80211_CMD_DEL_PMKSA, | |
8758 | .doit = nl80211_setdel_pmksa, | |
8759 | .policy = nl80211_policy, | |
8760 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8761 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8762 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
8763 | }, |
8764 | { | |
8765 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
8766 | .doit = nl80211_flush_pmksa, | |
8767 | .policy = nl80211_policy, | |
8768 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8769 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 8770 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 8771 | }, |
9588bbd5 JM |
8772 | { |
8773 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
8774 | .doit = nl80211_remain_on_channel, | |
8775 | .policy = nl80211_policy, | |
8776 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8777 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8778 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
8779 | }, |
8780 | { | |
8781 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8782 | .doit = nl80211_cancel_remain_on_channel, | |
8783 | .policy = nl80211_policy, | |
8784 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8785 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8786 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 8787 | }, |
13ae75b1 JM |
8788 | { |
8789 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
8790 | .doit = nl80211_set_tx_bitrate_mask, | |
8791 | .policy = nl80211_policy, | |
8792 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8793 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8794 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 8795 | }, |
026331c4 | 8796 | { |
2e161f78 JB |
8797 | .cmd = NL80211_CMD_REGISTER_FRAME, |
8798 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
8799 | .policy = nl80211_policy, |
8800 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 8801 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 8802 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
8803 | }, |
8804 | { | |
2e161f78 JB |
8805 | .cmd = NL80211_CMD_FRAME, |
8806 | .doit = nl80211_tx_mgmt, | |
026331c4 | 8807 | .policy = nl80211_policy, |
f7ca38df | 8808 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8809 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
8810 | NL80211_FLAG_NEED_RTNL, |
8811 | }, | |
8812 | { | |
8813 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
8814 | .doit = nl80211_tx_mgmt_cancel_wait, | |
8815 | .policy = nl80211_policy, | |
026331c4 | 8816 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 8817 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 8818 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 8819 | }, |
ffb9eb3d KV |
8820 | { |
8821 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
8822 | .doit = nl80211_set_power_save, | |
8823 | .policy = nl80211_policy, | |
8824 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8825 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8826 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
8827 | }, |
8828 | { | |
8829 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
8830 | .doit = nl80211_get_power_save, | |
8831 | .policy = nl80211_policy, | |
8832 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
8833 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8834 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 8835 | }, |
d6dc1a38 JO |
8836 | { |
8837 | .cmd = NL80211_CMD_SET_CQM, | |
8838 | .doit = nl80211_set_cqm, | |
8839 | .policy = nl80211_policy, | |
8840 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8841 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8842 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 8843 | }, |
f444de05 JB |
8844 | { |
8845 | .cmd = NL80211_CMD_SET_CHANNEL, | |
8846 | .doit = nl80211_set_channel, | |
8847 | .policy = nl80211_policy, | |
8848 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
8849 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8850 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 8851 | }, |
e8347eba BJ |
8852 | { |
8853 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
8854 | .doit = nl80211_set_wds_peer, | |
8855 | .policy = nl80211_policy, | |
8856 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
8857 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
8858 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 8859 | }, |
29cbe68c JB |
8860 | { |
8861 | .cmd = NL80211_CMD_JOIN_MESH, | |
8862 | .doit = nl80211_join_mesh, | |
8863 | .policy = nl80211_policy, | |
8864 | .flags = GENL_ADMIN_PERM, | |
8865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8866 | NL80211_FLAG_NEED_RTNL, | |
8867 | }, | |
8868 | { | |
8869 | .cmd = NL80211_CMD_LEAVE_MESH, | |
8870 | .doit = nl80211_leave_mesh, | |
8871 | .policy = nl80211_policy, | |
8872 | .flags = GENL_ADMIN_PERM, | |
8873 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8874 | NL80211_FLAG_NEED_RTNL, | |
8875 | }, | |
dfb89c56 | 8876 | #ifdef CONFIG_PM |
ff1b6e69 JB |
8877 | { |
8878 | .cmd = NL80211_CMD_GET_WOWLAN, | |
8879 | .doit = nl80211_get_wowlan, | |
8880 | .policy = nl80211_policy, | |
8881 | /* can be retrieved by unprivileged users */ | |
8882 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8883 | NL80211_FLAG_NEED_RTNL, | |
8884 | }, | |
8885 | { | |
8886 | .cmd = NL80211_CMD_SET_WOWLAN, | |
8887 | .doit = nl80211_set_wowlan, | |
8888 | .policy = nl80211_policy, | |
8889 | .flags = GENL_ADMIN_PERM, | |
8890 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8891 | NL80211_FLAG_NEED_RTNL, | |
8892 | }, | |
dfb89c56 | 8893 | #endif |
e5497d76 JB |
8894 | { |
8895 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
8896 | .doit = nl80211_set_rekey_data, | |
8897 | .policy = nl80211_policy, | |
8898 | .flags = GENL_ADMIN_PERM, | |
8899 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8900 | NL80211_FLAG_NEED_RTNL, | |
8901 | }, | |
109086ce AN |
8902 | { |
8903 | .cmd = NL80211_CMD_TDLS_MGMT, | |
8904 | .doit = nl80211_tdls_mgmt, | |
8905 | .policy = nl80211_policy, | |
8906 | .flags = GENL_ADMIN_PERM, | |
8907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8908 | NL80211_FLAG_NEED_RTNL, | |
8909 | }, | |
8910 | { | |
8911 | .cmd = NL80211_CMD_TDLS_OPER, | |
8912 | .doit = nl80211_tdls_oper, | |
8913 | .policy = nl80211_policy, | |
8914 | .flags = GENL_ADMIN_PERM, | |
8915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8916 | NL80211_FLAG_NEED_RTNL, | |
8917 | }, | |
28946da7 JB |
8918 | { |
8919 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
8920 | .doit = nl80211_register_unexpected_frame, | |
8921 | .policy = nl80211_policy, | |
8922 | .flags = GENL_ADMIN_PERM, | |
8923 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8924 | NL80211_FLAG_NEED_RTNL, | |
8925 | }, | |
7f6cf311 JB |
8926 | { |
8927 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
8928 | .doit = nl80211_probe_client, | |
8929 | .policy = nl80211_policy, | |
8930 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 8931 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
8932 | NL80211_FLAG_NEED_RTNL, |
8933 | }, | |
5e760230 JB |
8934 | { |
8935 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
8936 | .doit = nl80211_register_beacons, | |
8937 | .policy = nl80211_policy, | |
8938 | .flags = GENL_ADMIN_PERM, | |
8939 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
8940 | NL80211_FLAG_NEED_RTNL, | |
8941 | }, | |
1d9d9213 SW |
8942 | { |
8943 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
8944 | .doit = nl80211_set_noack_map, | |
8945 | .policy = nl80211_policy, | |
8946 | .flags = GENL_ADMIN_PERM, | |
8947 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8948 | NL80211_FLAG_NEED_RTNL, | |
8949 | }, | |
98104fde JB |
8950 | { |
8951 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
8952 | .doit = nl80211_start_p2p_device, | |
8953 | .policy = nl80211_policy, | |
8954 | .flags = GENL_ADMIN_PERM, | |
8955 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
8956 | NL80211_FLAG_NEED_RTNL, | |
8957 | }, | |
8958 | { | |
8959 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
8960 | .doit = nl80211_stop_p2p_device, | |
8961 | .policy = nl80211_policy, | |
8962 | .flags = GENL_ADMIN_PERM, | |
8963 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
8964 | NL80211_FLAG_NEED_RTNL, | |
8965 | }, | |
f4e583c8 AQ |
8966 | { |
8967 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
8968 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
8969 | .policy = nl80211_policy, |
8970 | .flags = GENL_ADMIN_PERM, | |
8971 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8972 | NL80211_FLAG_NEED_RTNL, | |
8973 | }, | |
8974 | { | |
8975 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
8976 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
8977 | .policy = nl80211_policy, |
8978 | .flags = GENL_ADMIN_PERM, | |
8979 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
8980 | NL80211_FLAG_NEED_RTNL, | |
8981 | }, | |
04f39047 SW |
8982 | { |
8983 | .cmd = NL80211_CMD_RADAR_DETECT, | |
8984 | .doit = nl80211_start_radar_detection, | |
8985 | .policy = nl80211_policy, | |
8986 | .flags = GENL_ADMIN_PERM, | |
8987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
8988 | NL80211_FLAG_NEED_RTNL, | |
8989 | }, | |
3713b4e3 JB |
8990 | { |
8991 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
8992 | .doit = nl80211_get_protocol_features, | |
8993 | .policy = nl80211_policy, | |
8994 | }, | |
355199e0 JM |
8995 | { |
8996 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
8997 | .doit = nl80211_update_ft_ies, | |
8998 | .policy = nl80211_policy, | |
8999 | .flags = GENL_ADMIN_PERM, | |
9000 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9001 | NL80211_FLAG_NEED_RTNL, | |
9002 | }, | |
5de17984 AS |
9003 | { |
9004 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9005 | .doit = nl80211_crit_protocol_start, | |
9006 | .policy = nl80211_policy, | |
9007 | .flags = GENL_ADMIN_PERM, | |
9008 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9009 | NL80211_FLAG_NEED_RTNL, | |
9010 | }, | |
9011 | { | |
9012 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9013 | .doit = nl80211_crit_protocol_stop, | |
9014 | .policy = nl80211_policy, | |
9015 | .flags = GENL_ADMIN_PERM, | |
9016 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9017 | NL80211_FLAG_NEED_RTNL, | |
9018 | } | |
55682965 | 9019 | }; |
9588bbd5 | 9020 | |
6039f6d2 JM |
9021 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
9022 | .name = "mlme", | |
9023 | }; | |
55682965 JB |
9024 | |
9025 | /* multicast groups */ | |
9026 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
9027 | .name = "config", | |
9028 | }; | |
2a519311 JB |
9029 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
9030 | .name = "scan", | |
9031 | }; | |
73d54c9e LR |
9032 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
9033 | .name = "regulatory", | |
9034 | }; | |
55682965 JB |
9035 | |
9036 | /* notification functions */ | |
9037 | ||
9038 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9039 | { | |
9040 | struct sk_buff *msg; | |
9041 | ||
fd2120ca | 9042 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9043 | if (!msg) |
9044 | return; | |
9045 | ||
3713b4e3 JB |
9046 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
9047 | false, NULL, NULL, NULL) < 0) { | |
55682965 JB |
9048 | nlmsg_free(msg); |
9049 | return; | |
9050 | } | |
9051 | ||
463d0183 JB |
9052 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9053 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
9054 | } |
9055 | ||
362a415d JB |
9056 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9057 | struct cfg80211_registered_device *rdev) | |
9058 | { | |
9059 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9060 | struct nlattr *nest; | |
9061 | int i; | |
9062 | ||
9063 | if (WARN_ON(!req)) | |
9064 | return 0; | |
9065 | ||
9066 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9067 | if (!nest) | |
9068 | goto nla_put_failure; | |
9360ffd1 DM |
9069 | for (i = 0; i < req->n_ssids; i++) { |
9070 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9071 | goto nla_put_failure; | |
9072 | } | |
362a415d JB |
9073 | nla_nest_end(msg, nest); |
9074 | ||
9075 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9076 | if (!nest) | |
9077 | goto nla_put_failure; | |
9360ffd1 DM |
9078 | for (i = 0; i < req->n_channels; i++) { |
9079 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9080 | goto nla_put_failure; | |
9081 | } | |
362a415d JB |
9082 | nla_nest_end(msg, nest); |
9083 | ||
9360ffd1 DM |
9084 | if (req->ie && |
9085 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9086 | goto nla_put_failure; | |
362a415d | 9087 | |
ed473771 SL |
9088 | if (req->flags) |
9089 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); | |
9090 | ||
362a415d JB |
9091 | return 0; |
9092 | nla_put_failure: | |
9093 | return -ENOBUFS; | |
9094 | } | |
9095 | ||
a538e2d5 JB |
9096 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9097 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9098 | struct wireless_dev *wdev, |
15e47304 | 9099 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9100 | u32 cmd) |
2a519311 JB |
9101 | { |
9102 | void *hdr; | |
9103 | ||
15e47304 | 9104 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9105 | if (!hdr) |
9106 | return -1; | |
9107 | ||
9360ffd1 | 9108 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9109 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9110 | wdev->netdev->ifindex)) || | |
9111 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9112 | goto nla_put_failure; |
2a519311 | 9113 | |
362a415d JB |
9114 | /* ignore errors and send incomplete event anyway */ |
9115 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9116 | |
9117 | return genlmsg_end(msg, hdr); | |
9118 | ||
9119 | nla_put_failure: | |
9120 | genlmsg_cancel(msg, hdr); | |
9121 | return -EMSGSIZE; | |
9122 | } | |
9123 | ||
807f8a8c LC |
9124 | static int |
9125 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9126 | struct cfg80211_registered_device *rdev, | |
9127 | struct net_device *netdev, | |
15e47304 | 9128 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9129 | { |
9130 | void *hdr; | |
9131 | ||
15e47304 | 9132 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9133 | if (!hdr) |
9134 | return -1; | |
9135 | ||
9360ffd1 DM |
9136 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9137 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9138 | goto nla_put_failure; | |
807f8a8c LC |
9139 | |
9140 | return genlmsg_end(msg, hdr); | |
9141 | ||
9142 | nla_put_failure: | |
9143 | genlmsg_cancel(msg, hdr); | |
9144 | return -EMSGSIZE; | |
9145 | } | |
9146 | ||
a538e2d5 | 9147 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9148 | struct wireless_dev *wdev) |
a538e2d5 JB |
9149 | { |
9150 | struct sk_buff *msg; | |
9151 | ||
58050fce | 9152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
9153 | if (!msg) |
9154 | return; | |
9155 | ||
fd014284 | 9156 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
9157 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
9158 | nlmsg_free(msg); | |
9159 | return; | |
9160 | } | |
9161 | ||
463d0183 JB |
9162 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9163 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
9164 | } |
9165 | ||
2a519311 | 9166 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 9167 | struct wireless_dev *wdev) |
2a519311 JB |
9168 | { |
9169 | struct sk_buff *msg; | |
9170 | ||
fd2120ca | 9171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9172 | if (!msg) |
9173 | return; | |
9174 | ||
fd014284 | 9175 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9176 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
9177 | nlmsg_free(msg); |
9178 | return; | |
9179 | } | |
9180 | ||
463d0183 JB |
9181 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9182 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9183 | } |
9184 | ||
9185 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 9186 | struct wireless_dev *wdev) |
2a519311 JB |
9187 | { |
9188 | struct sk_buff *msg; | |
9189 | ||
fd2120ca | 9190 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
9191 | if (!msg) |
9192 | return; | |
9193 | ||
fd014284 | 9194 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 9195 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
9196 | nlmsg_free(msg); |
9197 | return; | |
9198 | } | |
9199 | ||
463d0183 JB |
9200 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9201 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
9202 | } |
9203 | ||
807f8a8c LC |
9204 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
9205 | struct net_device *netdev) | |
9206 | { | |
9207 | struct sk_buff *msg; | |
9208 | ||
9209 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9210 | if (!msg) | |
9211 | return; | |
9212 | ||
9213 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
9214 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
9215 | nlmsg_free(msg); | |
9216 | return; | |
9217 | } | |
9218 | ||
9219 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9220 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9221 | } | |
9222 | ||
9223 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
9224 | struct net_device *netdev, u32 cmd) | |
9225 | { | |
9226 | struct sk_buff *msg; | |
9227 | ||
58050fce | 9228 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
9229 | if (!msg) |
9230 | return; | |
9231 | ||
9232 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
9233 | nlmsg_free(msg); | |
9234 | return; | |
9235 | } | |
9236 | ||
9237 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9238 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
9239 | } | |
9240 | ||
73d54c9e LR |
9241 | /* |
9242 | * This can happen on global regulatory changes or device specific settings | |
9243 | * based on custom world regulatory domains. | |
9244 | */ | |
9245 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
9246 | { | |
9247 | struct sk_buff *msg; | |
9248 | void *hdr; | |
9249 | ||
fd2120ca | 9250 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
9251 | if (!msg) |
9252 | return; | |
9253 | ||
9254 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
9255 | if (!hdr) { | |
9256 | nlmsg_free(msg); | |
9257 | return; | |
9258 | } | |
9259 | ||
9260 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
9261 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
9262 | goto nla_put_failure; | |
9263 | ||
9264 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
9265 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9266 | NL80211_REGDOM_TYPE_WORLD)) | |
9267 | goto nla_put_failure; | |
9268 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
9269 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9270 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
9271 | goto nla_put_failure; | |
9272 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
9273 | request->intersect) { | |
9274 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9275 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
9276 | goto nla_put_failure; | |
9277 | } else { | |
9278 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
9279 | NL80211_REGDOM_TYPE_COUNTRY) || | |
9280 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
9281 | request->alpha2)) | |
9282 | goto nla_put_failure; | |
9283 | } | |
9284 | ||
f4173766 | 9285 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
9286 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
9287 | goto nla_put_failure; | |
73d54c9e | 9288 | |
3b7b72ee | 9289 | genlmsg_end(msg, hdr); |
73d54c9e | 9290 | |
bc43b28c | 9291 | rcu_read_lock(); |
463d0183 | 9292 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
9293 | GFP_ATOMIC); |
9294 | rcu_read_unlock(); | |
73d54c9e LR |
9295 | |
9296 | return; | |
9297 | ||
9298 | nla_put_failure: | |
9299 | genlmsg_cancel(msg, hdr); | |
9300 | nlmsg_free(msg); | |
9301 | } | |
9302 | ||
6039f6d2 JM |
9303 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
9304 | struct net_device *netdev, | |
9305 | const u8 *buf, size_t len, | |
e6d6e342 | 9306 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
9307 | { |
9308 | struct sk_buff *msg; | |
9309 | void *hdr; | |
9310 | ||
e6d6e342 | 9311 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
9312 | if (!msg) |
9313 | return; | |
9314 | ||
9315 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9316 | if (!hdr) { | |
9317 | nlmsg_free(msg); | |
9318 | return; | |
9319 | } | |
9320 | ||
9360ffd1 DM |
9321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9322 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9323 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9324 | goto nla_put_failure; | |
6039f6d2 | 9325 | |
3b7b72ee | 9326 | genlmsg_end(msg, hdr); |
6039f6d2 | 9327 | |
463d0183 JB |
9328 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9329 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
9330 | return; |
9331 | ||
9332 | nla_put_failure: | |
9333 | genlmsg_cancel(msg, hdr); | |
9334 | nlmsg_free(msg); | |
9335 | } | |
9336 | ||
9337 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9338 | struct net_device *netdev, const u8 *buf, |
9339 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9340 | { |
9341 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9342 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
9343 | } |
9344 | ||
9345 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
9346 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9347 | size_t len, gfp_t gfp) |
6039f6d2 | 9348 | { |
e6d6e342 JB |
9349 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
9350 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
9351 | } |
9352 | ||
53b46b84 | 9353 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
9354 | struct net_device *netdev, const u8 *buf, |
9355 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
9356 | { |
9357 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9358 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
9359 | } |
9360 | ||
53b46b84 JM |
9361 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
9362 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 9363 | size_t len, gfp_t gfp) |
6039f6d2 JM |
9364 | { |
9365 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 9366 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
9367 | } |
9368 | ||
6ff57cf8 JB |
9369 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
9370 | size_t len) | |
cf4e594e | 9371 | { |
947add36 JB |
9372 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9373 | struct wiphy *wiphy = wdev->wiphy; | |
9374 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
9375 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
9376 | u32 cmd; | |
947add36 | 9377 | |
6ff57cf8 JB |
9378 | if (WARN_ON(len < 2)) |
9379 | return; | |
cf4e594e | 9380 | |
6ff57cf8 JB |
9381 | if (ieee80211_is_deauth(mgmt->frame_control)) |
9382 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
9383 | else | |
9384 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 9385 | |
6ff57cf8 JB |
9386 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
9387 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 9388 | } |
6ff57cf8 | 9389 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 9390 | |
1b06bb40 LR |
9391 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
9392 | struct net_device *netdev, int cmd, | |
e6d6e342 | 9393 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
9394 | { |
9395 | struct sk_buff *msg; | |
9396 | void *hdr; | |
9397 | ||
e6d6e342 | 9398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
9399 | if (!msg) |
9400 | return; | |
9401 | ||
9402 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9403 | if (!hdr) { | |
9404 | nlmsg_free(msg); | |
9405 | return; | |
9406 | } | |
9407 | ||
9360ffd1 DM |
9408 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9409 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9410 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
9411 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9412 | goto nla_put_failure; | |
1965c853 | 9413 | |
3b7b72ee | 9414 | genlmsg_end(msg, hdr); |
1965c853 | 9415 | |
463d0183 JB |
9416 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9417 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
9418 | return; |
9419 | ||
9420 | nla_put_failure: | |
9421 | genlmsg_cancel(msg, hdr); | |
9422 | nlmsg_free(msg); | |
9423 | } | |
9424 | ||
9425 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9426 | struct net_device *netdev, const u8 *addr, |
9427 | gfp_t gfp) | |
1965c853 JM |
9428 | { |
9429 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 9430 | addr, gfp); |
1965c853 JM |
9431 | } |
9432 | ||
9433 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
9434 | struct net_device *netdev, const u8 *addr, |
9435 | gfp_t gfp) | |
1965c853 | 9436 | { |
e6d6e342 JB |
9437 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
9438 | addr, gfp); | |
1965c853 JM |
9439 | } |
9440 | ||
b23aa676 SO |
9441 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
9442 | struct net_device *netdev, const u8 *bssid, | |
9443 | const u8 *req_ie, size_t req_ie_len, | |
9444 | const u8 *resp_ie, size_t resp_ie_len, | |
9445 | u16 status, gfp_t gfp) | |
9446 | { | |
9447 | struct sk_buff *msg; | |
9448 | void *hdr; | |
9449 | ||
58050fce | 9450 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9451 | if (!msg) |
9452 | return; | |
9453 | ||
9454 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
9455 | if (!hdr) { | |
9456 | nlmsg_free(msg); | |
9457 | return; | |
9458 | } | |
9459 | ||
9360ffd1 DM |
9460 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9461 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9462 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
9463 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
9464 | (req_ie && | |
9465 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9466 | (resp_ie && | |
9467 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9468 | goto nla_put_failure; | |
b23aa676 | 9469 | |
3b7b72ee | 9470 | genlmsg_end(msg, hdr); |
b23aa676 | 9471 | |
463d0183 JB |
9472 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9473 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9474 | return; |
9475 | ||
9476 | nla_put_failure: | |
9477 | genlmsg_cancel(msg, hdr); | |
9478 | nlmsg_free(msg); | |
9479 | ||
9480 | } | |
9481 | ||
9482 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
9483 | struct net_device *netdev, const u8 *bssid, | |
9484 | const u8 *req_ie, size_t req_ie_len, | |
9485 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
9486 | { | |
9487 | struct sk_buff *msg; | |
9488 | void *hdr; | |
9489 | ||
58050fce | 9490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
9491 | if (!msg) |
9492 | return; | |
9493 | ||
9494 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
9495 | if (!hdr) { | |
9496 | nlmsg_free(msg); | |
9497 | return; | |
9498 | } | |
9499 | ||
9360ffd1 DM |
9500 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9501 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9502 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
9503 | (req_ie && | |
9504 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
9505 | (resp_ie && | |
9506 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
9507 | goto nla_put_failure; | |
b23aa676 | 9508 | |
3b7b72ee | 9509 | genlmsg_end(msg, hdr); |
b23aa676 | 9510 | |
463d0183 JB |
9511 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9512 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
9513 | return; |
9514 | ||
9515 | nla_put_failure: | |
9516 | genlmsg_cancel(msg, hdr); | |
9517 | nlmsg_free(msg); | |
9518 | ||
9519 | } | |
9520 | ||
9521 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
9522 | struct net_device *netdev, u16 reason, | |
667503dd | 9523 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
9524 | { |
9525 | struct sk_buff *msg; | |
9526 | void *hdr; | |
9527 | ||
58050fce | 9528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
9529 | if (!msg) |
9530 | return; | |
9531 | ||
9532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
9533 | if (!hdr) { | |
9534 | nlmsg_free(msg); | |
9535 | return; | |
9536 | } | |
9537 | ||
9360ffd1 DM |
9538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9539 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9540 | (from_ap && reason && | |
9541 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
9542 | (from_ap && | |
9543 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
9544 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
9545 | goto nla_put_failure; | |
b23aa676 | 9546 | |
3b7b72ee | 9547 | genlmsg_end(msg, hdr); |
b23aa676 | 9548 | |
463d0183 JB |
9549 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9550 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
9551 | return; |
9552 | ||
9553 | nla_put_failure: | |
9554 | genlmsg_cancel(msg, hdr); | |
9555 | nlmsg_free(msg); | |
9556 | ||
9557 | } | |
9558 | ||
04a773ad JB |
9559 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
9560 | struct net_device *netdev, const u8 *bssid, | |
9561 | gfp_t gfp) | |
9562 | { | |
9563 | struct sk_buff *msg; | |
9564 | void *hdr; | |
9565 | ||
fd2120ca | 9566 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
9567 | if (!msg) |
9568 | return; | |
9569 | ||
9570 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
9571 | if (!hdr) { | |
9572 | nlmsg_free(msg); | |
9573 | return; | |
9574 | } | |
9575 | ||
9360ffd1 DM |
9576 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9577 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9578 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
9579 | goto nla_put_failure; | |
04a773ad | 9580 | |
3b7b72ee | 9581 | genlmsg_end(msg, hdr); |
04a773ad | 9582 | |
463d0183 JB |
9583 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9584 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
9585 | return; |
9586 | ||
9587 | nla_put_failure: | |
9588 | genlmsg_cancel(msg, hdr); | |
9589 | nlmsg_free(msg); | |
9590 | } | |
9591 | ||
947add36 JB |
9592 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
9593 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 9594 | { |
947add36 JB |
9595 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9596 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
9597 | struct sk_buff *msg; |
9598 | void *hdr; | |
9599 | ||
947add36 JB |
9600 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
9601 | return; | |
9602 | ||
9603 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
9604 | ||
c93b5e71 JC |
9605 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
9606 | if (!msg) | |
9607 | return; | |
9608 | ||
9609 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
9610 | if (!hdr) { | |
9611 | nlmsg_free(msg); | |
9612 | return; | |
9613 | } | |
9614 | ||
9360ffd1 | 9615 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
9616 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9617 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
9618 | (ie_len && ie && |
9619 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
9620 | goto nla_put_failure; | |
c93b5e71 | 9621 | |
3b7b72ee | 9622 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
9623 | |
9624 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9625 | nl80211_mlme_mcgrp.id, gfp); | |
9626 | return; | |
9627 | ||
9628 | nla_put_failure: | |
9629 | genlmsg_cancel(msg, hdr); | |
9630 | nlmsg_free(msg); | |
9631 | } | |
947add36 | 9632 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 9633 | |
a3b8b056 JM |
9634 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
9635 | struct net_device *netdev, const u8 *addr, | |
9636 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 9637 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
9638 | { |
9639 | struct sk_buff *msg; | |
9640 | void *hdr; | |
9641 | ||
e6d6e342 | 9642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
9643 | if (!msg) |
9644 | return; | |
9645 | ||
9646 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
9647 | if (!hdr) { | |
9648 | nlmsg_free(msg); | |
9649 | return; | |
9650 | } | |
9651 | ||
9360ffd1 DM |
9652 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9653 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
9654 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
9655 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
9656 | (key_id != -1 && | |
9657 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
9658 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
9659 | goto nla_put_failure; | |
a3b8b056 | 9660 | |
3b7b72ee | 9661 | genlmsg_end(msg, hdr); |
a3b8b056 | 9662 | |
463d0183 JB |
9663 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
9664 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
9665 | return; |
9666 | ||
9667 | nla_put_failure: | |
9668 | genlmsg_cancel(msg, hdr); | |
9669 | nlmsg_free(msg); | |
9670 | } | |
9671 | ||
6bad8766 LR |
9672 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
9673 | struct ieee80211_channel *channel_before, | |
9674 | struct ieee80211_channel *channel_after) | |
9675 | { | |
9676 | struct sk_buff *msg; | |
9677 | void *hdr; | |
9678 | struct nlattr *nl_freq; | |
9679 | ||
fd2120ca | 9680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
9681 | if (!msg) |
9682 | return; | |
9683 | ||
9684 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
9685 | if (!hdr) { | |
9686 | nlmsg_free(msg); | |
9687 | return; | |
9688 | } | |
9689 | ||
9690 | /* | |
9691 | * Since we are applying the beacon hint to a wiphy we know its | |
9692 | * wiphy_idx is valid | |
9693 | */ | |
9360ffd1 DM |
9694 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
9695 | goto nla_put_failure; | |
6bad8766 LR |
9696 | |
9697 | /* Before */ | |
9698 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
9699 | if (!nl_freq) | |
9700 | goto nla_put_failure; | |
cdc89b97 | 9701 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
9702 | goto nla_put_failure; |
9703 | nla_nest_end(msg, nl_freq); | |
9704 | ||
9705 | /* After */ | |
9706 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
9707 | if (!nl_freq) | |
9708 | goto nla_put_failure; | |
cdc89b97 | 9709 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
9710 | goto nla_put_failure; |
9711 | nla_nest_end(msg, nl_freq); | |
9712 | ||
3b7b72ee | 9713 | genlmsg_end(msg, hdr); |
6bad8766 | 9714 | |
463d0183 JB |
9715 | rcu_read_lock(); |
9716 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
9717 | GFP_ATOMIC); | |
9718 | rcu_read_unlock(); | |
6bad8766 LR |
9719 | |
9720 | return; | |
9721 | ||
9722 | nla_put_failure: | |
9723 | genlmsg_cancel(msg, hdr); | |
9724 | nlmsg_free(msg); | |
9725 | } | |
9726 | ||
9588bbd5 JM |
9727 | static void nl80211_send_remain_on_chan_event( |
9728 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 9729 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 9730 | struct ieee80211_channel *chan, |
9588bbd5 JM |
9731 | unsigned int duration, gfp_t gfp) |
9732 | { | |
9733 | struct sk_buff *msg; | |
9734 | void *hdr; | |
9735 | ||
9736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9737 | if (!msg) | |
9738 | return; | |
9739 | ||
9740 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
9741 | if (!hdr) { | |
9742 | nlmsg_free(msg); | |
9743 | return; | |
9744 | } | |
9745 | ||
9360ffd1 | 9746 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9747 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9748 | wdev->netdev->ifindex)) || | |
00f53350 | 9749 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 9750 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
9751 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
9752 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
9753 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9754 | goto nla_put_failure; | |
9588bbd5 | 9755 | |
9360ffd1 DM |
9756 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
9757 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
9758 | goto nla_put_failure; | |
9588bbd5 | 9759 | |
3b7b72ee | 9760 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
9761 | |
9762 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9763 | nl80211_mlme_mcgrp.id, gfp); | |
9764 | return; | |
9765 | ||
9766 | nla_put_failure: | |
9767 | genlmsg_cancel(msg, hdr); | |
9768 | nlmsg_free(msg); | |
9769 | } | |
9770 | ||
947add36 JB |
9771 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
9772 | struct ieee80211_channel *chan, | |
9773 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 9774 | { |
947add36 JB |
9775 | struct wiphy *wiphy = wdev->wiphy; |
9776 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9777 | ||
9778 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 9779 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 9780 | rdev, wdev, cookie, chan, |
42d97a59 | 9781 | duration, gfp); |
9588bbd5 | 9782 | } |
947add36 | 9783 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 9784 | |
947add36 JB |
9785 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
9786 | struct ieee80211_channel *chan, | |
9787 | gfp_t gfp) | |
9588bbd5 | 9788 | { |
947add36 JB |
9789 | struct wiphy *wiphy = wdev->wiphy; |
9790 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9791 | ||
9792 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 9793 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 9794 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 9795 | } |
947add36 | 9796 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 9797 | |
947add36 JB |
9798 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
9799 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 9800 | { |
947add36 JB |
9801 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9802 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
9803 | struct sk_buff *msg; |
9804 | ||
947add36 JB |
9805 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
9806 | ||
58050fce | 9807 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
9808 | if (!msg) |
9809 | return; | |
9810 | ||
66266b3a JL |
9811 | if (nl80211_send_station(msg, 0, 0, 0, |
9812 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
9813 | nlmsg_free(msg); |
9814 | return; | |
9815 | } | |
9816 | ||
9817 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9818 | nl80211_mlme_mcgrp.id, gfp); | |
9819 | } | |
947add36 | 9820 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 9821 | |
947add36 | 9822 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 9823 | { |
947add36 JB |
9824 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9825 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
9826 | struct sk_buff *msg; |
9827 | void *hdr; | |
9828 | ||
947add36 JB |
9829 | trace_cfg80211_del_sta(dev, mac_addr); |
9830 | ||
58050fce | 9831 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
9832 | if (!msg) |
9833 | return; | |
9834 | ||
9835 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
9836 | if (!hdr) { | |
9837 | nlmsg_free(msg); | |
9838 | return; | |
9839 | } | |
9840 | ||
9360ffd1 DM |
9841 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9842 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
9843 | goto nla_put_failure; | |
ec15e68b | 9844 | |
3b7b72ee | 9845 | genlmsg_end(msg, hdr); |
ec15e68b JM |
9846 | |
9847 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9848 | nl80211_mlme_mcgrp.id, gfp); | |
9849 | return; | |
9850 | ||
9851 | nla_put_failure: | |
9852 | genlmsg_cancel(msg, hdr); | |
9853 | nlmsg_free(msg); | |
9854 | } | |
947add36 | 9855 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 9856 | |
947add36 JB |
9857 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
9858 | enum nl80211_connect_failed_reason reason, | |
9859 | gfp_t gfp) | |
ed44a951 | 9860 | { |
947add36 JB |
9861 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
9862 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
9863 | struct sk_buff *msg; |
9864 | void *hdr; | |
9865 | ||
9866 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
9867 | if (!msg) | |
9868 | return; | |
9869 | ||
9870 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
9871 | if (!hdr) { | |
9872 | nlmsg_free(msg); | |
9873 | return; | |
9874 | } | |
9875 | ||
9876 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9877 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
9878 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
9879 | goto nla_put_failure; | |
9880 | ||
9881 | genlmsg_end(msg, hdr); | |
9882 | ||
9883 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
9884 | nl80211_mlme_mcgrp.id, gfp); | |
9885 | return; | |
9886 | ||
9887 | nla_put_failure: | |
9888 | genlmsg_cancel(msg, hdr); | |
9889 | nlmsg_free(msg); | |
9890 | } | |
947add36 | 9891 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 9892 | |
b92ab5d8 JB |
9893 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
9894 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
9895 | { |
9896 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9897 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
9898 | struct sk_buff *msg; | |
9899 | void *hdr; | |
15e47304 | 9900 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 9901 | |
15e47304 | 9902 | if (!nlportid) |
28946da7 JB |
9903 | return false; |
9904 | ||
9905 | msg = nlmsg_new(100, gfp); | |
9906 | if (!msg) | |
9907 | return true; | |
9908 | ||
b92ab5d8 | 9909 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
9910 | if (!hdr) { |
9911 | nlmsg_free(msg); | |
9912 | return true; | |
9913 | } | |
9914 | ||
9360ffd1 DM |
9915 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9916 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
9917 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
9918 | goto nla_put_failure; | |
28946da7 | 9919 | |
9c90a9f6 | 9920 | genlmsg_end(msg, hdr); |
15e47304 | 9921 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
9922 | return true; |
9923 | ||
9924 | nla_put_failure: | |
9925 | genlmsg_cancel(msg, hdr); | |
9926 | nlmsg_free(msg); | |
9927 | return true; | |
9928 | } | |
9929 | ||
947add36 JB |
9930 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
9931 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9932 | { |
947add36 JB |
9933 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9934 | bool ret; | |
9935 | ||
9936 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
9937 | ||
9938 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9939 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
9940 | trace_cfg80211_return_bool(false); | |
9941 | return false; | |
9942 | } | |
9943 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
9944 | addr, gfp); | |
9945 | trace_cfg80211_return_bool(ret); | |
9946 | return ret; | |
b92ab5d8 | 9947 | } |
947add36 | 9948 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 9949 | |
947add36 JB |
9950 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
9951 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 9952 | { |
947add36 JB |
9953 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9954 | bool ret; | |
9955 | ||
9956 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
9957 | ||
9958 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
9959 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
9960 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
9961 | trace_cfg80211_return_bool(false); | |
9962 | return false; | |
9963 | } | |
9964 | ret = __nl80211_unexpected_frame(dev, | |
9965 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
9966 | addr, gfp); | |
9967 | trace_cfg80211_return_bool(ret); | |
9968 | return ret; | |
b92ab5d8 | 9969 | } |
947add36 | 9970 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 9971 | |
2e161f78 | 9972 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 9973 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 JB |
9974 | int freq, int sig_dbm, |
9975 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 | 9976 | { |
71bbc994 | 9977 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
9978 | struct sk_buff *msg; |
9979 | void *hdr; | |
026331c4 JM |
9980 | |
9981 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
9982 | if (!msg) | |
9983 | return -ENOMEM; | |
9984 | ||
2e161f78 | 9985 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
9986 | if (!hdr) { |
9987 | nlmsg_free(msg); | |
9988 | return -ENOMEM; | |
9989 | } | |
9990 | ||
9360ffd1 | 9991 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
9992 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9993 | netdev->ifindex)) || | |
a838490b | 9994 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
9995 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
9996 | (sig_dbm && | |
9997 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
9998 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
9999 | goto nla_put_failure; | |
026331c4 | 10000 | |
3b7b72ee | 10001 | genlmsg_end(msg, hdr); |
026331c4 | 10002 | |
15e47304 | 10003 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10004 | |
10005 | nla_put_failure: | |
10006 | genlmsg_cancel(msg, hdr); | |
10007 | nlmsg_free(msg); | |
10008 | return -ENOBUFS; | |
10009 | } | |
10010 | ||
947add36 JB |
10011 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10012 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10013 | { |
947add36 JB |
10014 | struct wiphy *wiphy = wdev->wiphy; |
10015 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10016 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10017 | struct sk_buff *msg; |
10018 | void *hdr; | |
10019 | ||
947add36 JB |
10020 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10021 | ||
026331c4 JM |
10022 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10023 | if (!msg) | |
10024 | return; | |
10025 | ||
2e161f78 | 10026 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10027 | if (!hdr) { |
10028 | nlmsg_free(msg); | |
10029 | return; | |
10030 | } | |
10031 | ||
9360ffd1 | 10032 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10033 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10034 | netdev->ifindex)) || | |
a838490b | 10035 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10036 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10037 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10038 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10039 | goto nla_put_failure; | |
026331c4 | 10040 | |
3b7b72ee | 10041 | genlmsg_end(msg, hdr); |
026331c4 JM |
10042 | |
10043 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
10044 | return; | |
10045 | ||
10046 | nla_put_failure: | |
10047 | genlmsg_cancel(msg, hdr); | |
10048 | nlmsg_free(msg); | |
10049 | } | |
947add36 | 10050 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10051 | |
947add36 JB |
10052 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10053 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10054 | gfp_t gfp) | |
d6dc1a38 | 10055 | { |
947add36 JB |
10056 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10057 | struct wiphy *wiphy = wdev->wiphy; | |
10058 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10059 | struct sk_buff *msg; |
10060 | struct nlattr *pinfoattr; | |
10061 | void *hdr; | |
10062 | ||
947add36 JB |
10063 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10064 | ||
58050fce | 10065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10066 | if (!msg) |
10067 | return; | |
10068 | ||
10069 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10070 | if (!hdr) { | |
10071 | nlmsg_free(msg); | |
10072 | return; | |
10073 | } | |
10074 | ||
9360ffd1 | 10075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10076 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10077 | goto nla_put_failure; |
d6dc1a38 JO |
10078 | |
10079 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10080 | if (!pinfoattr) | |
10081 | goto nla_put_failure; | |
10082 | ||
9360ffd1 DM |
10083 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10084 | rssi_event)) | |
10085 | goto nla_put_failure; | |
d6dc1a38 JO |
10086 | |
10087 | nla_nest_end(msg, pinfoattr); | |
10088 | ||
3b7b72ee | 10089 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
10090 | |
10091 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10092 | nl80211_mlme_mcgrp.id, gfp); | |
10093 | return; | |
10094 | ||
10095 | nla_put_failure: | |
10096 | genlmsg_cancel(msg, hdr); | |
10097 | nlmsg_free(msg); | |
10098 | } | |
947add36 | 10099 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10100 | |
947add36 JB |
10101 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10102 | struct net_device *netdev, const u8 *bssid, | |
10103 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10104 | { |
10105 | struct sk_buff *msg; | |
10106 | struct nlattr *rekey_attr; | |
10107 | void *hdr; | |
10108 | ||
58050fce | 10109 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10110 | if (!msg) |
10111 | return; | |
10112 | ||
10113 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10114 | if (!hdr) { | |
10115 | nlmsg_free(msg); | |
10116 | return; | |
10117 | } | |
10118 | ||
9360ffd1 DM |
10119 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10120 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10121 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10122 | goto nla_put_failure; | |
e5497d76 JB |
10123 | |
10124 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10125 | if (!rekey_attr) | |
10126 | goto nla_put_failure; | |
10127 | ||
9360ffd1 DM |
10128 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10129 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10130 | goto nla_put_failure; | |
e5497d76 JB |
10131 | |
10132 | nla_nest_end(msg, rekey_attr); | |
10133 | ||
3b7b72ee | 10134 | genlmsg_end(msg, hdr); |
e5497d76 JB |
10135 | |
10136 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10137 | nl80211_mlme_mcgrp.id, gfp); | |
10138 | return; | |
10139 | ||
10140 | nla_put_failure: | |
10141 | genlmsg_cancel(msg, hdr); | |
10142 | nlmsg_free(msg); | |
10143 | } | |
10144 | ||
947add36 JB |
10145 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10146 | const u8 *replay_ctr, gfp_t gfp) | |
10147 | { | |
10148 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10149 | struct wiphy *wiphy = wdev->wiphy; | |
10150 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10151 | ||
10152 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
10153 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
10154 | } | |
10155 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
10156 | ||
10157 | static void | |
10158 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
10159 | struct net_device *netdev, int index, | |
10160 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
10161 | { |
10162 | struct sk_buff *msg; | |
10163 | struct nlattr *attr; | |
10164 | void *hdr; | |
10165 | ||
58050fce | 10166 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
10167 | if (!msg) |
10168 | return; | |
10169 | ||
10170 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
10171 | if (!hdr) { | |
10172 | nlmsg_free(msg); | |
10173 | return; | |
10174 | } | |
10175 | ||
9360ffd1 DM |
10176 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10177 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10178 | goto nla_put_failure; | |
c9df56b4 JM |
10179 | |
10180 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
10181 | if (!attr) | |
10182 | goto nla_put_failure; | |
10183 | ||
9360ffd1 DM |
10184 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
10185 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
10186 | (preauth && | |
10187 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
10188 | goto nla_put_failure; | |
c9df56b4 JM |
10189 | |
10190 | nla_nest_end(msg, attr); | |
10191 | ||
3b7b72ee | 10192 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
10193 | |
10194 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10195 | nl80211_mlme_mcgrp.id, gfp); | |
10196 | return; | |
10197 | ||
10198 | nla_put_failure: | |
10199 | genlmsg_cancel(msg, hdr); | |
10200 | nlmsg_free(msg); | |
10201 | } | |
10202 | ||
947add36 JB |
10203 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
10204 | const u8 *bssid, bool preauth, gfp_t gfp) | |
10205 | { | |
10206 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10207 | struct wiphy *wiphy = wdev->wiphy; | |
10208 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10209 | ||
10210 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
10211 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
10212 | } | |
10213 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
10214 | ||
10215 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
10216 | struct net_device *netdev, | |
10217 | struct cfg80211_chan_def *chandef, | |
10218 | gfp_t gfp) | |
5314526b TP |
10219 | { |
10220 | struct sk_buff *msg; | |
10221 | void *hdr; | |
10222 | ||
58050fce | 10223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
10224 | if (!msg) |
10225 | return; | |
10226 | ||
10227 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
10228 | if (!hdr) { | |
10229 | nlmsg_free(msg); | |
10230 | return; | |
10231 | } | |
10232 | ||
683b6d3b JB |
10233 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
10234 | goto nla_put_failure; | |
10235 | ||
10236 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 10237 | goto nla_put_failure; |
5314526b TP |
10238 | |
10239 | genlmsg_end(msg, hdr); | |
10240 | ||
10241 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10242 | nl80211_mlme_mcgrp.id, gfp); | |
10243 | return; | |
10244 | ||
10245 | nla_put_failure: | |
10246 | genlmsg_cancel(msg, hdr); | |
10247 | nlmsg_free(msg); | |
10248 | } | |
10249 | ||
947add36 JB |
10250 | void cfg80211_ch_switch_notify(struct net_device *dev, |
10251 | struct cfg80211_chan_def *chandef) | |
84f10708 | 10252 | { |
947add36 JB |
10253 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10254 | struct wiphy *wiphy = wdev->wiphy; | |
10255 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10256 | ||
10257 | trace_cfg80211_ch_switch_notify(dev, chandef); | |
10258 | ||
10259 | wdev_lock(wdev); | |
10260 | ||
10261 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10262 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) | |
10263 | goto out; | |
10264 | ||
10265 | wdev->channel = chandef->chan; | |
10266 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
10267 | out: | |
10268 | wdev_unlock(wdev); | |
10269 | return; | |
10270 | } | |
10271 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
10272 | ||
10273 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
10274 | const u8 *peer, u32 num_packets, | |
10275 | u32 rate, u32 intvl, gfp_t gfp) | |
10276 | { | |
10277 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10278 | struct wiphy *wiphy = wdev->wiphy; | |
10279 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
10280 | struct sk_buff *msg; |
10281 | struct nlattr *pinfoattr; | |
10282 | void *hdr; | |
10283 | ||
10284 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10285 | if (!msg) | |
10286 | return; | |
10287 | ||
10288 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10289 | if (!hdr) { | |
10290 | nlmsg_free(msg); | |
10291 | return; | |
10292 | } | |
10293 | ||
10294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 10295 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
10296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10297 | goto nla_put_failure; | |
10298 | ||
10299 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10300 | if (!pinfoattr) | |
10301 | goto nla_put_failure; | |
10302 | ||
10303 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
10304 | goto nla_put_failure; | |
10305 | ||
10306 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
10307 | goto nla_put_failure; | |
10308 | ||
10309 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
10310 | goto nla_put_failure; | |
10311 | ||
10312 | nla_nest_end(msg, pinfoattr); | |
10313 | ||
10314 | genlmsg_end(msg, hdr); | |
10315 | ||
10316 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10317 | nl80211_mlme_mcgrp.id, gfp); | |
10318 | return; | |
10319 | ||
10320 | nla_put_failure: | |
10321 | genlmsg_cancel(msg, hdr); | |
10322 | nlmsg_free(msg); | |
10323 | } | |
947add36 | 10324 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 10325 | |
04f39047 SW |
10326 | void |
10327 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
10328 | struct cfg80211_chan_def *chandef, | |
10329 | enum nl80211_radar_event event, | |
10330 | struct net_device *netdev, gfp_t gfp) | |
10331 | { | |
10332 | struct sk_buff *msg; | |
10333 | void *hdr; | |
10334 | ||
10335 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10336 | if (!msg) | |
10337 | return; | |
10338 | ||
10339 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
10340 | if (!hdr) { | |
10341 | nlmsg_free(msg); | |
10342 | return; | |
10343 | } | |
10344 | ||
10345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
10346 | goto nla_put_failure; | |
10347 | ||
10348 | /* NOP and radar events don't need a netdev parameter */ | |
10349 | if (netdev) { | |
10350 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
10351 | ||
10352 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10353 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10354 | goto nla_put_failure; | |
10355 | } | |
10356 | ||
10357 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
10358 | goto nla_put_failure; | |
10359 | ||
10360 | if (nl80211_send_chandef(msg, chandef)) | |
10361 | goto nla_put_failure; | |
10362 | ||
9c90a9f6 | 10363 | genlmsg_end(msg, hdr); |
04f39047 SW |
10364 | |
10365 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10366 | nl80211_mlme_mcgrp.id, gfp); | |
10367 | return; | |
10368 | ||
10369 | nla_put_failure: | |
10370 | genlmsg_cancel(msg, hdr); | |
10371 | nlmsg_free(msg); | |
10372 | } | |
10373 | ||
947add36 JB |
10374 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
10375 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 10376 | { |
947add36 JB |
10377 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10378 | struct wiphy *wiphy = wdev->wiphy; | |
10379 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
10380 | struct sk_buff *msg; |
10381 | struct nlattr *pinfoattr; | |
10382 | void *hdr; | |
10383 | ||
947add36 JB |
10384 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
10385 | ||
58050fce | 10386 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
10387 | if (!msg) |
10388 | return; | |
10389 | ||
10390 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10391 | if (!hdr) { | |
10392 | nlmsg_free(msg); | |
10393 | return; | |
10394 | } | |
10395 | ||
9360ffd1 | 10396 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10397 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
10398 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
10399 | goto nla_put_failure; | |
c063dbf5 JB |
10400 | |
10401 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10402 | if (!pinfoattr) | |
10403 | goto nla_put_failure; | |
10404 | ||
9360ffd1 DM |
10405 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
10406 | goto nla_put_failure; | |
c063dbf5 JB |
10407 | |
10408 | nla_nest_end(msg, pinfoattr); | |
10409 | ||
3b7b72ee | 10410 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
10411 | |
10412 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10413 | nl80211_mlme_mcgrp.id, gfp); | |
10414 | return; | |
10415 | ||
10416 | nla_put_failure: | |
10417 | genlmsg_cancel(msg, hdr); | |
10418 | nlmsg_free(msg); | |
10419 | } | |
947add36 | 10420 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 10421 | |
7f6cf311 JB |
10422 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
10423 | u64 cookie, bool acked, gfp_t gfp) | |
10424 | { | |
10425 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10426 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10427 | struct sk_buff *msg; | |
10428 | void *hdr; | |
7f6cf311 | 10429 | |
4ee3e063 BL |
10430 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
10431 | ||
58050fce | 10432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 10433 | |
7f6cf311 JB |
10434 | if (!msg) |
10435 | return; | |
10436 | ||
10437 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
10438 | if (!hdr) { | |
10439 | nlmsg_free(msg); | |
10440 | return; | |
10441 | } | |
10442 | ||
9360ffd1 DM |
10443 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10444 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10445 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
10446 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10447 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10448 | goto nla_put_failure; | |
7f6cf311 | 10449 | |
9c90a9f6 | 10450 | genlmsg_end(msg, hdr); |
7f6cf311 JB |
10451 | |
10452 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10453 | nl80211_mlme_mcgrp.id, gfp); | |
10454 | return; | |
10455 | ||
10456 | nla_put_failure: | |
10457 | genlmsg_cancel(msg, hdr); | |
10458 | nlmsg_free(msg); | |
10459 | } | |
10460 | EXPORT_SYMBOL(cfg80211_probe_status); | |
10461 | ||
5e760230 JB |
10462 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
10463 | const u8 *frame, size_t len, | |
37c73b5f | 10464 | int freq, int sig_dbm) |
5e760230 JB |
10465 | { |
10466 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10467 | struct sk_buff *msg; | |
10468 | void *hdr; | |
37c73b5f | 10469 | struct cfg80211_beacon_registration *reg; |
5e760230 | 10470 | |
4ee3e063 BL |
10471 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
10472 | ||
37c73b5f BG |
10473 | spin_lock_bh(&rdev->beacon_registrations_lock); |
10474 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10475 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
10476 | if (!msg) { | |
10477 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10478 | return; | |
10479 | } | |
5e760230 | 10480 | |
37c73b5f BG |
10481 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
10482 | if (!hdr) | |
10483 | goto nla_put_failure; | |
5e760230 | 10484 | |
37c73b5f BG |
10485 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10486 | (freq && | |
10487 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
10488 | (sig_dbm && | |
10489 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
10490 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
10491 | goto nla_put_failure; | |
5e760230 | 10492 | |
37c73b5f | 10493 | genlmsg_end(msg, hdr); |
5e760230 | 10494 | |
37c73b5f BG |
10495 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
10496 | } | |
10497 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
10498 | return; |
10499 | ||
10500 | nla_put_failure: | |
37c73b5f BG |
10501 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
10502 | if (hdr) | |
10503 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
10504 | nlmsg_free(msg); |
10505 | } | |
10506 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
10507 | ||
cd8f7cb4 JB |
10508 | #ifdef CONFIG_PM |
10509 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
10510 | struct cfg80211_wowlan_wakeup *wakeup, | |
10511 | gfp_t gfp) | |
10512 | { | |
10513 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10514 | struct sk_buff *msg; | |
10515 | void *hdr; | |
9c90a9f6 | 10516 | int size = 200; |
cd8f7cb4 JB |
10517 | |
10518 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
10519 | ||
10520 | if (wakeup) | |
10521 | size += wakeup->packet_present_len; | |
10522 | ||
10523 | msg = nlmsg_new(size, gfp); | |
10524 | if (!msg) | |
10525 | return; | |
10526 | ||
10527 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
10528 | if (!hdr) | |
10529 | goto free_msg; | |
10530 | ||
10531 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10532 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10533 | goto free_msg; | |
10534 | ||
10535 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10536 | wdev->netdev->ifindex)) | |
10537 | goto free_msg; | |
10538 | ||
10539 | if (wakeup) { | |
10540 | struct nlattr *reasons; | |
10541 | ||
10542 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10543 | ||
10544 | if (wakeup->disconnect && | |
10545 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
10546 | goto free_msg; | |
10547 | if (wakeup->magic_pkt && | |
10548 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
10549 | goto free_msg; | |
10550 | if (wakeup->gtk_rekey_failure && | |
10551 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
10552 | goto free_msg; | |
10553 | if (wakeup->eap_identity_req && | |
10554 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
10555 | goto free_msg; | |
10556 | if (wakeup->four_way_handshake && | |
10557 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
10558 | goto free_msg; | |
10559 | if (wakeup->rfkill_release && | |
10560 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
10561 | goto free_msg; | |
10562 | ||
10563 | if (wakeup->pattern_idx >= 0 && | |
10564 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
10565 | wakeup->pattern_idx)) | |
10566 | goto free_msg; | |
10567 | ||
2a0e047e JB |
10568 | if (wakeup->tcp_match) |
10569 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); | |
10570 | ||
10571 | if (wakeup->tcp_connlost) | |
10572 | nla_put_flag(msg, | |
10573 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); | |
10574 | ||
10575 | if (wakeup->tcp_nomoretokens) | |
10576 | nla_put_flag(msg, | |
10577 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); | |
10578 | ||
cd8f7cb4 JB |
10579 | if (wakeup->packet) { |
10580 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
10581 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
10582 | ||
10583 | if (!wakeup->packet_80211) { | |
10584 | pkt_attr = | |
10585 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
10586 | len_attr = | |
10587 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
10588 | } | |
10589 | ||
10590 | if (wakeup->packet_len && | |
10591 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
10592 | goto free_msg; | |
10593 | ||
10594 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
10595 | wakeup->packet)) | |
10596 | goto free_msg; | |
10597 | } | |
10598 | ||
10599 | nla_nest_end(msg, reasons); | |
10600 | } | |
10601 | ||
9c90a9f6 | 10602 | genlmsg_end(msg, hdr); |
cd8f7cb4 JB |
10603 | |
10604 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10605 | nl80211_mlme_mcgrp.id, gfp); | |
10606 | return; | |
10607 | ||
10608 | free_msg: | |
10609 | nlmsg_free(msg); | |
10610 | } | |
10611 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
10612 | #endif | |
10613 | ||
3475b094 JM |
10614 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
10615 | enum nl80211_tdls_operation oper, | |
10616 | u16 reason_code, gfp_t gfp) | |
10617 | { | |
10618 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10619 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10620 | struct sk_buff *msg; | |
10621 | void *hdr; | |
3475b094 JM |
10622 | |
10623 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
10624 | reason_code); | |
10625 | ||
10626 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10627 | if (!msg) | |
10628 | return; | |
10629 | ||
10630 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
10631 | if (!hdr) { | |
10632 | nlmsg_free(msg); | |
10633 | return; | |
10634 | } | |
10635 | ||
10636 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10637 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10638 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
10639 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
10640 | (reason_code > 0 && | |
10641 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
10642 | goto nla_put_failure; | |
10643 | ||
9c90a9f6 | 10644 | genlmsg_end(msg, hdr); |
3475b094 JM |
10645 | |
10646 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10647 | nl80211_mlme_mcgrp.id, gfp); | |
10648 | return; | |
10649 | ||
10650 | nla_put_failure: | |
10651 | genlmsg_cancel(msg, hdr); | |
10652 | nlmsg_free(msg); | |
10653 | } | |
10654 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
10655 | ||
026331c4 JM |
10656 | static int nl80211_netlink_notify(struct notifier_block * nb, |
10657 | unsigned long state, | |
10658 | void *_notify) | |
10659 | { | |
10660 | struct netlink_notify *notify = _notify; | |
10661 | struct cfg80211_registered_device *rdev; | |
10662 | struct wireless_dev *wdev; | |
37c73b5f | 10663 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
10664 | |
10665 | if (state != NETLINK_URELEASE) | |
10666 | return NOTIFY_DONE; | |
10667 | ||
10668 | rcu_read_lock(); | |
10669 | ||
5e760230 | 10670 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 10671 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 10672 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
10673 | |
10674 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10675 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
10676 | list) { | |
10677 | if (reg->nlportid == notify->portid) { | |
10678 | list_del(®->list); | |
10679 | kfree(reg); | |
10680 | break; | |
10681 | } | |
10682 | } | |
10683 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 10684 | } |
026331c4 JM |
10685 | |
10686 | rcu_read_unlock(); | |
10687 | ||
10688 | return NOTIFY_DONE; | |
10689 | } | |
10690 | ||
10691 | static struct notifier_block nl80211_netlink_notifier = { | |
10692 | .notifier_call = nl80211_netlink_notify, | |
10693 | }; | |
10694 | ||
355199e0 JM |
10695 | void cfg80211_ft_event(struct net_device *netdev, |
10696 | struct cfg80211_ft_event_params *ft_event) | |
10697 | { | |
10698 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
10699 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10700 | struct sk_buff *msg; | |
10701 | void *hdr; | |
355199e0 JM |
10702 | |
10703 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
10704 | ||
10705 | if (!ft_event->target_ap) | |
10706 | return; | |
10707 | ||
10708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10709 | if (!msg) | |
10710 | return; | |
10711 | ||
10712 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
10713 | if (!hdr) { | |
10714 | nlmsg_free(msg); | |
10715 | return; | |
10716 | } | |
10717 | ||
10718 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
10719 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
10720 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); | |
10721 | if (ft_event->ies) | |
10722 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); | |
10723 | if (ft_event->ric_ies) | |
10724 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
10725 | ft_event->ric_ies); | |
10726 | ||
9c90a9f6 | 10727 | genlmsg_end(msg, hdr); |
355199e0 JM |
10728 | |
10729 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
10730 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
10731 | } | |
10732 | EXPORT_SYMBOL(cfg80211_ft_event); | |
10733 | ||
5de17984 AS |
10734 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
10735 | { | |
10736 | struct cfg80211_registered_device *rdev; | |
10737 | struct sk_buff *msg; | |
10738 | void *hdr; | |
10739 | u32 nlportid; | |
10740 | ||
10741 | rdev = wiphy_to_dev(wdev->wiphy); | |
10742 | if (!rdev->crit_proto_nlportid) | |
10743 | return; | |
10744 | ||
10745 | nlportid = rdev->crit_proto_nlportid; | |
10746 | rdev->crit_proto_nlportid = 0; | |
10747 | ||
10748 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10749 | if (!msg) | |
10750 | return; | |
10751 | ||
10752 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
10753 | if (!hdr) | |
10754 | goto nla_put_failure; | |
10755 | ||
10756 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10757 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
10758 | goto nla_put_failure; | |
10759 | ||
10760 | genlmsg_end(msg, hdr); | |
10761 | ||
10762 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
10763 | return; | |
10764 | ||
10765 | nla_put_failure: | |
10766 | if (hdr) | |
10767 | genlmsg_cancel(msg, hdr); | |
10768 | nlmsg_free(msg); | |
10769 | ||
10770 | } | |
10771 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
10772 | ||
55682965 JB |
10773 | /* initialisation/exit functions */ |
10774 | ||
10775 | int nl80211_init(void) | |
10776 | { | |
0d63cbb5 | 10777 | int err; |
55682965 | 10778 | |
0d63cbb5 MM |
10779 | err = genl_register_family_with_ops(&nl80211_fam, |
10780 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
10781 | if (err) |
10782 | return err; | |
10783 | ||
55682965 JB |
10784 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
10785 | if (err) | |
10786 | goto err_out; | |
10787 | ||
2a519311 JB |
10788 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
10789 | if (err) | |
10790 | goto err_out; | |
10791 | ||
73d54c9e LR |
10792 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
10793 | if (err) | |
10794 | goto err_out; | |
10795 | ||
6039f6d2 JM |
10796 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
10797 | if (err) | |
10798 | goto err_out; | |
10799 | ||
aff89a9b JB |
10800 | #ifdef CONFIG_NL80211_TESTMODE |
10801 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
10802 | if (err) | |
10803 | goto err_out; | |
10804 | #endif | |
10805 | ||
026331c4 JM |
10806 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
10807 | if (err) | |
10808 | goto err_out; | |
10809 | ||
55682965 JB |
10810 | return 0; |
10811 | err_out: | |
10812 | genl_unregister_family(&nl80211_fam); | |
10813 | return err; | |
10814 | } | |
10815 | ||
10816 | void nl80211_exit(void) | |
10817 | { | |
026331c4 | 10818 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
10819 | genl_unregister_family(&nl80211_fam); |
10820 | } |